openstax_accounts 7.10.0 → 7.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/routines/openstax/accounts/search_local_accounts.rb +16 -2
- data/lib/openstax/accounts/version.rb +1 -1
- data/spec/dummy/log/test.log +21536 -0
- data/spec/routines/openstax/accounts/search_accounts_shared_examples.rb +160 -0
- data/spec/routines/openstax/accounts/search_accounts_spec.rb +3 -126
- data/spec/routines/openstax/accounts/search_local_accounts_spec.rb +6 -0
- metadata +11 -1
@@ -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
|
-
|
4
|
-
|
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstax_accounts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Slavinsky
|
@@ -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
|
@@ -462,7 +468,9 @@ files:
|
|
462
468
|
- spec/models/openstax/accounts/group_spec.rb
|
463
469
|
- spec/routines/openstax/accounts/create_group_spec.rb
|
464
470
|
- spec/routines/openstax/accounts/find_or_create_account_spec.rb
|
471
|
+
- spec/routines/openstax/accounts/search_accounts_shared_examples.rb
|
465
472
|
- spec/routines/openstax/accounts/search_accounts_spec.rb
|
473
|
+
- spec/routines/openstax/accounts/search_local_accounts_spec.rb
|
466
474
|
- spec/routines/openstax/accounts/sync_accounts_spec.rb
|
467
475
|
- spec/routines/openstax/accounts/sync_groups_spec.rb
|
468
476
|
- spec/spec_helper.rb
|
@@ -552,6 +560,8 @@ test_files:
|
|
552
560
|
- spec/routines/openstax/accounts/create_group_spec.rb
|
553
561
|
- spec/routines/openstax/accounts/sync_accounts_spec.rb
|
554
562
|
- spec/routines/openstax/accounts/find_or_create_account_spec.rb
|
563
|
+
- spec/routines/openstax/accounts/search_local_accounts_spec.rb
|
564
|
+
- spec/routines/openstax/accounts/search_accounts_shared_examples.rb
|
555
565
|
- spec/routines/openstax/accounts/sync_groups_spec.rb
|
556
566
|
- spec/routines/openstax/accounts/search_accounts_spec.rb
|
557
567
|
- spec/vcr_helper.rb
|