canard 0.5.0.pre → 0.6.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +5 -5
  2. data/.hound.yml +3 -0
  3. data/.rubocop.yml +27 -0
  4. data/.rubocop_todo.yml +37 -0
  5. data/.travis.yml +1 -1
  6. data/Gemfile +7 -6
  7. data/README.md +40 -37
  8. data/Rakefile +5 -2
  9. data/canard.gemspec +8 -7
  10. data/lib/ability.rb +14 -13
  11. data/lib/canard.rb +4 -2
  12. data/lib/canard/abilities.rb +7 -9
  13. data/lib/canard/adapters/active_record.rb +32 -29
  14. data/lib/canard/adapters/mongoid.rb +18 -11
  15. data/lib/canard/find_abilities.rb +8 -9
  16. data/lib/canard/railtie.rb +11 -16
  17. data/lib/canard/user_model.rb +66 -67
  18. data/lib/canard/version.rb +3 -1
  19. data/lib/generators/ability_definition.rb +16 -14
  20. data/lib/generators/canard/ability/ability_generator.rb +16 -12
  21. data/lib/generators/rspec/ability/ability_generator.rb +9 -9
  22. data/lib/tasks/canard.rake +6 -6
  23. data/test/abilities/administrators.rb +2 -2
  24. data/test/canard/abilities_test.rb +14 -21
  25. data/test/canard/ability_test.rb +40 -52
  26. data/test/canard/adapters/active_record_test.rb +71 -135
  27. data/test/canard/adapters/mongoid_test.rb +61 -132
  28. data/test/canard/canard_test.rb +8 -10
  29. data/test/canard/find_abilities_test.rb +9 -11
  30. data/test/canard/user_model_test.rb +22 -32
  31. data/test/dummy/Rakefile +3 -1
  32. data/test/dummy/app/abilities/admins.rb +4 -4
  33. data/test/dummy/app/abilities/authors.rb +3 -3
  34. data/test/dummy/app/abilities/editors.rb +2 -2
  35. data/test/dummy/app/abilities/guests.rb +3 -3
  36. data/test/dummy/app/abilities/users.rb +4 -4
  37. data/test/dummy/app/controllers/application_controller.rb +2 -0
  38. data/test/dummy/app/models/activity.rb +3 -1
  39. data/test/dummy/app/models/member.rb +3 -3
  40. data/test/dummy/app/models/mongoid_user.rb +5 -3
  41. data/test/dummy/app/models/plain_ruby_non_user.rb +2 -2
  42. data/test/dummy/app/models/plain_ruby_user.rb +3 -3
  43. data/test/dummy/app/models/post.rb +3 -1
  44. data/test/dummy/app/models/user.rb +3 -2
  45. data/test/dummy/app/models/user_without_role.rb +4 -4
  46. data/test/dummy/app/models/user_without_role_mask.rb +3 -3
  47. data/test/dummy/config.ru +3 -1
  48. data/test/dummy/config/application.rb +9 -8
  49. data/test/dummy/config/boot.rb +4 -2
  50. data/test/dummy/config/environment.rb +3 -1
  51. data/test/dummy/config/environments/development.rb +2 -0
  52. data/test/dummy/config/environments/test.rb +4 -2
  53. data/test/dummy/config/initializers/secret_token.rb +2 -0
  54. data/test/dummy/config/initializers/session_store.rb +3 -1
  55. data/test/dummy/config/initializers/wrap_parameters.rb +3 -1
  56. data/test/dummy/config/mongoid3.yml +5 -1
  57. data/test/dummy/config/routes.rb +2 -0
  58. data/test/dummy/db/migrate/20120430083231_initialize_db.rb +7 -7
  59. data/test/dummy/db/schema.rb +11 -11
  60. data/test/dummy/script/rails +4 -2
  61. data/test/support/reloadable.rb +14 -15
  62. data/test/test_helper.rb +7 -13
  63. metadata +18 -18
  64. data/test/dummy/config/mongoid2.yml +0 -9
@@ -1,27 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../ability_definition'
2
4
 
3
5
  module Canard
4
6
  module Generators
5
- class AbilityGenerator < Rails::Generators::NamedBase
6
- source_root File.expand_path('../templates', __FILE__)
7
- argument :ability_definitions, :type => :array, :default => [], :banner => "can:[read,update]:[user,account] cannot:[create,destroy]:user"
7
+ class AbilityGenerator < Rails::Generators::NamedBase # :nodoc:
8
+ source_root File.expand_path('templates', __dir__)
9
+ argument :ability_definitions,
10
+ type: :array,
11
+ default: [],
12
+ banner: 'can:[read,update]:[user,account] cannot:[create,destroy]:user'
8
13
 
9
14
  def generate_ability
