strongbolt 0.3.12 → 0.3.13

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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 "GET #index" do
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 "should assign user groups" do
24
- expect(assigns :user_groups).to eq [user_group]
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 "GET #new" do
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 "GET #show" do
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 "should assign user group" do
53
- expect(assigns :user_group).to eq user_group
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 "GET #edit" do
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 "should assign user group" do
70
- expect(assigns :user_group).to eq user_group
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 "POST #create" do
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 "should redirect to show" do
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 "should create an user group" do
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 "when invalid attributes" do
102
-
88
+ context 'when invalid attributes' do
103
89
  let(:attributes) { {} }
104
90
 
105
- it "should redirect_to new" do
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 "should not create an user group" do
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 "should set flash danger" do
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 "PUT #update" do
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 "should update attributes" do
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 "should not update attributes" do
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 "should set flash danger" do
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 "DELETE #destroy" do
168
-
143
+ describe 'DELETE #destroy' do
169
144
  let(:destroy) { delete :destroy, id: user_group.id }
170
145
 
171
- context "when no user" do
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 "should set flash success" do
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 "should delete a user group" do
157
+ it 'should delete a user group' do
184
158
  expect do
185
159
  destroy
186
- end.to change(UserGroup, :count).by -1
160
+ end.to change(UserGroup, :count).by(-1)
187
161
  end
188
-
189
162
  end
190
163
 
191
- context "when has users" do
192
-
164
+ context 'when has users' do
193
165
  before { user_group.users << Fabricate(:user) }
194
166
 
195
- it "should redirect to show" do
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 "should set flash danger" do
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 "should not delete a user group" do
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 "spec_helper"
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 "POST #create" do
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 "should have add user to group" do
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 "when redoing" do
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 "should not have added it twice" do
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 "DELETE #destroy" do
45
- context "when valid user group and user" do
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 "should have removed user" do
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 "when redoing" do
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 "spec_helper"
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 "GET #show" do
11
- it "should not raise error" do
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 "should be success" do
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 = [:index, :show, :new, :create, :update, :edit, :destroy]
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
@@ -1,3 +1,3 @@
1
1
  class TestController < ActionController::Base
2
2
  def render(*attributes); end
3
- end
3
+ end
@@ -2,4 +2,4 @@ class WithoutAuthorizationController < ApplicationController
2
2
  def show
3
3
  head :ok
4
4
  end
5
- end
5
+ end
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
3
  require_relative '../config/boot'
4
4
  require 'rails/commands'
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
4
  run Rails.application
@@ -1,15 +1,15 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
3
  # Pick the frameworks you want:
4
- require "active_record/railtie"
5
- require "action_controller/railtie"
4
+ require 'active_record/railtie'
5
+ require 'action_controller/railtie'
6
6
  # require "action_mailer/railtie"
7
- require "action_view/railtie"
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 "strongbolt"
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
-
@@ -1,3 +1,3 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Rails.application.config.action_dispatch.cookies_serializer = :json
3
+ Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -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 "without_authorization"
32
- end
31
+ config.skip_controller_authorization_for 'without_authorization'
32
+ end
@@ -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 "without_authorization" => "without_authorization#show"
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, :force => true do |t|
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, :default => false, :null => false
10
- t.boolean :require_tenant_access, :default => true, :null => false
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, :force => true do |t|
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, :force => true do |t|
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, :id => false, :force => true do |t|
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, :id => false, :force => true do |t|
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, :id => false, :force => true do |t|
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, :force => true do |t|
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
-