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.
Files changed (77) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +1 -0
  3. data/Rakefile +6 -6
  4. data/app/models/openstax/accounts/account.rb +34 -24
  5. data/app/models/openstax/accounts/application_group.rb +7 -0
  6. data/app/models/openstax/accounts/group.rb +132 -0
  7. data/app/models/openstax/accounts/group_member.rb +40 -0
  8. data/app/models/openstax/accounts/group_nesting.rb +62 -0
  9. data/app/models/openstax/accounts/group_owner.rb +40 -0
  10. data/app/representers/openstax/accounts/api/v1/application_group_representer.rb +25 -0
  11. data/app/representers/openstax/accounts/api/v1/application_groups_representer.rb +16 -0
  12. data/app/representers/openstax/accounts/api/v1/group_nesting_representer.rb +18 -0
  13. data/app/representers/openstax/accounts/api/v1/group_representer.rb +50 -0
  14. data/app/representers/openstax/accounts/api/v1/group_user_representer.rb +21 -0
  15. data/app/routines/openstax/accounts/search_accounts.rb +7 -14
  16. data/app/routines/openstax/accounts/sync_accounts.rb +32 -18
  17. data/app/routines/openstax/accounts/sync_groups.rb +61 -0
  18. data/app/routines/openstax/accounts/update_group_caches.rb +27 -0
  19. data/app/views/openstax/accounts/shared/accounts/_index.html.erb +0 -3
  20. data/config/initializers/action_interceptor.rb +1 -1
  21. data/db/migrate/20140811182433_create_openstax_accounts_groups.rb +16 -0
  22. data/db/migrate/20140811182505_create_openstax_accounts_group_members.rb +13 -0
  23. data/db/migrate/20140811182527_create_openstax_accounts_group_owners.rb +13 -0
  24. data/db/migrate/20140811182553_create_openstax_accounts_group_nestings.rb +13 -0
  25. data/lib/generators/openstax/accounts/schedule/templates/schedule.rb +1 -0
  26. data/lib/openstax/accounts/current_user_manager.rb +2 -2
  27. data/lib/openstax/accounts/has_many_through_groups.rb +45 -0
  28. data/lib/openstax/accounts/version.rb +1 -1
  29. data/lib/openstax_accounts.rb +165 -11
  30. data/spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb +1 -1
  31. data/spec/controllers/openstax/accounts/sessions_controller_spec.rb +1 -1
  32. data/spec/dummy/app/controllers/api/application_groups_controller.rb +11 -0
  33. data/spec/dummy/app/controllers/api/dummy_controller.rb +2 -1
  34. data/spec/dummy/app/controllers/api/group_members_controller.rb +11 -0
  35. data/spec/dummy/app/controllers/api/group_nestings_controller.rb +11 -0
  36. data/spec/dummy/app/controllers/api/group_owners_controller.rb +11 -0
  37. data/spec/dummy/app/controllers/api/groups_controller.rb +15 -0
  38. data/spec/dummy/app/controllers/api/users_controller.rb +4 -0
  39. data/spec/dummy/app/models/ownership.rb +7 -0
  40. data/spec/dummy/app/models/user.rb +11 -8
  41. data/spec/dummy/config/application.rb +0 -33
  42. data/spec/dummy/config/boot.rb +4 -9
  43. data/spec/dummy/config/database.yml +8 -8
  44. data/spec/dummy/config/environment.rb +3 -3
  45. data/spec/dummy/config/environments/development.rb +20 -12
  46. data/spec/dummy/config/environments/production.rb +42 -29
  47. data/spec/dummy/config/environments/test.rb +16 -12
  48. data/spec/dummy/config/initializers/assets.rb +8 -0
  49. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  50. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  51. data/spec/dummy/config/initializers/inflections.rb +6 -5
  52. data/spec/dummy/config/initializers/mime_types.rb +0 -1
  53. data/spec/dummy/config/initializers/session_store.rb +1 -6
  54. data/spec/dummy/config/initializers/wrap_parameters.rb +6 -6
  55. data/spec/dummy/config/routes.rb +23 -0
  56. data/spec/dummy/config/secrets.yml +8 -0
  57. data/spec/dummy/db/migrate/1_create_users.rb +2 -2
  58. data/spec/dummy/db/migrate/2_create_ownerships.rb +11 -0
  59. data/spec/dummy/db/schema.rb +72 -20
  60. data/spec/dummy/db/test.sqlite3 +0 -0
  61. data/spec/dummy/log/development.log +186 -0
  62. data/spec/dummy/log/test.log +2078 -0
  63. data/spec/factories/openstax_accounts_account.rb +3 -2
  64. data/spec/factories/openstax_accounts_group.rb +7 -0
  65. data/spec/factories/openstax_accounts_group_member.rb +6 -0
  66. data/spec/factories/openstax_accounts_group_nesting.rb +6 -0
  67. data/spec/factories/openstax_accounts_group_owner.rb +6 -0
  68. data/spec/lib/openstax/accounts/current_user_manager_spec.rb +9 -3
  69. data/spec/lib/openstax/accounts/has_many_through_groups_spec.rb +53 -0
  70. data/spec/lib/openstax_accounts_spec.rb +189 -25
  71. data/spec/models/openstax/accounts/account_spec.rb +16 -1
  72. data/spec/models/openstax/accounts/anonymous_account_spec.rb +1 -1
  73. data/spec/models/openstax/accounts/group_spec.rb +20 -0
  74. data/spec/routines/openstax/accounts/sync_accounts_spec.rb +70 -0
  75. data/spec/routines/openstax/accounts/sync_groups_spec.rb +125 -0
  76. metadata +73 -56
  77. 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