10
- template "abilities.rb.erb", Abilities.default_path + "/#{file_name.pluralize}.rb"
15
+ template 'abilities.rb.erb', Abilities.default_path + "/#{file_name.pluralize}.rb"
11
16
  end
12
-
13
- hook_for :test_framework, :as => 'ability'
14
-
17
+
18
+ hook_for :test_framework, as: 'ability'
19
+
15
20
  private
16
-
17
- def definitions(&block)
21
+
22
+ def definitions
18
23
  ability_definitions.each { |definition| AbilityDefinition.parse(definition) }
19
-
24
+
20
25
  AbilityDefinition.models.sort.each do |model, definition|
21
26
  yield model, definition
22
27
  end
23
28
  end
24
-
25
29
  end
26
30
  end
27
- end
31
+ end
@@ -1,27 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'generators/rspec'
2
4
  require_relative '../../ability_definition'
3
5
 
4
6
  module Rspec
5
7
  module Generators
6
8
  class AbilityGenerator < Base
7
- @_rspec_source_root = File.expand_path('../templates', __FILE__)
8
- argument :ability_definitions, :type => :array, :default => [], :banner => "can:abilities:models cannot:abilities:models"
9
+ @_rspec_source_root = File.expand_path('templates', __dir__)
10
+ argument :ability_definitions, type: :array, default: [], banner: 'can:abilities:models cannot:abilities:models'
9
11
 
10
12
  def generate_ability_spec
11
- template "abilities_spec.rb.erb", "spec/abilities/#{file_name.pluralize}_spec.rb"
13
+ template 'abilities_spec.rb.erb', "spec/abilities/#{file_name.pluralize}_spec.rb"
12
14
  end
13
-
15
+
14
16
  private
15
-
16
- def definitions(&block)
17
+
18
+ def definitions
17
19
  ability_definitions.each { |definition| AbilityDefinition.parse(definition) }
18
-
20
+
19
21
  AbilityDefinition.models.sort.each do |model, definition|
20
22
  yield model, definition
21
23
  end
22
24
  end
23
-
24
25
  end
25
-
26
26
  end
27
27
  end
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  namespace :canard do
2
4
  desc 'Upgrades deprecated ability definition syntax and moves the files from abilities to app/abilities'
3
- task :upgrade => :environment do
5
+ task upgrade: :environment do
4
6
  require 'rake/clean'
5
7
  source_path = 'abilities'
6
8
  destination_path = Canard::Abilities.definition_paths.first
7
9
 
8
- Dir.mkdir(destination_path) unless Dir.exists?(destination_path)
10
+ Dir.mkdir(destination_path) unless Dir.exist?(destination_path)
9
11
 
10
- if Dir.exists?(source_path)
12
+ if Dir.exist?(source_path)
11
13
  Dir[File.join(source_path, '*.rb')].each do |input_file|
12
14
  input = File.read(input_file)
13
15
  output = input.gsub(/abilities_for/, 'Canard::Abilities.for')
@@ -16,8 +18,6 @@ namespace :canard do
16
18
  File.delete(input_file)
17
19
  end
18
20
  Dir.delete(source_path)
19
- else
20
21
  end
21
-
22
22
  end
23
- end
23
+ end
@@ -1,5 +1,5 @@
1
- Canard::Abilities.for(:administrator) do
1
+ # frozen_string_literal: true
2
2
 
3
+ Canard::Abilities.for(:administrator) do
3
4
  can :manage, [Activity, User]
4
-
5
5
  end
@@ -1,61 +1,56 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
  require 'canard'
3
5
 
4
6
  describe 'Canard::Abilities' do
5
-
6
7
  subject { Canard::Abilities }
7
8
 
8
- describe "ability_paths" do
9
-
10
- it "defaults to app/abilities" do
9
+ describe 'ability_paths' do
10
+ it 'defaults to app/abilities' do
11
11
  subject.definition_paths.must_include 'app/abilities'
12
12
  end
13
13
 
14
- it "appends paths" do
14
+ it 'appends paths' do
15
15
  subject.definition_paths << 'other_abilities'
16
16
  subject.definition_paths.must_include 'other_abilities'
17
17
  end
18
18
 
19
- it "can be overwritten" do
19
+ it 'can be overwritten' do
20
20
  subject.definition_paths = ['other_abilities']
21
21
 
22
22
  subject.definition_paths.must_equal ['other_abilities']
23
23
  end
24
-
25
24
  end
26
25
 
27
- describe "default_path" do
28
-
29
- it "defaults to app/abilities" do
26
+ describe 'default_path' do
27
+ it 'defaults to app/abilities' do
30
28
  subject.default_path.must_equal 'app/abilities'
31
29
  end
32
30
 
