openstax_accounts 7.3.0 → 7.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/openstax/accounts/account.rb +3 -1
- data/app/representers/openstax/accounts/api/v1/account_representer.rb +16 -0
- data/app/routines/openstax/accounts/find_or_create_account.rb +3 -2
- data/app/routines/openstax/accounts/sync_accounts.rb +1 -1
- data/db/migrate/9_add_uuid_and_role_to_accounts_accounts.rb +9 -0
- data/lib/openstax/accounts/api.rb +4 -2
- data/lib/openstax/accounts/configuration.rb +8 -0
- data/lib/openstax/accounts/version.rb +1 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +4 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +379 -0
- data/spec/dummy/log/test.log +48112 -0
- data/spec/factories/openstax_accounts_account.rb +2 -0
- data/spec/lib/openstax/accounts/api_spec.rb +25 -45
- data/spec/models/openstax/accounts/account_spec.rb +6 -0
- data/spec/routines/openstax/accounts/find_or_create_account_spec.rb +4 -2
- data/spec/routines/openstax/accounts/sync_accounts_spec.rb +3 -1
- metadata +3 -2
@@ -4,5 +4,7 @@ FactoryGirl.define do
|
|
4
4
|
username { SecureRandom.hex.to_s }
|
5
5
|
access_token { SecureRandom.hex.to_s }
|
6
6
|
faculty_status { OpenStax::Accounts::Account.faculty_statuses[:no_faculty_info] }
|
7
|
+
role { OpenStax::Accounts::Account.roles[:unknown_role] }
|
8
|
+
uuid { SecureRandom.uuid }
|
7
9
|
end
|
8
10
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
1
3
|
module OpenStax
|
2
4
|
module Accounts
|
3
5
|
describe Api do
|
@@ -6,29 +8,30 @@ module OpenStax
|
|
6
8
|
first_name: 'Some', last_name: 'User', full_name: 'SomeUser',
|
7
9
|
title: 'Sir', openstax_uid: 1, access_token: 'secret') }
|
8
10
|
|
11
|
+
def reset(controller)
|
12
|
+
controller.last_action = nil
|
13
|
+
controller.last_json = nil
|
14
|
+
controller.last_params = nil
|
15
|
+
end
|
16
|
+
|
9
17
|
it 'makes api requests' do
|
10
|
-
|
11
|
-
expect(::Api::DummyController.last_params).to be_nil
|
18
|
+
reset(::Api::DummyController)
|
12
19
|
Api.request(:post, 'dummy', :params => {:test => true})
|
13
20
|
expect(::Api::DummyController.last_action).to eq :dummy
|
14
21
|
expect(::Api::DummyController.last_params).to include 'test' => 'true'
|
15
22
|
end
|
16
23
|
|
17
24
|
context 'users' do
|
18
|
-
|
25
|
+
before(:each) { reset(::Api::UsersController) }
|
19
26
|
let!(:account) { FactoryGirl.create :openstax_accounts_account }
|
20
27
|
|
21
28
|
it 'makes api call to users index' do
|
22
|
-
::Api::UsersController.last_action = nil
|
23
|
-
::Api::UsersController.last_params = nil
|
24
29
|
Api.search_accounts('something')
|
25
30
|
expect(::Api::UsersController.last_action).to eq :index
|
26
31
|
expect(::Api::UsersController.last_params).to include :q => 'something'
|
27
32
|
end
|
28
33
|
|
29
34
|
it 'makes api call to user update' do
|
30
|
-
::Api::UsersController.last_action = nil
|
31
|
-
::Api::UsersController.last_json = nil
|
32
35
|
Api.update_account(account)
|
33
36
|
expect(::Api::UsersController.last_action).to eq :update
|
34
37
|
expect(::Api::UsersController.last_json).to include(
|
@@ -37,8 +40,6 @@ module OpenStax
|
|
37
40
|
end
|
38
41
|
|
39
42
|
it 'makes api call to (temp) user create by email' do
|
40
|
-
::Api::UsersController.last_action = nil
|
41
|
-
::Api::UsersController.last_json = nil
|
42
43
|
Api.find_or_create_account(email: 'dummy@dum.my')
|
43
44
|
expect(::Api::UsersController.last_action).to eq :create
|
44
45
|
expect(::Api::UsersController.last_json).to(
|
@@ -47,52 +48,51 @@ module OpenStax
|
|
47
48
|
end
|
48
49
|
|
49
50
|
it 'makes api call to (temp) user create by username' do
|
50
|
-
::Api::UsersController.last_action = nil
|
51
|
-
::Api::UsersController.last_json = nil
|
52
51
|
Api.find_or_create_account(username: 'dummy')
|
53
52
|
expect(::Api::UsersController.last_action).to eq :create
|
54
53
|
expect(::Api::UsersController.last_json).to(
|
55
54
|
include('username' => 'dummy')
|
56
55
|
)
|
57
56
|
end
|
58
|
-
|
59
57
|
end
|
60
58
|
|
61
59
|
context 'application_users' do
|
60
|
+
before(:each) { reset(::Api::ApplicationUsersController) }
|
62
61
|
|
63
62
|
it 'makes api call to application_users index' do
|
64
|
-
::Api::ApplicationUsersController.last_action = nil
|
65
|
-
::Api::ApplicationUsersController.last_params = nil
|
66
63
|
Api.search_application_accounts('something')
|
67
64
|
expect(::Api::ApplicationUsersController.last_action).to eq :index
|
68
65
|
expect(::Api::ApplicationUsersController.last_params).to include :q => 'something'
|
69
66
|
end
|
70
67
|
|
71
68
|
it 'makes api call to application_users updates' do
|
72
|
-
::Api::ApplicationUsersController.last_action = nil
|
73
69
|
Api.get_application_account_updates
|
74
70
|
expect(::Api::ApplicationUsersController.last_action).to eq :updates
|
71
|
+
expect(::Api::ApplicationUsersController.last_params).to include limit: "250"
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'does not limit updates call if param blank' do
|
75
|
+
allow(OpenStax::Accounts.configuration).to receive(:max_user_updates_per_request) { "" }
|
76
|
+
Api.get_application_account_updates
|
77
|
+
expect(::Api::ApplicationUsersController.last_action).to eq :updates
|
78
|
+
expect(::Api::ApplicationUsersController.last_params.keys).not_to include "limit"
|
75
79
|
end
|
76
80
|
|
77
81
|
it 'makes api call to application_users updated' do
|
78
|
-
::Api::ApplicationUsersController.last_action = nil
|
79
|
-
::Api::ApplicationUsersController.last_json = nil
|
80
82
|
Api.mark_account_updates_as_read([{id: 1, read_updates: 1}])
|
81
83
|
expect(::Api::ApplicationUsersController.last_action).to eq :updated
|
82
84
|
expect(::Api::ApplicationUsersController.last_json).to include(
|
83
85
|
{'id' => 1, 'read_updates' => 1})
|
84
86
|
end
|
85
|
-
|
86
87
|
end
|
87
88
|
|
88
89
|
context 'groups' do
|
90
|
+
before(:each) { reset(::Api::GroupsController) }
|
89
91
|
|
90
92
|
let!(:account) { FactoryGirl.create :openstax_accounts_account }
|
91
93
|
let!(:group) { FactoryGirl.create :openstax_accounts_group }
|
92
94
|
|
93
95
|
it 'makes api call to groups create' do
|
94
|
-
::Api::GroupsController.last_action = nil
|
95
|
-
::Api::GroupsController.last_json = nil
|
96
96
|
Api.create_group(account, group)
|
97
97
|
expect(::Api::GroupsController.last_action).to eq :create
|
98
98
|
expect(::Api::GroupsController.last_json).to include(
|
@@ -101,9 +101,6 @@ module OpenStax
|
|
101
101
|
|
102
102
|
it 'makes api call to group update' do
|
103
103
|
group.save!
|
104
|
-
::Api::GroupsController.last_action = nil
|
105
|
-
::Api::GroupsController.last_params = nil
|
106
|
-
::Api::GroupsController.last_json = nil
|
107
104
|
Api.update_group(account, group)
|
108
105
|
expect(::Api::GroupsController.last_action).to eq :update
|
109
106
|
expect(::Api::GroupsController.last_params).to include(
|
@@ -114,24 +111,20 @@ module OpenStax
|
|
114
111
|
|
115
112
|
it 'makes api call to group destroy' do
|
116
113
|
group.save!
|
117
|
-
::Api::GroupsController.last_action = nil
|
118
|
-
::Api::GroupsController.last_params = nil
|
119
114
|
Api.destroy_group(account, group)
|
120
115
|
expect(::Api::GroupsController.last_action).to eq :destroy
|
121
116
|
expect(::Api::GroupsController.last_params).to include(
|
122
117
|
{'id' => group.openstax_uid.to_s})
|
123
118
|
end
|
124
|
-
|
125
119
|
end
|
126
120
|
|
127
121
|
context 'group_members' do
|
122
|
+
before(:each) { reset(::Api::GroupMembersController) }
|
128
123
|
|
129
124
|
let!(:account) { FactoryGirl.create :openstax_accounts_account }
|
130
125
|
let!(:group_member) { FactoryGirl.build :openstax_accounts_group_member }
|
131
126
|
|
132
127
|
it 'makes api call to group_members create' do
|
133
|
-
::Api::GroupMembersController.last_action = nil
|
134
|
-
::Api::GroupMembersController.last_params = nil
|
135
128
|
Api.create_group_member(account, group_member)
|
136
129
|
expect(::Api::GroupMembersController.last_action).to eq :create
|
137
130
|
expect(::Api::GroupMembersController.last_params).to include(
|
@@ -141,25 +134,21 @@ module OpenStax
|
|
141
134
|
|
142
135
|
it 'makes api call to group_member destroy' do
|
143
136
|
group_member.save!
|
144
|
-
::Api::GroupMembersController.last_action = nil
|
145
|
-
::Api::GroupMembersController.last_params = nil
|
146
137
|
Api.destroy_group_member(account, group_member)
|
147
138
|
expect(::Api::GroupMembersController.last_action).to eq :destroy
|
148
139
|
expect(::Api::GroupMembersController.last_params).to include(
|
149
140
|
{'group_id' => group_member.group_id.to_s,
|
150
141
|
'user_id' => group_member.user_id.to_s})
|
151
142
|
end
|
152
|
-
|
153
143
|
end
|
154
144
|
|
155
145
|
context 'group_owners' do
|
146
|
+
before(:each) { reset(::Api::GroupOwnersController) }
|
156
147
|
|
157
148
|
let!(:account) { FactoryGirl.create :openstax_accounts_account }
|
158
149
|
let!(:group_owner) { FactoryGirl.build :openstax_accounts_group_owner }
|
159
150
|
|
160
151
|
it 'makes api call to group_owners create' do
|
161
|
-
::Api::GroupOwnersController.last_action = nil
|
162
|
-
::Api::GroupOwnersController.last_params = nil
|
163
152
|
Api.create_group_owner(account, group_owner)
|
164
153
|
expect(::Api::GroupOwnersController.last_action).to eq :create
|
165
154
|
expect(::Api::GroupOwnersController.last_params).to include(
|
@@ -169,25 +158,21 @@ module OpenStax
|
|
169
158
|
|
170
159
|
it 'makes api call to group_owner destroy' do
|
171
160
|
group_owner.save!
|
172
|
-
::Api::GroupOwnersController.last_action = nil
|
173
|
-
::Api::GroupOwnersController.last_params = nil
|
174
161
|
Api.destroy_group_owner(account, group_owner)
|
175
162
|
expect(::Api::GroupOwnersController.last_action).to eq :destroy
|
176
163
|
expect(::Api::GroupOwnersController.last_params).to include(
|
177
164
|
{'group_id' => group_owner.group_id.to_s,
|
178
165
|
'user_id' => group_owner.user_id.to_s})
|
179
166
|
end
|
180
|
-
|
181
167
|
end
|
182
168
|
|
183
169
|
context 'group_nestings' do
|
170
|
+
before(:each) { reset(::Api::GroupNestingsController) }
|
184
171
|
|
185
172
|
let!(:account) { FactoryGirl.create :openstax_accounts_account }
|
186
173
|
let!(:group_nesting) { FactoryGirl.build :openstax_accounts_group_nesting }
|
187
174
|
|
188
175
|
it 'makes api call to group_nestings (create)' do
|
189
|
-
::Api::GroupNestingsController.last_action = nil
|
190
|
-
::Api::GroupNestingsController.last_params = nil
|
191
176
|
Api.create_group_nesting(account, group_nesting)
|
192
177
|
expect(::Api::GroupNestingsController.last_action).to eq :create
|
193
178
|
expect(::Api::GroupNestingsController.last_params).to include(
|
@@ -197,36 +182,31 @@ module OpenStax
|
|
197
182
|
|
198
183
|
it 'makes api call to group_nesting (destroy)' do
|
199
184
|
group_nesting.save!
|
200
|
-
::Api::GroupNestingsController.last_action = nil
|
201
|
-
::Api::GroupNestingsController.last_params = nil
|
202
185
|
Api.destroy_group_nesting(account, group_nesting)
|
203
186
|
expect(::Api::GroupNestingsController.last_action).to eq :destroy
|
204
187
|
expect(::Api::GroupNestingsController.last_params).to include(
|
205
188
|
{'group_id' => group_nesting.container_group_id.to_s,
|
206
189
|
'member_group_id' => group_nesting.member_group_id.to_s})
|
207
190
|
end
|
208
|
-
|
209
191
|
end
|
210
192
|
|
211
193
|
context 'application_groups' do
|
194
|
+
before(:each) { reset(::Api::ApplicationGroupsController) }
|
212
195
|
|
213
196
|
it 'makes api call to application_groups_updates' do
|
214
|
-
::Api::ApplicationGroupsController.last_action = nil
|
215
197
|
Api.get_application_group_updates
|
216
198
|
expect(::Api::ApplicationGroupsController.last_action).to eq :updates
|
217
199
|
end
|
218
200
|
|
219
201
|
it 'makes api call to application_groups_updated' do
|
220
|
-
::Api::ApplicationGroupsController.last_action = nil
|
221
|
-
::Api::ApplicationGroupsController.last_json = nil
|
222
202
|
Api.mark_group_updates_as_read([{id: 1, read_updates: 1}])
|
223
203
|
expect(::Api::ApplicationGroupsController.last_action).to eq :updated
|
224
204
|
expect(::Api::ApplicationGroupsController.last_json).to include(
|
225
205
|
{'id' => 1, 'read_updates' => 1})
|
226
206
|
end
|
227
|
-
|
228
207
|
end
|
229
208
|
|
230
209
|
end
|
210
|
+
|
231
211
|
end
|
232
212
|
end
|
@@ -34,6 +34,12 @@ module OpenStax::Accounts
|
|
34
34
|
FactoryGirl.create(:openstax_accounts_account, username: nil)
|
35
35
|
}.not_to raise_error
|
36
36
|
end
|
37
|
+
|
38
|
+
it 'requires a role' do
|
39
|
+
expect{
|
40
|
+
FactoryGirl.create(:openstax_accounts_account, role: nil)
|
41
|
+
}.to raise_error(ActiveRecord::RecordInvalid)
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
context 'updates' do
|
@@ -36,7 +36,8 @@ module OpenStax
|
|
36
36
|
expect(OpenStax::Accounts::Api).to receive(:find_or_create_account).with(
|
37
37
|
email: 'bob@example.com', username: nil, password: nil,
|
38
38
|
first_name: 'Bob', last_name: 'Smith', full_name: 'Bob Smith',
|
39
|
-
salesforce_contact_id: 'b0b', faculty_status: :rejected_faculty
|
39
|
+
salesforce_contact_id: 'b0b', faculty_status: :rejected_faculty,
|
40
|
+
role: :instructor
|
40
41
|
).and_return(find_or_create_account_response)
|
41
42
|
|
42
43
|
FindOrCreateAccount.call(
|
@@ -45,7 +46,8 @@ module OpenStax
|
|
45
46
|
last_name: 'Smith',
|
46
47
|
full_name: 'Bob Smith',
|
47
48
|
salesforce_contact_id: 'b0b',
|
48
|
-
faculty_status: :rejected_faculty
|
49
|
+
faculty_status: :rejected_faculty,
|
50
|
+
role: :instructor
|
49
51
|
)
|
50
52
|
end
|
51
53
|
|
@@ -10,7 +10,7 @@ module OpenStax
|
|
10
10
|
allow_any_instance_of(controller_class).to(
|
11
11
|
receive(:updates) do |controller|
|
12
12
|
controller.render :json => [{id: 1, application_id: 1,
|
13
|
-
user: {id: 2, username: 'user'},
|
13
|
+
user: {id: 2, username: 'user', self_reported_role: 'instructor', uuid: 'booyah'},
|
14
14
|
unread_updates: 1, default_contact_info_id: 1},
|
15
15
|
{id: 3, application_id: 1,
|
16
16
|
user: {id: 4, username: 'fuego'},
|
@@ -36,6 +36,8 @@ module OpenStax
|
|
36
36
|
expect(Account.count).to eq 2
|
37
37
|
expect(Account.first.openstax_uid).to eq 2
|
38
38
|
expect(Account.first.username).to eq 'user'
|
39
|
+
expect(Account.first.role).to eq 'instructor'
|
40
|
+
expect(Account.first.uuid).to eq 'booyah'
|
39
41
|
expect(Account.last.openstax_uid).to eq 4
|
40
42
|
expect(Account.last.username).to eq 'fuego'
|
41
43
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstax_accounts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Slavinsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -370,6 +370,7 @@ files:
|
|
370
370
|
- db/migrate/6_add_salesforce_contact_id_to_accounts_accounts.rb
|
371
371
|
- db/migrate/7_change_accounts_openstax_uid_to_be_nullable.rb
|
372
372
|
- db/migrate/8_change_accounts_username_to_be_nullable.rb
|
373
|
+
- db/migrate/9_add_uuid_and_role_to_accounts_accounts.rb
|
373
374
|
- lib/generators/openstax/accounts/schedule/USAGE
|
374
375
|
- lib/generators/openstax/accounts/schedule/schedule_generator.rb
|
375
376
|
- lib/generators/openstax/accounts/schedule/templates/schedule.rb
|