openstax_accounts 7.10.0 → 7.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,5 +7,6 @@ FactoryBot.define do
7
7
  role { OpenStax::Accounts::Account.roles[:unknown_role] }
8
8
  uuid { SecureRandom.uuid }
9
9
  support_identifier { "cs_#{SecureRandom.hex(4)}" }
10
+ is_test true
10
11
  end
11
12
  end
@@ -0,0 +1,160 @@
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,129 +1,6 @@
1
1
  require 'spec_helper'
2
+ require_relative 'search_accounts_shared_examples'
2
3
 
3
- module OpenStax
4
- module Accounts
5
-
6
- RSpec.describe SearchAccounts, type: :routine do
7
-
8
- let!(:account_1) { FactoryBot.create :openstax_accounts_account,
9
- first_name: 'John',
10
- last_name: 'Stravinsky',
11
- username: 'jstrav' }
12
- let!(:account_2) { FactoryBot.create :openstax_accounts_account,
13
- first_name: 'Mary',
14
- last_name: 'Mighty',
15
- full_name: 'Mary Mighty',
16
- username: 'mary' }
17
- let!(:account_3) { FactoryBot.create :openstax_accounts_account,
18
- first_name: 'John',
19
- last_name: 'Stead',
20
- username: 'jstead' }
21
-
22
- let!(:account_4) { FactoryBot.create :openstax_accounts_account,
23
- first_name: 'Bob',
24
- last_name: 'JST',
25
- username: 'bigbear' }
26
-
27
- it "should match based on username" do
28
- outcome = SearchAccounts.call('username:jstra').outputs.items
29
- expect(outcome).to eq [account_1]
30
- end
31
-
32
- it "should ignore leading wildcards on username searches" do
33
- outcome = SearchAccounts.call('username:%rav').outputs.items
34
- expect(outcome).to eq []
35
- end
36
-
37
- it "should match based on one first name" do
38
- outcome = SearchAccounts.call('first_name:"John"').outputs.items
39
- expect(outcome).to eq [account_3, account_1]
40
- end
41
-
42
- it "should match based on one full name" do
43
- outcome = SearchAccounts.call('full_name:"Mary Mighty"').outputs.items
44
- expect(outcome).to eq [account_2]
45
- end
46
-
47
- it "should return all results if the query is empty" do
48
- outcome = SearchAccounts.call("").outputs.items
49
- expect(outcome).to eq [account_4, account_3, account_1, account_2]
50
- end
51
-
52
- it "should match any field when no prefix given" do
53
- outcome = SearchAccounts.call("jst").outputs.items
54
- expect(outcome).to eq [account_4, account_3, account_1]
55
- end
56
-
57
- it "should match any field when no prefix given and intersect when prefix given" do
58
- outcome = SearchAccounts.call("jst username:jst").outputs.items
59
- expect(outcome).to eq [account_3, account_1]
60
- end
61
-
62
- it "shouldn't allow users to add their own wildcards" do
63
- outcome = SearchAccounts.call("username:'%ar'").outputs.items
64
- expect(outcome).to eq []
65
- end
66
-
67
- it "should gather comma-separated unprefixed search terms" do
68
- outcome = SearchAccounts.call("john,mighty").outputs.items
69
- expect(outcome).to eq [account_3, account_1, account_2]
70
- end
71
-
72
- it "should not gather space-separated unprefixed search terms" do
73
- outcome = SearchAccounts.call("john mighty").outputs.items
74
- expect(outcome).to eq []
75
- end
76
-
77
- context "pagination and sorting" do
78
-
79
- let!(:billy_accounts) {
80
- (0..45).to_a.collect{|ii|
81
- FactoryBot.create :openstax_accounts_account,
82
- first_name: "Billy#{ii.to_s.rjust(2, '0')}",
83
- last_name: "Bob_#{(45-ii).to_s.rjust(2,'0')}",
84
- username: "billy_#{ii.to_s.rjust(2, '0')}"
85
- }
86
- }
87
-
88
- it "should return the first page of values by default when requested" do
89
- outcome = SearchAccounts.call("username:billy", per_page: 20).outputs.items
90
- expect(outcome.length).to eq 20
91
- expect(outcome[0]).to eq Account.find_by!(username: "billy_00")
92
- expect(outcome[19]).to eq Account.find_by!(username: "billy_19")
93
- end
94
-
95
- it "should return the second page when requested" do
96
- outcome = SearchAccounts.call("username:billy", page: 2, per_page: 20).outputs.items
97
- expect(outcome.length).to eq 20
98
- expect(outcome[0]).to eq Account.find_by!(username: "billy_20")
99
- expect(outcome[19]).to eq Account.find_by!(username: "billy_39")
100
- end
101
-
102
- it "should return the incomplete 3rd page when requested" do
103
- outcome = SearchAccounts.call("username:billy", page: 3, per_page: 20).outputs.items
104
- expect(outcome.length).to eq 6
105
- expect(outcome[5]).to eq Account.find_by!(username: "billy_45")
106
- end
107
-
108
- end
109
-
110
- context "sorting" do
111
-
112
- let!(:bob_brown) { FactoryBot.create :openstax_accounts_account, first_name: "Bob", last_name: "Brown", username: "foo_bb" }
113
- let!(:bob_jones) { FactoryBot.create :openstax_accounts_account, first_name: "Bob", last_name: "Jones", username: "foo_bj" }
114
- let!(:tim_jones) { FactoryBot.create :openstax_accounts_account, first_name: "Tim", last_name: "Jones", username: "foo_tj" }
115
-
116
- it "should allow sort by multiple fields in different directions" do
117
- outcome = SearchAccounts.call("username:foo", order_by: "first_name, last_name DESC").outputs.items
118
- expect(outcome).to eq [bob_jones, bob_brown, tim_jones]
119
-
120
- outcome = SearchAccounts.call("username:foo", order_by: "first_name, last_name ASC").outputs.items
121
- expect(outcome).to eq [bob_brown, bob_jones, tim_jones]
122
- end
123
-
124
- end
125
-
126
- end
127
-
128
- end
4
+ RSpec.describe OpenStax::Accounts::SearchAccounts, type: :routine do
5
+ include_examples 'search accounts'
129
6
  end