33
- it "can be changhed" do
31
+ it 'can be changhed' do
34
32
  subject.default_path = 'other_abilities'
35
33
 
36
34
  subject.default_path.must_equal 'other_abilities'
37
35
  end
38
-
39
-
40
36
  end
41
37
 
42
- describe "for" do
43
-
44
- it "adds the block to the definitions" do
45
- block = lambda { puts 'some block' }
38
+ describe 'for' do
39
+ it 'adds the block to the definitions' do
40
+ block = -> { puts 'some block' }
46
41
 
47
42
  subject.for(:definition, &block)
48
43
 
49
44
  assert_equal block, subject.definitions[:definition]
50
45
  end
51
46
 
52
- it "normalises the key to a symbol" do
47
+ it 'normalises the key to a symbol' do
53
48
  subject.for('definition') { puts 'a block' }
54
49
 
55
50
  subject.definitions.keys.must_include :definition
56
51
  end
57
52
 
58
- it "rasises ArgumentError if no block is provided" do
53
+ it 'rasises ArgumentError if no block is provided' do
59
54
  proc { subject.for(:definition) }.must_raise ArgumentError
60
55
  end
61
56
 
@@ -64,7 +59,5 @@ describe 'Canard::Abilities' do
64
59
 
65
60
  subject.definitions.keys.must_include :not_camel_case
66
61
  end
67
-
68
62
  end
69
-
70
63
  end
@@ -1,47 +1,42 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  describe Ability do
4
-
5
6
  before do
6
- Canard::Abilities.definition_paths = [File.expand_path('../../dummy/app/abilities', __FILE__)]
7
+ Canard::Abilities.definition_paths = [File.expand_path('../dummy/app/abilities', __dir__)]
7
8
  # reload abilities because the reloader will have removed them after the railtie ran
8
9
  Canard.find_abilities
9
10
  end
10
11
 
11
- describe "new" do
12
-
13
- describe "with a user" do
14
-
12
+ describe 'new' do
13
+ describe 'with a user' do
15
14
  let(:user) { User.new }
16
15
  subject { Ability.new(user) }
17
16
 
18
- it "assign the user to Ability#user" do
17
+ it 'assign the user to Ability#user' do
19
18
  subject.user.must_equal user
20
19
  end
21
-
22
20
  end
23
21
 
24
- describe "with a model that references a user" do
25
-
22
+ describe 'with a model that references a user' do
26
23
  let(:user) { User.create }
27
- let(:member) { Member.new(:user => user) }
24
+ let(:member) { Member.new(user: user) }
28
25
 
29
26
  subject { Ability.new(member) }
30
27
 
31
- it "assign the user to Ability#user" do
28
+ it 'assign the user to Ability#user' do
32
29
  subject.user.must_equal user
33
30
  end
34
-
35
31
  end
36
32
 
37
- describe "with a user that has author role" do
38
-
39
- let(:user) { User.create(:roles => [:author]) }
40
- let(:member) { Member.create(:user => user) }
41
- let(:other_member) { Member.new(:user => User.create) }
33
+ describe 'with a user that has author role' do
34
+ let(:user) { User.create(roles: [:author]) }
35
+ let(:member) { Member.create(user: user) }
36
+ let(:other_member) { Member.new(user: User.create) }
42
37
  subject { Ability.new(user) }
43
38
 
44
- it "has all the abilities of the base class" do
39
+ it 'has all the abilities of the base class' do
45
40
  subject.can?(:edit, member).must_equal true
46
41
  subject.can?(:update, member).must_equal true
47
42
 
@@ -49,7 +44,7 @@ describe Ability do
49
44
  subject.can?(:update, other_member).wont_equal true
50
45
  end
51
46
 
52
- it "has all the abilities of an author" do
47
+ it 'has all the abilities of an author' do
53
48
  subject.can?(:new, Post).must_equal true
54
49
  subject.can?(:create, Post).must_equal true
55
50
  subject.can?(:edit, Post).must_equal true
@@ -58,21 +53,19 @@ describe Ability do
58
53
  subject.can?(:index, Post).must_equal true
59
54
  end
60
55
 
61
- it "has no admin abilities" do
56
+ it 'has no admin abilities' do
62
57
  subject.cannot?(:destroy, Post).must_equal true
63
58
  end
64
-
65
59
  end
66
60
 
67
- describe "with a user that has admin and author roles" do
68
-
69
- let(:user) { User.create(:roles => [:author, :admin]) }
70
- let(:member) { Member.create(:user => user) }
61
+ describe 'with a user that has admin and author roles' do
62
+ let(:user) { User.create(roles: %i[author admin]) }
63
+ let(:member) { Member.create(user: user) }
71
64
  let(:other_user) { User.create }
