openstax_accounts 4.1.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -1
  3. data/app/controllers/openstax/accounts/application_controller.rb +1 -1
  4. data/app/models/openstax/accounts/account.rb +11 -6
  5. data/app/models/openstax/accounts/anonymous_account.rb +1 -1
  6. data/app/models/openstax/accounts/application_account.rb +2 -1
  7. data/app/models/openstax/accounts/group.rb +14 -12
  8. data/app/models/openstax/accounts/group_member.rb +10 -10
  9. data/app/models/openstax/accounts/group_nesting.rb +7 -13
  10. data/app/models/openstax/accounts/group_owner.rb +10 -10
  11. data/app/representers/openstax/accounts/api/v1/account_representer.rb +4 -3
  12. data/app/representers/openstax/accounts/api/v1/application_account_representer.rb +7 -2
  13. data/app/representers/openstax/accounts/api/v1/application_accounts_representer.rb +0 -2
  14. data/app/representers/openstax/accounts/api/v1/application_group_representer.rb +7 -2
  15. data/app/representers/openstax/accounts/api/v1/application_groups_representer.rb +0 -2
  16. data/app/representers/openstax/accounts/api/v1/group_nesting_representer.rb +1 -1
  17. data/app/representers/openstax/accounts/api/v1/group_representer.rb +1 -1
  18. data/app/representers/openstax/accounts/api/v1/group_user_representer.rb +1 -1
  19. data/app/routines/openstax/accounts/search_accounts.rb +1 -1
  20. data/app/routines/openstax/accounts/sync_accounts.rb +24 -27
  21. data/app/routines/openstax/accounts/sync_groups.rb +22 -26
  22. data/lib/openstax/accounts/action_controller/base.rb +61 -0
  23. data/lib/openstax/accounts/api.rb +270 -0
  24. data/lib/openstax/accounts/configuration.rb +77 -0
  25. data/lib/openstax/accounts/engine.rb +13 -11
  26. data/lib/openstax/accounts/has_many_through_groups/active_record/base.rb +51 -0
  27. data/lib/openstax/accounts/version.rb +1 -1
  28. data/lib/openstax_accounts.rb +8 -331
  29. data/spec/dummy/app/controllers/api/users_controller.rb +4 -0
  30. data/spec/dummy/config/routes.rb +3 -1
  31. data/spec/dummy/log/test.log +152307 -0
  32. data/spec/lib/openstax/accounts/api_spec.rb +232 -0
  33. data/spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb +57 -0
  34. data/spec/routines/openstax/accounts/sync_accounts_spec.rb +5 -9
  35. data/spec/routines/openstax/accounts/sync_groups_spec.rb +38 -39
  36. metadata +27 -16
  37. data/lib/openstax/accounts/extend_builtins.rb +0 -50
  38. data/lib/openstax/accounts/has_many_through_groups.rb +0 -47
  39. data/spec/lib/openstax/accounts/has_many_through_groups_spec.rb +0 -53
  40. data/spec/lib/openstax_accounts_spec.rb +0 -210
