openstax_accounts 7.9.0 → 7.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/handlers/openstax/accounts/sessions_callback.rb +1 -0
  3. data/app/models/openstax/accounts/account.rb +3 -3
  4. data/app/representers/openstax/accounts/api/v1/account_representer.rb +6 -0
  5. data/app/representers/openstax/accounts/api/v1/unclaimed_account_representer.rb +6 -0
  6. data/app/routines/openstax/accounts/dev/create_account.rb +2 -1
  7. data/app/routines/openstax/accounts/find_or_create_account.rb +3 -0
  8. data/app/routines/openstax/accounts/sync_accounts.rb +9 -6
  9. data/db/migrate/11_add_support_identifier_to_accounts_accounts.rb +8 -0
  10. data/lib/openstax/accounts/version.rb +1 -1
  11. data/spec/cassettes/OpenStax_Accounts_FindOrCreateAccount/can_create_users.yml +9 -9
  12. data/spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb +1 -1
  13. data/spec/controllers/openstax/accounts/forwards_params_spec.rb +1 -1
  14. data/spec/controllers/openstax/accounts/sessions_controller_spec.rb +1 -1
  15. data/spec/controllers/openstax/accounts/uses_this_engine_controller_spec.rb +1 -1
  16. data/spec/dummy/db/schema.rb +3 -0
  17. data/spec/dummy/log/development.log +560 -0
  18. data/spec/dummy/log/test.log +27696 -0
  19. data/spec/factories/openstax_accounts_account.rb +7 -6
  20. data/spec/handlers/openstax/accounts/accounts_search_spec.rb +1 -1
  21. data/spec/handlers/openstax/accounts/dev/accounts_search_spec.rb +1 -1
  22. data/spec/handlers/openstax/accounts/sessions_callback_spec.rb +27 -7
  23. data/spec/lib/openstax/accounts/api_spec.rb +1 -1
  24. data/spec/lib/openstax/accounts/configuration_spec.rb +1 -1
  25. data/spec/lib/openstax/accounts/current_user_manager_spec.rb +1 -1
  26. data/spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb +1 -1
  27. data/spec/models/openstax/accounts/account_spec.rb +5 -1
  28. data/spec/models/openstax/accounts/anonymous_account_spec.rb +1 -1
  29. data/spec/models/openstax/accounts/group_spec.rb +1 -1
  30. data/spec/routines/openstax/accounts/create_group_spec.rb +1 -1
  31. data/spec/routines/openstax/accounts/find_or_create_account_spec.rb +18 -8
  32. data/spec/routines/openstax/accounts/search_accounts_spec.rb +1 -1
  33. data/spec/routines/openstax/accounts/sync_accounts_spec.rb +39 -29
  34. data/spec/routines/openstax/accounts/sync_groups_spec.rb +47 -65
  35. data/spec/spec_helper.rb +17 -9
  36. metadata +17 -2
@@ -1,10 +1,11 @@
1
1
  FactoryBot.define do
2
2
  factory :openstax_accounts_account, class: OpenStax::Accounts::Account do
3
- openstax_uid { -SecureRandom.hex(4).to_i(16)/2 }
4
- username { SecureRandom.hex.to_s }
5
- access_token { SecureRandom.hex.to_s }
6
- faculty_status { OpenStax::Accounts::Account.faculty_statuses[:no_faculty_info] }
7
- role { OpenStax::Accounts::Account.roles[:unknown_role] }
8
- uuid { SecureRandom.uuid }
3
+ openstax_uid { -SecureRandom.hex(4).to_i(16)/2 }
4
+ username { SecureRandom.hex.to_s }
5
+ access_token { SecureRandom.hex.to_s }
6
+ faculty_status { OpenStax::Accounts::Account.faculty_statuses[:no_faculty_info] }
7
+ role { OpenStax::Accounts::Account.roles[:unknown_role] }
8
+ uuid { SecureRandom.uuid }
9
+ support_identifier { "cs_#{SecureRandom.hex(4)}" }
9
10
  end
10
11
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module OpenStax
4
4
  module Accounts
5
5
 
6
- describe AccountsSearch do
6
+ RSpec.describe AccountsSearch do
7
7
 