72
- let(:other_member) { Member.new(:user => other_user) }
65
+ let(:other_member) { Member.new(user: other_user) }
73
66
  subject { Ability.new(user) }
74
67
 
75
- it "has all the abilities of the base class" do
68
+ it 'has all the abilities of the base class' do
76
69
  subject.can?(:edit, member).must_equal true
77
70
  subject.can?(:update, member).must_equal true
78
71
 
@@ -80,27 +73,26 @@ describe Ability do
80
73
  subject.cannot?(:update, other_member).must_equal true
81
74
  end
82
75
 
83
- it "has all the abilities of an author" do
76
+ it 'has all the abilities of an author' do
84
77
  subject.can?(:new, Post).must_equal true
85
78
  end
86
79
 
87
- it "has the abilities of an admin" do
80
+ it 'has the abilities of an admin' do
88
81
  subject.can?(:manage, Post).must_equal true
89
82
  subject.can?(:manage, other_user).must_equal true
90
83
  subject.can?(:destroy, other_user).must_equal true
91
84
  subject.cannot?(:destroy, user).must_equal true
92
85
  end
93
-
94
86
  end
95
87
 
96
- describe "a user with editor role" do
97
- let(:user) { User.create(:roles => [:editor]) }
98
- let(:member) { Member.create(:user => user) }
88
+ describe 'a user with editor role' do
89
+ let(:user) { User.create(roles: [:editor]) }
90
+ let(:member) { Member.create(user: user) }
99
91
  let(:other_user) { User.create }
100
- let(:other_member) { Member.new(:user => other_user) }
92
+ let(:other_member) { Member.new(user: other_user) }
101
93
  subject { Ability.new(user) }
102
94
 
103
- it "has all the abilities of the base class" do
95
+ it 'has all the abilities of the base class' do
104
96
  subject.can?(:edit, member).must_equal true
105
97
  subject.can?(:update, member).must_equal true
106
98
 
@@ -113,14 +105,12 @@ describe Ability do
113
105
  subject.can?(:read, Post).must_equal true
114
106
  subject.cannot?(:create, Post).must_equal true
115
107
  end
116
-
117
108
  end
118
109
 
119
- describe "with no user" do
120
-
110
+ describe 'with no user' do
121
111
  subject { Ability.new }
122
112
 
123
- it "applies the guest abilities" do
113
+ it 'applies the guest abilities' do
124
114
  subject.can?(:index, Post)
125
115
  subject.can?(:show, Post)
126
116
 
@@ -133,30 +123,29 @@ describe Ability do
133
123
  end
134
124
  end
135
125
 
136
- describe "with an instance of an anonymous class that has author role" do
137
-
126
+ describe 'with an instance of an anonymous class that has author role' do
138
127
  let(:klass) do
139
128
  Class.new do
140
129
  extend Canard::UserModel
141
130
  attr_accessor :roles_mask
142
- acts_as_user :roles => [:author, :admin]
143
- def initialize(*roles); self.roles = roles; end
131
+ acts_as_user roles: %i[author admin]
132
+ def initialize(*roles)
133
+ self.roles = roles
134
+ end
144
135
  end
145
136
  end
146
137
  let(:instance) { klass.new(:author) }
147
138
 
148
- describe "for base class abilities" do
149
-
150
- it "does nothing" do
139
+ describe 'for base class abilities' do
140
+ it 'does nothing' do
151
141
  proc { Ability.new(instance) }.must_be_silent
152
142
  end
153
143
  end
154
144
 
155
- describe "for assigned roles" do
156
-
145
+ describe 'for assigned roles' do
157
146
  subject { Ability.new(instance) }
158
147
 
159
- it "has all the abilities of an author" do
148
+ it 'has all the abilities of an author' do
160
149
  subject.can?(:new, Post).must_equal true
161
150
  subject.can?(:create, Post).must_equal true
162
151
  subject.can?(:edit, Post).must_equal true
@@ -165,11 +154,10 @@ describe Ability do
165
154
  subject.can?(:index, Post).must_equal true
166
155
  end
167
156
 
168
- it "has no admin abilities" do
157
+ it 'has no admin abilities' do
169
158
  subject.cannot?(:destroy, Post).must_equal true
170
159
  end
171
160
  end
172
-
173
161
  end
174
162
  end
175
163
  end
@@ -1,32 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  describe Canard::Adapters::ActiveRecord do
4
-
5
6
  describe 'acts_as_user' do
6
-
7
7
  describe 'with a role_mask' do
8
-
9
8
  describe 'and :roles => [] specified' do
10
-
11
9
  it 'sets the valid_roles for the class' do
12
- User.valid_roles.must_equal [:viewer, :author, :admin, :editor]
10
+ User.valid_roles.must_equal %i[viewer author admin editor]
13
11
  end
