openstax_accounts 7.13.0 → 8.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/openstax/accounts/application_controller.rb +1 -1
  3. data/app/controllers/openstax/accounts/dev/accounts_controller.rb +1 -1
  4. data/app/controllers/openstax/accounts/dev/base_controller.rb +1 -1
  5. data/app/controllers/openstax/accounts/sessions_controller.rb +7 -8
  6. data/app/handlers/openstax/accounts/sessions_callback.rb +17 -37
  7. data/app/models/openstax/accounts/account.rb +33 -1
  8. data/app/models/openstax/accounts/group.rb +12 -8
  9. data/app/models/openstax/accounts/group_nesting.rb +8 -7
  10. data/app/representers/openstax/accounts/api/v1/unclaimed_account_representer.rb +1 -7
  11. data/app/routines/openstax/accounts/find_or_create_account.rb +9 -9
  12. data/app/routines/openstax/accounts/find_or_create_from_sso.rb +23 -0
  13. data/app/routines/openstax/accounts/sync_accounts.rb +1 -6
  14. data/config/routes.rb +11 -11
  15. data/db/migrate/0_create_openstax_accounts_accounts.rb +1 -1
  16. data/db/migrate/10_assign_missing_uuids_for_local_accounts.rb +2 -2
  17. data/db/migrate/11_add_support_identifier_to_accounts_accounts.rb +1 -1
  18. data/db/migrate/12_add_is_test_to_accounts_accounts.rb +1 -1
  19. data/db/migrate/13_add_school_type_to_accounts_accounts.rb +1 -1
  20. data/db/migrate/1_create_openstax_accounts_groups.rb +1 -1
  21. data/db/migrate/2_create_openstax_accounts_group_members.rb +1 -1
  22. data/db/migrate/3_create_openstax_accounts_group_owners.rb +1 -1
  23. data/db/migrate/4_create_openstax_accounts_group_nestings.rb +1 -1
  24. data/db/migrate/5_add_faculty_status_to_accounts_accounts.rb +1 -1
  25. data/db/migrate/6_add_salesforce_contact_id_to_accounts_accounts.rb +1 -1
  26. data/db/migrate/7_change_accounts_openstax_uid_to_be_nullable.rb +1 -1
  27. data/db/migrate/8_change_accounts_username_to_be_nullable.rb +1 -1
  28. data/db/migrate/9_add_uuid_and_role_to_accounts_accounts.rb +1 -1
  29. data/lib/omniauth/strategies/openstax.rb +6 -23
  30. data/lib/openstax/accounts/configuration.rb +16 -0
  31. data/lib/openstax/accounts/current_user_manager.rb +20 -0
  32. data/lib/openstax/accounts/has_many_through_groups/active_record/base.rb +5 -5
  33. data/lib/openstax/accounts/sso.rb +61 -0
  34. data/lib/openstax/accounts/version.rb +1 -1
  35. data/lib/openstax_accounts.rb +6 -7
  36. data/lib/tasks/sync.rake +3 -3
  37. data/spec/factories/openstax_accounts_account.rb +1 -1
  38. data/spec/factories/openstax_accounts_group.rb +3 -3
  39. data/spec/factories/openstax_accounts_group_member.rb +1 -1
  40. data/spec/factories/openstax_accounts_group_nesting.rb +1 -1
  41. data/spec/factories/openstax_accounts_group_owner.rb +1 -1
  42. metadata +34 -212
  43. data/Rakefile +0 -22
  44. data/spec/cassettes/OpenStax_Accounts_FindOrCreateAccount/can_create_users.yml +0 -303
  45. data/spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb +0 -27
  46. data/spec/controllers/openstax/accounts/forwards_params_spec.rb +0 -75
  47. data/spec/controllers/openstax/accounts/sessions_controller_spec.rb +0 -71
  48. data/spec/controllers/openstax/accounts/uses_this_engine_controller_spec.rb +0 -22
  49. data/spec/dummy/README.md +0 -1
  50. data/spec/dummy/Rakefile +0 -7
  51. data/spec/dummy/app/access_policies/account_access_policy.rb +0 -11
  52. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  53. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  54. data/spec/dummy/app/controllers/api/application_groups_controller.rb +0 -11
  55. data/spec/dummy/app/controllers/api/application_users_controller.rb +0 -15
  56. data/spec/dummy/app/controllers/api/dummy_controller.rb +0 -12
  57. data/spec/dummy/app/controllers/api/group_members_controller.rb +0 -11
  58. data/spec/dummy/app/controllers/api/group_nestings_controller.rb +0 -11
  59. data/spec/dummy/app/controllers/api/group_owners_controller.rb +0 -11
  60. data/spec/dummy/app/controllers/api/groups_controller.rb +0 -15
  61. data/spec/dummy/app/controllers/api/users_controller.rb +0 -15
  62. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  63. data/spec/dummy/app/controllers/oauth_controller.rb +0 -10
  64. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  65. data/spec/dummy/app/models/anonymous_user.rb +0 -48
  66. data/spec/dummy/app/models/ownership.rb +0 -7
  67. data/spec/dummy/app/models/user.rb +0 -29
  68. data/spec/dummy/config.ru +0 -5
  69. data/spec/dummy/config/application.rb +0 -23
  70. data/spec/dummy/config/boot.rb +0 -5
  71. data/spec/dummy/config/database.yml +0 -15
  72. data/spec/dummy/config/environment.rb +0 -5
  73. data/spec/dummy/config/environments/development.rb +0 -40
  74. data/spec/dummy/config/environments/production.rb +0 -82
  75. data/spec/dummy/config/environments/test.rb +0 -39
  76. data/spec/dummy/config/initializers/access_policies.rb +0 -1
  77. data/spec/dummy/config/initializers/assets.rb +0 -8
  78. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  79. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  80. data/spec/dummy/config/initializers/doorkeeper.rb +0 -75
  81. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  82. data/spec/dummy/config/initializers/inflections.rb +0 -16
  83. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  84. data/spec/dummy/config/initializers/openstax_accounts.rb +0 -14
  85. data/spec/dummy/config/initializers/session_store.rb +0 -3
  86. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  87. data/spec/dummy/config/locales/en.yml +0 -5
  88. data/spec/dummy/config/routes.rb +0 -45
  89. data/spec/dummy/config/secrets.yml +0 -8
  90. data/spec/dummy/db/development.sqlite3 +0 -0
  91. data/spec/dummy/db/migrate/1000_create_users.rb +0 -11
  92. data/spec/dummy/db/migrate/1001_create_ownerships.rb +0 -11
  93. data/spec/dummy/db/schema.rb +0 -113
  94. data/spec/dummy/db/test.sqlite3 +0 -0
  95. data/spec/dummy/log/development.log +0 -5137
  96. data/spec/dummy/log/test.log +0 -162651
  97. data/spec/dummy/public/404.html +0 -26
  98. data/spec/dummy/public/422.html +0 -26
  99. data/spec/dummy/public/500.html +0 -25
  100. data/spec/dummy/public/favicon.ico +0 -0
  101. data/spec/dummy/script/rails +0 -6
  102. data/spec/handlers/openstax/accounts/accounts_search_spec.rb +0 -63
  103. data/spec/handlers/openstax/accounts/dev/accounts_search_spec.rb +0 -55
  104. data/spec/handlers/openstax/accounts/sessions_callback_spec.rb +0 -119
  105. data/spec/lib/openstax/accounts/api_spec.rb +0 -212
  106. data/spec/lib/openstax/accounts/configuration_spec.rb +0 -39
  107. data/spec/lib/openstax/accounts/current_user_manager_spec.rb +0 -157
  108. data/spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb +0 -57
  109. data/spec/models/openstax/accounts/account_spec.rb +0 -114
  110. data/spec/models/openstax/accounts/anonymous_account_spec.rb +0 -9
  111. data/spec/models/openstax/accounts/group_spec.rb +0 -51
  112. data/spec/routines/openstax/accounts/create_group_spec.rb +0 -32
  113. data/spec/routines/openstax/accounts/find_or_create_account_spec.rb +0 -76
  114. data/spec/routines/openstax/accounts/search_accounts_shared_examples.rb +0 -160
  115. data/spec/routines/openstax/accounts/search_accounts_spec.rb +0 -6
  116. data/spec/routines/openstax/accounts/search_local_accounts_spec.rb +0 -6
  117. data/spec/routines/openstax/accounts/sync_accounts_spec.rb +0 -101
  118. data/spec/routines/openstax/accounts/sync_groups_spec.rb +0 -143
  119. data/spec/spec_helper.rb +0 -109
  120. data/spec/vcr_helper.rb +0 -14