@@ -0,0 +1,232 @@
1
+ module OpenStax
2
+ module Accounts
3
+ describe Api do
4
+
5
+ let!(:account) { OpenStax::Accounts::Account.create(username: 'some_user',
6
+ first_name: 'Some', last_name: 'User', full_name: 'SomeUser',
7
+ title: 'Sir', openstax_uid: 1, access_token: 'secret') }
8
+
9
+ it 'makes api requests' do
10
+ expect(::Api::DummyController.last_action).to be_nil
11
+ expect(::Api::DummyController.last_params).to be_nil
12
+ Api.request(:post, 'dummy', :params => {:test => true})
13
+ expect(::Api::DummyController.last_action).to eq :dummy
14
+ expect(::Api::DummyController.last_params).to include 'test' => 'true'
15
+ end
16
+
17
+ context 'users' do
18
+
19
+ let!(:account) { FactoryGirl.create :openstax_accounts_account }
20
+
21
+ it 'makes api call to users index' do
22
+ ::Api::UsersController.last_action = nil
23
+ ::Api::UsersController.last_params = nil
24
+ Api.search_accounts('something')
25
+ expect(::Api::UsersController.last_action).to eq :index
26
+ expect(::Api::UsersController.last_params).to include :q => 'something'
27
+ end
28
+
29
+ it 'makes api call to user update' do
30
+ ::Api::UsersController.last_action = nil
31
+ ::Api::UsersController.last_json = nil
32
+ Api.update_account(account)
33
+ expect(::Api::UsersController.last_action).to eq :update
34
+ expect(::Api::UsersController.last_json).to include(
35
+ account.attributes.slice('username', 'first_name',
36
+ 'last_name', 'full_name', 'title'))
37
+ end
38
+
39
+ it 'makes api call to (temp) user create by email' do
40
+ ::Api::UsersController.last_action = nil
41
+ ::Api::UsersController.last_json = nil
42
+ Api.create_temp_account(email: 'dummy@dum.my')
43
+ expect(::Api::UsersController.last_action).to eq :create
44
+ expect(::Api::UsersController.last_json).to(
45
+ include('email' => 'dummy@dum.my')
46
+ )
47
+ end
48
+
49
+ it 'makes api call to (temp) user create by username' do
50
+ ::Api::UsersController.last_action = nil
51
+ ::Api::UsersController.last_json = nil
52
+ Api.create_temp_account(username: 'dummy')
53
+ expect(::Api::UsersController.last_action).to eq :create
54
+ expect(::Api::UsersController.last_json).to(
55
+ include('username' => 'dummy')
56
+ )
57
+ end
58
+
59
+ end
60
+
61
+ context 'application_users' do
62
+
63
+ it 'makes api call to application_users index' do
64
+ ::Api::ApplicationUsersController.last_action = nil
65
+ ::Api::ApplicationUsersController.last_params = nil
66
+ Api.search_application_accounts('something')
67
+ expect(::Api::ApplicationUsersController.last_action).to eq :index
68
+ expect(::Api::ApplicationUsersController.last_params).to include :q => 'something'
69
+ end
70
+
71
+ it 'makes api call to application_users updates' do
72
+ ::Api::ApplicationUsersController.last_action = nil
73
+ Api.get_application_account_updates
74
+ expect(::Api::ApplicationUsersController.last_action).to eq :updates
75
+ end
76
+
77
+ it 'makes api call to application_users updated' do
78
+ ::Api::ApplicationUsersController.last_action = nil
79
+ ::Api::ApplicationUsersController.last_json = nil
80
+ Api.mark_account_updates_as_read([{id: 1, read_updates: 1}])
81
+ expect(::Api::ApplicationUsersController.last_action).to eq :updated
82
+ expect(::Api::ApplicationUsersController.last_json).to include(
83
+ {'id' => 1, 'read_updates' => 1})
84
+ end
85
+
86
+ end
87
+
88
+ context 'groups' do
89
+
90
+ let!(:account) { FactoryGirl.create :openstax_accounts_account }
91
+ let!(:group) { FactoryGirl.create :openstax_accounts_group }
92
+
93
+ it 'makes api call to groups create' do
94
+ ::Api::GroupsController.last_action = nil
95
+ ::Api::GroupsController.last_json = nil
96
+ Api.create_group(account, group)
97
+ expect(::Api::GroupsController.last_action).to eq :create
98
+ expect(::Api::GroupsController.last_json).to include(
99
+ {'name' => 'MyGroup', 'is_public' => false})
100
+ end
101
+
102
+ it 'makes api call to group update' do
103
+ group.save!
104
+ ::Api::GroupsController.last_action = nil
105
+ ::Api::GroupsController.last_params = nil
106
+ ::Api::GroupsController.last_json = nil
107
+ Api.update_group(account, group)
108
+ expect(::Api::GroupsController.last_action).to eq :update
109
+ expect(::Api::GroupsController.last_params).to include(
110
+ {'id' => group.openstax_uid.to_s})
111
+ expect(::Api::GroupsController.last_json).to include(
112
+ {'name' => group.name, 'is_public' => group.is_public})
113
+ end
114
+
115
+ it 'makes api call to group destroy' do
116
+ group.save!
117
+ ::Api::GroupsController.last_action = nil
118
+ ::Api::GroupsController.last_params = nil
119
+ Api.destroy_group(account, group)
120
+ expect(::Api::GroupsController.last_action).to eq :destroy
121
+ expect(::Api::GroupsController.last_params).to include(
122
+ {'id' => group.openstax_uid.to_s})
123
+ end
124
+
125
+ end
126
+
127
+ context 'group_members' do
128
+
129
+ let!(:account) { FactoryGirl.create :openstax_accounts_account }
130
+ let!(:group_member) { FactoryGirl.build :openstax_accounts_group_member }
131
+
132
+ it 'makes api call to group_members create' do
133
+ ::Api::GroupMembersController.last_action = nil
134
+ ::Api::GroupMembersController.last_params = nil
135
+ Api.create_group_member(account, group_member)
136
+ expect(::Api::GroupMembersController.last_action).to eq :create
137
+ expect(::Api::GroupMembersController.last_params).to include(
138
+ {'group_id' => group_member.group_id.to_s,
139
+ 'user_id' => group_member.user_id.to_s})
140
+ end
141
+
142
+ it 'makes api call to group_member destroy' do
143
+ group_member.save!
144
+ ::Api::GroupMembersController.last_action = nil
145
+ ::Api::GroupMembersController.last_params = nil
146
+ Api.destroy_group_member(account, group_member)
147
+ expect(::Api::GroupMembersController.last_action).to eq :destroy
148
+ expect(::Api::GroupMembersController.last_params).to include(
149
+ {'group_id' => group_member.group_id.to_s,
150
+ 'user_id' => group_member.user_id.to_s})
151
+ end
152
+
153
+ end
154
+
155
+ context 'group_owners' do
156
+
157
+ let!(:account) { FactoryGirl.create :openstax_accounts_account }
158
+ let!(:group_owner) { FactoryGirl.build :openstax_accounts_group_owner }
159
+
160
+ it 'makes api call to group_owners create' do
161
+ ::Api::GroupOwnersController.last_action = nil
162
+ ::Api::GroupOwnersController.last_params = nil
163
+ Api.create_group_owner(account, group_owner)
164
+ expect(::Api::GroupOwnersController.last_action).to eq :create
165
+ expect(::Api::GroupOwnersController.last_params).to include(
166
+ {'group_id' => group_owner.group_id.to_s,
167
+ 'user_id' => group_owner.user_id.to_s})
168
+ end
169
+
170
+ it 'makes api call to group_owner destroy' do
171
+ group_owner.save!
172
+ ::Api::GroupOwnersController.last_action = nil
173
+ ::Api::GroupOwnersController.last_params = nil
174
+ Api.destroy_group_owner(account, group_owner)
175
+ expect(::Api::GroupOwnersController.last_action).to eq :destroy
176
+ expect(::Api::GroupOwnersController.last_params).to include(
177
+ {'group_id' => group_owner.group_id.to_s,
178
+ 'user_id' => group_owner.user_id.to_s})
179
+ end
180
+
181
+ end
182
+
183
+ context 'group_nestings' do
184
+
185
+ let!(:account) { FactoryGirl.create :openstax_accounts_account }
186
+ let!(:group_nesting) { FactoryGirl.build :openstax_accounts_group_nesting }
187
+
188
+ it 'makes api call to group_nestings (create)' do
189
+ ::Api::GroupNestingsController.last_action = nil
190
+ ::Api::GroupNestingsController.last_params = nil
191
+ Api.create_group_nesting(account, group_nesting)
192
+ expect(::Api::GroupNestingsController.last_action).to eq :create
193
+ expect(::Api::GroupNestingsController.last_params).to include(
194
+ {'group_id' => group_nesting.container_group_id.to_s,
195
+ 'member_group_id' => group_nesting.member_group_id.to_s})
196
+ end
197
+
198
+ it 'makes api call to group_nesting (destroy)' do
199
+ group_nesting.save!
200
+ ::Api::GroupNestingsController.last_action = nil
201
+ ::Api::GroupNestingsController.last_params = nil
202
+ Api.destroy_group_nesting(account, group_nesting)
203
+ expect(::Api::GroupNestingsController.last_action).to eq :destroy
204
+ expect(::Api::GroupNestingsController.last_params).to include(
205
+ {'group_id' => group_nesting.container_group_id.to_s,
206
+ 'member_group_id' => group_nesting.member_group_id.to_s})
207
+ end
208
+
209
+ end
210
+
211
+ context 'application_groups' do
212
+
213
+ it 'makes api call to application_groups_updates' do
214
+ ::Api::ApplicationGroupsController.last_action = nil
215
+ Api.get_application_group_updates
216
+ expect(::Api::ApplicationGroupsController.last_action).to eq :updates
217
+ end
218
+
219
+ it 'makes api call to application_groups_updated' do
220
+ ::Api::ApplicationGroupsController.last_action = nil
221
+ ::Api::ApplicationGroupsController.last_json = nil
222
+ Api.mark_group_updates_as_read([{id: 1, read_updates: 1}])
223
+ expect(::Api::ApplicationGroupsController.last_action).to eq :updated
224
+ expect(::Api::ApplicationGroupsController.last_json).to include(
225
+ {'id' => 1, 'read_updates' => 1})
226
+ end
227
+
228
+ end
229
+
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,57 @@
1
+ module OpenStax
2
+ module Accounts
3
+ module HasManyThroughGroups
4
+ module ActiveRecord
5
+ describe Base do
6
+ let!(:account_1) { FactoryGirl.create(:openstax_accounts_account,
7
+ username: 'some_user',
8
+ openstax_uid: 1) }
9
+ let!(:user_1) { User.create(:account => account_1) }
10
+
11
+ let!(:account_2) { FactoryGirl.create(:openstax_accounts_account,
12
+ username: 'another_user',
13
+ openstax_uid: 2) }
14
+ let!(:user_2) { User.create(:account => account_2) }
15
+
16
+ let!(:group_nesting) { FactoryGirl.create(:openstax_accounts_group_nesting) }
17
+
18
+ before(:each) do
19
+ group_nesting.member_group.add_member(account_1)
20
+ end
21
+
22
+ it 'allows users to retrieve all nested has_many_through_groups objects' do
23
+ expect(user_1.ownerships).to be_empty
24
+
25
+ o = Ownership.new
26
+ o.owner = user_2
27
+ o.save!
28
+
29
+ expect(user_1.reload.ownerships).to be_empty
30
+
31
+ o2 = Ownership.new
32
+ o2.owner = user_1
33
+ o2.save!
34
+
35
+ expect(user_1.reload.ownerships).to include(o2)
36
+
37
+ o3 = Ownership.new
38
+ o3.owner = group_nesting.member_group
39
+ o3.save!
40
+
41
+ expect(user_1.reload.ownerships).to include(o2)
42
+ expect(user_1.ownerships).to include(o3)
43
+
44
+ o4 = Ownership.new
45
+ o4.owner = group_nesting.container_group
46
+ o4.save!
47
+
48
+ expect(user_1.reload.ownerships).to include(o2)
49
+ expect(user_1.ownerships).to include(o3)
50
+ expect(user_1.ownerships).to include(o4)
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -17,15 +17,11 @@ module OpenStax
17
17
  unread_updates: 2, default_contact_info_id: 5}]