14
-
15
12
  end
16
13
 
17
14
  describe 'and no :roles => [] specified' do
18
-
19
15
  it 'sets no roles' do
20
16
  UserWithoutRole.valid_roles.must_equal []
21
17
  end
22
18
  end
23
-
24
19
  end
25
20
 
26
21
  describe 'with no roles_mask' do
27
-
28
22
  before do
29
- UserWithoutRoleMask.acts_as_user :roles => [:viewer, :admin]
23
+ UserWithoutRoleMask.acts_as_user roles: %i[viewer admin]
30
24
  end
31
25
 
32
26
  it 'sets no roles' do
@@ -34,48 +28,43 @@ describe Canard::Adapters::ActiveRecord do
34
28
  end
35
29
  end
36
30
 
37
- describe "with no table" do
38
-
31
+ describe 'with no table' do
39
32
  subject { Class.new(ActiveRecord::Base) }
40
33
 
41
- it "sets no roles" do
42
- subject.class_eval { acts_as_user :roles => [:admin] }
34
+ it 'sets no roles' do
35
+ subject.class_eval { acts_as_user roles: [:admin] }
43
36
  subject.valid_roles.must_equal []
44
37
  end
45
38
 
46
- it "does not raise any errors" do
47
- proc { subject.class_eval { acts_as_user :roles => [:admin] } }.must_be_silent
39
+ it 'does not raise any errors' do
40
+ proc { subject.class_eval { acts_as_user roles: [:admin] } }.must_be_silent
48
41
  end
49
42
 
50
- it "returns nil" do
51
- subject.class_eval { acts_as_user :roles => [:admin] }.must_be_nil
43
+ it 'returns nil' do
44
+ subject.class_eval { acts_as_user roles: [:admin] }.must_be_nil
52
45
  end
53
46
  end
54
47
 
55
48
  describe 'with an alternative roles_mask specified' do
56
-
57
49
  before do
58
- UserWithoutRoleMask.acts_as_user :roles_mask => :my_roles_mask, :roles => [:viewer, :admin]
50
+ UserWithoutRoleMask.acts_as_user roles_mask: :my_roles_mask, roles: %i[viewer admin]
59
51
  end
60
52
 
61
53
  it 'sets no roles' do
62
- UserWithoutRoleMask.valid_roles.must_equal [:viewer, :admin]
54
+ UserWithoutRoleMask.valid_roles.must_equal %i[viewer admin]
63
55
  end
64
56
  end
65
-
66
57
  end
67
58
 
68
- describe "scopes" do
69
-
70
- describe "on an ActiveRecord model with roles" do
71
-
59
+ describe 'scopes' do
60
+ describe 'on an ActiveRecord model with roles' do
72
61
  before do
73
62
  @no_role = User.create
74
- @admin_author_viewer = User.create(:roles => [:admin, :author, :viewer])
75
- @author_viewer = User.create(:roles => [:author, :viewer])
76
- @viewer = User.create(:roles => [:viewer])
77
- @admin_only = User.create(:roles => [:admin])
78
- @author_only = User.create(:roles => [:author])
63
+ @admin_author_viewer = User.create(roles: %i[admin author viewer])
64
+ @author_viewer = User.create(roles: %i[author viewer])
65
+ @viewer = User.create(roles: [:viewer])
66
+ @admin_only = User.create(roles: [:admin])
67
+ @author_only = User.create(roles: [:author])
79
68
  end
80
69
 
81
70
  after do
@@ -84,25 +73,23 @@ describe Canard::Adapters::ActiveRecord do
84
73
 
85
74
  subject { User }
86
75
 
87
- it "adds a scope to return instances with each role" do
76
+ it 'adds a scope to return instances with each role' do
88
77
  subject.must_respond_to :admins
89
78
  subject.must_respond_to :authors
90
79
  subject.must_respond_to :viewers
91
80
  end
92
81
 
93
- it "adds a scope to return instances without each role" do
82
+ it 'adds a scope to return instances without each role' do
94
83
  subject.must_respond_to :non_admins
95
84
  subject.must_respond_to :non_authors
96
85
  subject.must_respond_to :non_viewers
97
86
  end
98
87
 
99
- describe "finding instances with a role" do
100
-
101
- describe "admins scope" do
102
-
88
+ describe 'finding instances with a role' do
89
+ describe 'admins scope' do
103
90
  subject { User.admins.sort_by(&:id) }
104
91
 
105
- it "returns only admins" do
92
+ it 'returns only admins' do
106
93
  subject.must_equal [@admin_author_viewer, @admin_only].sort_by(&:id)
107
94
  end
108
95
 
@@ -112,14 +99,12 @@ describe Canard::Adapters::ActiveRecord do
112
99
  subject.wont_include @author_only
