strongbolt 0.3.12 → 0.3.13

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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +56 -0
  3. data/.rubocop_todo.yml +91 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +18 -2
  6. data/Rakefile +1 -1
  7. data/app/controllers/strongbolt/capabilities_controller.rb +36 -45
  8. data/app/controllers/strongbolt/roles_controller.rb +39 -47
  9. data/app/controllers/strongbolt/security_controller.rb +2 -3
  10. data/app/controllers/strongbolt/user_groups_controller.rb +48 -54
  11. data/app/controllers/strongbolt/user_groups_users_controller.rb +2 -4
  12. data/app/controllers/strongbolt_controller.rb +1 -1
  13. data/circle.yml +13 -0
  14. data/lib/generators/strongbolt/fix_generator.rb +5 -6
  15. data/lib/generators/strongbolt/fix_unique_group_members_generator.rb +2 -3
  16. data/lib/generators/strongbolt/indexes_generator.rb +3 -4
  17. data/lib/generators/strongbolt/install_generator.rb +8 -9
  18. data/lib/generators/strongbolt/templates/fix_unique_group_members.rb +1 -1
  19. data/lib/generators/strongbolt/templates/indexes.rb +1 -1
  20. data/lib/generators/strongbolt/templates/migration.rb +11 -12
  21. data/lib/generators/strongbolt/templates/strongbolt.rb +1 -1
  22. data/lib/generators/strongbolt/views_generator.rb +4 -4
  23. data/lib/strongbolt.rb +51 -54
  24. data/lib/strongbolt/base.rb +1 -1
  25. data/lib/strongbolt/bolted.rb +12 -13
  26. data/lib/strongbolt/bolted_controller.rb +46 -57
  27. data/lib/strongbolt/capabilities_role.rb +5 -5
  28. data/lib/strongbolt/capability.rb +32 -31
  29. data/lib/strongbolt/configuration.rb +18 -19
  30. data/lib/strongbolt/controllers/url_helpers.rb +5 -5
  31. data/lib/strongbolt/engine.rb +9 -9
  32. data/lib/strongbolt/errors.rb +4 -4
  33. data/lib/strongbolt/generators/migration.rb +4 -6
  34. data/lib/strongbolt/helpers.rb +5 -7
  35. data/lib/strongbolt/rails/routes.rb +4 -4
  36. data/lib/strongbolt/role.rb +11 -12
  37. data/lib/strongbolt/roles_user_group.rb +5 -5
  38. data/lib/strongbolt/rspec.rb +2 -2
  39. data/lib/strongbolt/rspec/user.rb +13 -15
  40. data/lib/strongbolt/tenantable.rb +78 -80
  41. data/lib/strongbolt/user_abilities.rb +44 -54
  42. data/lib/strongbolt/user_group.rb +8 -10
  43. data/lib/strongbolt/user_groups_user.rb +6 -6
  44. data/lib/strongbolt/version.rb +1 -1
  45. data/lib/tasks/strongbolt_tasks.rake +4 -4
  46. data/spec/controllers/strongbolt/capabilities_controller_spec.rb +28 -45
  47. data/spec/controllers/strongbolt/roles_controller_spec.rb +39 -72
  48. data/spec/controllers/strongbolt/user_groups_controller_spec.rb +34 -65
  49. data/spec/controllers/strongbolt/user_groups_users_controller_spec.rb +11 -19
  50. data/spec/controllers/without_authorization_controller_spec.rb +5 -5
  51. data/spec/dummy/app/controllers/posts_controller.rb +2 -2
  52. data/spec/dummy/app/controllers/test_controller.rb +1 -1
  53. data/spec/dummy/app/controllers/without_authorization_controller.rb +1 -1
  54. data/spec/dummy/bin/rails +1 -1
  55. data/spec/dummy/config.ru +1 -1
  56. data/spec/dummy/config/application.rb +4 -5
  57. data/spec/dummy/config/initializers/cookies_serializer.rb +1 -1
  58. data/spec/dummy/config/initializers/strongbolt.rb +2 -2
  59. data/spec/dummy/config/routes.rb +1 -3
  60. data/spec/dummy/db/migrate/20150630212236_create_strongbolt_tables.rb +9 -10
  61. data/spec/dummy/db/migrate/20150630212251_create_strongbolt_tables_indexes.rb +2 -2
  62. data/spec/dummy/db/migrate/20160531110509_fix_unique_group_members.rb +1 -1
  63. data/spec/fabricators/capability_fabricator.rb +4 -4
  64. data/spec/fabricators/role_fabricator.rb +3 -3
  65. data/spec/fabricators/user_fabricator.rb +2 -2
  66. data/spec/fabricators/user_group_fabricator.rb +3 -3
  67. data/spec/fixtures/application.rb +6 -3
  68. data/spec/fixtures/controllers.rb +1 -1
  69. data/spec/spec_helper.rb +7 -8
  70. data/spec/strongbolt/bolted_controller_spec.rb +110 -208
  71. data/spec/strongbolt/bolted_spec.rb +26 -40
  72. data/spec/strongbolt/capability_spec.rb +72 -86
  73. data/spec/strongbolt/configuration_spec.rb +33 -46
  74. data/spec/strongbolt/controllers/url_helpers_spec.rb +7 -9
  75. data/spec/strongbolt/helpers_spec.rb +14 -16
  76. data/spec/strongbolt/role_spec.rb +32 -35
  77. data/spec/strongbolt/tenantable_spec.rb +88 -86
  78. data/spec/strongbolt/user_abilities_multiple_tenants_spec.rb +29 -34
  79. data/spec/strongbolt/user_abilities_spec.rb +142 -188
  80. data/spec/strongbolt/user_group_spec.rb +14 -14
  81. data/spec/strongbolt/users_tenant_spec.rb +10 -12
  82. data/spec/strongbolt_spec.rb +53 -73
  83. data/spec/support/controller_macros.rb +1 -3
  84. data/spec/support/db_setup.rb +31 -25
  85. data/spec/support/helpers.rb +12 -12
  86. data/spec/support/transactional_specs.rb +1 -3
  87. data/strongbolt.gemspec +14 -12
  88. metadata +20 -3