18
18
  end)
19
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
20
+ account = OpenStax::Accounts::Account.new
21
+ account.username = 'u'
22
+ account.openstax_uid = 2
23
+ account.syncing = true
24
+ account.save!
29
25
 
30
26
  begin
31
27
  OpenStax::Accounts.configuration.enable_stubbing = false
@@ -24,45 +24,44 @@ module OpenStax
24
24
  unread_updates: 2, default_contact_info_id: 5}]
25
25
  end)
26
26
 
27
- begin
28
- OpenStax::Accounts.syncing = true
29
- u = OpenStax::Accounts::Account.new
30
- u.openstax_uid = 2
31
- u.username = 'User'
32
- u.save!
33
-
34
- u2 = OpenStax::Accounts::Account.new
35
- u2.openstax_uid = 3
36
- u2.username = 'Fuego'
37
- u2.save!
38
-
39
- g = OpenStax::Accounts::Group.new
40
- g.name = 'Member Group'
41
- g.openstax_uid = 2
42
- g.save!
43
-
44
- gm = GroupMember.new
45
- gm.group = g
46
- gm.user = u
47
- gm.save!
48
-
49
- g2 = OpenStax::Accounts::Group.new
50
- g2.name = 'Container Group'
51
- g2.openstax_uid = 4
52
- g2.save!
53
-
54
- go = GroupOwner.new
55
- go.group = g2
56
- go.user = u
57
- go.save!
58
-
59
- gn = GroupNesting.new
60
- gn.container_group = g2
61
- gn.member_group = g
62
- gn.save!
63
- ensure
64
- OpenStax::Accounts.syncing = false
65
- end
27
+ u = OpenStax::Accounts::Account.new
28
+ u.openstax_uid = 2
29
+ u.username = 'User'
30
+ u.syncing = true
31
+ u.save!
32
+
33
+ u2 = OpenStax::Accounts::Account.new
34
+ u2.openstax_uid = 3
35
+ u2.username = 'Fuego'
36
+ u2.syncing = true
37
+ u2.save!
38
+
39
+ g = OpenStax::Accounts::Group.new
40
+ g.name = 'Member Group'
41
+ g.openstax_uid = 2
42
+ g.syncing = true
43
+ g.save!
44
+
45
+ gm = GroupMember.new
46
+ gm.group = g
47
+ gm.user = u
48
+ gm.save!
49
+
50
+ g2 = OpenStax::Accounts::Group.new
51
+ g2.name = 'Container Group'
52
+ g2.openstax_uid = 4
53
+ g2.syncing = true
54
+ g2.save!
55
+
56
+ go = GroupOwner.new
57
+ go.group = g2
58
+ go.user = u
59
+ go.save!
60
+
61
+ gn = GroupNesting.new
62
+ gn.container_group = g2
63
+ gn.member_group = g
64
+ gn.save!
66
65
 