@@ -1,76 +0,0 @@
1
- require 'spec_helper'
2
- require 'vcr_helper'
3
-
4
- module OpenStax
5
- module Accounts
6
-
7
- RSpec.describe FindOrCreateAccount, type: :routine, vcr: VCR_OPTS do
8
-
9
- before(:all) do
10
- @previous_url = OpenStax::Accounts.configuration.openstax_accounts_url
11
- @previous_enable_stubbing = OpenStax::Accounts.configuration.enable_stubbing
12
- OpenStax::Accounts.configuration.openstax_accounts_url = "http://localhost:2999/"
13
- OpenStax::Accounts.configuration.enable_stubbing = false
14
- OpenStax::Accounts::Api.client.site = "http://localhost:2999/"
15
- end
16
-
17
- it 'can create users' do
18
- account_1 = described_class.call(
19
- email: 'alice@example.com', role: 'instructor'
20
- ).outputs.account
21
- expect(account_1).to be_persisted
22
- expect(account_1.uuid).to(
23
- match(/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i)
24
- )
25
- expect(account_1.support_identifier).to match(/\Acs_[0-9a-f]{8}\z/i)
26
- expect(account_1.role).to eq 'instructor'
27
-
28
- account_2 = described_class.call(username: 'alice').outputs.account
29
- expect(account_2).to be_persisted
30
- expect(account_1).not_to eq(account_2)
31
-
32
- account_3 = described_class.call(username: 'alice2',
33
- password: 'abcdefghijklmnop').outputs.account
34
- expect(account_3).to be_persisted
35
- expect(account_1).not_to eq(account_3)
36
- expect(account_2).not_to eq(account_3)
37
- end
38
-
39
- it 'passes params to the API when creating users' do
40
- find_or_create_account_response = double('Response')
41
- allow(find_or_create_account_response).to receive(:status).and_return(201)
42
- allow(find_or_create_account_response).to(
43
- receive(:body).and_return(
44
- "{\"id\":1,\"uuid\":\"#{SecureRandom.uuid
45
- }\",\"support_identifier\":\"cs_#{SecureRandom.hex(4)}\"}"
46
- )
47
- )
48
- expect(OpenStax::Accounts::Api).to receive(:find_or_create_account).with(
49
- email: 'bob@example.com', username: nil, password: nil,
50
- first_name: 'Bob', last_name: 'Smith', full_name: 'Bob Smith',
51
- salesforce_contact_id: 'b0b', faculty_status: :rejected_faculty,
52
- role: :instructor, school_type: :college
53
- ).and_return(find_or_create_account_response)
54
-
55
- described_class.call(
56
- email: 'bob@example.com',
57
- first_name: 'Bob',
58
- last_name: 'Smith',
59
- full_name: 'Bob Smith',
60
- salesforce_contact_id: 'b0b',
61
- faculty_status: :rejected_faculty,
62
- role: :instructor,
63
- school_type: :college
64
- )
65
- end
66
-
67
- after(:all) do
68
- OpenStax::Accounts.configuration.openstax_accounts_url = @previous_url
69
- OpenStax::Accounts.configuration.enable_stubbing = @previous_enable_stubbing
70
- OpenStax::Accounts::Api.client.site = @previous_url
71
- end
72
-
73
- end
74
-
75
- end
76
- end
@@ -1,160 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.shared_examples 'search accounts' do
4
-
5
- let!(:account_1) do
6
- FactoryBot.create :openstax_accounts_account, first_name: 'John',
7
- last_name: 'Stravinsky',
8
- username: 'jstrav'
9
- end
10
- let!(:account_2) do
11
- FactoryBot.create :openstax_accounts_account, first_name: 'Mary',
12
- last_name: 'Mighty',
13
- full_name: 'Mary Mighty',
14
- username: 'mary'
15
- end
16
- let!(:account_3) do
17
- FactoryBot.create :openstax_accounts_account, first_name: 'John',
18
- last_name: 'Stead',
19
- username: 'jstead'
20
- end
21
-
22
- let!(:account_4) do
23
- FactoryBot.create :openstax_accounts_account, first_name: 'Bob',
24
- last_name: 'JST',
25
- username: 'bigbear'
26
- end
27
-
28
- it 'should match based on username' do
29
- outcome = described_class.call('username:jstra').outputs.items
30
- expect(outcome).to eq [account_1]
31
- end
32
-
33
- it 'should ignore leading wildcards on username searches' do
34
- outcome = described_class.call('username:%rav').outputs.items
35
- expect(outcome).to eq []
36
- end
37
-
38
- it 'should match based on one first name' do
39
- outcome = described_class.call('first_name:"John"').outputs.items
40
- expect(outcome).to eq [account_3, account_1]
41
- end
42
-
43
- it 'should match based on one full name' do
44
- outcome = described_class.call('full_name:"Mary Mighty"').outputs.items
45
- expect(outcome).to eq [account_2]
46
- end
47
-
48
- it 'should match based on id (openstax_uid)' do
49
- outcome = described_class.call("id:#{account_3.openstax_uid}").outputs.items
50
- expect(outcome).to eq [account_3]
51
- end
52
-
53
- it 'should match based on uuid' do
54
- outcome = described_class.call("uuid:#{account_3.uuid}").outputs.items
55
- expect(outcome).to eq [account_3]
56
- end
57
-
58
- it 'should match based on support_identifier' do
59
- outcome = described_class.call(
60
- "support_identifier:#{account_3.support_identifier}"
61
- ).outputs.items
62
- expect(outcome).to eq [account_3]
63
- end
64
-
65
- it 'should return all results if the query is empty' do
66
- outcome = described_class.call('').outputs.items
67
- expect(outcome).to eq [account_4, account_3, account_1, account_2]
68
- end
69
-
70
- it 'should match any field when no prefix given' do
71
- outcome = described_class.call('jst').outputs.items
72
- expect(outcome).to eq [account_4, account_3, account_1]
73
- end
74
-
75
- it 'should match any field when no prefix given and intersect when prefix given' do
76
- outcome = described_class.call('jst username:jst').outputs.items
77
- expect(outcome).to eq [account_3, account_1]
78
- end
79
-
80
- it 'shouldn\'t allow users to add their own wildcards' do
81
- outcome = described_class.call("username:'%ar'").outputs.items
82
- expect(outcome).to eq []
83
- end
84
-
85
- it 'should gather comma-separated unprefixed search terms' do
86
- outcome = described_class.call('john,mighty').outputs.items
87
- expect(outcome).to eq [account_3, account_1, account_2]
88
- end
89
-
90
- it 'should not gather space-separated unprefixed search terms' do
91
- outcome = described_class.call('john mighty').outputs.items
92
- expect(outcome).to eq []
93
- end
94
-
95
- context 'pagination and sorting' do
96
-
97
- let!(:billy_accounts) do
98
- (0..45).to_a.map do |ii|
99
- FactoryBot.create :openstax_accounts_account,
100
- first_name: "Billy#{ii.to_s.rjust(2, '0')}",
101
- last_name: "Bob_#{(45-ii).to_s.rjust(2,'0')}",
102
- username: "billy_#{ii.to_s.rjust(2, '0')}"
103
- end
104
- end
105
-
106
- it 'should return the first page of values by default when requested' do
107
- outcome = described_class.call('username:billy', per_page: 20).outputs.items
108
- expect(outcome.length).to eq 20
109
- expect(outcome[0]).to eq OpenStax::Accounts::Account.find_by!(username: 'billy_00')
110
- expect(outcome[19]).to eq OpenStax::Accounts::Account.find_by!(username: 'billy_19')
111
- end
112
-
113
- it 'should return the second page when requested' do
114
- outcome = described_class.call('username:billy', page: 2, per_page: 20).outputs.items
115
- expect(outcome.length).to eq 20
116
- expect(outcome[0]).to eq OpenStax::Accounts::Account.find_by!(username: 'billy_20')
117
- expect(outcome[19]).to eq OpenStax::Accounts::Account.find_by!(username: 'billy_39')
118
- end
119
-
120
- it 'should return the incomplete 3rd page when requested' do
121
- outcome = described_class.call('username:billy', page: 3, per_page: 20).outputs.items
122
- expect(outcome.length).to eq 6
123
- expect(outcome[5]).to eq OpenStax::Accounts::Account.find_by!(username: 'billy_45')
124
- end
125
-
126
- end
127
-
128
- context 'sorting' do
129
-
130
- let!(:bob_brown) do
131
- FactoryBot.create :openstax_accounts_account, first_name: 'Bob',
132
- last_name: 'Brown',
133
- username: 'foo_bb'
134
- end
135
- let!(:bob_jones) do
136
- FactoryBot.create :openstax_accounts_account, first_name: 'Bob',
137
- last_name: 'Jones',
138
- username: 'foo_bj'
139
- end
140
- let!(:tim_jones) do
141
- FactoryBot.create :openstax_accounts_account, first_name: 'Tim',
142
- last_name: 'Jones',
143
- username: 'foo_tj'
144
- end
145
-
146
- it 'should allow sort by multiple fields in different directions' do
147
- outcome = described_class.call(
148
- 'username:foo', order_by: 'first_name, last_name DESC'
149
- ).outputs.items
150
- expect(outcome).to eq [bob_jones, bob_brown, tim_jones]
151
-
152
- outcome = described_class.call(
153
- 'username:foo', order_by: 'first_name, last_name ASC'
154
- ).outputs.items
155
- expect(outcome).to eq [bob_brown, bob_jones, tim_jones]
156
- end
157
-
158
- end
159
-
160
- end
@@ -1,6 +0,0 @@
1
- require 'spec_helper'
2
- require_relative 'search_accounts_shared_examples'
3
-
4
- RSpec.describe OpenStax::Accounts::SearchAccounts, type: :routine do
5
- include_examples 'search accounts'
6
- end
@@ -1,6 +0,0 @@
1
- require 'spec_helper'
2
- require_relative 'search_accounts_shared_examples'
3
-
4
- RSpec.describe OpenStax::Accounts::SearchLocalAccounts, type: :routine do
5
- include_examples 'search accounts'
6
- end
@@ -1,101 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module OpenStax
4
- module Accounts
5
-
6
- RSpec.describe SyncAccounts, type: :routine do
7
-
8
- it 'can sync accounts' do
9
- controller_class = ::Api::ApplicationUsersController
10
- uuid_1 = SecureRandom.uuid
11
- uuid_2 = SecureRandom.uuid
12
- support_identifier_1 = "cs_#{SecureRandom.hex(4)}"
13
- support_identifier_2 = "cs_#{SecureRandom.hex(4)}"
14
- allow_any_instance_of(controller_class).to(
15
- receive(:updates) do |controller|
16
- controller.render json: [
17
- {
18
- id: 1,
19
- application_id: 1,
20
- user: {
21
- id: 2,
22
- username: 'user',
23
- self_reported_role: 'instructor',
24
- uuid: uuid_1,
25
- support_identifier: support_identifier_1,
26
- is_test: true
27
- },
28
- unread_updates: 1,
29
- default_contact_info_id: 1
30
- },
31
- {
32
- id: 3,
33
- application_id: 1,
34
- user: {
35
- id: 4,
36
- username: 'fuego',
37
- uuid: uuid_2,
38
- support_identifier: support_identifier_2
39
- },
40
- unread_updates: 2,
41
- default_contact_info_id: 5
42
- }
43
- ]
44
- end
45
- )
46
-
47
- account = FactoryBot.create :openstax_accounts_account, username: 'u', openstax_uid: 2
48
- account.syncing = true
49
-
50
- begin
51
- OpenStax::Accounts.configuration.enable_stubbing = false
52
- expect(account.reload.openstax_uid).to eq 2
53
- expect(account.username).to eq 'u'
54
- expect(Account.find_by(openstax_uid: 4)).to be_nil
55
-
56
- controller_class.last_action = nil
57
- controller_class.last_json = nil
58
-
59
- expect { SyncAccounts.call }.to change { Account.count }.by(1)
60
-
61
- account_2 = Account.find_by(openstax_uid: 4)
62
-
63
- expect(account.reload.openstax_uid).to eq 2
64
- expect(account.username).to eq 'user'
65
- expect(account.role).to eq 'instructor'
66
- expect(account.uuid).to eq uuid_1
67
- expect(account.support_identifier).to eq support_identifier_1
68
- expect(account.is_test).to eq true
69
- expect(account_2.username).to eq 'fuego'
70
- expect(account_2.uuid).to eq uuid_2
71
- expect(account_2.support_identifier).to eq support_identifier_2
72
- expect(account_2.is_test).to be_nil
73
-
74
- expect(controller_class.last_action).to eq :updated
75
- expect(controller_class.last_json).to eq [
76
- {'user_id' => 2, 'read_updates' => 1}, {'user_id' => 4, 'read_updates' => 2}
77
- ]
78
-
79
- controller_class.last_action = nil
80
- controller_class.last_json = nil
81
-
82
- expect { SyncAccounts.call }.not_to change { Account.count }
83
-
84
- expect(account.reload.openstax_uid).to eq 2
85
- expect(account.username).to eq 'user'
86
- expect(account_2.reload.openstax_uid).to eq 4
87
- expect(account_2.username).to eq 'fuego'
88
-
89
- expect(controller_class.last_action).to eq :updated
90
- expect(controller_class.last_json).to eq [
91
- {'user_id' => 2, 'read_updates' => 1}, {'user_id' => 4, 'read_updates' => 2}
92
- ]
93
- ensure
94
- OpenStax::Accounts.configuration.enable_stubbing = true
95
- end
96
- end
97
-
98
- end
99
-
100
- end
101
- end
@@ -1,143 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module OpenStax
4
- module Accounts
5
-
6
- RSpec.describe SyncGroups, type: :routine do
7
-
8
- it 'can sync groups' do
9
- controller_class = ::Api::ApplicationGroupsController
10
- allow_any_instance_of(controller_class).to(
11
- receive(:updates) do |controller|
12
- controller.render json: [
13
- {
14
- id: 1,
15
- application_id: 1,
16
- group: {
17
- id: 2,
18
- name: 'M',
19
- members: [],
20
- owners: [],
21
- nestings: [
22
- {
23
- container_group_id: 2,
24
- member_group_id: 3
25
- }
26
- ]
27
- },
28
- unread_updates: 1,
29
- default_contact_info_id: 1
30
- },
31
- {
32
- id: 3,
33
- application_id: 1,
34
- group: {
35
- id: 3,
36
- name: 'Fuego\'s Deputies',
37
- members: [
38
- {
39
- group_id: 3,
40
- user: {
41
- id: 2,
42
- username: 'User'
43
- }
44
- }
45
- ],
46
- owners: [
47
- {
48
- group_id: 3,
49
- user: {
50
- id: 3,
51
- username: 'Fuego'
52
- }
53
- }
54
- ],
55
- nestings: []
56
- },
57
- unread_updates: 2,
58
- default_contact_info_id: 5
59
- }
60
- ]
61
- end
62
- )
63
-
64
- u = FactoryBot.create :openstax_accounts_account, openstax_uid: 2, username: 'User'
65
- u.syncing = true
66
-
67
- u2 = FactoryBot.create :openstax_accounts_account, openstax_uid: 3, username: 'Fuego'
68
- u2.syncing = true
69
-
70
- g = FactoryBot.create :openstax_accounts_group, openstax_uid: 2, name: 'Member Group'
71
- g.syncing = true
72
-
73
- gm = FactoryBot.create :openstax_accounts_group_member, group: g, user: u
74
-
75
- g2 = FactoryBot.create :openstax_accounts_group, openstax_uid: 4, name: 'Container Group'
76
- g2.syncing = true
77
-
78
- go = FactoryBot.create :openstax_accounts_group_owner, group: g2, user: u
79
-
80
- gn = FactoryBot.create :openstax_accounts_group_nesting, container_group: g2,
81
- member_group: g
82
-
83
- begin
84
- OpenStax::Accounts.configuration.enable_stubbing = false
85
- expect(g.reload.openstax_uid).to eq 2
86
- expect(g.name).to eq 'Member Group'
87
- expect(g.members).to eq [ u ]
88
- expect(g2.reload.openstax_uid).to eq 4
89
- expect(g2.name).to eq 'Container Group'
90
- expect(g2.member_groups).to eq [ g ]
91
- expect(g2.owners).to eq [ u ]
92
-
93
- controller_class.last_action = nil
94
- controller_class.last_json = nil
95
-
96
- expect { SyncGroups.call }.to change { Group.count }.by(1)
97
-
98
- g3 = Group.find_by(openstax_uid: 3)
99
-
100
- expect(g.reload.openstax_uid).to eq 2
101
- expect(g.name).to eq 'M'
102
- expect(g.member_groups).to eq [ g3 ]
103
- expect(g2.reload.openstax_uid).to eq 4
104
- expect(g2.name).to eq 'Container Group'
105
- expect(g2.member_groups).to eq [ g ]
106
- expect(g3.name).to eq 'Fuego\'s Deputies'
107
- expect(g3.owners).to eq [ u2 ]
108
- expect(g3.members).to eq [ u ]
109
-
110
- expect(controller_class.last_action).to eq :updated
111
- expect(controller_class.last_json).to eq [
112
- {'group_id' => 2, 'read_updates' => 1}, {'group_id' => 3, 'read_updates' => 2}
113
- ]
114
-
115
- controller_class.last_action = nil
116
- controller_class.last_json = nil
117
-
118
- expect { SyncGroups.call }.not_to change { Group.count }
119
-
120
- expect(g.reload.openstax_uid).to eq 2
121
- expect(g.name).to eq 'M'
122
- expect(g.member_groups).to eq [ g3 ]
123
- expect(g2.reload.openstax_uid).to eq 4
124
- expect(g2.name).to eq 'Container Group'
125
- expect(g2.member_groups).to eq [ g ]
126
- expect(g3.reload.openstax_uid).to eq 3
127
- expect(g3.name).to eq 'Fuego\'s Deputies'
128
- expect(g3.owners).to eq [ u2 ]
129
- expect(g3.members).to eq [ u ]
130
-
131
- expect(controller_class.last_action).to eq :updated
132
- expect(controller_class.last_json).to eq [
133
- {'group_id' => 2, 'read_updates' => 1}, {'group_id' => 3, 'read_updates' => 2}
134
- ]
135
- ensure
136
- OpenStax::Accounts.configuration.enable_stubbing = true
137
- end
138
- end
139
-
140
- end
141
-
142
- end
143
- end