113
100
  subject.wont_include @viewer
114
101
  end
115
-
116
102
  end
117
103
 
118
- describe "authors scope" do
119
-
104
+ describe 'authors scope' do
120
105
  subject { User.authors.sort_by(&:id) }
121
106
 
122
- it "returns only authors" do
107
+ it 'returns only authors' do
123
108
  subject.must_equal [@admin_author_viewer, @author_viewer, @author_only].sort_by(&:id)
124
109
  end
125
110
 
@@ -128,14 +113,12 @@ describe Canard::Adapters::ActiveRecord do
128
113
  subject.wont_include @admin_only
129
114
  subject.wont_include @viewer
130
115
  end
131
-
132
116
  end
133
117
 
134
- describe "viewers scope" do
135
-
118
+ describe 'viewers scope' do
136
119
  subject { User.viewers.sort_by(&:id) }
137
120
 
138
- it "returns only viewers" do
121
+ it 'returns only viewers' do
139
122
  subject.must_equal [@admin_author_viewer, @author_viewer, @viewer].sort_by(&:id)
140
123
  end
141
124
 
@@ -144,18 +127,14 @@ describe Canard::Adapters::ActiveRecord do
144
127
  subject.wont_include @admin_only
145
128
  subject.wont_include @author_only
146
129
  end
147
-
148
130
  end
149
-
150
131
  end
151
132
 
152
- describe "finding instances without a role" do
153
-
154
- describe "non_admins scope" do
155
-
133
+ describe 'finding instances without a role' do
134
+ describe 'non_admins scope' do
156
135
  subject { User.non_admins.sort_by(&:id) }
157
136
 
158
- it "returns only non_admins" do
137
+ it 'returns only non_admins' do
159
138
  subject.must_equal [@no_role, @author_viewer, @viewer, @author_only].sort_by(&:id)
160
139
  end
161
140
 
@@ -163,14 +142,12 @@ describe Canard::Adapters::ActiveRecord do
163
142
  subject.wont_include @admin_author_viewer
164
143
  subject.wont_include @admin_only
165
144
  end
166
-
167
145
  end
168
146
 
169
- describe "non_authors scope" do
170
-
147
+ describe 'non_authors scope' do
171
148
  subject { User.non_authors.sort_by(&:id) }
172
149
 
173
- it "returns only non_authors" do
150
+ it 'returns only non_authors' do
174
151
  subject.must_equal [@no_role, @viewer, @admin_only].sort_by(&:id)
175
152
  end
176
153
 
@@ -179,14 +156,12 @@ describe Canard::Adapters::ActiveRecord do
179
156
  subject.wont_include @author_viewer
180
157
  subject.wont_include @author_only
181
158
  end
182
-
183
159
  end
184
160
 
185
- describe "non_viewers scope" do
186
-
161
+ describe 'non_viewers scope' do
187
162
  subject { User.non_viewers.sort_by(&:id) }
188
163
 
189
- it "returns only non_viewers" do
164
+ it 'returns only non_viewers' do
190
165
  subject.must_equal [@no_role, @admin_only, @author_only].sort_by(&:id)
191
166
  end
192
167
 
@@ -195,18 +170,14 @@ describe Canard::Adapters::ActiveRecord do
195
170
  subject.wont_include @author_viewer
196
171
  subject.wont_include @viewer
197
172
  end
198
-
199
173
  end
200
-
201
174
  end
202
175
 
203
- describe "with_any_role" do
204
-
205
- describe "specifying admin only" do
206
-
176
+ describe 'with_any_role' do
177
+ describe 'specifying admin only' do
207
178
  subject { User.with_any_role(:admin).sort_by(&:id) }
208
179
 
209
- it "returns only admins" do
180
+ it 'returns only admins' do
210
181
  subject.must_equal [@admin_author_viewer, @admin_only].sort_by(&:id)
211
182
  end
212
183
 
@@ -216,14 +187,12 @@ describe Canard::Adapters::ActiveRecord do
216
187
  subject.wont_include @author_only
217
188
  subject.wont_include @viewer
218
189
  end
219
-
220
190
  end
221
191
 
222
- describe "specifying author only" do
223
-
192
+ describe 'specifying author only' do
224
193
  subject { User.with_any_role(:author).sort_by(&:id) }
225
194
 
226
- it "returns only authors" do
195
+ it 'returns only authors' do
227
196
  subject.must_equal [@admin_author_viewer, @author_viewer, @author_only].sort_by(&:id)
228
197
  end
229
198
 
@@ -232,14 +201,12 @@ describe Canard::Adapters::ActiveRecord do
232
201
  subject.wont_include @admin_only
233
202
  subject.wont_include @viewer