@@ -1,22 +1,20 @@
1
1
  module Strongbolt
2
2
  class UserGroup < Base
3
-
4
3
  has_many :user_groups_users,
5
- :class_name => "Strongbolt::UserGroupsUser",
6
- :dependent => :restrict_with_exception,
7
- :inverse_of => :user_group
8
- has_many :users, :through => :user_groups_users
4
+ class_name: 'Strongbolt::UserGroupsUser',
5
+ dependent: :restrict_with_exception,
6
+ inverse_of: :user_group
7
+ has_many :users, through: :user_groups_users
9
8
 
10
9
  has_many :roles_user_groups,
11
- :class_name => "Strongbolt::RolesUserGroup",
12
- :dependent => :delete_all,
13
- :inverse_of => :user_group
10
+ class_name: 'Strongbolt::RolesUserGroup',
11
+ dependent: :delete_all,
12
+ inverse_of: :user_group
14
13
 
15
- has_many :roles, :through => :roles_user_groups
14
+ has_many :roles, through: :roles_user_groups
16
15
 
17
16
  has_many :capabilities, through: :roles
18
17
 
19
18
  validates_presence_of :name
20
-
21
19
  end
22
20
  end
@@ -1,15 +1,15 @@
1
1
  module Strongbolt
2
2
  class UserGroupsUser < Base
3
- authorize_as "Strongbolt::UserGroup"
3
+ authorize_as 'Strongbolt::UserGroup'
4
4
 
5
5
  belongs_to :user_group,
6
- :class_name => "Strongbolt::UserGroup",
7
- :inverse_of => :user_groups_users
6
+ class_name: 'Strongbolt::UserGroup',
7
+ inverse_of: :user_groups_users
8
8
 
9
9
  belongs_to :user,
10
- :class_name => Configuration.user_class,
11
- :foreign_key => :user_id,
12
- :inverse_of => :user_groups_users
10
+ class_name: Configuration.user_class,
11
+ foreign_key: :user_id,
12
+ inverse_of: :user_groups_users
13
13
 
14
14
  validates_presence_of :user_group, :user
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module Strongbolt
2
- VERSION = "0.3.12"
2
+ VERSION = '0.3.13'.freeze
3
3
  end
@@ -2,7 +2,7 @@ namespace :strongbolt do
2
2
  #
3
3
  # Create full authorization roles that allows to get started using StrongBolt
4
4
  #
5
- task :seed => :environment do
5
+ task seed: :environment do
6
6
  ActiveRecord::Base.transaction do
7
7
  #
8
8
  # Creates capabilities for all models/actions
@@ -10,16 +10,16 @@ namespace :strongbolt do
10
10
  Strongbolt::Capability.models.each do |model|
11
11
  Strongbolt::Capability::Actions.each do |action|
12
12
  Strongbolt::Capability.where(model: model, action: action,
13
- require_tenant_access: false).first_or_create
13
+ require_tenant_access: false).first_or_create
14
14
  end
15
15
  end
16
16
 
