openstax_accounts 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +1 -0
- data/Rakefile +6 -6
- data/app/models/openstax/accounts/account.rb +34 -24
- data/app/models/openstax/accounts/application_group.rb +7 -0
- data/app/models/openstax/accounts/group.rb +132 -0
- data/app/models/openstax/accounts/group_member.rb +40 -0
- data/app/models/openstax/accounts/group_nesting.rb +62 -0
- data/app/models/openstax/accounts/group_owner.rb +40 -0
- data/app/representers/openstax/accounts/api/v1/application_group_representer.rb +25 -0
- data/app/representers/openstax/accounts/api/v1/application_groups_representer.rb +16 -0
- data/app/representers/openstax/accounts/api/v1/group_nesting_representer.rb +18 -0
- data/app/representers/openstax/accounts/api/v1/group_representer.rb +50 -0
- data/app/representers/openstax/accounts/api/v1/group_user_representer.rb +21 -0
- data/app/routines/openstax/accounts/search_accounts.rb +7 -14
- data/app/routines/openstax/accounts/sync_accounts.rb +32 -18
- data/app/routines/openstax/accounts/sync_groups.rb +61 -0
- data/app/routines/openstax/accounts/update_group_caches.rb +27 -0
- data/app/views/openstax/accounts/shared/accounts/_index.html.erb +0 -3
- data/config/initializers/action_interceptor.rb +1 -1
- data/db/migrate/20140811182433_create_openstax_accounts_groups.rb +16 -0
- data/db/migrate/20140811182505_create_openstax_accounts_group_members.rb +13 -0
- data/db/migrate/20140811182527_create_openstax_accounts_group_owners.rb +13 -0
- data/db/migrate/20140811182553_create_openstax_accounts_group_nestings.rb +13 -0
- data/lib/generators/openstax/accounts/schedule/templates/schedule.rb +1 -0
- data/lib/openstax/accounts/current_user_manager.rb +2 -2
- data/lib/openstax/accounts/has_many_through_groups.rb +45 -0
- data/lib/openstax/accounts/version.rb +1 -1
- data/lib/openstax_accounts.rb +165 -11
- data/spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb +1 -1
- data/spec/controllers/openstax/accounts/sessions_controller_spec.rb +1 -1
- data/spec/dummy/app/controllers/api/application_groups_controller.rb +11 -0
- data/spec/dummy/app/controllers/api/dummy_controller.rb +2 -1
- data/spec/dummy/app/controllers/api/group_members_controller.rb +11 -0
- data/spec/dummy/app/controllers/api/group_nestings_controller.rb +11 -0
- data/spec/dummy/app/controllers/api/group_owners_controller.rb +11 -0
- data/spec/dummy/app/controllers/api/groups_controller.rb +15 -0
- data/spec/dummy/app/controllers/api/users_controller.rb +4 -0
- data/spec/dummy/app/models/ownership.rb +7 -0
- data/spec/dummy/app/models/user.rb +11 -8
- data/spec/dummy/config/application.rb +0 -33
- data/spec/dummy/config/boot.rb +4 -9
- data/spec/dummy/config/database.yml +8 -8
- data/spec/dummy/config/environment.rb +3 -3
- data/spec/dummy/config/environments/development.rb +20 -12
- data/spec/dummy/config/environments/production.rb +42 -29
- data/spec/dummy/config/environments/test.rb +16 -12
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +6 -5
- data/spec/dummy/config/initializers/mime_types.rb +0 -1
- data/spec/dummy/config/initializers/session_store.rb +1 -6
- data/spec/dummy/config/initializers/wrap_parameters.rb +6 -6
- data/spec/dummy/config/routes.rb +23 -0
- data/spec/dummy/config/secrets.yml +8 -0
- data/spec/dummy/db/migrate/1_create_users.rb +2 -2
- data/spec/dummy/db/migrate/2_create_ownerships.rb +11 -0
- data/spec/dummy/db/schema.rb +72 -20
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +186 -0
- data/spec/dummy/log/test.log +2078 -0
- data/spec/factories/openstax_accounts_account.rb +3 -2
- data/spec/factories/openstax_accounts_group.rb +7 -0
- data/spec/factories/openstax_accounts_group_member.rb +6 -0
- data/spec/factories/openstax_accounts_group_nesting.rb +6 -0
- data/spec/factories/openstax_accounts_group_owner.rb +6 -0
- data/spec/lib/openstax/accounts/current_user_manager_spec.rb +9 -3
- data/spec/lib/openstax/accounts/has_many_through_groups_spec.rb +53 -0
- data/spec/lib/openstax_accounts_spec.rb +189 -25
- data/spec/models/openstax/accounts/account_spec.rb +16 -1
- data/spec/models/openstax/accounts/anonymous_account_spec.rb +1 -1
- data/spec/models/openstax/accounts/group_spec.rb +20 -0
- data/spec/routines/openstax/accounts/sync_accounts_spec.rb +70 -0
- data/spec/routines/openstax/accounts/sync_groups_spec.rb +125 -0
- metadata +73 -56
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
@@ -1,6 +1,7 @@
|
|
1
1
|
FactoryGirl.define do
|
2
2
|
factory :openstax_accounts_account, :class => OpenStax::Accounts::Account do
|
3
|
-
|
4
|
-
|
3
|
+
openstax_uid { -SecureRandom.hex.to_i(16) }
|
4
|
+
username { SecureRandom.hex.to_s }
|
5
|
+
access_token { SecureRandom.hex.to_s }
|
5
6
|
end
|
6
7
|
end
|
@@ -4,7 +4,7 @@ module OpenStax
|
|
4
4
|
let!(:account) { FactoryGirl.create(:openstax_accounts_account,
|
5
5
|
username: 'some_user',
|
6
6
|
openstax_uid: 1) }
|
7
|
-
let!(:user) { User.create(:
|
7
|
+
let!(:user) { User.create(:account => account) }
|
8
8
|
|
9
9
|
let!(:request) { double('request',
|
10
10
|
:host => 'localhost',
|
@@ -17,7 +17,10 @@ module OpenStax
|
|
17
17
|
let!(:session) { {} }
|
18
18
|
|
19
19
|
let!(:cookies) { ActionDispatch::Cookies::CookieJar.new(
|
20
|
-
SecureRandom.hex,
|
20
|
+
ActiveSupport::KeyGenerator.new(SecureRandom.hex),
|
21
|
+
'localhost', false,
|
22
|
+
encrypted_cookie_salt: 'encrypted cookie salt',
|
23
|
+
encrypted_signed_cookie_salt: 'encrypted signed cookie salt') }
|
21
24
|
|
22
25
|
let!(:current_user_manager) { CurrentUserManager.new(
|
23
26
|
request, session, cookies) }
|
@@ -67,7 +70,10 @@ module OpenStax
|
|
67
70
|
|
68
71
|
# Secure cookies are not sent with non-SSL requests
|
69
72
|
unsecure_cookies = ActionDispatch::Cookies::CookieJar.new(
|
70
|
-
SecureRandom.hex,
|
73
|
+
ActiveSupport::KeyGenerator.new(SecureRandom.hex),
|
74
|
+
'localhost', false,
|
75
|
+
encrypted_cookie_salt: 'encrypted cookie salt',
|
76
|
+
encrypted_signed_cookie_salt: 'encrypted signed cookie salt')
|
71
77
|
unsecure_cookies[:account_id] = cookies[:account_id]
|
72
78
|
|
73
79
|
current_user_manager = CurrentUserManager.new(
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module OpenStax
|
2
|
+
module Accounts
|
3
|
+
describe HasManyThroughGroups do
|
4
|
+
let!(:account_1) { FactoryGirl.create(:openstax_accounts_account,
|
5
|
+
username: 'some_user',
|
6
|
+
openstax_uid: 1) }
|
7
|
+
let!(:user_1) { User.create(:account => account_1) }
|
8
|
+
|
9
|
+
let!(:account_2) { FactoryGirl.create(:openstax_accounts_account,
|
10
|
+
username: 'another_user',
|
11
|
+
openstax_uid: 2) }
|
12
|
+
let!(:user_2) { User.create(:account => account_2) }
|
13
|
+
|
14
|
+
let!(:group_nesting) { FactoryGirl.create(:openstax_accounts_group_nesting) }
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
group_nesting.member_group.add_member(account_1)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'allows users to retrieve all nested has_many_through_groups objects' do
|
21
|
+
expect(user_1.ownerships).to be_empty
|
22
|
+
|
23
|
+
o = Ownership.new
|
24
|
+
o.owner = user_2
|
25
|
+
o.save!
|
26
|
+
|
27
|
+
expect(user_1.reload.ownerships).to be_empty
|
28
|
+
|
29
|
+
o2 = Ownership.new
|
30
|
+
o2.owner = user_1
|
31
|
+
o2.save!
|
32
|
+
|
33
|
+
expect(user_1.reload.ownerships).to include(o2)
|
34
|
+
|
35
|
+
o3 = Ownership.new
|
36
|
+
o3.owner = group_nesting.member_group
|
37
|
+
o3.save!
|
38
|
+
|
39
|
+
expect(user_1.reload.ownerships).to include(o2)
|
40
|
+
expect(user_1.ownerships).to include(o3)
|
41
|
+
|
42
|
+
o4 = Ownership.new
|
43
|
+
o4.owner = group_nesting.container_group
|
44
|
+
o4.save!
|
45
|
+
|
46
|
+
expect(user_1.reload.ownerships).to include(o2)
|
47
|
+
expect(user_1.ownerships).to include(o3)
|
48
|
+
expect(user_1.ownerships).to include(o4)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module OpenStax
|
2
2
|
describe Accounts do
|
3
|
+
|
3
4
|
let!(:account) { OpenStax::Accounts::Account.create(username: 'some_user',
|
4
|
-
|
5
|
+
first_name: 'Some', last_name: 'User', full_name: 'SomeUser',
|
6
|
+
title: 'Sir', openstax_uid: 1, access_token: 'secret') }
|
5
7
|
|
6
8
|
it 'makes api calls' do
|
7
9
|
expect(Api::DummyController.last_action).to be_nil
|
@@ -11,36 +13,198 @@ module OpenStax
|
|
11
13
|
expect(Api::DummyController.last_params).to include 'test' => 'true'
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
context 'users' do
|
17
|
+
|
18
|
+
let!(:account) { FactoryGirl.create :openstax_accounts_account }
|
19
|
+
|
20
|
+
it 'makes api call to users index' do
|
21
|
+
Api::UsersController.last_action = nil
|
22
|
+
Api::UsersController.last_params = nil
|
23
|
+
Accounts.search_accounts('something')
|
24
|
+
expect(Api::UsersController.last_action).to eq :index
|
25
|
+
expect(Api::UsersController.last_params).to include :q => 'something'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'makes api call to user update' do
|
29
|
+
Api::UsersController.last_action = nil
|
30
|
+
Api::UsersController.last_json = nil
|
31
|
+
Accounts.update_account(account)
|
32
|
+
expect(Api::UsersController.last_action).to eq :update
|
33
|
+
expect(Api::UsersController.last_json).to include(
|
34
|
+
account.attributes.slice('username', 'first_name',
|
35
|
+
'last_name', 'full_name', 'title'))
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'application_users' do
|
41
|
+
|
42
|
+
it 'makes api call to application_users index' do
|
43
|
+
Api::ApplicationUsersController.last_action = nil
|
44
|
+
Api::ApplicationUsersController.last_params = nil
|
45
|
+
Accounts.search_application_accounts('something')
|
46
|
+
expect(Api::ApplicationUsersController.last_action).to eq :index
|
47
|
+
expect(Api::ApplicationUsersController.last_params).to include :q => 'something'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'makes api call to application_users updates' do
|
51
|
+
Api::ApplicationUsersController.last_action = nil
|
52
|
+
Accounts.get_application_account_updates
|
53
|
+
expect(Api::ApplicationUsersController.last_action).to eq :updates
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'makes api call to application_users updated' do
|
57
|
+
Api::ApplicationUsersController.last_action = nil
|
58
|
+
Api::ApplicationUsersController.last_json = nil
|
59
|
+
Accounts.mark_account_updates_as_read([{id: 1, read_updates: 1}])
|
60
|
+
expect(Api::ApplicationUsersController.last_action).to eq :updated
|
61
|
+
expect(Api::ApplicationUsersController.last_json).to include(
|
62
|
+
{'id' => 1, 'read_updates' => 1})
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'groups' do
|
68
|
+
|
69
|
+
let!(:account) { FactoryGirl.create :openstax_accounts_account }
|
70
|
+
let!(:group) { FactoryGirl.create :openstax_accounts_group }
|
71
|
+
|
72
|
+
it 'makes api call to groups create' do
|
73
|
+
Api::GroupsController.last_action = nil
|
74
|
+
Api::GroupsController.last_json = nil
|
75
|
+
Accounts.create_group(account, group)
|
76
|
+
expect(Api::GroupsController.last_action).to eq :create
|
77
|
+
expect(Api::GroupsController.last_json).to include(
|
78
|
+
{'name' => 'MyGroup', 'is_public' => false})
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'makes api call to group update' do
|
82
|
+
group.save!
|
83
|
+
Api::GroupsController.last_action = nil
|
84
|
+
Api::GroupsController.last_params = nil
|
85
|
+
Api::GroupsController.last_json = nil
|
86
|
+
Accounts.update_group(account, group)
|
87
|
+
expect(Api::GroupsController.last_action).to eq :update
|
88
|
+
expect(Api::GroupsController.last_params).to include(
|
89
|
+
{'id' => group.openstax_uid.to_s})
|
90
|
+
expect(Api::GroupsController.last_json).to include(
|
91
|
+
{'name' => group.name, 'is_public' => group.is_public})
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'makes api call to group destroy' do
|
95
|
+
group.save!
|
96
|
+
Api::GroupsController.last_action = nil
|
97
|
+
Api::GroupsController.last_params = nil
|
98
|
+
Accounts.destroy_group(account, group)
|
99
|
+
expect(Api::GroupsController.last_action).to eq :destroy
|
100
|
+
expect(Api::GroupsController.last_params).to include(
|
101
|
+
{'id' => group.openstax_uid.to_s})
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'group_members' do
|
107
|
+
|
108
|
+
let!(:account) { FactoryGirl.create :openstax_accounts_account }
|
109
|
+
let!(:group_member) { FactoryGirl.build :openstax_accounts_group_member }
|
110
|
+
|
111
|
+
it 'makes api call to group_members create' do
|
112
|
+
Api::GroupMembersController.last_action = nil
|
113
|
+
Api::GroupMembersController.last_params = nil
|
114
|
+
Accounts.create_group_member(account, group_member)
|
115
|
+
expect(Api::GroupMembersController.last_action).to eq :create
|
116
|
+
expect(Api::GroupMembersController.last_params).to include(
|
117
|
+
{'group_id' => group_member.group_id.to_s,
|
118
|
+
'user_id' => group_member.user_id.to_s})
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'makes api call to group_member destroy' do
|
122
|
+
group_member.save!
|
123
|
+
Api::GroupMembersController.last_action = nil
|
124
|
+
Api::GroupMembersController.last_params = nil
|
125
|
+
Accounts.destroy_group_member(account, group_member)
|
126
|
+
expect(Api::GroupMembersController.last_action).to eq :destroy
|
127
|
+
expect(Api::GroupMembersController.last_params).to include(
|
128
|
+
{'group_id' => group_member.group_id.to_s,
|
129
|
+
'user_id' => group_member.user_id.to_s})
|
130
|
+
end
|
131
|
+
|
20
132
|
end
|
21
133
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
134
|
+
context 'group_owners' do
|
135
|
+
|
136
|
+
let!(:account) { FactoryGirl.create :openstax_accounts_account }
|
137
|
+
let!(:group_owner) { FactoryGirl.build :openstax_accounts_group_owner }
|
138
|
+
|
139
|
+
it 'makes api call to group_owners create' do
|
140
|
+
Api::GroupOwnersController.last_action = nil
|
141
|
+
Api::GroupOwnersController.last_params = nil
|
142
|
+
Accounts.create_group_owner(account, group_owner)
|
143
|
+
expect(Api::GroupOwnersController.last_action).to eq :create
|
144
|
+
expect(Api::GroupOwnersController.last_params).to include(
|
145
|
+
{'group_id' => group_owner.group_id.to_s,
|
146
|
+
'user_id' => group_owner.user_id.to_s})
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'makes api call to group_owner destroy' do
|
150
|
+
group_owner.save!
|
151
|
+
Api::GroupOwnersController.last_action = nil
|
152
|
+
Api::GroupOwnersController.last_params = nil
|
153
|
+
Accounts.destroy_group_owner(account, group_owner)
|
154
|
+
expect(Api::GroupOwnersController.last_action).to eq :destroy
|
155
|
+
expect(Api::GroupOwnersController.last_params).to include(
|
156
|
+
{'group_id' => group_owner.group_id.to_s,
|
157
|
+
'user_id' => group_owner.user_id.to_s})
|
158
|
+
end
|
159
|
+
|
28
160
|
end
|
29
161
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
162
|
+
context 'group_nestings' do
|
163
|
+
|
164
|
+
let!(:account) { FactoryGirl.create :openstax_accounts_account }
|
165
|
+
let!(:group_nesting) { FactoryGirl.build :openstax_accounts_group_nesting }
|
166
|
+
|
167
|
+
it 'makes api call to group_nestings (create)' do
|
168
|
+
Api::GroupNestingsController.last_action = nil
|
169
|
+
Api::GroupNestingsController.last_params = nil
|
170
|
+
Accounts.create_group_nesting(account, group_nesting)
|
171
|
+
expect(Api::GroupNestingsController.last_action).to eq :create
|
172
|
+
expect(Api::GroupNestingsController.last_params).to include(
|
173
|
+
{'group_id' => group_nesting.container_group_id.to_s,
|
174
|
+
'member_group_id' => group_nesting.member_group_id.to_s})
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'makes api call to group_nesting (destroy)' do
|
178
|
+
group_nesting.save!
|
179
|
+
Api::GroupNestingsController.last_action = nil
|
180
|
+
Api::GroupNestingsController.last_params = nil
|
181
|
+
Accounts.destroy_group_nesting(account, group_nesting)
|
182
|
+
expect(Api::GroupNestingsController.last_action).to eq :destroy
|
183
|
+
expect(Api::GroupNestingsController.last_params).to include(
|
184
|
+
{'group_id' => group_nesting.container_group_id.to_s,
|
185
|
+
'member_group_id' => group_nesting.member_group_id.to_s})
|
186
|
+
end
|
187
|
+
|
36
188
|
end
|
37
189
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
190
|
+
context 'application_groups' do
|
191
|
+
|
192
|
+
it 'makes api call to application_groups_updates' do
|
193
|
+
Api::ApplicationGroupsController.last_action = nil
|
194
|
+
Accounts.get_application_group_updates
|
195
|
+
expect(Api::ApplicationGroupsController.last_action).to eq :updates
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'makes api call to application_groups_updated' do
|
199
|
+
Api::ApplicationGroupsController.last_action = nil
|
200
|
+
Api::ApplicationGroupsController.last_json = nil
|
201
|
+
Accounts.mark_group_updates_as_read([{id: 1, read_updates: 1}])
|
202
|
+
expect(Api::ApplicationGroupsController.last_action).to eq :updated
|
203
|
+
expect(Api::ApplicationGroupsController.last_json).to include(
|
204
|
+
{'id' => 1, 'read_updates' => 1})
|
205
|
+
end
|
206
|
+
|
44
207
|
end
|
208
|
+
|
45
209
|
end
|
46
210
|
end
|
@@ -2,8 +2,23 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module OpenStax::Accounts
|
4
4
|
describe Account do
|
5
|
+
context 'validation' do
|
6
|
+
it 'requires a unique openstax_uid' do
|
7
|
+
account = FactoryGirl.build(:openstax_accounts_account, openstax_uid: nil)
|
8
|
+
expect(account).not_to be_valid
|
9
|
+
expect(account.errors[:openstax_uid]).to eq(['can\'t be blank'])
|
10
|
+
|
11
|
+
account.openstax_uid = 1
|
12
|
+
account.save!
|
13
|
+
|
14
|
+
account_2 = FactoryGirl.build(:openstax_accounts_account, openstax_uid: 1)
|
15
|
+
expect(account_2).not_to be_valid
|
16
|
+
expect(account_2.errors[:openstax_uid]).to eq(['has already been taken'])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
5
20
|
it 'is not anonymous' do
|
6
|
-
expect(Account.new.is_anonymous?).to
|
21
|
+
expect(Account.new.is_anonymous?).to eq false
|
7
22
|
end
|
8
23
|
end
|
9
24
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module OpenStax::Accounts
|
4
|
+
describe Group do
|
5
|
+
context 'validation' do
|
6
|
+
it 'requires a unique openstax_uid' do
|
7
|
+
group = FactoryGirl.build(:openstax_accounts_group, openstax_uid: nil)
|
8
|
+
expect(group).not_to be_valid
|
9
|
+
expect(group.errors[:openstax_uid]).to eq(['can\'t be blank'])
|
10
|
+
|
11
|
+
group.openstax_uid = 1
|
12
|
+
group.save!
|
13
|
+
|
14
|
+
group_2 = FactoryGirl.build(:openstax_accounts_group, openstax_uid: 1)
|
15
|
+
expect(group_2).not_to be_valid
|
16
|
+
expect(group_2.errors[:openstax_uid]).to eq(['has already been taken'])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module OpenStax
|
4
|
+
module Accounts
|
5
|
+
|
6
|
+
describe SyncAccounts do
|
7
|
+
|
8
|
+
it 'can sync accounts' do
|
9
|
+
controller_class = ::Api::ApplicationUsersController
|
10
|
+
allow_any_instance_of(controller_class).to(
|
11
|
+
receive(:updates) do |controller|
|
12
|
+
controller.render :json => [{id: 1, application_id: 1,
|
13
|
+
user: {id: 2, username: 'user'},
|
14
|
+
unread_updates: 1, default_contact_info_id: 1},
|
15
|
+
{id: 3, application_id: 1,
|
16
|
+
user: {id: 4, username: 'fuego'},
|
17
|
+
unread_updates: 2, default_contact_info_id: 5}]
|
18
|
+
end)
|
19
|
+
|
20
|
+
begin
|
21
|
+
OpenStax::Accounts.syncing = true
|
22
|
+
account = OpenStax::Accounts::Account.new
|
23
|
+
account.username = 'u'
|
24
|
+
account.openstax_uid = 2
|
25
|
+
account.save!
|
26
|
+
ensure
|
27
|
+
OpenStax::Accounts.syncing = false
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
OpenStax::Accounts.configuration.enable_stubbing = false
|
32
|
+
expect(Account.count).to eq 1
|
33
|
+
expect(Account.first.openstax_uid).to eq 2
|
34
|
+
expect(Account.first.username).to eq 'u'
|
35
|
+
|
36
|
+
controller_class.last_action = nil
|
37
|
+
controller_class.last_json = nil
|
38
|
+
SyncAccounts.call
|
39
|
+
expect(Account.count).to eq 2
|
40
|
+
expect(Account.first.openstax_uid).to eq 2
|
41
|
+
expect(Account.first.username).to eq 'user'
|
42
|
+
expect(Account.last.openstax_uid).to eq 4
|
43
|
+
expect(Account.last.username).to eq 'fuego'
|
44
|
+
|
45
|
+
expect(controller_class.last_action).to eq :updated
|
46
|
+
expect(controller_class.last_json).to eq [{'user_id' => 2, 'read_updates' => 1},
|
47
|
+
{'user_id' => 4, 'read_updates' => 2}]
|
48
|
+
|
49
|
+
controller_class.last_action = nil
|
50
|
+
controller_class.last_json = nil
|
51
|
+
|
52
|
+
SyncAccounts.call
|
53
|
+
expect(Account.count).to eq 2
|
54
|
+
expect(Account.first.openstax_uid).to eq 2
|
55
|
+
expect(Account.first.username).to eq 'user'
|
56
|
+
expect(Account.last.openstax_uid).to eq 4
|
57
|
+
expect(Account.last.username).to eq 'fuego'
|
58
|
+
|
59
|
+
expect(controller_class.last_action).to eq :updated
|
60
|
+
expect(controller_class.last_json).to eq [{'user_id' => 2, 'read_updates' => 1},
|
61
|
+
{'user_id' => 4, 'read_updates' => 2}]
|
62
|
+
ensure
|
63
|
+
OpenStax::Accounts.configuration.enable_stubbing = true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|