@@ -0,0 +1,6 @@
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
@@ -20,9 +20,10 @@ module OpenStax
20
20
  user: {
21
21
  id: 2,
22
22
  username: 'user',
23
+ self_reported_role: 'instructor',
23
24
  uuid: uuid_1,
24
25
  support_identifier: support_identifier_1,
25
- self_reported_role: 'instructor'
26
+ is_test: true
26
27
  },
27
28
  unread_updates: 1,
28
29
  default_contact_info_id: 1
@@ -32,9 +33,9 @@ module OpenStax
32
33
  application_id: 1,
33
34
  user: {
34
35
  id: 4,
36
+ username: 'fuego',
35
37
  uuid: uuid_2,
36
- support_identifier: support_identifier_2,
37
- username: 'fuego'
38
+ support_identifier: support_identifier_2
38
39
  },
39
40
  unread_updates: 2,
40
41
  default_contact_info_id: 5
@@ -57,16 +58,18 @@ module OpenStax
57
58
 
58
59
  expect { SyncAccounts.call }.to change { Account.count }.by(1)
59
60
 
60
- account2 = Account.find_by(openstax_uid: 4)
61
+ account_2 = Account.find_by(openstax_uid: 4)
61
62
 
62
63
  expect(account.reload.openstax_uid).to eq 2
63
64
  expect(account.username).to eq 'user'
64
65
  expect(account.role).to eq 'instructor'
65
66
  expect(account.uuid).to eq uuid_1
66
67
  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
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
70
73
 
71
74
  expect(controller_class.last_action).to eq :updated
72
75
  expect(controller_class.last_json).to eq [
@@ -80,8 +83,8 @@ module OpenStax
80
83
 
81
84
  expect(account.reload.openstax_uid).to eq 2
82
85
  expect(account.username).to eq 'user'
83
- expect(account2.reload.openstax_uid).to eq 4
84
- expect(account2.username).to eq 'fuego'
86
+ expect(account_2.reload.openstax_uid).to eq 4
87
+ expect(account_2.username).to eq 'fuego'
85
88
 
86
89
  expect(controller_class.last_action).to eq :updated
87
90
  expect(controller_class.last_json).to eq [
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: 7.10.0
4
+ version: 7.12.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: 2017-12-20 00:00:00.000000000 Z
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '4.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: omniauth
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -364,6 +370,7 @@ files:
364
370
  - db/migrate/0_create_openstax_accounts_accounts.rb
365
371
  - db/migrate/10_assign_missing_uuids_for_local_accounts.rb
366
372
  - db/migrate/11_add_support_identifier_to_accounts_accounts.rb
373
+ - db/migrate/12_add_is_test_to_accounts_accounts.rb
367
374
  - db/migrate/1_create_openstax_accounts_groups.rb
368
375
  - db/migrate/2_create_openstax_accounts_group_members.rb
369
376
  - db/migrate/3_create_openstax_accounts_group_owners.rb
@@ -462,7 +469,9 @@ files:
462
469
  - spec/models/openstax/accounts/group_spec.rb
463
470
  - spec/routines/openstax/accounts/create_group_spec.rb
464
471
  - spec/routines/openstax/accounts/find_or_create_account_spec.rb
472
+ - spec/routines/openstax/accounts/search_accounts_shared_examples.rb
465
473
  - spec/routines/openstax/accounts/search_accounts_spec.rb
474
+ - spec/routines/openstax/accounts/search_local_accounts_spec.rb
466
475
  - spec/routines/openstax/accounts/sync_accounts_spec.rb
467
476
  - spec/routines/openstax/accounts/sync_groups_spec.rb
468
477
  - spec/spec_helper.rb
@@ -552,6 +561,8 @@ test_files:
552
561
  - spec/routines/openstax/accounts/create_group_spec.rb
553
562
  - spec/routines/openstax/accounts/sync_accounts_spec.rb
554
563
  - spec/routines/openstax/accounts/find_or_create_account_spec.rb
564
+ - spec/routines/openstax/accounts/search_local_accounts_spec.rb
565
+ - spec/routines/openstax/accounts/search_accounts_shared_examples.rb
555
566
  - spec/routines/openstax/accounts/sync_groups_spec.rb
556
567
  - spec/routines/openstax/accounts/search_accounts_spec.rb
557
568
  - spec/vcr_helper.rb