17
17
  # The role
18
- role = Strongbolt::Role.create! name: "FULL ACCESS (TEMPORARY)"
18
+ role = Strongbolt::Role.create! name: 'FULL ACCESS (TEMPORARY)'
19
19
  role.capabilities = Strongbolt::Capability.all
20
20
 
21
21
  # The user group
22
- ug = Strongbolt::UserGroup.create! name: "FULL ACCESS USERS (TEMPORARY)"
22
+ ug = Strongbolt::UserGroup.create! name: 'FULL ACCESS USERS (TEMPORARY)'
23
23
  ug.roles << role
24
24
 
25
25
  # Assign to all users
@@ -1,16 +1,14 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module Strongbolt
4
-
5
4
  describe CapabilitiesController do
6
-
7
5
  subject { response }
8
6
 
9
7
  # #
10
8
  # # GET #index
11
9
  # #
12
10
  # describe "GET #index" do
13
-
11
+
14
12
  # before do
15
13
  # Fabricate :capability
16
14
  # get :index
@@ -27,7 +25,6 @@ module Strongbolt
27
25
 
28
26
  # end # End GET #index
29
27
 
30
-
31
28
  # #
32
29
  # # GET #show
33
30
  # #
@@ -48,10 +45,9 @@ module Strongbolt
48
45
  #
49
46
  # POST #create
50
47
  #
51
- describe "POST #create" do
52
-
48
+ describe 'POST #create' do
53
49
  let(:create) { post :create, capability: attributes }
54
-
50
+
55
51
  # context "when valid attributes" do
56
52
  # let(:attributes) { Fabricate.attributes_for :capability }
57
53
 
@@ -67,35 +63,34 @@ module Strongbolt
67
63
  # end
68
64
  # end
69
65
 
70
- context "when valid attributes and role id present" do
71
-
66
+ context 'when valid attributes and role id present' do
72
67
  let(:role) { Fabricate :role }
73
68
  let(:attributes) { Fabricate.attributes_for :capability }
74
69
 
75
- context "html" do
70
+ context 'html' do
76
71
  let(:create) { post :create, capability: attributes, role_id: role.id }
77
72
 
78
- it "should redirect to role" do
73
+ it 'should redirect to role' do
79
74
  create
80
75
  expect(response).to redirect_to role_path(role)
81
76
  end
82
77
 
83
- it "should add a capability to the role" do
78
+ it 'should add a capability to the role' do
84
79
  expect do
85
80
  create
86
81
  end.to change(role.capabilities, :count).by 1
87
82
  end
88
83
  end
89
84
 
90
- context "json" do |variable|
85
+ context 'json' do |_variable|
91
86
  let(:create) { post :create, capability: attributes, role_id: role.id, format: :json }
92
87
 
93
- it "should redirect to role" do
88
+ it 'should redirect to role' do
94
89
  create
95
- expect(response.code).to eq "200"
90
+ expect(response.code).to eq '200'
96
91
  end
97
92
 
98
- it "should add a capability to the role" do
93
+ it 'should add a capability to the role' do
99
94
  expect do
100
95
  create
101
96
  end.to change(role.capabilities, :count).by 1
@@ -129,16 +124,12 @@ module Strongbolt
129
124
  # expect(response).to redirect_to capabilities_path
130
125
  # end
131
126
  # end
132
-
133
127
  end # END POST #create
134
128
 
135
-
136
-
137
129
  #
138
130
  # DELETE #destroy
139
131
  #
140
- describe "DELETE #destroy" do
141
-
132
+ describe 'DELETE #destroy' do
142
133
  before do
143
134
  @capability = Fabricate :capability
144
135
  end
@@ -167,7 +158,7 @@ module Strongbolt
167
158
  # before do
168
159
  # capability.roles << Fabricate(:role)
169
160
  # end
170
-
161
+
171
162
  # it "should redirect to capabilities list" do
172
163
  # destroy
173
164
  # expect(response).to redirect_to capability_path(capability)
@@ -186,69 +177,61 @@ module Strongbolt
186
177
 
187
178
  # end
188
179
 
189
- context "when role_id given" do
180
+ context 'when role_id given' do
190
181
  let(:role) { Fabricate :role }
191
-
182
+
192
183
  before do
193
184
  role.capabilities << capability
194
185
  end
195
186
 
196
- context "when capability id given" do
197
-
187
+ context 'when capability id given' do
198
188
  let(:destroy) { delete :destroy, id: capability.id, role_id: role.id }
199
189
 
200
-
201
- it "should not delete a capability" do
190
+ it 'should not delete a capability' do
202
191
  expect do
