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.
- checksums.yaml +5 -5
- data/.hound.yml +3 -0
- data/.rubocop.yml +27 -0
- data/.rubocop_todo.yml +37 -0
- data/.travis.yml +1 -1
- data/Gemfile +7 -6
- data/README.md +40 -37
- data/Rakefile +5 -2
- data/canard.gemspec +8 -7
- data/lib/ability.rb +14 -13
- data/lib/canard.rb +4 -2
- data/lib/canard/abilities.rb +7 -9
- data/lib/canard/adapters/active_record.rb +32 -29
- data/lib/canard/adapters/mongoid.rb +18 -11
- data/lib/canard/find_abilities.rb +8 -9
- data/lib/canard/railtie.rb +11 -16
- data/lib/canard/user_model.rb +66 -67
- data/lib/canard/version.rb +3 -1
- data/lib/generators/ability_definition.rb +16 -14
- data/lib/generators/canard/ability/ability_generator.rb +16 -12
- data/lib/generators/rspec/ability/ability_generator.rb +9 -9
- data/lib/tasks/canard.rake +6 -6
- data/test/abilities/administrators.rb +2 -2
- data/test/canard/abilities_test.rb +14 -21
- data/test/canard/ability_test.rb +40 -52
- data/test/canard/adapters/active_record_test.rb +71 -135
- data/test/canard/adapters/mongoid_test.rb +61 -132
- data/test/canard/canard_test.rb +8 -10
- data/test/canard/find_abilities_test.rb +9 -11
- data/test/canard/user_model_test.rb +22 -32
- data/test/dummy/Rakefile +3 -1
- data/test/dummy/app/abilities/admins.rb +4 -4
- data/test/dummy/app/abilities/authors.rb +3 -3
- data/test/dummy/app/abilities/editors.rb +2 -2
- data/test/dummy/app/abilities/guests.rb +3 -3
- data/test/dummy/app/abilities/users.rb +4 -4
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/models/activity.rb +3 -1
- data/test/dummy/app/models/member.rb +3 -3
- data/test/dummy/app/models/mongoid_user.rb +5 -3
- data/test/dummy/app/models/plain_ruby_non_user.rb +2 -2
- data/test/dummy/app/models/plain_ruby_user.rb +3 -3
- data/test/dummy/app/models/post.rb +3 -1
- data/test/dummy/app/models/user.rb +3 -2
- data/test/dummy/app/models/user_without_role.rb +4 -4
- data/test/dummy/app/models/user_without_role_mask.rb +3 -3
- data/test/dummy/config.ru +3 -1
- data/test/dummy/config/application.rb +9 -8
- data/test/dummy/config/boot.rb +4 -2
- data/test/dummy/config/environment.rb +3 -1
- data/test/dummy/config/environments/development.rb +2 -0
- data/test/dummy/config/environments/test.rb +4 -2
- data/test/dummy/config/initializers/secret_token.rb +2 -0
- data/test/dummy/config/initializers/session_store.rb +3 -1
- data/test/dummy/config/initializers/wrap_parameters.rb +3 -1
- data/test/dummy/config/mongoid3.yml +5 -1
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/db/migrate/20120430083231_initialize_db.rb +7 -7
- data/test/dummy/db/schema.rb +11 -11
- data/test/dummy/script/rails +4 -2
- data/test/support/reloadable.rb +14 -15
- data/test/test_helper.rb +7 -13
- metadata +18 -18
- data/test/dummy/config/mongoid2.yml +0 -9
data/test/canard/canard_test.rb
CHANGED
@@ -1,30 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
require 'canard'
|
3
5
|
|
4
6
|
describe Canard do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
it "should be an accessor" do
|
7
|
+
describe 'ability_definitions' do
|
8
|
+
it 'should be an accessor' do
|
9
9
|
Canard.must_respond_to(:ability_definitions)
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'should be a hash' do
|
13
13
|
Canard.ability_definitions.must_be_instance_of Hash
|
14
14
|
end
|
15
|
-
|
16
15
|
end
|
17
16
|
|
18
|
-
describe
|
19
|
-
|
20
|
-
it "returns a snake case version of the string" do
|
17
|
+
describe 'ability_key' do
|
18
|
+
it 'returns a snake case version of the string' do
|
21
19
|
class_name = 'CamelCaseString'
|
22
20
|
key = :camel_case_string
|
23
21
|
|
24
22
|
Canard.ability_key(class_name).must_equal key
|
25
23
|
end
|
26
24
|
|
27
|
-
it
|
25
|
+
it 'prepends namespaces to the class name' do
|
28
26
|
class_name = 'Namespace::CamelCaseString'
|
29
27
|
key = :namespace_camel_case_string
|
30
28
|
|
@@ -1,35 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe Canard do
|
4
|
-
|
5
|
-
describe "find_abilities" do
|
6
|
-
|
6
|
+
describe 'find_abilities' do
|
7
7
|
before do
|
8
|
-
Canard::Abilities.definition_paths = [File.expand_path('
|
8
|
+
Canard::Abilities.definition_paths = [File.expand_path('../dummy/app/abilities', __dir__)]
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'loads the abilities into ability_definitions' do
|
12
12
|
Canard.find_abilities
|
13
13
|
|
14
14
|
Canard.ability_definitions.keys.must_include :admin
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'finds abilities in the default path' do
|
18
18
|
Canard.find_abilities
|
19
19
|
|
20
20
|
Canard.ability_definitions.keys.must_include :author
|
21
21
|
Canard.ability_definitions.keys.wont_include :administrator
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
Canard::Abilities.definition_paths << File.expand_path('
|
24
|
+
it 'finds abilities in additional paths' do
|
25
|
+
Canard::Abilities.definition_paths << File.expand_path('../abilities', __dir__)
|
26
26
|
Canard.find_abilities
|
27
27
|
|
28
28
|
Canard.ability_definitions.keys.must_include :author
|
29
29
|
Canard.ability_definitions.keys.must_include :administrator
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'reloads existing abilities' do
|
33
33
|
Canard.find_abilities
|
34
34
|
Canard::Abilities.send(:instance_variable_set, '@definitions', {})
|
35
35
|
Canard.find_abilities
|
@@ -37,7 +37,5 @@ describe Canard do
|
|
37
37
|
Canard.ability_definitions.keys.must_include :author
|
38
38
|
Canard.ability_definitions.keys.must_include :admin
|
39
39
|
end
|
40
|
-
|
41
40
|
end
|
42
|
-
|
43
41
|
end
|
@@ -1,11 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe Canard::UserModel do
|
4
|
-
|
5
6
|
describe 'acts_as_user' do
|
6
|
-
|
7
|
-
describe "integrating RoleModel" do
|
8
|
-
|
7
|
+
describe 'integrating RoleModel' do
|
9
8
|
before do
|
10
9
|
PlainRubyUser.acts_as_user
|
11
10
|
end
|
@@ -16,21 +15,18 @@ describe Canard::UserModel do
|
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
19
|
-
describe
|
20
|
-
|
18
|
+
describe 'with a roles_mask' do
|
21
19
|
describe 'and :roles => [] specified' do
|
22
|
-
|
23
20
|
before do
|
24
|
-
PlainRubyUser.acts_as_user :
|
21
|
+
PlainRubyUser.acts_as_user roles: %i[viewer author admin]
|
25
22
|
end
|
26
23
|
|
27
24
|
it 'sets the valid_roles for the class' do
|
28
|
-
PlainRubyUser.valid_roles.must_equal [
|
25
|
+
PlainRubyUser.valid_roles.must_equal %i[viewer author admin]
|
29
26
|
end
|
30
27
|
end
|
31
28
|
|
32
29
|
describe 'and no :roles => [] specified' do
|
33
|
-
|
34
30
|
before do
|
35
31
|
PlainRubyUser.acts_as_user
|
36
32
|
end
|
@@ -41,41 +37,37 @@ describe Canard::UserModel do
|
|
41
37
|
end
|
42
38
|
end
|
43
39
|
|
44
|
-
describe
|
45
|
-
|
40
|
+
describe 'with no roles_mask' do
|
46
41
|
before do
|
47
|
-
PlainRubyNonUser.acts_as_user :
|
42
|
+
PlainRubyNonUser.acts_as_user roles: %i[viewer author admin]
|
48
43
|
end
|
49
44
|
|
50
|
-
it
|
45
|
+
it 'sets no roles' do
|
51
46
|
PlainRubyNonUser.valid_roles.must_equal []
|
52
47
|
end
|
53
48
|
end
|
54
49
|
|
55
|
-
describe
|
56
|
-
|
50
|
+
describe 'setting the role_mask' do
|
57
51
|
before do
|
58
52
|
PlainRubyNonUser.send :attr_accessor, :my_roles
|
59
|
-
PlainRubyNonUser.acts_as_user :
|
53
|
+
PlainRubyNonUser.acts_as_user roles: %i[viewer author], roles_mask: :my_roles
|
60
54
|
end
|
61
55
|
|
62
56
|
it 'sets the valid_roles for the class' do
|
63
|
-
PlainRubyNonUser.valid_roles.must_equal [
|
57
|
+
PlainRubyNonUser.valid_roles.must_equal %i[viewer author]
|
64
58
|
end
|
65
59
|
end
|
66
60
|
end
|
67
61
|
|
68
|
-
describe
|
69
|
-
|
62
|
+
describe 'scopes' do
|
70
63
|
before do
|
71
|
-
PlainRubyUser.acts_as_user :
|
64
|
+
PlainRubyUser.acts_as_user roles: %i[viewer author admin]
|
72
65
|
end
|
73
66
|
|
74
|
-
describe
|
75
|
-
|
67
|
+
describe 'on a plain Ruby class' do
|
76
68
|
subject { PlainRubyUser }
|
77
69
|
|
78
|
-
it
|
70
|
+
it 'creates no scope methods' do
|
79
71
|
subject.wont_respond_to :admins
|
80
72
|
subject.wont_respond_to :authors
|
81
73
|
subject.wont_respond_to :viewers
|
@@ -90,26 +82,24 @@ describe Canard::UserModel do
|
|
90
82
|
end
|
91
83
|
|
92
84
|
describe Canard::UserModel::InstanceMethods do
|
93
|
-
|
94
85
|
before do
|
95
|
-
Canard::Abilities.default_path = File.expand_path('
|
86
|
+
Canard::Abilities.default_path = File.expand_path('../dummy/app/abilities', __dir__)
|
96
87
|
# reload abilities because the reloader will have removed them after the railtie ran
|
97
88
|
Canard.find_abilities
|
98
89
|
end
|
99
90
|
|
100
|
-
describe
|
101
|
-
|
91
|
+
describe 'ability' do
|
102
92
|
before do
|
103
|
-
PlainRubyUser.acts_as_user :
|
93
|
+
PlainRubyUser.acts_as_user roles: %i[admin author]
|
104
94
|
end
|
105
95
|
|
106
96
|
subject { PlainRubyUser.new(:author).ability }
|
107
97
|
|
108
|
-
it
|
98
|
+
it 'returns an ability for this instance' do
|
109
99
|
subject.must_be_instance_of Ability
|
110
100
|
end
|
111
101
|
|
112
|
-
it
|
102
|
+
it 'has the users abilities' do
|
113
103
|
subject.can?(:new, Post).must_equal true
|
114
104
|
subject.can?(:create, Post).must_equal true
|
115
105
|
subject.can?(:edit, Post).must_equal true
|
@@ -118,7 +108,7 @@ describe Canard::UserModel::InstanceMethods do
|
|
118
108
|
subject.can?(:index, Post).must_equal true
|
119
109
|
end
|
120
110
|
|
121
|
-
it
|
111
|
+
it 'has no other abilities' do
|
122
112
|
subject.cannot?(:destroy, Post).must_equal true
|
123
113
|
end
|
124
114
|
end
|
data/test/dummy/Rakefile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
5
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
6
|
|
5
|
-
require File.expand_path('
|
7
|
+
require File.expand_path('config/application', __dir__)
|
6
8
|
|
7
9
|
Dummy::Application.load_tasks
|
data/test/dummy/config.ru
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('boot', __dir__)
|
2
4
|
|
3
5
|
# Pick the frameworks you want:
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
6
|
+
require 'active_record/railtie'
|
7
|
+
require 'action_controller/railtie'
|
8
|
+
require 'active_resource/railtie'
|
9
|
+
require 'rails/test_unit/railtie'
|
8
10
|
|
9
|
-
Bundler.require
|
11
|
+
Bundler.require if defined?(Bundler)
|
10
12
|
require 'canard'
|
11
13
|
|
12
14
|
module Dummy
|
13
15
|
class Application < Rails::Application
|
14
16
|
# Configure the default encoding used in templates for Ruby 1.9.
|
15
|
-
config.encoding =
|
17
|
+
config.encoding = 'utf-8'
|
16
18
|
|
17
19
|
# Configure sensitive parameters which will be filtered from the log file.
|
18
20
|
config.filter_parameters += [:password]
|
@@ -29,4 +31,3 @@ module Dummy
|
|
29
31
|
config.active_record.whitelist_attributes = true
|
30
32
|
end
|
31
33
|
end
|
32
|
-
|
data/test/dummy/config/boot.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
|
-
gemfile = File.expand_path('
|
4
|
+
gemfile = File.expand_path('../../../Gemfile', __dir__)
|
3
5
|
|
4
6
|
if File.exist?(gemfile)
|
5
7
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -7,4 +9,4 @@ if File.exist?(gemfile)
|
|
7
9
|
Bundler.setup
|
8
10
|
end
|
9
11
|
|
10
|
-
|
12
|
+
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
|