234
203
  end
235
-
236
204
  end
237
205
 
238
- describe "specifying viewer only" do
239
-
206
+ describe 'specifying viewer only' do
240
207
  subject { User.with_any_role(:viewer).sort_by(&:id) }
241
208
 
242
- it "returns only viewers" do
209
+ it 'returns only viewers' do
243
210
  subject.must_equal [@admin_author_viewer, @author_viewer, @viewer].sort_by(&:id)
244
211
  end
245
212
 
@@ -248,14 +215,12 @@ describe Canard::Adapters::ActiveRecord do
248
215
  subject.wont_include @admin_only
249
216
  subject.wont_include @author_only
250
217
  end
251
-
252
218
  end
253
219
 
254
- describe "specifying admin and author" do
255
-
220
+ describe 'specifying admin and author' do
256
221
  subject { User.with_any_role(:admin, :author).sort_by(&:id) }
257
222
 
258
- it "returns only admins and authors" do
223
+ it 'returns only admins and authors' do
259
224
  subject.must_equal [@admin_author_viewer, @author_viewer, @admin_only, @author_only].sort_by(&:id)
260
225
  end
261
226
 
@@ -263,14 +228,12 @@ describe Canard::Adapters::ActiveRecord do
263
228
  subject.wont_include @no_role
264
229
  subject.wont_include @viewer
265
230
  end
266
-
267
231
  end
268
232
 
269
- describe "specifying admin and viewer" do
270
-
233
+ describe 'specifying admin and viewer' do
271
234
  subject { User.with_any_role(:admin, :viewer).sort_by(&:id) }
272
235
 
273
- it "returns only admins and viewers" do
236
+ it 'returns only admins and viewers' do
274
237
  subject.must_equal [@admin_author_viewer, @author_viewer, @admin_only, @viewer].sort_by(&:id)
275
238
  end
276
239
 
@@ -278,14 +241,12 @@ describe Canard::Adapters::ActiveRecord do
278
241
  subject.wont_include @no_role
279
242
  subject.wont_include @author_only
280
243
  end
281
-
282
244
  end
283
245
 
284
- describe "specifying author and viewer" do
285
-
246
+ describe 'specifying author and viewer' do
286
247
  subject { User.with_any_role(:author, :viewer).sort_by(&:id) }
287
248
 
288
- it "returns only authors and viewers" do
249
+ it 'returns only authors and viewers' do
289
250
  subject.must_equal [@admin_author_viewer, @author_viewer, @author_only, @viewer].sort_by(&:id)
290
251
  end
291
252
 
@@ -293,32 +254,26 @@ describe Canard::Adapters::ActiveRecord do
293
254
  subject.wont_include @no_role
294
255
  subject.wont_include @admin_only
295
256
  end
296
-
297
257
  end
298
258
 
299
- describe "specifying admin, author and viewer" do
300
-
259
+ describe 'specifying admin, author and viewer' do
301
260
  subject { User.with_any_role(:admin, :author, :viewer).sort_by(&:id) }
302
261
 
303
- it "returns only admins, authors and viewers" do
262
+ it 'returns only admins, authors and viewers' do
304
263
  subject.must_equal [@admin_author_viewer, @author_viewer, @admin_only, @author_only, @viewer].sort_by(&:id)
305
264
  end
306
265
 
307
266
  it "doesn't return non admins, authors or viewers" do
308
267
  subject.wont_include @no_role
309
268
  end
310
-
311
269
  end
312
-
313
270
  end
314
271
 
315
- describe "with_all_roles" do
316
-
317
- describe "specifying admin only" do
318
-
272
+ describe 'with_all_roles' do
273
+ describe 'specifying admin only' do
319
274
  subject { User.with_all_roles(:admin).sort_by(&:id) }
320
275
 
321
- it "returns only admins" do
276
+ it 'returns only admins' do
322
277
  subject.must_equal [@admin_author_viewer, @admin_only].sort_by(&:id)
323
278
  end
324
279
 
@@ -328,14 +283,12 @@ describe Canard::Adapters::ActiveRecord do
328
283
  subject.wont_include @author_only
329
284
  subject.wont_include @viewer
330
285
  end
331
-
332
286
  end
333
287
 
334
- describe "specifying author only" do
335
-
288
+ describe 'specifying author only' do
336
289
  subject { User.with_all_roles(:author).sort_by(&:id) }
337
290
 
338
- it "returns only authors" do
291
+ it 'returns only authors' do
339
292
  subject.must_equal [@admin_author_viewer, @author_viewer, @author_only].sort_by(&:id)
340
293
  end
341
294
 
@@ -344,14 +297,12 @@ describe Canard::Adapters::ActiveRecord do
344
297
  subject.wont_include @admin_only