203
192
  destroy
204
193
  end.not_to change(Capability, :count)
205
194
  end
206
195
 
207
- it "should remove the capability from role" do
196
+ it 'should remove the capability from role' do
208
197
  destroy
209
198
  role.reload
210
199
  expect(role.capabilities).not_to include capability
211
200
  end
212
201
 
213
- it "should redirect to role" do
202
+ it 'should redirect to role' do
214
203
  destroy
215
204
  expect(response).to redirect_to role_path(role)
216
205
  end
217
-
218
206
  end
219
207
 
220
- context "when capability data given and format json" do
208
+ context 'when capability data given and format json' do
221
209
  let(:attributes) do
222
- {model: capability.model, require_ownership: capability.require_ownership,
210
+ { model: capability.model, require_ownership: capability.require_ownership,
223
211
  require_tenant_access: capability.require_tenant_access,
224
- action: capability.action}
212
+ action: capability.action }
225
213
  end
226
214
 
227
215
  let(:destroy) { delete :destroy, role_id: role.id, capability: capability.attributes, format: :json }
228
216
 
229
- it "should not delete a capability" do
217
+ it 'should not delete a capability' do
230
218
  expect do
231
219
  destroy
232
220
  end.not_to change(Capability, :count)
233
221
  end
234
222
 
235
- it "should remove the capability from role" do
223
+ it 'should remove the capability from role' do
236
224
  destroy
237
225
  role.reload
238
226
  expect(role.capabilities).not_to include capability
239
227
  end
240
228
 
241
- it "should render 200" do
229
+ it 'should render 200' do
242
230
  destroy
243
- expect(response.code).to eq "200"
231
+ expect(response.code).to eq '200'
244
232
  end
245
233
  end
246
234
  end
247
-
248
-
249
235
  end
250
-
251
-
252
236
  end
253
-
254
- end
237
+ end
@@ -1,9 +1,7 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module Strongbolt
4
-
5
4
  describe RolesController do
6
-
7
5
  let!(:role) { Fabricate :role }
8
6
 
9
7
  let(:valid_attributes) { Fabricate.attributes_for :role }
@@ -15,214 +13,183 @@ module Strongbolt
15
13
  #
16
14
  # GET #index
17
15
  #
18
- describe "GET #index" do
19
-
16
+ describe 'GET #index' do
20
17
  before { get :index }
21
18
 
22
19
  it { should be_success }
23
20
 
24
21
  it { should render_template :index }
25
22
 
26
- it "should assign roles" do
27
- expect(assigns :roles).to eq [role]
23
+ it 'should assign roles' do
24
+ expect(assigns(:roles)).to eq [role]
28
25
  end
29
-
30
26
  end
31
27
 
32
28
  #
33
29
  # GET #new
34
30
  #
35
- describe "GET #new" do
36
-
31
+ describe 'GET #new' do
37
32
  before { get :new }
38
33
 
39
34
  it { should be_success }
40
35
 
41
36
  it { should render_template :new }
42
-
43
37
  end
44
38
 
45
-
46
39
  #
47
40
  # GET #show
48
41
  #
49
- describe "GET #show" do
50
-
42
+ describe 'GET #show' do
51
43
  # Some children
52
44
  let(:role2) { Fabricate :role, parent: role }
53
- let!(:role3) { Fabricate :role, parent: role2 }
54
-
45
+ let!(:role3) { Fabricate :role, parent: role2 }
46
+
55
47
  before { get :show, id: role.id }
56
48
 
57
49
  it { should be_success }
58
50
 
59
- it "should assign role" do
60
- expect(assigns :role).to eq role
51
+ it 'should assign role' do
52
+ expect(assigns(:role)).to eq role
61
53
  end
62
54
 
63
- it "should assign children" do
64
- expect(assigns :descendants).to eq [role2, role3]
55
+ it 'should assign children' do
56
+ expect(assigns(:descendants)).to eq [role2, role3]
65
57
  end
66
58
 
67
59
  it { should render_template :show }
68
-
69
60
  end
70
61
 
71
62
  #
72
63
  # GET #edit
73
64
  #
74
- describe "GET #edit" do
75
-
65
+ describe 'GET #edit' do
76
66
  before { get :edit, id: role.id }
77
67
 
78
68
  it { should be_success }
79
69
 
80
- it "should assign role" do
81
- expect(assigns :role).to eq role
70
+ it 'should assign role' do
71
+ expect(assigns(:role)).to eq role
82
72
  end
83
73
 
84
74
  it { should render_template :edit }
85
-
86
75
  end
87
76
 
88
77
  #