8
8
  let!(:account_1) { FactoryBot.create :openstax_accounts_account,
9
9
  first_name: 'John',
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module OpenStax
4
4
  module Accounts
5
5
 
6
- describe Dev::AccountsSearch do
6
+ RSpec.describe Dev::AccountsSearch do
7
7
 
8
8
  let!(:account_1) { FactoryBot.create :openstax_accounts_account,
9
9
  first_name: 'John',
@@ -3,22 +3,25 @@ require 'spec_helper'
3
3
  module OpenStax
4
4
  module Accounts
5
5
 
6
- describe SessionsCallback do
6
+ RSpec.describe SessionsCallback do
7
7
 
8
8
  context "faculty_status" do
9
- it "should deal with faculty status it doesn't know (e.g. if Accounts updated but this repo not)" do
10
- result = described_class.handle(request: mock_omniauth_request(faculty_status: "howdy_ho"))
9
+ it "should default to no_faculty_info if the received faculty_status is unknown" +
10
+ " (e.g. if Accounts is updated but this repo is not)" do
11
+ result = described_class.handle(
12
+ request: mock_omniauth_request(faculty_status: "howdy_ho")
13
+ )
11
14
  expect(result.outputs.account).to be_no_faculty_info
12
15
  end
13
16
 
14
- it "should deal with faculty status that is not present" do
17
+ it "should default to no_faculty_info if faculty status is not present" do
15
18
  request = mock_omniauth_request()
16
19
  remove_faculty_status!(request)
17
20
  result = described_class.handle(request: request)
18
21
  expect(result.outputs.account).to be_no_faculty_info
19
22
  end
20
23
 
21
- it "should deal with null nickname" do
24
+ it "should deal with null nicknames" do
22
25
  with_stubbing(false) do
23
26
  request = mock_omniauth_request
24
27
  remove_nickname!(request)
@@ -37,14 +40,28 @@ module OpenStax
37
40
  end
38
41
  end
39
42
 
43
+ context "support_identifier" do
44
+ it "sets the support_identifier on the account" do
45
+ support_identifier = "cs_#{SecureRandom.hex(4)}"
46
+ result = described_class.handle(
47
+ request: mock_omniauth_request(support_identifier: support_identifier)
48
+ )
49
+ expect(result.outputs.account.support_identifier).to eq support_identifier
50
+ end
51
+ end
52
+
40
53
  context "role" do
41
54
  it "sets the role on the account" do
42
- result = described_class.handle(request: mock_omniauth_request(self_reported_role: "instructor"))
55
+ result = described_class.handle(
56
+ request: mock_omniauth_request(self_reported_role: "instructor")
57
+ )
43
58
  expect(result.outputs.account.role).to eq "instructor"
44
59
  end
45
60
 
46
61
  it "deals with unknown role (e.g. if Accounts update but this repo not)" do
47
- result = described_class.handle(request: mock_omniauth_request(self_reported_role: "howdy_ho"))
62
+ result = described_class.handle(
63
+ request: mock_omniauth_request(self_reported_role: "howdy_ho")
64
+ )
48
65
  expect(result.outputs.account).to be_unknown_role
49
66
  end
50
67
  end
@@ -53,6 +70,7 @@ module OpenStax
53
70
  it "updates the user's data" do
54
71
  existing_account = FactoryBot.create :openstax_accounts_account
55
72
  uuid = SecureRandom.uuid
73
+ support_identifier = "cs_#{SecureRandom.hex(4)}"
56
74
  result = described_class.handle(
57
75
  request: mock_omniauth_request(
58
76
  uid: existing_account.openstax_uid,
@@ -62,6 +80,7 @@ module OpenStax
62
80
  nickname: "191919",
63
81
  faculty_status: "confirmed_faculty",
64
82
  uuid: uuid,
83
+ support_identifier: support_identifier,
65
84
  self_reported_role: "instructor")
66
85
  )
67
86
 
@@ -73,6 +92,7 @@ module OpenStax
73
92
  expect(account.username).to eq "191919"
74
93
  expect(account).to be_confirmed_faculty
75
94
  expect(account.uuid).to eq uuid
95
+ expect(account.support_identifier).to eq support_identifier
76
96
  expect(account).to be_instructor
77
97
  end
78
98
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module OpenStax
4
4
  module Accounts
5
- describe Api do
5
+ RSpec.describe Api do
6
6
 
7
7
  let!(:account) { OpenStax::Accounts::Account.create(username: 'some_user',
8
8
  first_name: 'Some', last_name: 'User', full_name: 'SomeUser',
@@ -1,6 +1,6 @@
1
1
  module OpenStax
2
2
  module Accounts
3
- describe Configuration do
3
+ RSpec.describe Configuration do
4
4
 
5
5
  let!(:config) { Configuration.new.tap {|c| c.openstax_accounts_url = "https://accounts.openstax.org"} }
6
6
  let!(:a_fake_request) { OpenStruct.new(url: "http://foo.com") }
@@ -1,6 +1,6 @@
1
1
  module OpenStax
2
2
  module Accounts
3
- describe CurrentUserManager do
3
+ RSpec.describe CurrentUserManager do
4
4
  let!(:account) { FactoryBot.create(:openstax_accounts_account,
5
5
  username: 'some_user',
6
6
  openstax_uid: 1) }
@@ -2,7 +2,7 @@ module OpenStax
2
2
  module Accounts
3
3
  module HasManyThroughGroups
4
4
  module ActiveRecord
5
- describe Base do
5
+ RSpec.describe Base do
6
6
  let!(:account_1) { FactoryBot.create(:openstax_accounts_account,
7
7
  username: 'some_user',
8
8
  openstax_uid: 1) }
@@ -1,9 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module OpenStax::Accounts
4
- RSpec.describe Account do
4
+ RSpec.describe Account, type: :model do
5
5
  subject(:account) { FactoryBot.create(:openstax_accounts_account) }
6
6
 
7
+ it { is_expected.to validate_presence_of(:uuid) }
8
+ it { is_expected.to validate_uniqueness_of(:uuid).case_insensitive }
9
+ it { is_expected.to validate_uniqueness_of(:support_identifier).case_insensitive.allow_nil }
10
+
7
11
  context 'validation' do
8
12
  it 'requires a unique openstax_uid, if given' do
9
13
  account.openstax_uid = nil
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module OpenStax::Accounts
4
- describe AnonymousAccount do
4
+ RSpec.describe AnonymousAccount, type: :model do
5
5
  it 'is anonymous' do
6
6
  expect(AnonymousAccount.instance.is_anonymous?).to eq true
7
7
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module OpenStax::Accounts
4
- describe Group do
4
+ RSpec.describe Group, type: :model do
5
5
  context 'validation' do
6
6
  it 'requires a unique openstax_uid' do
7
7
  group = FactoryBot.build(:openstax_accounts_group, openstax_uid: nil)
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module OpenStax
4
4
  module Accounts
5
5
 
6
- describe CreateGroup, type: :routine do
6
+ RSpec.describe CreateGroup, type: :routine do
7
7
 
8
8
  before(:all) do
9
9
  @previous_enable_stubbing = OpenStax::Accounts.configuration.enable_stubbing
@@ -4,7 +4,7 @@ require 'vcr_helper'
4
4
  module OpenStax
5
5
  module Accounts
6
6
 
7
- describe FindOrCreateAccount, type: :routine, vcr: VCR_OPTS do
7
+ RSpec.describe FindOrCreateAccount, type: :routine, vcr: VCR_OPTS do
8
8
 
9
9
  before(:all) do
10
10
  @previous_url = OpenStax::Accounts.configuration.openstax_accounts_url
@@ -15,17 +15,22 @@ module OpenStax
15
15
  end
16
16
 
17
17
  it 'can create users' do
18
- account_1 = FindOrCreateAccount.call(email: 'alice@example.com', role: 'instructor').outputs.account
18
+ account_1 = described_class.call(
19
+ email: 'alice@example.com', role: 'instructor'
20
+ ).outputs.account
19
21
  expect(account_1).to be_persisted
20
- expect(account_1.uuid).to match(/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i)
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)
21
26
  expect(account_1.role).to eq 'instructor'
22
27
 
23
- account_2 = FindOrCreateAccount.call(username: 'alice').outputs.account
28
+ account_2 = described_class.call(username: 'alice').outputs.account
24
29
  expect(account_2).to be_persisted
25
30
  expect(account_1).not_to eq(account_2)
26
31
 
27
- account_3 = FindOrCreateAccount.call(username: 'alice2',
28
- password: 'abcdefghijklmnop').outputs.account
32
+ account_3 = described_class.call(username: 'alice2',
33
+ password: 'abcdefghijklmnop').outputs.account
29
34
  expect(account_3).to be_persisted
30
35
  expect(account_1).not_to eq(account_3)
31
36
  expect(account_2).not_to eq(account_3)
@@ -34,7 +39,12 @@ module OpenStax
34
39
  it 'passes params to the API when creating users' do
35
40
  find_or_create_account_response = double('Response')
36
41
  allow(find_or_create_account_response).to receive(:status).and_return(201)
37
- allow(find_or_create_account_response).to receive(:body).and_return('{"id":1}')
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
+ )
38
48
  expect(OpenStax::Accounts::Api).to receive(:find_or_create_account).with(
39
49
  email: 'bob@example.com', username: nil, password: nil,
40
50
  first_name: 'Bob', last_name: 'Smith', full_name: 'Bob Smith',
@@ -42,7 +52,7 @@ module OpenStax
42
52
  role: :instructor
43
53
  ).and_return(find_or_create_account_response)
44
54
 
45
- FindOrCreateAccount.call(
55
+ described_class.call(
46
56
  email: 'bob@example.com',
47
57
  first_name: 'Bob',
48
58
  last_name: 'Smith',
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module OpenStax
4
4
  module Accounts
5
5
 
6
- describe SearchAccounts, type: :routine do
6
+ RSpec.describe SearchAccounts, type: :routine do
7
7
 
8
8
  let!(:account_1) { FactoryBot.create :openstax_accounts_account,
9
9
  first_name: 'John',
@@ -3,11 +3,14 @@ require 'spec_helper'
3
3
  module OpenStax
4
4
  module Accounts
5
5
 
6
- describe SyncAccounts, type: :routine do
6
+ RSpec.describe SyncAccounts, type: :routine do
7
7
 
8
8
  it 'can sync accounts' do
9
9
  controller_class = ::Api::ApplicationUsersController
10
- uuid = SecureRandom.uuid
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)}"
11
14
  allow_any_instance_of(controller_class).to(
12
15
  receive(:updates) do |controller|
13
16
  controller.render json: [
@@ -17,8 +20,9 @@ module OpenStax
17
20
  user: {
18
21
  id: 2,
19
22
  username: 'user',
20
- self_reported_role: 'instructor',
21
- uuid: uuid
23
+ uuid: uuid_1,
24
+ support_identifier: support_identifier_1,
25
+ self_reported_role: 'instructor'
22
26
  },
23
27
  unread_updates: 1,
24
28
  default_contact_info_id: 1
@@ -28,6 +32,8 @@ module OpenStax
28
32
  application_id: 1,
29
33
  user: {
30
34
  id: 4,
35
+ uuid: uuid_2,
36
+ support_identifier: support_identifier_2,
31
37
  username: 'fuego'
32
38
  },
33
39
  unread_updates: 2,
@@ -37,46 +43,50 @@ module OpenStax
37
43
  end
38
44
  )
39
45
 
40
- account = OpenStax::Accounts::Account.new
41
- account.username = 'u'
42
- account.openstax_uid = 2
46
+ account = FactoryBot.create :openstax_accounts_account, username: 'u', openstax_uid: 2
43
47
  account.syncing = true
44
- account.save!
45
48
 
46
49
  begin
47
50
  OpenStax::Accounts.configuration.enable_stubbing = false
48
- expect(Account.count).to eq 1
49
- expect(Account.first.openstax_uid).to eq 2
50
- expect(Account.first.username).to eq 'u'
51
+ expect(account.reload.openstax_uid).to eq 2
52
+ expect(account.username).to eq 'u'
53
+ expect(Account.find_by(openstax_uid: 4)).to be_nil
51
54
 
52
55
  controller_class.last_action = nil
53
56
  controller_class.last_json = nil
54
- SyncAccounts.call
55
- expect(Account.count).to eq 2
56
- expect(Account.first.openstax_uid).to eq 2
57
- expect(Account.first.username).to eq 'user'
58
- expect(Account.first.role).to eq 'instructor'
59
- expect(Account.first.uuid).to eq uuid
60
- expect(Account.last.openstax_uid).to eq 4
61
- expect(Account.last.username).to eq 'fuego'
57
+
58
+ expect { SyncAccounts.call }.to change { Account.count }.by(1)
59
+
60
+ account2 = Account.find_by(openstax_uid: 4)
61
+
62
+ expect(account.reload.openstax_uid).to eq 2
63
+ expect(account.username).to eq 'user'
64
+ expect(account.role).to eq 'instructor'
65
+ expect(account.uuid).to eq uuid_1
66
+ expect(account.support_identifier).to eq support_identifier_1
67
+ expect(account2.username).to eq 'fuego'
68
+ expect(account2.uuid).to eq uuid_2
69
+ expect(account2.support_identifier).to eq support_identifier_2
62
70
 
63
71
  expect(controller_class.last_action).to eq :updated
64
- expect(controller_class.last_json).to eq [{'user_id' => 2, 'read_updates' => 1},
65
- {'user_id' => 4, 'read_updates' => 2}]
72
+ expect(controller_class.last_json).to eq [
73
+ {'user_id' => 2, 'read_updates' => 1}, {'user_id' => 4, 'read_updates' => 2}
74
+ ]
66
75
 
67
76
  controller_class.last_action = nil
68
77
  controller_class.last_json = nil
69
78
 
70
- SyncAccounts.call
71
- expect(Account.count).to eq 2
72
- expect(Account.first.openstax_uid).to eq 2
73
- expect(Account.first.username).to eq 'user'
74
- expect(Account.last.openstax_uid).to eq 4
75
- expect(Account.last.username).to eq 'fuego'
79
+ expect { SyncAccounts.call }.not_to change { Account.count }
80
+
81
+ expect(account.reload.openstax_uid).to eq 2
82
+ expect(account.username).to eq 'user'
83
+ expect(account2.reload.openstax_uid).to eq 4
84
+ expect(account2.username).to eq 'fuego'
76
85
 
77
86
  expect(controller_class.last_action).to eq :updated
78
- expect(controller_class.last_json).to eq [{'user_id' => 2, 'read_updates' => 1},
79
- {'user_id' => 4, 'read_updates' => 2}]
87
+ expect(controller_class.last_json).to eq [
88
+ {'user_id' => 2, 'read_updates' => 1}, {'user_id' => 4, 'read_updates' => 2}
89
+ ]
80
90
  ensure
81
91
  OpenStax::Accounts.configuration.enable_stubbing = true
82
92
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module OpenStax
4
4
  module Accounts
5
5
 
6
- describe SyncGroups, type: :routine do
6
+ RSpec.describe SyncGroups, type: :routine do
7
7
 
8
8
  it 'can sync groups' do
9
9
  controller_class = ::Api::ApplicationGroupsController
@@ -61,95 +61,77 @@ module OpenStax
61
61
  end
62
62
  )
63
63
 
64
- u = OpenStax::Accounts::Account.new
65
- u.openstax_uid = 2
66
- u.username = 'User'
64
+ u = FactoryBot.create :openstax_accounts_account, openstax_uid: 2, username: 'User'
67
65
  u.syncing = true
68
- u.save!
69
66
 
70
- u2 = OpenStax::Accounts::Account.new
71
- u2.openstax_uid = 3
72
- u2.username = 'Fuego'
67
+ u2 = FactoryBot.create :openstax_accounts_account, openstax_uid: 3, username: 'Fuego'
73
68
  u2.syncing = true
74
- u2.save!
75
69
 
76
- g = OpenStax::Accounts::Group.new
77
- g.name = 'Member Group'
78
- g.openstax_uid = 2
70
+ g = FactoryBot.create :openstax_accounts_group, openstax_uid: 2, name: 'Member Group'
79
71
  g.syncing = true
80
- g.save!
81
72
 
82
- gm = GroupMember.new
83
- gm.group = g
84
- gm.user = u
85
- gm.save!
73
+ gm = FactoryBot.create :openstax_accounts_group_member, group: g, user: u
86
74
 
87
- g2 = OpenStax::Accounts::Group.new
88
- g2.name = 'Container Group'
89
- g2.openstax_uid = 4
75
+ g2 = FactoryBot.create :openstax_accounts_group, openstax_uid: 4, name: 'Container Group'
90
76
  g2.syncing = true
91
- g2.save!
92
77
 
93
- go = GroupOwner.new
94
- go.group = g2
95
- go.user = u
96
- go.save!
78
+ go = FactoryBot.create :openstax_accounts_group_owner, group: g2, user: u
97
79
 
98
- gn = GroupNesting.new
99
- gn.container_group = g2
100
- gn.member_group = g
101
- gn.save!
80
+ gn = FactoryBot.create :openstax_accounts_group_nesting, container_group: g2,
81
+ member_group: g
102
82
 
103
83
  begin
104
84
  OpenStax::Accounts.configuration.enable_stubbing = false
105
- expect(Group.count).to eq 2
106
- expect(Group.first.openstax_uid).to eq 2
107
- expect(Group.first.name).to eq 'Member Group'
108
- expect(Group.first.members).to include u
109
- expect(Group.last.openstax_uid).to eq 4
110
- expect(Group.last.name).to eq 'Container Group'
111
- expect(Group.last.member_groups).to include g
112
- expect(Group.last.owners).to include u
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 ]
113
92
 
114
93
  controller_class.last_action = nil
115
94
  controller_class.last_json = nil
116
95
 
117
- SyncGroups.call
118
- expect(Group.count).to eq 3
119
- expect(Group.first.openstax_uid).to eq 2
120
- expect(Group.first.name).to eq 'M'
121
- expect(Group.first.member_groups).to include Group.last
122
- expect(Group.all.second.openstax_uid).to eq 4
123
- expect(Group.all.second.name).to eq 'Container Group'
124
- expect(Group.all.second.member_groups).to include Group.first
125
- expect(Group.last.openstax_uid).to eq 3
126
- expect(Group.last.name).to eq 'Fuego\'s Deputies'
127
- expect(Group.last.owners).to include Account.last
128
- expect(Group.last.members).to include Account.first
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 ]
129
109
 
130
110
  expect(controller_class.last_action).to eq :updated
131
- expect(controller_class.last_json).to eq [{'group_id' => 2, 'read_updates' => 1},
132
- {'group_id' => 3, 'read_updates' => 2}]
111
+ expect(controller_class.last_json).to eq [
112
+ {'group_id' => 2, 'read_updates' => 1}, {'group_id' => 3, 'read_updates' => 2}
113
+ ]
133
114
 
134
115
  controller_class.last_action = nil
135
116
  controller_class.last_json = nil
136
117
 
137
- SyncGroups.call
138
- expect(Group.count).to eq 3
139
- expect(Group.first.openstax_uid).to eq 2
140
- expect(Group.first.name).to eq 'M'
141
- expect(Group.first.member_groups).to include Group.last
142
- expect(Group.all.second.openstax_uid).to eq 4
143
- expect(Group.all.second.name).to eq 'Container Group'
144
- expect(Group.all.second.member_groups).to include Group.first
145
- expect(Group.last.openstax_uid).to eq 3
146
- expect(Group.last.name).to eq 'Fuego\'s Deputies'
147
- expect(Group.last.owners).to include Account.last
148
- expect(Group.last.members).to include Account.first
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 ]
149
130
 
150
131
  expect(controller_class.last_action).to eq :updated
151
- expect(controller_class.last_json).to eq [{'group_id' => 2, 'read_updates' => 1},
152
- {'group_id' => 3, 'read_updates' => 2}]
132
+ expect(controller_class.last_json).to eq [
133
+ {'group_id' => 2, 'read_updates' => 1}, {'group_id' => 3, 'read_updates' => 2}
134
+ ]
153
135
  ensure
154
136
  OpenStax::Accounts.configuration.enable_stubbing = true
155
137
  end