345
298
  subject.wont_include @viewer
346
299
  end
347
-
348
300
  end
349
301
 
350
- describe "specifying viewer only" do
351
-
302
+ describe 'specifying viewer only' do
352
303
  subject { User.with_all_roles(:viewer).sort_by(&:id) }
353
304
 
354
- it "returns only viewers" do
305
+ it 'returns only viewers' do
355
306
  subject.must_equal [@admin_author_viewer, @author_viewer, @viewer].sort_by(&:id)
356
307
  end
357
308
 
@@ -360,14 +311,12 @@ describe Canard::Adapters::ActiveRecord do
360
311
  subject.wont_include @admin_only
361
312
  subject.wont_include @author_only
362
313
  end
363
-
364
314
  end
365
315
 
366
- describe "specifying admin and author" do
367
-
316
+ describe 'specifying admin and author' do
368
317
  subject { User.with_all_roles(:admin, :author).sort_by(&:id) }
369
318
 
370
- it "returns only admins and authors" do
319
+ it 'returns only admins and authors' do
371
320
  subject.must_equal [@admin_author_viewer].sort_by(&:id)
372
321
  end
373
322
 
@@ -378,14 +327,12 @@ describe Canard::Adapters::ActiveRecord do
378
327
  subject.wont_include @admin_only
379
328
  subject.wont_include @viewer
380
329
  end
381
-
382
330
  end
383
331
 
384
- describe "specifying admin and viewer" do
385
-
332
+ describe 'specifying admin and viewer' do
386
333
  subject { User.with_all_roles(:admin, :viewer).sort_by(&:id) }
387
334
 
388
- it "returns only admins and viewers" do
335
+ it 'returns only admins and viewers' do
389
336
  subject.must_equal [@admin_author_viewer].sort_by(&:id)
390
337
  end
391
338
 
@@ -396,14 +343,12 @@ describe Canard::Adapters::ActiveRecord do
396
343
  subject.wont_include @admin_only
397
344
  subject.wont_include @viewer
398
345
  end
399
-
400
346
  end
401
347
 
402
- describe "specifying author and viewer" do
403
-
348
+ describe 'specifying author and viewer' do
404
349
  subject { User.with_all_roles(:author, :viewer).sort_by(&:id) }
405
350
 
406
- it "returns only authors and viewers" do
351
+ it 'returns only authors and viewers' do
407
352
  subject.must_equal [@admin_author_viewer, @author_viewer].sort_by(&:id)
408
353
  end
409
354
 
@@ -413,14 +358,12 @@ describe Canard::Adapters::ActiveRecord do
413
358
  subject.wont_include @author_only
414
359
  subject.wont_include @viewer
415
360
  end
416
-
417
361
  end
418
362
 
419
- describe "specifying admin, author and viewer" do
420
-
363
+ describe 'specifying admin, author and viewer' do
421
364
  subject { User.with_all_roles(:admin, :author, :viewer).sort_by(&:id) }
422
365
 
423
- it "returns only admins, authors and viewers" do
366
+ it 'returns only admins, authors and viewers' do
424
367
  subject.must_equal [@admin_author_viewer].sort_by(&:id)
425
368
  end
426
369
 
@@ -431,18 +374,14 @@ describe Canard::Adapters::ActiveRecord do
431
374
  subject.wont_include @admin_only
432
375
  subject.wont_include @viewer
433
376
  end
434
-
435
377
  end
436
-
437
378
  end
438
379
 
439
- describe "with_only_roles" do
440
-
441
- describe "specifying one role" do
442
-
380
+ describe 'with_only_roles' do
381
+ describe 'specifying one role' do
443
382
  subject { User.with_only_roles(:admin).sort_by(&:id) }
444
383
 
445
- it "returns users with just that role" do
384
+ it 'returns users with just that role' do
446
385
  subject.must_equal [@admin_only].sort_by(&:id)
447
386
  end
448
387
 
@@ -453,14 +392,12 @@ describe Canard::Adapters::ActiveRecord do
453
392
  subject.wont_include @author_only
454
393
  subject.wont_include @viewer
455
394
  end
456
-
457
395
  end
458
396
 
459
- describe "specifying multiple roles" do
460
-
397
+ describe 'specifying multiple roles' do
461
398
  subject { User.with_only_roles(:author, :viewer).sort_by(&:id) }
462
399
 
463
- it "returns only users with no more or less roles" do
400
+ it 'returns only users with no more or less roles' do
464
401
  subject.must_equal [@author_viewer].sort_by(&:id)
465
402
  end
466
403
 
@@ -475,5 +412,4 @@ describe Canard::Adapters::ActiveRecord do
475
412
  end
476
413
  end
477
414
  end
478
-
479
415
  end