67
66
  begin
68
67
  OpenStax::Accounts.configuration.enable_stubbing = false
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: 4.1.1
4
+ version: 5.0.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: 2015-03-20 00:00:00.000000000 Z
11
+ date: 2015-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -81,13 +81,24 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.5.0
83
83
  - !ruby/object:Gem::Dependency
84
- name: roar
84
+ name: representable
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '0.8'
90
- - - "<"
89
+ version: '2.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: roar
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
91
102
  - !ruby/object:Gem::Version
92
103
  version: '1.0'
93
104
  type: :runtime
@@ -95,9 +106,6 @@ dependencies:
95
106
  version_requirements: !ruby/object:Gem::Requirement
96
107
  requirements:
97
108
  - - ">="
98
- - !ruby/object:Gem::Version
99
- version: '0.8'
100
- - - "<"
101
109
  - !ruby/object:Gem::Version
102
110
  version: '1.0'
103
111
  - !ruby/object:Gem::Dependency
@@ -268,7 +276,8 @@ dependencies:
268
276
  - - ">="
269
277
  - !ruby/object:Gem::Version
270
278
  version: '0'
271
- description: Rails common code and bindings and for the 'accounts' API
279
+ description: This gem allows Rails apps to easily access the API's and login infrastructure
280
+ of OpenStax Accounts.
272
281
  email:
273
282
  - jps@kindlinglabs.com
274
283
  executables: []
@@ -330,11 +339,13 @@ files:
330
339
  - lib/generators/openstax/accounts/schedule/schedule_generator.rb
331
340
  - lib/generators/openstax/accounts/schedule/templates/schedule.rb
332
341
  - lib/omniauth/strategies/openstax.rb
342
+ - lib/openstax/accounts/action_controller/base.rb
343
+ - lib/openstax/accounts/api.rb
344
+ - lib/openstax/accounts/configuration.rb
333
345
  - lib/openstax/accounts/current_user_manager.rb
334
346
  - lib/openstax/accounts/default_account_user_mapper.rb
335
347
  - lib/openstax/accounts/engine.rb
336
- - lib/openstax/accounts/extend_builtins.rb
337
- - lib/openstax/accounts/has_many_through_groups.rb
348
+ - lib/openstax/accounts/has_many_through_groups/active_record/base.rb
338
349
  - lib/openstax/accounts/version.rb
339
350
  - lib/openstax_accounts.rb
340
351
  - spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb
@@ -398,9 +409,9 @@ files:
398
409
  - spec/factories/openstax_accounts_group_owner.rb
399
410
  - spec/handlers/openstax/accounts/accounts_search_spec.rb
400
411
  - spec/handlers/openstax/accounts/dev/accounts_search_spec.rb
412
+ - spec/lib/openstax/accounts/api_spec.rb
401
413
  - spec/lib/openstax/accounts/current_user_manager_spec.rb
402
- - spec/lib/openstax/accounts/has_many_through_groups_spec.rb
403
- - spec/lib/openstax_accounts_spec.rb
414
+ - spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb
404
415
  - spec/models/openstax/accounts/account_spec.rb
405
416
  - spec/models/openstax/accounts/anonymous_account_spec.rb
406
417
  - spec/models/openstax/accounts/group_spec.rb
@@ -430,7 +441,7 @@ rubyforge_project:
430
441
  rubygems_version: 2.4.6
431
442
  signing_key:
432
443
  specification_version: 4
433
- summary: Rails common code and bindings and for the 'accounts' API
444
+ summary: Rails common code and bindings for the 'accounts' API
434
445
  test_files:
435
446
  - spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb
436
447
  - spec/controllers/openstax/accounts/sessions_controller_spec.rb
@@ -493,9 +504,9 @@ test_files:
493
504
  - spec/factories/openstax_accounts_group_owner.rb
494
505
  - spec/handlers/openstax/accounts/accounts_search_spec.rb
495
506
  - spec/handlers/openstax/accounts/dev/accounts_search_spec.rb
507
+ - spec/lib/openstax/accounts/api_spec.rb
496
508
  - spec/lib/openstax/accounts/current_user_manager_spec.rb
497
- - spec/lib/openstax/accounts/has_many_through_groups_spec.rb
498
- - spec/lib/openstax_accounts_spec.rb
509
+ - spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb
499
510
  - spec/models/openstax/accounts/account_spec.rb
500
511
  - spec/models/openstax/accounts/anonymous_account_spec.rb
501
512
  - spec/models/openstax/accounts/group_spec.rb