rolify 3.1.0 → 4.0.0

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 (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -1
  3. data/.travis.yml +44 -11
  4. data/CHANGELOG.rdoc +70 -0
  5. data/CONTRIBUTORS +6 -0
  6. data/Gemfile +21 -2
  7. data/README.md +130 -68
  8. data/Rakefile +29 -4
  9. data/UPGRADE.rdoc +22 -0
  10. data/circle.yml +13 -0
  11. data/gemfiles/Gemfile.rails-3.2 +27 -0
  12. data/gemfiles/Gemfile.rails-4.0 +33 -0
  13. data/gemfiles/Gemfile.rails-4.1 +37 -0
  14. data/lib/generators/active_record/rolify_generator.rb +54 -0
  15. data/lib/generators/active_record/templates/README +8 -0
  16. data/lib/generators/active_record/templates/migration.rb +19 -0
  17. data/lib/generators/mongoid/rolify_generator.rb +55 -0
  18. data/lib/generators/mongoid/templates/README-mongoid +4 -0
  19. data/lib/generators/rolify/rolify_generator.rb +35 -0
  20. data/lib/generators/rolify/{role/templates/README-mongoid → templates/README} +1 -5
  21. data/lib/generators/rolify/templates/initializer.rb +7 -0
  22. data/lib/generators/rolify/templates/role-active_record.rb +11 -0
  23. data/lib/generators/rolify/{role/templates → templates}/role-mongoid.rb +9 -9
  24. data/lib/generators/rolify/user_generator.rb +39 -0
  25. data/lib/rolify/adapters/active_record/resource_adapter.rb +36 -6
  26. data/lib/rolify/adapters/active_record/role_adapter.rb +25 -13
  27. data/lib/rolify/adapters/active_record/scopes.rb +27 -0
  28. data/lib/rolify/adapters/base.rb +9 -0
  29. data/lib/rolify/adapters/mongoid/resource_adapter.rb +27 -6
  30. data/lib/rolify/adapters/mongoid/role_adapter.rb +35 -11
  31. data/lib/rolify/adapters/mongoid/scopes.rb +27 -0
  32. data/lib/rolify/configure.rb +36 -5
  33. data/lib/rolify/finders.rb +40 -0
  34. data/lib/rolify/matchers.rb +31 -0
  35. data/lib/rolify/railtie.rb +1 -1
  36. data/lib/rolify/resource.rb +19 -10
  37. data/lib/rolify/role.rb +33 -13
  38. data/lib/rolify/version.rb +1 -1
  39. data/lib/rolify.rb +46 -20
  40. data/rolify.gemspec +18 -24
  41. data/spec/README.rdoc +24 -0
  42. data/spec/generators/rolify/rolify_activerecord_generator_spec.rb +165 -0
  43. data/spec/generators/rolify/rolify_mongoid_generator_spec.rb +113 -0
  44. data/spec/generators_helper.rb +27 -0
  45. data/spec/rolify/config_spec.rb +20 -21
  46. data/spec/rolify/custom_spec.rb +11 -6
  47. data/spec/rolify/matchers_spec.rb +24 -0
  48. data/spec/rolify/namespace_spec.rb +24 -0
  49. data/spec/rolify/resource_spec.rb +135 -37
  50. data/spec/rolify/resourcifed_and_rolifed_spec.rb +24 -0
  51. data/spec/rolify/role_spec.rb +8 -9
  52. data/spec/rolify/shared_contexts.rb +22 -3
  53. data/spec/rolify/shared_examples/shared_examples_for_add_role.rb +10 -17
  54. data/spec/rolify/shared_examples/shared_examples_for_callbacks.rb +65 -0
  55. data/spec/rolify/shared_examples/shared_examples_for_dynamic.rb +64 -27
  56. data/spec/rolify/shared_examples/shared_examples_for_finders.rb +81 -0
  57. data/spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb +29 -29
  58. data/spec/rolify/shared_examples/shared_examples_for_has_any_role.rb +35 -35
  59. data/spec/rolify/shared_examples/shared_examples_for_has_role.rb +38 -38
  60. data/spec/rolify/shared_examples/shared_examples_for_only_has_role.rb +174 -0
  61. data/spec/rolify/shared_examples/shared_examples_for_remove_role.rb +28 -59
  62. data/spec/rolify/shared_examples/shared_examples_for_roles.rb +58 -32
  63. data/spec/rolify/shared_examples/shared_examples_for_scopes.rb +38 -0
  64. data/spec/spec_helper.rb +39 -3
  65. data/spec/support/adapters/active_record.rb +58 -7
  66. data/spec/support/adapters/mongoid.rb +110 -17
  67. data/spec/support/adapters/mongoid.yml +6 -0
  68. data/spec/support/data.rb +18 -15
  69. data/spec/support/schema.rb +31 -16
  70. data/spec/support/stream_helpers.rb +18 -0
  71. metadata +88 -84
  72. data/lib/generators/rolify/role/role_generator.rb +0 -41
  73. data/lib/generators/rolify/role/templates/README +0 -11
  74. data/lib/generators/rolify/role/templates/README-active_record +0 -21
  75. data/lib/generators/rolify/role/templates/initializer.rb +0 -7
  76. data/lib/generators/rolify/role/templates/migration.rb +0 -19
  77. data/lib/generators/rolify/role/templates/role-active_record.rb +0 -4
  78. data/spec/generators/rolify/role/role_generator_spec.rb +0 -197
metadata CHANGED
@@ -1,200 +1,204 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rolify
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
5
- prerelease:
4
+ version: 4.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Florent Monbillard
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-07 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: sqlite3
16
- requirement: &70359244800420 !ruby/object:Gem::Requirement
17
- none: false
14
+ name: ammeter
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: 1.1.2
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *70359244800420
25
- - !ruby/object:Gem::Dependency
26
- name: activerecord
27
- requirement: &70359244799000 !ruby/object:Gem::Requirement
28
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
29
23
  requirements:
30
- - - ! '>='
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: 3.1.0
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70359244799000
26
+ version: 1.1.2
36
27
  - !ruby/object:Gem::Dependency
37
- name: mongoid
38
- requirement: &70359244797140 !ruby/object:Gem::Requirement
39
- none: false
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
40
30
  requirements:
41
- - - ! '>='
31
+ - - ">="
42
32
  - !ruby/object:Gem::Version
43
- version: '2.3'
33
+ version: 1.7.12
44
34
  type: :development
45
35
  prerelease: false
46
- version_requirements: *70359244797140
47
- - !ruby/object:Gem::Dependency
48
- name: bson_ext
49
- requirement: &70359244794900 !ruby/object:Gem::Requirement
50
- none: false
36
+ version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ! '>='
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
55
- type: :development
56
- prerelease: false
57
- version_requirements: *70359244794900
40
+ version: 1.7.12
58
41
  - !ruby/object:Gem::Dependency
59
- name: ammeter
60
- requirement: &70359244792460 !ruby/object:Gem::Requirement
61
- none: false
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
62
44
  requirements:
63
- - - ! '>='
45
+ - - "~>"
64
46
  - !ruby/object:Gem::Version
65
- version: '0'
47
+ version: 10.4.2
66
48
  type: :development
67
49
  prerelease: false
68
- version_requirements: *70359244792460
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: &70359244791380 !ruby/object:Gem::Requirement
72
- none: false
50
+ version_requirements: !ruby/object:Gem::Requirement
73
51
  requirements:
74
- - - ! '>='
52
+ - - "~>"
75
53
  - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: *70359244791380
54
+ version: 10.4.2
80
55
  - !ruby/object:Gem::Dependency
81
- name: rspec
82
- requirement: &70359244788860 !ruby/object:Gem::Requirement
83
- none: false
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
84
58
  requirements:
85
- - - ! '>='
59
+ - - '='
86
60
  - !ruby/object:Gem::Version
87
- version: '0'
61
+ version: 2.99.0
88
62
  type: :development
89
63
  prerelease: false
90
- version_requirements: *70359244788860
91
- - !ruby/object:Gem::Dependency
92
- name: bundler
93
- requirement: &70359244786160 !ruby/object:Gem::Requirement
94
- none: false
64
+ version_requirements: !ruby/object:Gem::Requirement
95
65
  requirements:
96
- - - ! '>='
66
+ - - '='
97
67
  - !ruby/object:Gem::Version
98
- version: '0'
99
- type: :development
100
- prerelease: false
101
- version_requirements: *70359244786160
68
+ version: 2.99.0
102
69
  description: Very simple Roles library without any authorization enforcement supporting
103
- scope on resource objects (instance or class)
70
+ scope on resource objects (instance or class). Supports ActiveRecord and Mongoid
71
+ ORMs.
104
72
  email:
105
73
  - f.monbillard@gmail.com
106
74
  executables: []
107
75
  extensions: []
108
76
  extra_rdoc_files: []
109
77
  files:
110
- - .gitignore
111
- - .travis.yml
78
+ - ".gitignore"
79
+ - ".travis.yml"
112
80
  - CHANGELOG.rdoc
81
+ - CONTRIBUTORS
113
82
  - Gemfile
114
83
  - LICENSE
115
84
  - README.md
116
85
  - Rakefile
117
86
  - UPGRADE.rdoc
118
- - lib/generators/rolify/role/role_generator.rb
119
- - lib/generators/rolify/role/templates/README
120
- - lib/generators/rolify/role/templates/README-active_record
121
- - lib/generators/rolify/role/templates/README-mongoid
122
- - lib/generators/rolify/role/templates/initializer.rb
123
- - lib/generators/rolify/role/templates/migration.rb
124
- - lib/generators/rolify/role/templates/role-active_record.rb
125
- - lib/generators/rolify/role/templates/role-mongoid.rb
87
+ - circle.yml
88
+ - gemfiles/Gemfile.rails-3.2
89
+ - gemfiles/Gemfile.rails-4.0
90
+ - gemfiles/Gemfile.rails-4.1
91
+ - lib/generators/active_record/rolify_generator.rb
92
+ - lib/generators/active_record/templates/README
93
+ - lib/generators/active_record/templates/migration.rb
94
+ - lib/generators/mongoid/rolify_generator.rb
95
+ - lib/generators/mongoid/templates/README-mongoid
96
+ - lib/generators/rolify/rolify_generator.rb
97
+ - lib/generators/rolify/templates/README
98
+ - lib/generators/rolify/templates/initializer.rb
99
+ - lib/generators/rolify/templates/role-active_record.rb
100
+ - lib/generators/rolify/templates/role-mongoid.rb
101
+ - lib/generators/rolify/user_generator.rb
126
102
  - lib/rolify.rb
127
103
  - lib/rolify/adapters/active_record/resource_adapter.rb
128
104
  - lib/rolify/adapters/active_record/role_adapter.rb
105
+ - lib/rolify/adapters/active_record/scopes.rb
129
106
  - lib/rolify/adapters/base.rb
130
107
  - lib/rolify/adapters/mongoid/resource_adapter.rb
131
108
  - lib/rolify/adapters/mongoid/role_adapter.rb
109
+ - lib/rolify/adapters/mongoid/scopes.rb
132
110
  - lib/rolify/configure.rb
133
111
  - lib/rolify/dynamic.rb
112
+ - lib/rolify/finders.rb
113
+ - lib/rolify/matchers.rb
134
114
  - lib/rolify/railtie.rb
135
115
  - lib/rolify/resource.rb
136
116
  - lib/rolify/role.rb
137
117
  - lib/rolify/utils.rb
138
118
  - lib/rolify/version.rb
139
119
  - rolify.gemspec
140
- - spec/generators/rolify/role/role_generator_spec.rb
120
+ - spec/README.rdoc
121
+ - spec/generators/rolify/rolify_activerecord_generator_spec.rb
122
+ - spec/generators/rolify/rolify_mongoid_generator_spec.rb
123
+ - spec/generators_helper.rb
141
124
  - spec/rolify/config_spec.rb
142
125
  - spec/rolify/custom_spec.rb
126
+ - spec/rolify/matchers_spec.rb
127
+ - spec/rolify/namespace_spec.rb
143
128
  - spec/rolify/resource_spec.rb
129
+ - spec/rolify/resourcifed_and_rolifed_spec.rb
144
130
  - spec/rolify/role_spec.rb
145
131
  - spec/rolify/shared_contexts.rb
146
132
  - spec/rolify/shared_examples/shared_examples_for_add_role.rb
133
+ - spec/rolify/shared_examples/shared_examples_for_callbacks.rb
147
134
  - spec/rolify/shared_examples/shared_examples_for_dynamic.rb
135
+ - spec/rolify/shared_examples/shared_examples_for_finders.rb
148
136
  - spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb
149
137
  - spec/rolify/shared_examples/shared_examples_for_has_any_role.rb
150
138
  - spec/rolify/shared_examples/shared_examples_for_has_role.rb
139
+ - spec/rolify/shared_examples/shared_examples_for_only_has_role.rb
151
140
  - spec/rolify/shared_examples/shared_examples_for_remove_role.rb
152
141
  - spec/rolify/shared_examples/shared_examples_for_roles.rb
142
+ - spec/rolify/shared_examples/shared_examples_for_scopes.rb
153
143
  - spec/spec_helper.rb
154
144
  - spec/support/adapters/active_record.rb
155
145
  - spec/support/adapters/mongoid.rb
146
+ - spec/support/adapters/mongoid.yml
156
147
  - spec/support/data.rb
157
148
  - spec/support/schema.rb
158
- homepage: https://github.com/EppO/rolify
159
- licenses: []
149
+ - spec/support/stream_helpers.rb
150
+ homepage: https://github.com/RolifyCommunity/rolify
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
160
154
  post_install_message:
161
155
  rdoc_options: []
162
156
  require_paths:
163
157
  - lib
164
158
  required_ruby_version: !ruby/object:Gem::Requirement
165
- none: false
166
159
  requirements:
167
- - - ! '>='
160
+ - - ">="
168
161
  - !ruby/object:Gem::Version
169
162
  version: '0'
170
163
  required_rubygems_version: !ruby/object:Gem::Requirement
171
- none: false
172
164
  requirements:
173
- - - ! '>='
165
+ - - ">="
174
166
  - !ruby/object:Gem::Version
175
167
  version: '0'
176
168
  requirements: []
177
169
  rubyforge_project: rolify
178
- rubygems_version: 1.8.17
170
+ rubygems_version: 2.2.2
179
171
  signing_key:
180
- specification_version: 3
172
+ specification_version: 4
181
173
  summary: Roles library with resource scoping
182
174
  test_files:
183
- - spec/generators/rolify/role/role_generator_spec.rb
175
+ - spec/README.rdoc
176
+ - spec/generators/rolify/rolify_activerecord_generator_spec.rb
177
+ - spec/generators/rolify/rolify_mongoid_generator_spec.rb
178
+ - spec/generators_helper.rb
184
179
  - spec/rolify/config_spec.rb
185
180
  - spec/rolify/custom_spec.rb
181
+ - spec/rolify/matchers_spec.rb
182
+ - spec/rolify/namespace_spec.rb
186
183
  - spec/rolify/resource_spec.rb
184
+ - spec/rolify/resourcifed_and_rolifed_spec.rb
187
185
  - spec/rolify/role_spec.rb
188
186
  - spec/rolify/shared_contexts.rb
189
187
  - spec/rolify/shared_examples/shared_examples_for_add_role.rb
188
+ - spec/rolify/shared_examples/shared_examples_for_callbacks.rb
190
189
  - spec/rolify/shared_examples/shared_examples_for_dynamic.rb
190
+ - spec/rolify/shared_examples/shared_examples_for_finders.rb
191
191
  - spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb
192
192
  - spec/rolify/shared_examples/shared_examples_for_has_any_role.rb
193
193
  - spec/rolify/shared_examples/shared_examples_for_has_role.rb
194
+ - spec/rolify/shared_examples/shared_examples_for_only_has_role.rb
194
195
  - spec/rolify/shared_examples/shared_examples_for_remove_role.rb
195
196
  - spec/rolify/shared_examples/shared_examples_for_roles.rb
197
+ - spec/rolify/shared_examples/shared_examples_for_scopes.rb
196
198
  - spec/spec_helper.rb
197
199
  - spec/support/adapters/active_record.rb
198
200
  - spec/support/adapters/mongoid.rb
201
+ - spec/support/adapters/mongoid.yml
199
202
  - spec/support/data.rb
200
203
  - spec/support/schema.rb
204
+ - spec/support/stream_helpers.rb
@@ -1,41 +0,0 @@
1
- require 'rails/generators/migration'
2
-
3
- module Rolify
4
- module Generators
5
- class RoleGenerator < Rails::Generators::Base
6
- include Rails::Generators::Migration
7
-
8
- source_root File.expand_path('../templates', __FILE__)
9
- argument :role_cname, :type => :string, :default => "Role"
10
- argument :user_cname, :type => :string, :default => "User"
11
- argument :orm_adapter, :type => :string, :default => "active_record"
12
- class_option :dynamic_shortcuts, :type => :boolean, :default => false
13
-
14
- desc "Generates a model with the given NAME and a migration file."
15
-
16
- def generate_role
17
- template "role-#{orm_adapter}.rb", "app/models/#{role_cname.underscore}.rb"
18
- inject_into_class(model_path, user_cname.camelize) do
19
- "\trolify" + (role_cname == "Role" ? "" : ":role_cname => '#{role_cname.camelize}'") + "\n"
20
- end
21
- end
22
-
23
- def copy_role_file
24
- template "initializer.rb", "config/initializers/rolify.rb"
25
- migration_template "migration.rb", "db/migrate/rolify_create_#{role_cname.tableize}" if orm_adapter == "active_record"
26
- end
27
-
28
- def model_path
29
- File.join("app", "models", "#{user_cname.underscore}.rb")
30
- end
31
-
32
- def self.next_migration_number(path)
33
- Time.now.utc.strftime("%Y%m%d%H%M%S")
34
- end
35
-
36
- def show_readme
37
- readme "README-#{orm_adapter}" if behavior == :invoke
38
- end
39
- end
40
- end
41
- end
@@ -1,11 +0,0 @@
1
- ===============================================================================
2
-
3
- Now, you just have to run the migration using rake command:
4
-
5
- rake db:migrate
6
-
7
- An initializer file has been created here: config/initializers/rolify.rb,
8
- you can change rolify settings to match your needs.
9
- Defaults values are commented out.
10
-
11
- ===============================================================================
@@ -1,21 +0,0 @@
1
- ===============================================================================
2
-
3
- An initializer file has been created here: config/initializers/rolify.rb, you
4
- can change rolify settings to match your needs.
5
- Defaults values are commented out.
6
-
7
- A Role class has been been created in app/models (with the name you gave as
8
- argument otherwise the default is role.rb), you can add your own business logic
9
- inside.
10
-
11
- Inside your User class (or the name you gave as argument otherwise the default
12
- is user.rb), rolify method has been inserted to provide rolify methods.
13
-
14
- Now, if you just have to run the migration using rake command:
15
-
16
- rake db:migrate
17
-
18
- and you will be able to add the resourcify method inside all models you want
19
- scoped by a role.
20
-
21
- ===============================================================================
@@ -1,7 +0,0 @@
1
- Rolify.configure do |config|
2
- # By default ORM adapter is ActiveRecord. uncomment to use mongoid
3
- <%= "# " if orm_adapter == "active_record" %>config.use_mongoid
4
-
5
- # Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false
6
- <%= "# " if !options[:dynamic_shortcuts] %>config.use_dynamic_shortcuts
7
- end
@@ -1,19 +0,0 @@
1
- class RolifyCreate<%= role_cname.pluralize.camelize %> < ActiveRecord::Migration
2
- def change
3
- create_table(:<%= role_cname.tableize %>) do |t|
4
- t.string :name
5
- t.references :resource, :polymorphic => true
6
-
7
- t.timestamps
8
- end
9
-
10
- create_table(:<%= (user_cname.tableize + "_" + role_cname.tableize) %>, :id => false) do |t|
11
- t.references :<%= user_cname.underscore.singularize %>
12
- t.references :<%= role_cname.underscore.singularize %>
13
- end
14
-
15
- add_index(:<%= role_cname.tableize %>, :name)
16
- add_index(:<%= role_cname.tableize %>, [ :name, :resource_type, :resource_id ])
17
- add_index(:<%= "#{user_cname.tableize}_#{role_cname.tableize}" %>, [ :<%= user_cname.underscore.singularize %>_id, :<%= role_cname.underscore.singularize %>_id ])
18
- end
19
- end
@@ -1,4 +0,0 @@
1
- class <%= role_cname.camelize %> < ActiveRecord::Base
2
- has_and_belongs_to_many :<%= user_cname.tableize %>, :join_table => :<%= "#{user_cname.tableize}_#{role_cname.tableize}" %>
3
- belongs_to :resource, :polymorphic => true
4
- end
@@ -1,197 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # Generators are not automatically loaded by Rails
4
- require 'generators/rolify/role/role_generator'
5
-
6
- describe Rolify::Generators::RoleGenerator do
7
- # Tell the generator where to put its output (what it thinks of as Rails.root)
8
- destination File.expand_path("../../../../../tmp", __FILE__)
9
- teardown :cleanup_destination_root
10
-
11
- before {
12
- prepare_destination
13
- }
14
-
15
- def cleanup_destination_root
16
- FileUtils.rm_rf destination_root
17
- end
18
-
19
- describe 'no arguments' do
20
- before(:all) { arguments [] }
21
-
22
- before {
23
- capture(:stdout) {
24
- generator.create_file "app/models/user.rb" do
25
- "class User < ActiveRecord::Base\nend"
26
- end
27
- }
28
- run_generator
29
- }
30
-
31
- describe 'config/initializers/rolify.rb' do
32
- subject { file('config/initializers/rolify.rb') }
33
- it { should exist }
34
- it { should contain "Rolify.configure do |config|"}
35
- it { should contain "# config.use_dynamic_shortcuts" }
36
- it { should contain "# config.use_mongoid" }
37
- end
38
-
39
- describe 'app/models/role.rb' do
40
- subject { file('app/models/role.rb') }
41
- it { should exist }
42
- it { should contain "class Role < ActiveRecord::Base" }
43
- it { should contain "has_and_belongs_to_many :users, :join_table => :users_roles" }
44
- it { should contain "belongs_to :resource, :polymorphic => true" }
45
- end
46
-
47
- describe 'app/models/user.rb' do
48
- subject { file('app/models/user.rb') }
49
- it { should contain "rolify" }
50
- end
51
-
52
- describe 'migration file' do
53
- subject { migration_file('db/migrate/rolify_create_roles.rb') }
54
-
55
- it { should be_a_migration }
56
- it { should contain "create_table(:roles) do" }
57
- it { should contain "create_table(:users_roles, :id => false) do" }
58
- end
59
- end
60
-
61
- describe 'specifying user and role names' do
62
- before(:all) { arguments %w(AdminRole AdminUser) }
63
-
64
- before {
65
- capture(:stdout) {
66
- generator.create_file "app/models/admin_user.rb" do
67
- "class AdminUser < ActiveRecord::Base\nend"
68
- end
69
- }
70
- run_generator
71
- }
72
-
73
- describe 'config/initializers/rolify.rb' do
74
- subject { file('config/initializers/rolify.rb') }
75
-
76
- it { should exist }
77
- it { should contain "Rolify.configure do |config|"}
78
- it { should contain "# config.use_dynamic_shortcuts" }
79
- it { should contain "# config.use_mongoid" }
80
- end
81
-
82
- describe 'app/models/rank.rb' do
83
- subject { file('app/models/admin_role.rb') }
84
-
85
- it { should exist }
86
- it { should contain "class AdminRole < ActiveRecord::Base" }
87
- it { should contain "has_and_belongs_to_many :admin_users, :join_table => :admin_users_admin_roles" }
88
- it { should contain "belongs_to :resource, :polymorphic => true" }
89
- end
90
-
91
- describe 'app/models/client.rb' do
92
- subject { file('app/models/admin_user.rb') }
93
-
94
- it { should contain "rolify" }
95
- end
96
-
97
- describe 'migration file' do
98
- subject { migration_file('db/migrate/rolify_create_admin_roles.rb') }
99
-
100
- it { should be_a_migration }
101
- it { should contain "create_table(:admin_roles)" }
102
- it { should contain "create_table(:admin_users_admin_roles, :id => false) do" }
103
- end
104
- end
105
-
106
- describe 'specifying dynamic shortcuts' do
107
- before(:all) { arguments [ "Role", "User", "--dynamic_shortcuts" ] }
108
-
109
- before {
110
- capture(:stdout) {
111
- generator.create_file "app/models/user.rb" do
112
- "class User < ActiveRecord::Base\nend"
113
- end
114
- }
115
- run_generator
116
- }
117
-
118
- describe 'config/initializers/rolify.rb' do
119
- subject { file('config/initializers/rolify.rb') }
120
- it { should exist }
121
- it { should contain "Rolify.configure do |config|"}
122
- it { should_not contain "# config.use_dynamic_shortcuts" }
123
- it { should contain "# config.use_mongoid" }
124
- end
125
-
126
- describe 'app/models/role.rb' do
127
- subject { file('app/models/role.rb') }
128
- it { should exist }
129
- it { should contain "class Role < ActiveRecord::Base" }
130
- it { should contain "has_and_belongs_to_many :users, :join_table => :users_roles" }
131
- it { should contain "belongs_to :resource, :polymorphic => true" }
132
- end
133
-
134
- describe 'app/models/user.rb' do
135
- subject { file('app/models/user.rb') }
136
- it { should contain "rolify" }
137
- end
138
-
139
- describe 'migration file' do
140
- subject { migration_file('db/migrate/rolify_create_roles.rb') }
141
-
142
- it { should be_a_migration }
143
- it { should contain "create_table(:roles) do" }
144
- it { should contain "create_table(:users_roles, :id => false) do" }
145
- end
146
- end
147
-
148
- describe 'specifying orm adapter' do
149
- before(:all) { arguments [ "Role", "User", "mongoid" ] }
150
-
151
- before {
152
- capture(:stdout) {
153
- generator.create_file "app/models/user.rb" do
154
- <<-CLASS
155
- class User
156
- include Mongoid::Document
157
-
158
- field :login, :type => String
159
- end
160
- CLASS
161
- end
162
- }
163
- run_generator
164
- }
165
-
166
- describe 'config/initializers/rolify.rb' do
167
- subject { file('config/initializers/rolify.rb') }
168
- it { should exist }
169
- it { should contain "Rolify.configure do |config|"}
170
- it { should_not contain "# config.use_mongoid" }
171
- it { should contain "# config.use_dynamic_shortcuts" }
172
- end
173
-
174
- describe 'app/models/role.rb' do
175
- subject { file('app/models/role.rb') }
176
- it { should exist }
177
- it { should contain "class Role\n" }
178
- it { should contain "has_and_belongs_to_many :users\n" }
179
- it { should contain "belongs_to :resource, :polymorphic => true" }
180
- it { should contain "field :name, :type => String" }
181
- it { should contain "index :name, unique: true" }
182
- it { should contain " index(\n"
183
- " [\n"
184
- " [:name, Mongo::ASCENDING],\n"
185
- " [:resource_type, Mongo::ASCENDING],\n"
186
- " [:resource_id, Mongo::ASCENDING]\n"
187
- " ],\n"
188
- " unique: true\n"
189
- " )\n" }
190
- end
191
-
192
- describe 'app/models/user.rb' do
193
- subject { file('app/models/user.rb') }
194
- it { should contain "rolify" }
195
- end
196
- end
197
- end