- sequence(:openstax_uid) { -SecureRandom.hex.to_i(16) }
4
- sequence(:username) { SecureRandom.hex }
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
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :openstax_accounts_group, :class => OpenStax::Accounts::Group do
3
+ openstax_uid { -SecureRandom.hex.to_i(16) }
4
+ name "MyGroup"
5
+ is_public false
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :openstax_accounts_group_member, :class => OpenStax::Accounts::GroupMember do
3
+ association :group, factory: :openstax_accounts_group
4
+ association :user, factory: :openstax_accounts_account
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :openstax_accounts_group_nesting, :class => OpenStax::Accounts::GroupNesting do
3
+ association :container_group, factory: :openstax_accounts_group
4
+ association :member_group, factory: :openstax_accounts_group
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :openstax_accounts_group_owner, :class => OpenStax::Accounts::GroupOwner do
3
+ association :group, factory: :openstax_accounts_group
4
+ association :user, factory: :openstax_accounts_account
5
+ end
6
+ 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(:openstax_accounts_account => account) }
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, 'localhost') }
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, 'localhost')
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
- openstax_uid: 1, access_token: 'secret') }
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
- it 'makes api call to accounts (index)' do
15
- Api::UsersController.last_action = nil
16
- Api::UsersController.last_params = nil
17
- Accounts.search_accounts('sth')
18
- expect(Api::UsersController.last_action).to eq :index
19
- expect(Api::UsersController.last_params).to include :q => 'sth'
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
- it 'makes api call to application_accounts (index)' do
23
- Api::ApplicationUsersController.last_action = nil
24
- Api::ApplicationUsersController.last_params = nil
25
- Accounts.search_application_accounts('sth')
26
- expect(Api::ApplicationUsersController.last_action).to eq :index
27
- expect(Api::ApplicationUsersController.last_params).to include :q => 'sth'
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
- it 'makes api call to application_users_updates' do
31
- Api::ApplicationUsersController.last_action = nil
32
- Api::ApplicationUsersController.last_params = nil
33
- Accounts.get_application_account_updates
34
- expect(Api::ApplicationUsersController.last_action).to eq :updates
35
- expect(Api::ApplicationUsersController.last_params).not_to be_nil
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
- it 'makes api call to application_users_updated' do
39
- Api::ApplicationUsersController.last_action = nil
40
- Api::ApplicationUsersController.last_params = nil
41
- Accounts.mark_updates_as_read({1 => 1})
42
- expect(Api::ApplicationUsersController.last_action).to eq :updated
43
- expect(Api::ApplicationUsersController.last_params[:application_users]).to include '1' => '1'
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 be_false
21
+ expect(Account.new.is_anonymous?).to eq false
7
22
  end
8
23
  end
9
24
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module OpenStax::Accounts
4
4
  describe AnonymousAccount do
5
5
  it 'is anonymous' do
6
- expect(AnonymousAccount.instance.is_anonymous?).to be_true
6
+ expect(AnonymousAccount.instance.is_anonymous?).to eq true
7
7
  end
8
8
  end
9
9
  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