g5_authenticatable 0.9.1.pre.2 → 1.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +23 -9
- data/Appraisals +17 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +11 -14
- data/README.md +40 -13
- data/app/controllers/concerns/g5_authenticatable/authorization.rb +4 -1
- data/app/controllers/g5_authenticatable/application_controller.rb +3 -0
- data/app/controllers/g5_authenticatable/error_controller.rb +3 -2
- data/app/controllers/g5_authenticatable/failure_app.rb +35 -0
- data/app/controllers/g5_authenticatable/sessions_controller.rb +7 -3
- data/app/helpers/g5_authenticatable/application_helper.rb +3 -0
- data/app/models/g5_authenticatable/role.rb +5 -2
- data/app/models/g5_authenticatable/user.rb +12 -5
- data/app/policies/g5_authenticatable/base_policy.rb +75 -58
- data/app/policies/g5_updatable/client_policy.rb +5 -5
- data/app/policies/g5_updatable/location_policy.rb +6 -5
- data/app/policies/g5_updatable/selectable_client_policy.rb +6 -7
- data/app/services/g5_authenticatable/impersonate_sessionable.rb +12 -7
- data/config/initializers/devise.rb +4 -0
- data/config/initializers/impersonate_strategy.rb +5 -2
- data/config/initializers/rolify.rb +2 -0
- data/config/routes.rb +3 -1
- data/g5_authenticatable.gemspec +11 -7
- data/gemfiles/rails_4.1.gemfile +28 -0
- data/gemfiles/rails_4.2.gemfile +28 -0
- data/gemfiles/rails_5.0.gemfile +28 -0
- data/gemfiles/rails_5.1.gemfile +28 -0
- data/lib/g5_authenticatable.rb +3 -1
- data/lib/g5_authenticatable/engine.rb +5 -2
- data/lib/g5_authenticatable/rspec.rb +2 -0
- data/lib/g5_authenticatable/test/controller_helpers.rb +14 -9
- data/lib/g5_authenticatable/test/env_helpers.rb +3 -0
- data/lib/g5_authenticatable/test/factories/client_users.rb +45 -0
- data/lib/g5_authenticatable/test/factories/global_users.rb +43 -0
- data/lib/g5_authenticatable/test/factories/location_users.rb +45 -0
- data/lib/g5_authenticatable/test/factories/roles.rb +63 -0
- data/lib/g5_authenticatable/test/factory.rb +7 -59
- data/lib/g5_authenticatable/test/feature_helpers.rb +31 -17
- data/lib/g5_authenticatable/test/request_helpers.rb +5 -1
- data/lib/g5_authenticatable/test/token_validation_helpers.rb +15 -10
- data/lib/g5_authenticatable/version.rb +3 -1
- data/lib/generators/g5_authenticatable/install/install_generator.rb +49 -37
- data/lib/generators/g5_authenticatable/install/templates/application_policy.rb +2 -0
- data/lib/generators/g5_authenticatable/install/templates/initializer.rb +2 -0
- data/lib/generators/g5_authenticatable/install/templates/migrate/add_g5_authenticatable_users_contact_info.rb +3 -1
- data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_roles.rb +3 -1
- data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_users.rb +3 -1
- data/lib/tasks/g5_authenticatable/purge_users.rake +2 -0
- data/spec/config/application_spec.rb +7 -4
- data/spec/controllers/application_controller_spec.rb +10 -5
- data/spec/controllers/concerns/g5_authenticatable/{authorization.rb → authorization_spec.rb} +11 -6
- data/spec/dummy/app/controllers/home_controller.rb +5 -5
- data/spec/dummy/app/controllers/rails_api/secure_resources_controller.rb +6 -4
- data/spec/dummy/app/models/post.rb +1 -1
- data/spec/dummy/config/environments/test.rb +25 -4
- data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
- data/spec/dummy/db/migrate/20140206070137_create_g5_authenticatable_users.rb +3 -1
- data/spec/dummy/db/migrate/20150428182339_add_g5_authenticatable_users_contact_info.rb +3 -1
- data/spec/dummy/db/migrate/20150429212919_create_g5_authenticatable_roles.rb +2 -1
- data/spec/dummy/db/migrate/20150509061150_create_posts.rb +3 -1
- data/spec/dummy/db/migrate/20150603224032_create_g5_updatable_clients_and_locations.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224033_create_integration_setting.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224034_remove_integration_setting.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224035_add_name_to_clients_and_locations.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20150603224036_update_names.g5_updatable.rb +3 -1
- data/spec/dummy/db/migrate/20170613201430_add_latitude_and_longitude_to_location.g5_updatable.rb +7 -0
- data/spec/dummy/db/migrate/20170613201431_copy_lat_long_props_to_lat_long_columns.g5_updatable.rb +20 -0
- data/spec/dummy/db/migrate/20170613201432_add_latitude_longitude_indexes_to_location.g5_updatable.rb +7 -0
- data/spec/dummy/db/migrate/{20161122070749_add_amenities.rb → 20170613201433_add_amenities.g5_updatable.rb} +2 -1
- data/spec/dummy/db/migrate/{20161209070749_add_client_urn_to_locations.rb → 20170613201434_add_client_urn_to_locations.g5_updatable.rb} +2 -1
- data/spec/dummy/db/migrate/20170613201435_add_points_of_interest.g5_updatable.rb +21 -0
- data/spec/dummy/db/migrate/20170613201436_add_unique_urn_indexes.g5_updatable.rb +11 -0
- data/spec/dummy/db/schema.rb +73 -61
- data/spec/factories/post.rb +2 -0
- data/spec/features/auth_error_path_spec.rb +3 -3
- data/spec/features/default_role_authorization_spec.rb +8 -4
- data/spec/features/sign_in_spec.rb +23 -13
- data/spec/features/token_validation_spec.rb +4 -2
- data/spec/g5_authenticatable/version_spec.rb +3 -1
- data/spec/lib/generators/g5_authenticatable/install_generator_spec.rb +73 -28
- data/spec/models/g5_authenticatable/role_spec.rb +8 -4
- data/spec/models/g5_authenticatable/user_spec.rb +119 -84
- data/spec/models/post_spec.rb +4 -2
- data/spec/policies/application_policy_spec.rb +80 -47
- data/spec/policies/client_policy_spec.rb +8 -5
- data/spec/policies/location_policy_spec.rb +21 -8
- data/spec/policies/selectable_client_policy_spec.rb +26 -15
- data/spec/rails_helper.rb +41 -0
- data/spec/requests/default_role_authorization_spec.rb +18 -14
- data/spec/requests/grape_api_spec.rb +7 -5
- data/spec/requests/rails_api_spec.rb +11 -9
- data/spec/requests/sign_out_spec.rb +10 -6
- data/spec/requests/token_validation_spec.rb +9 -5
- data/spec/routing/auth_error_routing_spec.rb +7 -6
- data/spec/routing/sign_out_routing_spec.rb +7 -5
- data/spec/services/g5_authenticatable/impersonate_sessionable_spec.rb +41 -18
- data/spec/spec_helper.rb +78 -45
- data/spec/support/devise.rb +3 -1
- data/spec/support/safe_request_helpers.rb +36 -0
- data/spec/support/shared_contexts/rake.rb +10 -4
- data/spec/support/shared_examples/super_admin_authorizer.rb +3 -1
- data/spec/tasks/purge_users_spec.rb +3 -1
- metadata +75 -39
- data/spec/controllers/.gitkeep +0 -0
data/spec/models/post_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe ApplicationPolicy do
|
4
6
|
subject(:policy) { described_class }
|
5
7
|
|
6
8
|
let(:user) { FactoryGirl.create(:g5_authenticatable_user) }
|
@@ -15,24 +17,18 @@ describe ApplicationPolicy do
|
|
15
17
|
let(:user) { FactoryGirl.create(:g5_authenticatable_super_admin) }
|
16
18
|
|
17
19
|
context 'when record exists in scope' do
|
18
|
-
it
|
19
|
-
expect(policy).to permit(user, record)
|
20
|
-
end
|
20
|
+
it { is_expected.to permit(user, record) }
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'when record does not exist in scope' do
|
24
24
|
let(:record) { FactoryGirl.build(:post) }
|
25
25
|
|
26
|
-
it
|
27
|
-
expect(policy).to_not permit(user, record)
|
28
|
-
end
|
26
|
+
it { is_expected.to_not permit(user, record) }
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
32
30
|
context 'when user is not a super_admin' do
|
33
|
-
it
|
34
|
-
expect(policy).to_not permit(user, record)
|
35
|
-
end
|
31
|
+
it { is_expected.to_not permit(user, record) }
|
36
32
|
end
|
37
33
|
end
|
38
34
|
|
@@ -71,23 +67,17 @@ describe ApplicationPolicy do
|
|
71
67
|
context 'when there is no user' do
|
72
68
|
let(:user) {}
|
73
69
|
|
74
|
-
it
|
75
|
-
expect(super_admin?).to eq(false)
|
76
|
-
end
|
70
|
+
it { is_expected.to eq(false) }
|
77
71
|
end
|
78
72
|
|
79
73
|
context 'when user does not have super_admin role' do
|
80
|
-
it
|
81
|
-
expect(super_admin?).to eq(false)
|
82
|
-
end
|
74
|
+
it { is_expected.to eq(false) }
|
83
75
|
end
|
84
76
|
|
85
77
|
context 'when user has the super_admin role' do
|
86
78
|
let(:user) { FactoryGirl.create(:g5_authenticatable_super_admin) }
|
87
79
|
|
88
|
-
it
|
89
|
-
expect(super_admin?).to eq(true)
|
90
|
-
end
|
80
|
+
it { is_expected.to eq(true) }
|
91
81
|
end
|
92
82
|
end
|
93
83
|
|
@@ -97,23 +87,17 @@ describe ApplicationPolicy do
|
|
97
87
|
context 'when there is no user' do
|
98
88
|
let(:user) {}
|
99
89
|
|
100
|
-
it
|
101
|
-
expect(admin?).to eq(false)
|
102
|
-
end
|
90
|
+
it { is_expected.to eq(false) }
|
103
91
|
end
|
104
92
|
|
105
93
|
context 'when user does not have admin role' do
|
106
|
-
it
|
107
|
-
expect(admin?).to eq(false)
|
108
|
-
end
|
94
|
+
it { is_expected.to eq(false) }
|
109
95
|
end
|
110
96
|
|
111
97
|
context 'when user has the admin role' do
|
112
98
|
let(:user) { FactoryGirl.create(:g5_authenticatable_admin) }
|
113
99
|
|
114
|
-
it
|
115
|
-
expect(admin?).to eq(true)
|
116
|
-
end
|
100
|
+
it { is_expected.to eq(true) }
|
117
101
|
end
|
118
102
|
end
|
119
103
|
|
@@ -123,23 +107,17 @@ describe ApplicationPolicy do
|
|
123
107
|
context 'when there is no user' do
|
124
108
|
let(:user) {}
|
125
109
|
|
126
|
-
it
|
127
|
-
expect(editor?).to eq(false)
|
128
|
-
end
|
110
|
+
it { is_expected.to eq(false) }
|
129
111
|
end
|
130
112
|
|
131
113
|
context 'when user does not have editor role' do
|
132
|
-
it
|
133
|
-
expect(editor?).to eq(false)
|
134
|
-
end
|
114
|
+
it { is_expected.to eq(false) }
|
135
115
|
end
|
136
116
|
|
137
117
|
context 'when user has the editor role' do
|
138
118
|
let(:user) { FactoryGirl.create(:g5_authenticatable_editor) }
|
139
119
|
|
140
|
-
it
|
141
|
-
expect(editor?).to eq(true)
|
142
|
-
end
|
120
|
+
it { is_expected.to eq(true) }
|
143
121
|
end
|
144
122
|
end
|
145
123
|
|
@@ -149,23 +127,78 @@ describe ApplicationPolicy do
|
|
149
127
|
context 'when there is no user' do
|
150
128
|
let(:user) {}
|
151
129
|
|
152
|
-
it
|
153
|
-
expect(viewer?).to eq(false)
|
154
|
-
end
|
130
|
+
it { is_expected.to eq(false) }
|
155
131
|
end
|
156
132
|
|
157
133
|
context 'when user does not have viewer role' do
|
158
134
|
let(:user) { FactoryGirl.create(:g5_authenticatable_editor) }
|
159
135
|
|
160
|
-
it
|
161
|
-
expect(viewer?).to eq(false)
|
162
|
-
end
|
136
|
+
it { is_expected.to eq(false) }
|
163
137
|
end
|
164
138
|
|
165
139
|
context 'when user has the viewer role' do
|
166
|
-
|
167
|
-
|
168
|
-
|
140
|
+
let(:user) { FactoryGirl.create(:g5_authenticatable_viewer) }
|
141
|
+
|
142
|
+
it { is_expected.to eq(true) }
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe '#global_role?' do
|
147
|
+
subject(:global_role?) { policy.new(user, record).global_role? }
|
148
|
+
|
149
|
+
let(:scoped_role) do
|
150
|
+
FactoryGirl.create(:g5_authenticatable_role, name: role_name,
|
151
|
+
resource: resource)
|
152
|
+
end
|
153
|
+
let(:resource) { FactoryGirl.create(:g5_updatable_client) }
|
154
|
+
|
155
|
+
context 'when there is no user' do
|
156
|
+
it { is_expected.to eq(false) }
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'when the user is a global super admin' do
|
160
|
+
let(:user) { FactoryGirl.create(:g5_authenticatable_super_admin) }
|
161
|
+
|
162
|
+
it { is_expected.to eq(true) }
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when the user is a global admin' do
|
166
|
+
let(:user) { FactoryGirl.create(:g5_authenticatable_admin) }
|
167
|
+
|
168
|
+
it { is_expected.to eq(true) }
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'when the user is a global editor' do
|
172
|
+
let(:user) { FactoryGirl.create(:g5_authenticatable_editor) }
|
173
|
+
|
174
|
+
it { is_expected.to eq(true) }
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'when the user is a global viewer' do
|
178
|
+
let(:user) { FactoryGirl.create(:g5_authenticatable_viewer) }
|
179
|
+
|
180
|
+
it { is_expected.to eq(true) }
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'when user is a scoped admin' do
|
184
|
+
let(:role_name) { :admin }
|
185
|
+
before { user.roles << scoped_role }
|
186
|
+
|
187
|
+
it { is_expected.to eq(false) }
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'when user is a scoped editor' do
|
191
|
+
let(:role_name) { :editor }
|
192
|
+
before { user.roles << scoped_role }
|
193
|
+
|
194
|
+
it { is_expected.to eq(false) }
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'when user is a scoped viewer' do
|
198
|
+
let(:role_name) { :viewer }
|
199
|
+
before { user.roles << scoped_role }
|
200
|
+
|
201
|
+
it { is_expected.to eq(false) }
|
169
202
|
end
|
170
203
|
end
|
171
204
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe G5Updatable::ClientPolicy do
|
4
6
|
subject(:policy) { described_class }
|
5
7
|
|
6
8
|
let(:user) { FactoryGirl.create(:g5_authenticatable_user) }
|
@@ -17,8 +19,9 @@ describe G5Updatable::ClientPolicy do
|
|
17
19
|
let!(:client_3) { FactoryGirl.create(:g5_updatable_client) }
|
18
20
|
|
19
21
|
describe '.resolve' do
|
20
|
-
|
21
|
-
|
22
|
+
subject do
|
23
|
+
G5Updatable::ClientPolicy::Scope.new(user, G5Updatable::Client).resolve
|
24
|
+
end
|
22
25
|
|
23
26
|
context 'with global role' do
|
24
27
|
before { user.add_role :admin }
|
@@ -38,7 +41,7 @@ describe G5Updatable::ClientPolicy do
|
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
41
|
-
context 'with many client roles'
|
44
|
+
context 'with many client roles' do
|
42
45
|
before do
|
43
46
|
user.add_role(:admin, client_1)
|
44
47
|
user.add_role(:admin, client_2)
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe G5Updatable::LocationPolicy do
|
4
6
|
subject(:policy) { described_class }
|
5
7
|
|
6
8
|
let(:user) { FactoryGirl.create(:g5_authenticatable_user) }
|
@@ -9,11 +11,19 @@ describe G5Updatable::LocationPolicy do
|
|
9
11
|
let!(:client_1) { FactoryGirl.create(:g5_updatable_client) }
|
10
12
|
let!(:client_2) { FactoryGirl.create(:g5_updatable_client) }
|
11
13
|
|
12
|
-
let!(:location_1)
|
13
|
-
|
14
|
+
let!(:location_1) do
|
15
|
+
FactoryGirl.create(:g5_updatable_location, client: client_1)
|
16
|
+
end
|
17
|
+
let!(:location_2) do
|
18
|
+
FactoryGirl.create(:g5_updatable_location, client: client_1)
|
19
|
+
end
|
14
20
|
|
15
|
-
let!(:location_3)
|
16
|
-
|
21
|
+
let!(:location_3) do
|
22
|
+
FactoryGirl.create(:g5_updatable_location, client: client_2)
|
23
|
+
end
|
24
|
+
let!(:location_4) do
|
25
|
+
FactoryGirl.create(:g5_updatable_location, client: client_2)
|
26
|
+
end
|
17
27
|
|
18
28
|
before do
|
19
29
|
user.roles = []
|
@@ -22,7 +32,10 @@ describe G5Updatable::LocationPolicy do
|
|
22
32
|
end
|
23
33
|
|
24
34
|
describe '.resolve' do
|
25
|
-
subject
|
35
|
+
subject do
|
36
|
+
G5Updatable::LocationPolicy::Scope.new(user, G5Updatable::Location)
|
37
|
+
.resolve
|
38
|
+
end
|
26
39
|
|
27
40
|
context 'with global role' do
|
28
41
|
before { user.add_role :admin }
|
@@ -42,7 +55,7 @@ describe G5Updatable::LocationPolicy do
|
|
42
55
|
end
|
43
56
|
end
|
44
57
|
|
45
|
-
context 'with many client roles'
|
58
|
+
context 'with many client roles' do
|
46
59
|
before do
|
47
60
|
user.add_role(:admin, location_1)
|
48
61
|
user.add_role(:admin, location_2)
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe G5Updatable::SelectableClientPolicy do
|
4
6
|
subject(:policy) { described_class }
|
5
7
|
|
6
8
|
let(:user) { FactoryGirl.create(:g5_authenticatable_user) }
|
@@ -17,13 +19,24 @@ describe G5Updatable::SelectableClientPolicy do
|
|
17
19
|
let!(:client_3) { FactoryGirl.create(:g5_updatable_client) }
|
18
20
|
|
19
21
|
describe '.resolve' do
|
20
|
-
subject
|
22
|
+
subject do
|
23
|
+
G5Updatable::SelectableClientPolicy::Scope.new(user, G5Updatable::Client)
|
24
|
+
.resolve
|
25
|
+
end
|
21
26
|
|
22
|
-
let!(:location_1)
|
23
|
-
|
27
|
+
let!(:location_1) do
|
28
|
+
FactoryGirl.create(:g5_updatable_location, client: client_1)
|
29
|
+
end
|
30
|
+
let!(:location_2) do
|
31
|
+
FactoryGirl.create(:g5_updatable_location, client: client_1)
|
32
|
+
end
|
24
33
|
|
25
|
-
let!(:location_3)
|
26
|
-
|
34
|
+
let!(:location_3) do
|
35
|
+
FactoryGirl.create(:g5_updatable_location, client: client_2)
|
36
|
+
end
|
37
|
+
let!(:location_4) do
|
38
|
+
FactoryGirl.create(:g5_updatable_location, client: client_2)
|
39
|
+
end
|
27
40
|
|
28
41
|
context 'with global role' do
|
29
42
|
before { user.add_role :admin }
|
@@ -46,11 +59,12 @@ describe G5Updatable::SelectableClientPolicy do
|
|
46
59
|
end
|
47
60
|
end
|
48
61
|
|
49
|
-
context 'with role for location and client
|
62
|
+
context 'with role for location and unrelated client' do
|
50
63
|
before do
|
51
64
|
user.add_role :admin, location_1
|
52
65
|
user.add_role :admin, client_2
|
53
66
|
end
|
67
|
+
|
54
68
|
it 'returns 1 client' do
|
55
69
|
expect(subject.length).to eq(2)
|
56
70
|
expect(subject).to include(client_1)
|
@@ -59,9 +73,8 @@ describe G5Updatable::SelectableClientPolicy do
|
|
59
73
|
end
|
60
74
|
|
61
75
|
context 'with a client role' do
|
62
|
-
before
|
63
|
-
|
64
|
-
end
|
76
|
+
before { user.add_role :admin, client_2 }
|
77
|
+
|
65
78
|
it 'returns 1 client' do
|
66
79
|
expect(subject.length).to eq(1)
|
67
80
|
expect(subject).to include(client_2)
|
@@ -69,14 +82,12 @@ describe G5Updatable::SelectableClientPolicy do
|
|
69
82
|
end
|
70
83
|
|
71
84
|
context 'with a location role' do
|
72
|
-
before
|
73
|
-
|
74
|
-
end
|
85
|
+
before { user.add_role :admin, location_1 }
|
86
|
+
|
75
87
|
it 'returns 1 client' do
|
76
88
|
expect(subject.length).to eq(1)
|
77
89
|
expect(subject).to include(client_1)
|
78
90
|
end
|
79
91
|
end
|
80
92
|
end
|
81
|
-
|
82
93
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
ENV['RAILS_ENV'] ||= 'test'
|
6
|
+
require File.expand_path('../dummy/config/environment', __FILE__)
|
7
|
+
|
8
|
+
require 'rspec/rails'
|
9
|
+
require 'capybara/rspec'
|
10
|
+
require 'webmock/rspec'
|
11
|
+
require 'g5_authenticatable/rspec'
|
12
|
+
require 'g5_updatable/rspec'
|
13
|
+
require 'g5_updatable/factories'
|
14
|
+
|
15
|
+
Rails.backtrace_cleaner.remove_silencers!
|
16
|
+
|
17
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
18
|
+
# in spec/support/ and its subdirectories.
|
19
|
+
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
23
|
+
# examples within a transaction, remove the following line or assign false
|
24
|
+
# instead of true.
|
25
|
+
config.use_transactional_fixtures = true
|
26
|
+
|
27
|
+
# If true, the base class of anonymous controllers will be inferred
|
28
|
+
# automatically. This will be the default behavior in future versions of
|
29
|
+
# rspec-rails.
|
30
|
+
config.infer_base_class_for_anonymous_controllers = false
|
31
|
+
|
32
|
+
# Controller tests live under spec/controllers, etc.
|
33
|
+
config.infer_spec_type_from_file_location!
|
34
|
+
end
|
35
|
+
|
36
|
+
Shoulda::Matchers.configure do |config|
|
37
|
+
config.integrate do |with|
|
38
|
+
with.test_framework :rspec
|
39
|
+
with.library :rails
|
40
|
+
end
|
41
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe 'Default role-based authorization API' do
|
4
6
|
let(:json) { JSON.parse(response.body) }
|
5
7
|
|
6
8
|
describe 'GET /posts', :auth_request do
|
7
|
-
subject(:get_posts) {
|
9
|
+
subject(:get_posts) { safe_get posts_path, format: :json }
|
8
10
|
|
9
11
|
let!(:post) { FactoryGirl.create(:post, author: user) }
|
10
12
|
let!(:other_post) { FactoryGirl.create(:post) }
|
@@ -19,7 +21,7 @@ describe 'Default role-based authorization API' do
|
|
19
21
|
end
|
20
22
|
|
21
23
|
it 'includes all posts' do
|
22
|
-
expect(json
|
24
|
+
expect(json).to include(
|
23
25
|
hash_including('id' => post.id,
|
24
26
|
'author_id' => post.author.id,
|
25
27
|
'content' => post.content),
|
@@ -38,7 +40,7 @@ describe 'Default role-based authorization API' do
|
|
38
40
|
end
|
39
41
|
|
40
42
|
describe 'GET /posts/:id', :auth_request do
|
41
|
-
subject(:show_post) {
|
43
|
+
subject(:show_post) { safe_get post_path(post.id), format: :json }
|
42
44
|
|
43
45
|
let(:post) { FactoryGirl.create(:post, author: user) }
|
44
46
|
|
@@ -59,7 +61,7 @@ describe 'Default role-based authorization API' do
|
|
59
61
|
end
|
60
62
|
|
61
63
|
context 'when user is not a super_admin' do
|
62
|
-
let(:user) { FactoryGirl.create(:
|
64
|
+
let(:user) { FactoryGirl.create(:g5_authenticatable_viewer) }
|
63
65
|
|
64
66
|
it 'returns forbidden' do
|
65
67
|
expect(response).to be_forbidden
|
@@ -68,10 +70,12 @@ describe 'Default role-based authorization API' do
|
|
68
70
|
end
|
69
71
|
|
70
72
|
describe 'POST /posts', :auth_request do
|
71
|
-
subject(:create_post)
|
73
|
+
subject(:create_post) do
|
74
|
+
safe_post posts_path, post: post_params, format: :json
|
75
|
+
end
|
72
76
|
|
73
77
|
let(:post_params) do
|
74
|
-
{content: post_obj.content, author_id: post_obj.author.id}
|
78
|
+
{ content: post_obj.content, author_id: post_obj.author.id }
|
75
79
|
end
|
76
80
|
let(:post_obj) { FactoryGirl.build(:post, author: user) }
|
77
81
|
|
@@ -80,7 +84,7 @@ describe 'Default role-based authorization API' do
|
|
80
84
|
|
81
85
|
it 'returns ok' do
|
82
86
|
create_post
|
83
|
-
expect(response).to
|
87
|
+
expect(response.status).to eq(201)
|
84
88
|
end
|
85
89
|
|
86
90
|
it 'creates a post' do
|
@@ -102,11 +106,11 @@ describe 'Default role-based authorization API' do
|
|
102
106
|
|
103
107
|
describe 'PUT /posts/:id', :auth_request do
|
104
108
|
subject(:update_post) do
|
105
|
-
|
109
|
+
safe_put post_path(post.id), post: post_params, format: :json
|
106
110
|
end
|
107
111
|
|
108
112
|
let(:post_params) do
|
109
|
-
{content: 'some brand new content', author_id: post.author.id}
|
113
|
+
{ content: 'some brand new content', author_id: post.author.id }
|
110
114
|
end
|
111
115
|
let(:post) { FactoryGirl.create(:post, author: user) }
|
112
116
|
|
@@ -115,7 +119,7 @@ describe 'Default role-based authorization API' do
|
|
115
119
|
|
116
120
|
it 'returns ok' do
|
117
121
|
update_post
|
118
|
-
expect(response).to
|
122
|
+
expect(response.status).to eq(204)
|
119
123
|
end
|
120
124
|
|
121
125
|
it 'updates the post' do
|
@@ -137,7 +141,7 @@ describe 'Default role-based authorization API' do
|
|
137
141
|
|
138
142
|
describe 'DELETE /posts/:id', :auth_request do
|
139
143
|
subject(:delete_post) do
|
140
|
-
|
144
|
+
safe_delete post_path(post.id), format: :json
|
141
145
|
end
|
142
146
|
|
143
147
|
let!(:post) { FactoryGirl.create(:post, author: user) }
|
@@ -147,7 +151,7 @@ describe 'Default role-based authorization API' do
|
|
147
151
|
|
148
152
|
it 'returns ok' do
|
149
153
|
delete_post
|
150
|
-
expect(response).to
|
154
|
+
expect(response.status).to eq(204)
|
151
155
|
end
|
152
156
|
|
153
157
|
it 'deletes the post' do
|