strongbolt 0.3.12 → 0.3.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +56 -0
- data/.rubocop_todo.yml +91 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +18 -2
- data/Rakefile +1 -1
- data/app/controllers/strongbolt/capabilities_controller.rb +36 -45
- data/app/controllers/strongbolt/roles_controller.rb +39 -47
- data/app/controllers/strongbolt/security_controller.rb +2 -3
- data/app/controllers/strongbolt/user_groups_controller.rb +48 -54
- data/app/controllers/strongbolt/user_groups_users_controller.rb +2 -4
- data/app/controllers/strongbolt_controller.rb +1 -1
- data/circle.yml +13 -0
- data/lib/generators/strongbolt/fix_generator.rb +5 -6
- data/lib/generators/strongbolt/fix_unique_group_members_generator.rb +2 -3
- data/lib/generators/strongbolt/indexes_generator.rb +3 -4
- data/lib/generators/strongbolt/install_generator.rb +8 -9
- data/lib/generators/strongbolt/templates/fix_unique_group_members.rb +1 -1
- data/lib/generators/strongbolt/templates/indexes.rb +1 -1
- data/lib/generators/strongbolt/templates/migration.rb +11 -12
- data/lib/generators/strongbolt/templates/strongbolt.rb +1 -1
- data/lib/generators/strongbolt/views_generator.rb +4 -4
- data/lib/strongbolt.rb +51 -54
- data/lib/strongbolt/base.rb +1 -1
- data/lib/strongbolt/bolted.rb +12 -13
- data/lib/strongbolt/bolted_controller.rb +46 -57
- data/lib/strongbolt/capabilities_role.rb +5 -5
- data/lib/strongbolt/capability.rb +32 -31
- data/lib/strongbolt/configuration.rb +18 -19
- data/lib/strongbolt/controllers/url_helpers.rb +5 -5
- data/lib/strongbolt/engine.rb +9 -9
- data/lib/strongbolt/errors.rb +4 -4
- data/lib/strongbolt/generators/migration.rb +4 -6
- data/lib/strongbolt/helpers.rb +5 -7
- data/lib/strongbolt/rails/routes.rb +4 -4
- data/lib/strongbolt/role.rb +11 -12
- data/lib/strongbolt/roles_user_group.rb +5 -5
- data/lib/strongbolt/rspec.rb +2 -2
- data/lib/strongbolt/rspec/user.rb +13 -15
- data/lib/strongbolt/tenantable.rb +78 -80
- data/lib/strongbolt/user_abilities.rb +44 -54
- data/lib/strongbolt/user_group.rb +8 -10
- data/lib/strongbolt/user_groups_user.rb +6 -6
- data/lib/strongbolt/version.rb +1 -1
- data/lib/tasks/strongbolt_tasks.rake +4 -4
- data/spec/controllers/strongbolt/capabilities_controller_spec.rb +28 -45
- data/spec/controllers/strongbolt/roles_controller_spec.rb +39 -72
- data/spec/controllers/strongbolt/user_groups_controller_spec.rb +34 -65
- data/spec/controllers/strongbolt/user_groups_users_controller_spec.rb +11 -19
- data/spec/controllers/without_authorization_controller_spec.rb +5 -5
- data/spec/dummy/app/controllers/posts_controller.rb +2 -2
- data/spec/dummy/app/controllers/test_controller.rb +1 -1
- data/spec/dummy/app/controllers/without_authorization_controller.rb +1 -1
- data/spec/dummy/bin/rails +1 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/config/application.rb +4 -5
- data/spec/dummy/config/initializers/cookies_serializer.rb +1 -1
- data/spec/dummy/config/initializers/strongbolt.rb +2 -2
- data/spec/dummy/config/routes.rb +1 -3
- data/spec/dummy/db/migrate/20150630212236_create_strongbolt_tables.rb +9 -10
- data/spec/dummy/db/migrate/20150630212251_create_strongbolt_tables_indexes.rb +2 -2
- data/spec/dummy/db/migrate/20160531110509_fix_unique_group_members.rb +1 -1
- data/spec/fabricators/capability_fabricator.rb +4 -4
- data/spec/fabricators/role_fabricator.rb +3 -3
- data/spec/fabricators/user_fabricator.rb +2 -2
- data/spec/fabricators/user_group_fabricator.rb +3 -3
- data/spec/fixtures/application.rb +6 -3
- data/spec/fixtures/controllers.rb +1 -1
- data/spec/spec_helper.rb +7 -8
- data/spec/strongbolt/bolted_controller_spec.rb +110 -208
- data/spec/strongbolt/bolted_spec.rb +26 -40
- data/spec/strongbolt/capability_spec.rb +72 -86
- data/spec/strongbolt/configuration_spec.rb +33 -46
- data/spec/strongbolt/controllers/url_helpers_spec.rb +7 -9
- data/spec/strongbolt/helpers_spec.rb +14 -16
- data/spec/strongbolt/role_spec.rb +32 -35
- data/spec/strongbolt/tenantable_spec.rb +88 -86
- data/spec/strongbolt/user_abilities_multiple_tenants_spec.rb +29 -34
- data/spec/strongbolt/user_abilities_spec.rb +142 -188
- data/spec/strongbolt/user_group_spec.rb +14 -14
- data/spec/strongbolt/users_tenant_spec.rb +10 -12
- data/spec/strongbolt_spec.rb +53 -73
- data/spec/support/controller_macros.rb +1 -3
- data/spec/support/db_setup.rb +31 -25
- data/spec/support/helpers.rb +12 -12
- data/spec/support/transactional_specs.rb +1 -3
- data/strongbolt.gemspec +14 -12
- metadata +20 -3
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Strongbolt
|
4
4
|
describe UserGroupsController do
|
5
|
-
|
6
5
|
let!(:user_group) { Fabricate :user_group }
|
7
6
|
|
8
7
|
let(:valid_attributes) { Fabricate.attributes_for :user_group }
|
@@ -12,205 +11,175 @@ module Strongbolt
|
|
12
11
|
#
|
13
12
|
# GET #index
|
14
13
|
#
|
15
|
-
describe
|
16
|
-
|
14
|
+
describe 'GET #index' do
|
17
15
|
before { get :index }
|
18
16
|
|
19
17
|
it { should be_success }
|
20
18
|
|
21
19
|
it { should render_template :index }
|
22
20
|
|
23
|
-
it
|
24
|
-
expect(assigns
|
21
|
+
it 'should assign user groups' do
|
22
|
+
expect(assigns(:user_groups)).to eq [user_group]
|
25
23
|
end
|
26
|
-
|
27
24
|
end
|
28
25
|
|
29
26
|
#
|
30
27
|
# GET #new
|
31
28
|
#
|
32
|
-
describe
|
33
|
-
|
29
|
+
describe 'GET #new' do
|
34
30
|
before { get :new }
|
35
31
|
|
36
32
|
it { should be_success }
|
37
33
|
|
38
34
|
it { should render_template :new }
|
39
|
-
|
40
35
|
end
|
41
36
|
|
42
|
-
|
43
37
|
#
|
44
38
|
# GET #show
|
45
39
|
#
|
46
|
-
describe
|
47
|
-
|
40
|
+
describe 'GET #show' do
|
48
41
|
before { get :show, id: user_group.id }
|
49
42
|
|
50
43
|
it { should be_success }
|
51
44
|
|
52
|
-
it
|
53
|
-
expect(assigns
|
45
|
+
it 'should assign user group' do
|
46
|
+
expect(assigns(:user_group)).to eq user_group
|
54
47
|
end
|
55
48
|
|
56
49
|
it { should render_template :show }
|
57
|
-
|
58
50
|
end
|
59
51
|
|
60
52
|
#
|
61
53
|
# GET #edit
|
62
54
|
#
|
63
|
-
describe
|
64
|
-
|
55
|
+
describe 'GET #edit' do
|
65
56
|
before { get :edit, id: user_group.id }
|
66
57
|
|
67
58
|
it { should be_success }
|
68
59
|
|
69
|
-
it
|
70
|
-
expect(assigns
|
60
|
+
it 'should assign user group' do
|
61
|
+
expect(assigns(:user_group)).to eq user_group
|
71
62
|
end
|
72
63
|
|
73
64
|
it { should render_template :edit }
|
74
|
-
|
75
65
|
end
|
76
66
|
|
77
67
|
#
|
78
68
|
# POST #create
|
79
69
|
#
|
80
|
-
describe
|
81
|
-
|
70
|
+
describe 'POST #create' do
|
82
71
|
let(:create) { post :create, user_group: attributes }
|
83
72
|
|
84
73
|
context 'when valid attributes' do
|
85
|
-
|
86
74
|
let(:attributes) { valid_attributes }
|
87
75
|
|
88
|
-
it
|
76
|
+
it 'should redirect to show' do
|
89
77
|
create
|
90
78
|
expect(response).to redirect_to user_group_path(UserGroup.last)
|
91
79
|
end
|
92
80
|
|
93
|
-
it
|
81
|
+
it 'should create an user group' do
|
94
82
|
expect do
|
95
83
|
create
|
96
84
|
end.to change(UserGroup, :count).by 1
|
97
85
|
end
|
98
|
-
|
99
86
|
end
|
100
87
|
|
101
|
-
context
|
102
|
-
|
88
|
+
context 'when invalid attributes' do
|
103
89
|
let(:attributes) { {} }
|
104
90
|
|
105
|
-
it
|
91
|
+
it 'should redirect_to new' do
|
106
92
|
create
|
107
93
|
expect(response).to redirect_to new_user_group_path
|
108
94
|
end
|
109
95
|
|
110
|
-
it
|
96
|
+
it 'should not create an user group' do
|
111
97
|
expect do
|
112
98
|
create
|
113
99
|
end.not_to change(UserGroup, :count)
|
114
100
|
end
|
115
101
|
|
116
|
-
it
|
102
|
+
it 'should set flash danger' do
|
117
103
|
create
|
118
104
|
expect(flash[:danger]).to be_present
|
119
105
|
end
|
120
|
-
|
121
106
|
end
|
122
|
-
|
123
107
|
end
|
124
108
|
|
125
|
-
|
126
109
|
#
|
127
110
|
# PUT #update
|
128
111
|
#
|
129
|
-
describe
|
130
|
-
|
112
|
+
describe 'PUT #update' do
|
131
113
|
before { put :update, id: user_group.id, user_group: attributes }
|
132
114
|
|
133
115
|
context 'when valid attributes' do
|
134
|
-
|
135
116
|
let(:attributes) { valid_attributes }
|
136
117
|
|
137
118
|
it { should redirect_to user_group_path(user_group) }
|
138
119
|
|
139
|
-
it
|
120
|
+
it 'should update attributes' do
|
140
121
|
expect(user_group.reload.name).to eq valid_attributes[:name]
|
141
122
|
end
|
142
|
-
|
143
123
|
end
|
144
124
|
|
145
125
|
context 'when invalid attributes' do
|
146
|
-
|
147
|
-
let(:attributes) { {name: ""} }
|
126
|
+
let(:attributes) { { name: '' } }
|
148
127
|
|
149
128
|
it { should redirect_to edit_user_group_path(user_group) }
|
150
129
|
|
151
|
-
it
|
152
|
-
expect(user_group.reload.name).not_to eq
|
130
|
+
it 'should not update attributes' do
|
131
|
+
expect(user_group.reload.name).not_to eq ''
|
153
132
|
end
|
154
133
|
|
155
|
-
it
|
134
|
+
it 'should set flash danger' do
|
156
135
|
expect(flash[:danger]).to be_present
|
157
136
|
end
|
158
|
-
|
159
137
|
end
|
160
|
-
|
161
138
|
end
|
162
139
|
|
163
|
-
|
164
140
|
#
|
165
141
|
# DELETE #destroy
|
166
142
|
#
|
167
|
-
describe
|
168
|
-
|
143
|
+
describe 'DELETE #destroy' do
|
169
144
|
let(:destroy) { delete :destroy, id: user_group.id }
|
170
145
|
|
171
|
-
context
|
172
|
-
|
173
|
-
it "should redirect to index" do
|
146
|
+
context 'when no user' do
|
147
|
+
it 'should redirect to index' do
|
174
148
|
destroy
|
175
149
|
expect(response).to redirect_to user_groups_path
|
176
150
|
end
|
177
151
|
|
178
|
-
it
|
152
|
+
it 'should set flash success' do
|
179
153
|
destroy
|
180
154
|
expect(flash[:success]).to be_present
|
181
155
|
end
|
182
156
|
|
183
|
-
it
|
157
|
+
it 'should delete a user group' do
|
184
158
|
expect do
|
185
159
|
destroy
|
186
|
-
end.to change(UserGroup, :count).by
|
160
|
+
end.to change(UserGroup, :count).by(-1)
|
187
161
|
end
|
188
|
-
|
189
162
|
end
|
190
163
|
|
191
|
-
context
|
192
|
-
|
164
|
+
context 'when has users' do
|
193
165
|
before { user_group.users << Fabricate(:user) }
|
194
166
|
|
195
|
-
it
|
167
|
+
it 'should redirect to show' do
|
196
168
|
destroy
|
197
169
|
expect(response).to redirect_to user_group_path(user_group)
|
198
170
|
end
|
199
171
|
|
200
|
-
it
|
172
|
+
it 'should set flash danger' do
|
201
173
|
destroy
|
202
174
|
expect(flash[:danger]).to be_present
|
203
175
|
end
|
204
176
|
|
205
|
-
it
|
177
|
+
it 'should not delete a user group' do
|
206
178
|
expect do
|
207
179
|
destroy
|
208
180
|
end.not_to change(UserGroup, :count)
|
209
181
|
end
|
210
|
-
|
211
182
|
end
|
212
|
-
|
213
183
|
end
|
214
|
-
|
215
184
|
end
|
216
|
-
end
|
185
|
+
end
|
@@ -1,8 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Strongbolt
|
4
4
|
describe UserGroupsUsersController do
|
5
|
-
|
6
5
|
let(:user_group) { Fabricate :user_group }
|
7
6
|
let(:user) { Fabricate :user }
|
8
7
|
|
@@ -11,39 +10,34 @@ module Strongbolt
|
|
11
10
|
#
|
12
11
|
# POST #create
|
13
12
|
#
|
14
|
-
describe
|
15
|
-
|
16
|
-
context "when valid user group and user" do
|
17
|
-
|
13
|
+
describe 'POST #create' do
|
14
|
+
context 'when valid user group and user' do
|
18
15
|
before { post :create, user_group_id: user_group.id, id: user.id }
|
19
16
|
|
20
17
|
it { should redirect_to user_group_path(user_group) }
|
21
18
|
|
22
|
-
it
|
19
|
+
it 'should have add user to group' do
|
23
20
|
user_group.reload
|
24
21
|
expect(user_group.users).to include user
|
25
22
|
end
|
26
23
|
|
27
|
-
context
|
24
|
+
context 'when redoing' do
|
28
25
|
before { post :create, user_group_id: user_group.id, id: user.id }
|
29
26
|
|
30
27
|
it { should redirect_to user_group_path(user_group) }
|
31
28
|
|
32
|
-
it
|
29
|
+
it 'should not have added it twice' do
|
33
30
|
expect(user_group.users.count).to eq 1
|
34
31
|
end
|
35
32
|
end
|
36
|
-
|
37
33
|
end
|
38
|
-
|
39
34
|
end
|
40
35
|
|
41
36
|
#
|
42
37
|
# DELETE #destroy
|
43
38
|
#
|
44
|
-
describe
|
45
|
-
context
|
46
|
-
|
39
|
+
describe 'DELETE #destroy' do
|
40
|
+
context 'when valid user group and user' do
|
47
41
|
before do
|
48
42
|
user_group.users << user
|
49
43
|
delete :destroy, user_group_id: user_group.id, id: user.id
|
@@ -51,19 +45,17 @@ module Strongbolt
|
|
51
45
|
|
52
46
|
it { should redirect_to user_group_path(user_group) }
|
53
47
|
|
54
|
-
it
|
48
|
+
it 'should have removed user' do
|
55
49
|
user_group.reload
|
56
50
|
expect(user_group.users).not_to include user
|
57
51
|
end
|
58
52
|
|
59
|
-
context
|
53
|
+
context 'when redoing' do
|
60
54
|
before { delete :destroy, user_group_id: user_group.id, id: user.id }
|
61
55
|
|
62
56
|
it { should redirect_to user_group_path(user_group) }
|
63
57
|
end
|
64
|
-
|
65
58
|
end
|
66
59
|
end
|
67
|
-
|
68
60
|
end
|
69
|
-
end
|
61
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WithoutAuthorizationController do
|
4
4
|
before do
|
@@ -7,14 +7,14 @@ describe WithoutAuthorizationController do
|
|
7
7
|
.and_return User.new
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
11
|
-
it
|
10
|
+
describe 'GET #show' do
|
11
|
+
it 'should not raise error' do
|
12
12
|
expect { get :show }.not_to raise_error
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'should be success' do
|
16
16
|
get :show
|
17
17
|
expect(response).to be_success
|
18
18
|
end
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# We create the controller we'll be using in our tests
|
3
3
|
#
|
4
|
-
RESTFUL_ACTIONS = [
|
4
|
+
RESTFUL_ACTIONS = %i[index show new create update edit destroy].freeze
|
5
5
|
|
6
6
|
class PostsController < TestController
|
7
7
|
include Strongbolt::BoltedController
|
@@ -15,4 +15,4 @@ class PostsController < TestController
|
|
15
15
|
def custom; end
|
16
16
|
|
17
17
|
def current_user; end
|
18
|
-
end
|
18
|
+
end
|
data/spec/dummy/bin/rails
CHANGED
data/spec/dummy/config.ru
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
2
|
|
3
3
|
# Pick the frameworks you want:
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require 'active_record/railtie'
|
5
|
+
require 'action_controller/railtie'
|
6
6
|
# require "action_mailer/railtie"
|
7
|
-
require
|
7
|
+
require 'action_view/railtie'
|
8
8
|
# require "sprockets/railtie"
|
9
9
|
# require "rails/test_unit/railtie"
|
10
10
|
|
11
11
|
Bundler.require(*Rails.groups)
|
12
|
-
require
|
12
|
+
require 'strongbolt'
|
13
13
|
|
14
14
|
module Dummy
|
15
15
|
class Application < Rails::Application
|
@@ -26,4 +26,3 @@ module Dummy
|
|
26
26
|
# config.i18n.default_locale = :de
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
@@ -28,5 +28,5 @@ Strongbolt.setup do |config|
|
|
28
28
|
#
|
29
29
|
# config.models = 'HABTM_Roles', 'HABTM_UserGroups', 'HABTM_Capabilities', 'HABTM_Users', 'HABTM_Roles'
|
30
30
|
|
31
|
-
config.skip_controller_authorization_for
|
32
|
-
end
|
31
|
+
config.skip_controller_authorization_for 'without_authorization'
|
32
|
+
end
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
|
3
2
|
strongbolt
|
4
3
|
|
5
4
|
resources :posts do
|
@@ -7,6 +6,5 @@ Rails.application.routes.draw do
|
|
7
6
|
end
|
8
7
|
resources :welcome
|
9
8
|
|
10
|
-
get
|
11
|
-
|
9
|
+
get 'without_authorization' => 'without_authorization#show'
|
12
10
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
class CreateStrongboltTables < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table :strongbolt_capabilities, :
|
3
|
+
create_table :strongbolt_capabilities, force: true do |t|
|
4
4
|
t.string :name
|
5
5
|
t.string :description
|
6
6
|
t.string :model
|
7
7
|
t.string :action
|
8
8
|
t.string :attr
|
9
|
-
t.boolean :require_ownership, :
|
10
|
-
t.boolean :require_tenant_access, :
|
9
|
+
t.boolean :require_ownership, default: false, null: false
|
10
|
+
t.boolean :require_tenant_access, default: true, null: false
|
11
11
|
|
12
12
|
t.timestamps
|
13
13
|
end
|
14
14
|
|
15
|
-
create_table :strongbolt_roles, :
|
15
|
+
create_table :strongbolt_roles, force: true do |t|
|
16
16
|
t.string :name
|
17
17
|
t.integer :parent_id
|
18
18
|
t.integer :lft
|
@@ -22,33 +22,32 @@ class CreateStrongboltTables < ActiveRecord::Migration
|
|
22
22
|
t.timestamps
|
23
23
|
end
|
24
24
|
|
25
|
-
create_table :strongbolt_user_groups, :
|
25
|
+
create_table :strongbolt_user_groups, force: true do |t|
|
26
26
|
t.string :name
|
27
27
|
t.text :description
|
28
28
|
|
29
29
|
t.timestamps
|
30
30
|
end
|
31
31
|
|
32
|
-
create_table :strongbolt_user_groups_users, :
|
32
|
+
create_table :strongbolt_user_groups_users, id: false, force: true do |t|
|
33
33
|
t.integer :user_group_id
|
34
34
|
t.integer :user_id
|
35
35
|
end
|
36
36
|
|
37
|
-
create_table :strongbolt_roles_user_groups, :
|
37
|
+
create_table :strongbolt_roles_user_groups, id: false, force: true do |t|
|
38
38
|
t.integer :user_group_id
|
39
39
|
t.integer :role_id
|
40
40
|
end
|
41
41
|
|
42
|
-
create_table :strongbolt_capabilities_roles, :
|
42
|
+
create_table :strongbolt_capabilities_roles, id: false, force: true do |t|
|
43
43
|
t.integer :role_id
|
44
44
|
t.integer :capability_id
|
45
45
|
end
|
46
46
|
|
47
|
-
create_table :strongbolt_users_tenants, :
|
47
|
+
create_table :strongbolt_users_tenants, force: true do |t|
|
48
48
|
t.integer :user_id
|
49
49
|
t.integer :tenant_id
|
50
50
|
t.string :type
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|