89
78
  # POST #create
90
79
  #
91
- describe "POST #create" do
92
-
80
+ describe 'POST #create' do
93
81
  let(:create) { post :create, role: attributes }
94
82
 
95
83
  context 'when valid attributes' do
96
-
97
84
  let(:attributes) { valid_attributes }
98
85
 
99
- it "should redirect to show" do
86
+ it 'should redirect to show' do
100
87
  create
101
88
  expect(response).to redirect_to role_path(Role.last)
102
89
  end
103
90
 
104
- it "should create an role" do
91
+ it 'should create an role' do
105
92
  expect do
106
93
  create
107
94
  end.to change(Role, :count).by 1
108
95
  end
109
-
110
96
  end
111
97
 
112
- context "when invalid attributes" do
113
-
98
+ context 'when invalid attributes' do
114
99
  let(:attributes) { {} }
115
100
 
116
- it "should redirect_to new" do
101
+ it 'should redirect_to new' do
117
102
  create
118
103
  expect(response).to redirect_to new_role_path
119
104
  end
120
105
 
121
- it "should not create a role" do
106
+ it 'should not create a role' do
122
107
  expect do
123
108
  create
124
109
  end.not_to change(Role, :count)
125
110
  end
126
111
 
127
- it "should set flash danger" do
112
+ it 'should set flash danger' do
128
113
  create
129
114
  expect(flash[:danger]).to be_present
130
115
  end
131
-
132
116
  end
133
-
134
117
  end
135
118
 
136
-
137
119
  #
138
120
  # PUT #update
139
121
  #
140
- describe "PUT #update" do
141
-
122
+ describe 'PUT #update' do
142
123
  before { put :update, id: role.id, role: attributes }
143
124
 
144
125
  context 'when valid attributes' do
145
-
146
126
  let(:attributes) { valid_attributes }
147
127
 
148
128
  it { should redirect_to role_path(role) }
149
129
 
150
- it "should update attributes" do
130
+ it 'should update attributes' do
151
131
  expect(role.reload.name).to eq valid_attributes[:name]
152
132
  end
153
-
154
133
  end
155
134
 
156
135
  context 'when invalid attributes' do
157
-
158
- let(:attributes) { {name: ""} }
136
+ let(:attributes) { { name: '' } }
159
137
 
160
138
  it { should redirect_to edit_role_path(role) }
161
139
 
162
- it "should not update attributes" do
163
- expect(role.reload.name).not_to eq ""
140
+ it 'should not update attributes' do
141
+ expect(role.reload.name).not_to eq ''
164
142
  end
165
143
 
166
- it "should set flash danger" do
144
+ it 'should set flash danger' do
167
145
  expect(flash[:danger]).to be_present
168
146
  end
169
-
170
147
  end
171
-
172
148
  end
173
149
 
174
-
175
150
  #
176
151
  # DELETE #destroy
177
152
  #
178
- describe "DELETE #destroy" do
179
-
153
+ describe 'DELETE #destroy' do
180
154
  let(:destroy) { delete :destroy, id: role.id }
181
155
 
182
- context "when no user" do
183
-
184
- it "should redirect to index" do
156
+ context 'when no user' do
157
+ it 'should redirect to index' do
185
158
  destroy
186
159
  expect(response).to redirect_to roles_path
187
160
  end
188
161
 
189
- it "should set flash success" do
162
+ it 'should set flash success' do
190
163
  destroy
191
164
  expect(flash[:success]).to be_present
192
165
  end
193
166
 
194
- it "should delete a role" do
167
+ it 'should delete a role' do
195
168
  expect do
196
169
  destroy
197
- end.to change(Role, :count).by -1
170
+ end.to change(Role, :count).by(-1)
198
171
  end
199
-
200
172
  end
201
173
 
202
- context "when has user groups" do
203
-
174
+ context 'when has user groups' do
204
175
  let(:role) { Fabricate :role_with_user_groups }
205
176
 
206
- it "should redirect to show" do
177
+ it 'should redirect to show' do
207
178
  destroy
208
179
  expect(response).to redirect_to role_path(role)
209
180
  end
210
181
 
211
- it "should set flash danger" do
182
+ it 'should set flash danger' do
212
183
  destroy
213
184
  expect(flash[:danger]).to be_present
214
185
  end
215
186
 
216
- it "should not delete a role" do
187
+ it 'should not delete a role' do
217
188
  expect do
218
189
  destroy
219
190
  end.not_to change(Role, :count)
220
191
  end
221
-
222
192
  end
223
-
224
193
  end
225
-
226
194
  end
227
-
228
- end
195
+ end