openstax_accounts 3.1.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/stylesheets/openstax/accounts/dev.css.scss +4 -0
  3. data/app/controllers/openstax/accounts/dev/accounts_controller.rb +2 -2
  4. data/app/handlers/openstax/accounts/accounts_search.rb +66 -0
  5. data/app/handlers/openstax/accounts/dev/accounts_search.rb +10 -21
  6. data/app/models/openstax/accounts/group.rb +12 -8
  7. data/app/representers/openstax/accounts/api/v1/account_representer.rb +5 -0
  8. data/app/representers/openstax/accounts/api/v1/account_search_representer.rb +12 -17
  9. data/app/representers/openstax/accounts/api/v1/application_account_search_representer.rb +3 -1
  10. data/app/routines/openstax/accounts/dev/create_account.rb +1 -1
  11. data/app/routines/openstax/accounts/search_accounts.rb +16 -171
  12. data/app/routines/openstax/accounts/search_local_accounts.rb +101 -0
  13. data/app/views/openstax/accounts/dev/accounts/_search_results.html.erb +19 -45
  14. data/app/views/openstax/accounts/dev/accounts/index.html.erb +11 -8
  15. data/app/views/openstax/accounts/shared/accounts/_search.html.erb +9 -6
  16. data/db/migrate/{20140811182433_create_openstax_accounts_groups.rb → 1_create_openstax_accounts_groups.rb} +0 -0
  17. data/db/migrate/{20140811182505_create_openstax_accounts_group_members.rb → 2_create_openstax_accounts_group_members.rb} +0 -0
  18. data/db/migrate/{20140811182527_create_openstax_accounts_group_owners.rb → 3_create_openstax_accounts_group_owners.rb} +0 -0
  19. data/db/migrate/{20140811182553_create_openstax_accounts_group_nestings.rb → 4_create_openstax_accounts_group_nestings.rb} +0 -0
  20. data/lib/openstax/accounts/engine.rb +1 -0
  21. data/lib/openstax/accounts/has_many_through_groups.rb +4 -2
  22. data/lib/openstax/accounts/version.rb +1 -1
  23. data/lib/openstax_accounts.rb +11 -5
  24. data/spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb +1 -1
  25. data/spec/controllers/openstax/accounts/sessions_controller_spec.rb +1 -1
  26. data/spec/dummy/app/access_policies/account_access_policy.rb +11 -0
  27. data/spec/dummy/app/controllers/oauth_controller.rb +2 -0
  28. data/spec/dummy/config/environments/production.rb +1 -1
  29. data/spec/dummy/config/environments/test.rb +1 -1
  30. data/spec/dummy/config/initializers/access_policies.rb +1 -0
  31. data/spec/dummy/config/initializers/doorkeeper.rb +75 -0
  32. data/spec/dummy/config/initializers/openstax_accounts.rb +2 -1
  33. data/spec/dummy/db/migrate/{1_create_users.rb → 5_create_users.rb} +0 -0
  34. data/spec/dummy/db/migrate/{2_create_ownerships.rb → 6_create_ownerships.rb} +0 -0
  35. data/spec/dummy/db/schema.rb +1 -1
  36. data/spec/factories/openstax_accounts_account.rb +1 -1
  37. data/spec/factories/openstax_accounts_group.rb +1 -1
  38. data/spec/handlers/openstax/accounts/accounts_search_spec.rb +63 -0
  39. data/spec/handlers/openstax/accounts/dev/accounts_search_spec.rb +55 -0
  40. data/spec/lib/openstax_accounts_spec.rb +66 -66
  41. data/spec/routines/openstax/accounts/search_accounts_spec.rb +23 -23
  42. metadata +60 -15
  43. data/app/routines/openstax/accounts/dev/search_accounts.rb +0 -27
@@ -9,5 +9,6 @@ OpenStax::Accounts.configure do |config|
9
9
  config.openstax_application_secret = 'secret'
10
10
  config.account_user_mapper = User
11
11
  config.logout_via = :delete
12
- config.max_matching_accounts = 47
12
+ config.min_search_characters = 3
13
+ config.max_search_items = 10
13
14
  end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20140811182553) do
14
+ ActiveRecord::Schema.define(version: 6) do
15
15
 
16
16
  create_table "openstax_accounts_accounts", force: true do |t|
17
17
  t.integer "openstax_uid", null: false
@@ -1,6 +1,6 @@
1
1
  FactoryGirl.define do
2
2
  factory :openstax_accounts_account, :class => OpenStax::Accounts::Account do
3
- openstax_uid { -SecureRandom.hex.to_i(16) }
3
+ openstax_uid { -SecureRandom.hex(4).to_i(16)/2 }
4
4
  username { SecureRandom.hex.to_s }
5
5
  access_token { SecureRandom.hex.to_s }
6
6
  end
@@ -1,6 +1,6 @@
1
1
  FactoryGirl.define do
2
2
  factory :openstax_accounts_group, :class => OpenStax::Accounts::Group do
3
- openstax_uid { -SecureRandom.hex.to_i(16) }
3
+ openstax_uid { -SecureRandom.hex(4).to_i(16)/2 }
4
4
  name "MyGroup"
5
5
  is_public false
6
6
  end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ module OpenStax
4
+ module Accounts
5
+
6
+ describe AccountsSearch do
7
+
8
+ let!(:account_1) { FactoryGirl.create :openstax_accounts_account,
9
+ first_name: 'John',
10
+ last_name: 'Stravinsky',
11
+ username: 'jstrav' }
12
+ let!(:account_2) { FactoryGirl.create :openstax_accounts_account,
13
+ first_name: 'Mary',
14
+ last_name: 'Mighty',
15
+ full_name: 'Mary Mighty',
16
+ username: 'mary' }
17
+ let!(:account_3) { FactoryGirl.create :openstax_accounts_account,
18
+ first_name: 'John',
19
+ last_name: 'Stead',
20
+ username: 'jstead' }
21
+
22
+ let!(:account_4) { FactoryGirl.create :openstax_accounts_account,
23
+ first_name: 'Bob',
24
+ last_name: 'JST',
25
+ username: 'bigbear' }
26
+
27
+ let!(:billy_accounts) {
28
+ (0..49).to_a.collect{|ii|
29
+ FactoryGirl.create :openstax_accounts_account,
30
+ first_name: "Billy#{ii.to_s.rjust(2, '0')}",
31
+ last_name: "Bob_#{(49-ii).to_s.rjust(2,'0')}",
32
+ username: "billy_#{ii.to_s.rjust(2, '0')}"
33
+ }
34
+ }
35
+
36
+ it "should match based on username" do
37
+ outputs = AccountsSearch.call(params: {search: {query: "username:jstra"}}).outputs
38
+ expect(outputs.total_count).to eq 1
39
+ expect(outputs.items).to eq [account_1]
40
+ end
41
+
42
+ it "should return no results if the query is too short" do
43
+ routine = AccountsSearch.call(params: {search: {query: ""}})
44
+ outputs = routine.outputs
45
+ errors = routine.errors
46
+ expect(outputs.total_count).to be_nil
47
+ expect(outputs.items).to be_nil
48
+ expect(errors.last.code).to eq :query_too_short
49
+ end
50
+
51
+ it "should return no results if the limit is exceeded" do
52
+ routine = AccountsSearch.call(params: {search: {query: "billy"}})
53
+ outputs = routine.outputs
54
+ errors = routine.errors
55
+ expect(outputs.total_count).to eq 50
56
+ expect(outputs.items).to be_nil
57
+ expect(errors.last.code).to eq :too_many_items
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ module OpenStax
4
+ module Accounts
5
+
6
+ describe Dev::AccountsSearch do
7
+
8
+ let!(:account_1) { FactoryGirl.create :openstax_accounts_account,
9
+ first_name: 'John',
10
+ last_name: 'Stravinsky',
11
+ username: 'jstrav' }
12
+ let!(:account_2) { FactoryGirl.create :openstax_accounts_account,
13
+ first_name: 'Mary',
14
+ last_name: 'Mighty',
15
+ full_name: 'Mary Mighty',
16
+ username: 'mary' }
17
+ let!(:account_3) { FactoryGirl.create :openstax_accounts_account,
18
+ first_name: 'John',
19
+ last_name: 'Stead',
20
+ username: 'jstead' }
21
+
22
+ let!(:account_4) { FactoryGirl.create :openstax_accounts_account,
23
+ first_name: 'Bob',
24
+ last_name: 'JST',
25
+ username: 'bigbear' }
26
+
27
+ let!(:billy_accounts) {
28
+ (0..49).to_a.collect{|ii|
29
+ FactoryGirl.create :openstax_accounts_account,
30
+ first_name: "Billy#{ii.to_s.rjust(2, '0')}",
31
+ last_name: "Bob_#{(49-ii).to_s.rjust(2,'0')}",
32
+ username: "billy_#{ii.to_s.rjust(2, '0')}"
33
+ }
34
+ }
35
+
36
+ it "should match based on username" do
37
+ outputs = Dev::AccountsSearch.call(params: {search: {query: "username:jstra"}}).outputs
38
+ expect(outputs.total_count).to eq 1
39
+ expect(outputs.items).to eq [account_1]
40
+ end
41
+
42
+ it "should have no limits" do
43
+ routine = Dev::AccountsSearch.call(params: {search: {query: ""}})
44
+ outputs = routine.outputs
45
+ errors = routine.errors
46
+ expect(outputs.total_count).to eq 54
47
+ expect(outputs.items).to eq [account_4, billy_accounts, account_3,
48
+ account_1, account_2].flatten
49
+ expect(errors).to be_empty
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
@@ -6,11 +6,11 @@ module OpenStax
6
6
  title: 'Sir', openstax_uid: 1, access_token: 'secret') }
7
7
 
8
8
  it 'makes api calls' do
9
- expect(Api::DummyController.last_action).to be_nil
10
- expect(Api::DummyController.last_params).to be_nil
9
+ expect(::Api::DummyController.last_action).to be_nil
10
+ expect(::Api::DummyController.last_params).to be_nil
11
11
  Accounts.api_call(:post, 'dummy', :params => {:test => true})
12
- expect(Api::DummyController.last_action).to eq :dummy
13
- expect(Api::DummyController.last_params).to include 'test' => 'true'
12
+ expect(::Api::DummyController.last_action).to eq :dummy
13
+ expect(::Api::DummyController.last_params).to include 'test' => 'true'
14
14
  end
15
15
 
16
16
  context 'users' do
@@ -18,19 +18,19 @@ module OpenStax
18
18
  let!(:account) { FactoryGirl.create :openstax_accounts_account }
19
19
 
20
20
  it 'makes api call to users index' do
21
- Api::UsersController.last_action = nil
22
- Api::UsersController.last_params = nil
21
+ ::Api::UsersController.last_action = nil
22
+ ::Api::UsersController.last_params = nil
23
23
  Accounts.search_accounts('something')
24
- expect(Api::UsersController.last_action).to eq :index
25
- expect(Api::UsersController.last_params).to include :q => 'something'
24
+ expect(::Api::UsersController.last_action).to eq :index
25
+ expect(::Api::UsersController.last_params).to include :q => 'something'
26
26
  end
27
27
 
28
28
  it 'makes api call to user update' do
29
- Api::UsersController.last_action = nil
30
- Api::UsersController.last_json = nil
29
+ ::Api::UsersController.last_action = nil
30
+ ::Api::UsersController.last_json = nil
31
31
  Accounts.update_account(account)
32
- expect(Api::UsersController.last_action).to eq :update
33
- expect(Api::UsersController.last_json).to include(
32
+ expect(::Api::UsersController.last_action).to eq :update
33
+ expect(::Api::UsersController.last_json).to include(
34
34
  account.attributes.slice('username', 'first_name',
35
35
  'last_name', 'full_name', 'title'))
36
36
  end
@@ -40,25 +40,25 @@ module OpenStax
40
40
  context 'application_users' do
41
41
 
42
42
  it 'makes api call to application_users index' do
43
- Api::ApplicationUsersController.last_action = nil
44
- Api::ApplicationUsersController.last_params = nil
43
+ ::Api::ApplicationUsersController.last_action = nil
44
+ ::Api::ApplicationUsersController.last_params = nil
45
45
  Accounts.search_application_accounts('something')
46
- expect(Api::ApplicationUsersController.last_action).to eq :index
47
- expect(Api::ApplicationUsersController.last_params).to include :q => 'something'
46
+ expect(::Api::ApplicationUsersController.last_action).to eq :index
47
+ expect(::Api::ApplicationUsersController.last_params).to include :q => 'something'
48
48
  end
49
49
 
50
50
  it 'makes api call to application_users updates' do
51
- Api::ApplicationUsersController.last_action = nil
51
+ ::Api::ApplicationUsersController.last_action = nil
52
52
  Accounts.get_application_account_updates
53
- expect(Api::ApplicationUsersController.last_action).to eq :updates
53
+ expect(::Api::ApplicationUsersController.last_action).to eq :updates
54
54
  end
55
55
 
56
56
  it 'makes api call to application_users updated' do
57
- Api::ApplicationUsersController.last_action = nil
58
- Api::ApplicationUsersController.last_json = nil
57
+ ::Api::ApplicationUsersController.last_action = nil
58
+ ::Api::ApplicationUsersController.last_json = nil
59
59
  Accounts.mark_account_updates_as_read([{id: 1, read_updates: 1}])
60
- expect(Api::ApplicationUsersController.last_action).to eq :updated
61
- expect(Api::ApplicationUsersController.last_json).to include(
60
+ expect(::Api::ApplicationUsersController.last_action).to eq :updated
61
+ expect(::Api::ApplicationUsersController.last_json).to include(
62
62
  {'id' => 1, 'read_updates' => 1})
63
63
  end
64
64
 
@@ -70,34 +70,34 @@ module OpenStax
70
70
  let!(:group) { FactoryGirl.create :openstax_accounts_group }
71
71
 
72
72
  it 'makes api call to groups create' do
73
- Api::GroupsController.last_action = nil
74
- Api::GroupsController.last_json = nil
73
+ ::Api::GroupsController.last_action = nil
74
+ ::Api::GroupsController.last_json = nil
75
75
  Accounts.create_group(account, group)
76
- expect(Api::GroupsController.last_action).to eq :create
77
- expect(Api::GroupsController.last_json).to include(
76
+ expect(::Api::GroupsController.last_action).to eq :create
77
+ expect(::Api::GroupsController.last_json).to include(
78
78
  {'name' => 'MyGroup', 'is_public' => false})
79
79
  end
80
80
 
81
81
  it 'makes api call to group update' do
82
82
  group.save!
83
- Api::GroupsController.last_action = nil
84
- Api::GroupsController.last_params = nil
85
- Api::GroupsController.last_json = nil
83
+ ::Api::GroupsController.last_action = nil
84
+ ::Api::GroupsController.last_params = nil
85
+ ::Api::GroupsController.last_json = nil
86
86
  Accounts.update_group(account, group)
87
- expect(Api::GroupsController.last_action).to eq :update
88
- expect(Api::GroupsController.last_params).to include(
87
+ expect(::Api::GroupsController.last_action).to eq :update
88
+ expect(::Api::GroupsController.last_params).to include(
89
89
  {'id' => group.openstax_uid.to_s})
90
- expect(Api::GroupsController.last_json).to include(
90
+ expect(::Api::GroupsController.last_json).to include(
91
91
  {'name' => group.name, 'is_public' => group.is_public})
92
92
  end
93
93
 
94
94
  it 'makes api call to group destroy' do
95
95
  group.save!
96
- Api::GroupsController.last_action = nil
97
- Api::GroupsController.last_params = nil
96
+ ::Api::GroupsController.last_action = nil
97
+ ::Api::GroupsController.last_params = nil
98
98
  Accounts.destroy_group(account, group)
99
- expect(Api::GroupsController.last_action).to eq :destroy
100
- expect(Api::GroupsController.last_params).to include(
99
+ expect(::Api::GroupsController.last_action).to eq :destroy
100
+ expect(::Api::GroupsController.last_params).to include(
101
101
  {'id' => group.openstax_uid.to_s})
102
102
  end
103
103
 
@@ -109,22 +109,22 @@ module OpenStax
109
109
  let!(:group_member) { FactoryGirl.build :openstax_accounts_group_member }
110
110
 
111
111
  it 'makes api call to group_members create' do
112
- Api::GroupMembersController.last_action = nil
113
- Api::GroupMembersController.last_params = nil
112
+ ::Api::GroupMembersController.last_action = nil
113
+ ::Api::GroupMembersController.last_params = nil
114
114
  Accounts.create_group_member(account, group_member)
115
- expect(Api::GroupMembersController.last_action).to eq :create
116
- expect(Api::GroupMembersController.last_params).to include(
115
+ expect(::Api::GroupMembersController.last_action).to eq :create
116
+ expect(::Api::GroupMembersController.last_params).to include(
117
117
  {'group_id' => group_member.group_id.to_s,
118
118
  'user_id' => group_member.user_id.to_s})
119
119
  end
120
120
 
121
121
  it 'makes api call to group_member destroy' do
122
122
  group_member.save!
123
- Api::GroupMembersController.last_action = nil
124
- Api::GroupMembersController.last_params = nil
123
+ ::Api::GroupMembersController.last_action = nil
124
+ ::Api::GroupMembersController.last_params = nil
125
125
  Accounts.destroy_group_member(account, group_member)
126
- expect(Api::GroupMembersController.last_action).to eq :destroy
127
- expect(Api::GroupMembersController.last_params).to include(
126
+ expect(::Api::GroupMembersController.last_action).to eq :destroy
127
+ expect(::Api::GroupMembersController.last_params).to include(
128
128
  {'group_id' => group_member.group_id.to_s,
129
129
  'user_id' => group_member.user_id.to_s})
130
130
  end
@@ -137,22 +137,22 @@ module OpenStax
137
137
  let!(:group_owner) { FactoryGirl.build :openstax_accounts_group_owner }
138
138
 
139
139
  it 'makes api call to group_owners create' do
140
- Api::GroupOwnersController.last_action = nil
141
- Api::GroupOwnersController.last_params = nil
140
+ ::Api::GroupOwnersController.last_action = nil
141
+ ::Api::GroupOwnersController.last_params = nil
142
142
  Accounts.create_group_owner(account, group_owner)
143
- expect(Api::GroupOwnersController.last_action).to eq :create
144
- expect(Api::GroupOwnersController.last_params).to include(
143
+ expect(::Api::GroupOwnersController.last_action).to eq :create
144
+ expect(::Api::GroupOwnersController.last_params).to include(
145
145
  {'group_id' => group_owner.group_id.to_s,
146
146
  'user_id' => group_owner.user_id.to_s})
147
147
  end
148
148
 
149
149
  it 'makes api call to group_owner destroy' do
150
150
  group_owner.save!
151
- Api::GroupOwnersController.last_action = nil
152
- Api::GroupOwnersController.last_params = nil
151
+ ::Api::GroupOwnersController.last_action = nil
152
+ ::Api::GroupOwnersController.last_params = nil
153
153
  Accounts.destroy_group_owner(account, group_owner)
154
- expect(Api::GroupOwnersController.last_action).to eq :destroy
155
- expect(Api::GroupOwnersController.last_params).to include(
154
+ expect(::Api::GroupOwnersController.last_action).to eq :destroy
155
+ expect(::Api::GroupOwnersController.last_params).to include(
156
156
  {'group_id' => group_owner.group_id.to_s,
157
157
  'user_id' => group_owner.user_id.to_s})
158
158
  end
@@ -165,22 +165,22 @@ module OpenStax
165
165
  let!(:group_nesting) { FactoryGirl.build :openstax_accounts_group_nesting }
166
166
 
167
167
  it 'makes api call to group_nestings (create)' do
168
- Api::GroupNestingsController.last_action = nil
169
- Api::GroupNestingsController.last_params = nil
168
+ ::Api::GroupNestingsController.last_action = nil
169
+ ::Api::GroupNestingsController.last_params = nil
170
170
  Accounts.create_group_nesting(account, group_nesting)
171
- expect(Api::GroupNestingsController.last_action).to eq :create
172
- expect(Api::GroupNestingsController.last_params).to include(
171
+ expect(::Api::GroupNestingsController.last_action).to eq :create
172
+ expect(::Api::GroupNestingsController.last_params).to include(
173
173
  {'group_id' => group_nesting.container_group_id.to_s,
174
174
  'member_group_id' => group_nesting.member_group_id.to_s})
175
175
  end
176
176
 
177
177
  it 'makes api call to group_nesting (destroy)' do
178
178
  group_nesting.save!
179
- Api::GroupNestingsController.last_action = nil
180
- Api::GroupNestingsController.last_params = nil
179
+ ::Api::GroupNestingsController.last_action = nil
180
+ ::Api::GroupNestingsController.last_params = nil
181
181
  Accounts.destroy_group_nesting(account, group_nesting)
182
- expect(Api::GroupNestingsController.last_action).to eq :destroy
183
- expect(Api::GroupNestingsController.last_params).to include(
182
+ expect(::Api::GroupNestingsController.last_action).to eq :destroy
183
+ expect(::Api::GroupNestingsController.last_params).to include(
184
184
  {'group_id' => group_nesting.container_group_id.to_s,
185
185
  'member_group_id' => group_nesting.member_group_id.to_s})
186
186
  end
@@ -190,17 +190,17 @@ module OpenStax
190
190
  context 'application_groups' do
191
191
 
192
192
  it 'makes api call to application_groups_updates' do
193
- Api::ApplicationGroupsController.last_action = nil
193
+ ::Api::ApplicationGroupsController.last_action = nil
194
194
  Accounts.get_application_group_updates
195
- expect(Api::ApplicationGroupsController.last_action).to eq :updates
195
+ expect(::Api::ApplicationGroupsController.last_action).to eq :updates
196
196
  end
197
197
 
198
198
  it 'makes api call to application_groups_updated' do
199
- Api::ApplicationGroupsController.last_action = nil
200
- Api::ApplicationGroupsController.last_json = nil
199
+ ::Api::ApplicationGroupsController.last_action = nil
200
+ ::Api::ApplicationGroupsController.last_json = nil
201
201
  Accounts.mark_group_updates_as_read([{id: 1, read_updates: 1}])
202
- expect(Api::ApplicationGroupsController.last_action).to eq :updated
203
- expect(Api::ApplicationGroupsController.last_json).to include(
202
+ expect(::Api::ApplicationGroupsController.last_action).to eq :updated
203
+ expect(::Api::ApplicationGroupsController.last_json).to include(
204
204
  {'id' => 1, 'read_updates' => 1})
205
205
  end
206
206
 
@@ -25,50 +25,55 @@ module OpenStax
25
25
  username: 'bigbear' }
26
26
 
27
27
  it "should match based on username" do
28
- outcome = SearchAccounts.call('username:jstra').outputs.accounts.all
28
+ outcome = SearchAccounts.call('username:jstra').outputs.items
29
29
  expect(outcome).to eq [account_1]
30
30
  end
31
31
 
32
32
  it "should ignore leading wildcards on username searches" do
33
- outcome = SearchAccounts.call('username:%rav').outputs.accounts.all
33
+ outcome = SearchAccounts.call('username:%rav').outputs.items
34
34
  expect(outcome).to eq []
35
35
  end
36
36
 
37
37
  it "should match based on one first name" do
38
- outcome = SearchAccounts.call('first_name:"John"').outputs.accounts.all
38
+ outcome = SearchAccounts.call('first_name:"John"').outputs.items
39
39
  expect(outcome).to eq [account_3, account_1]
40
40
  end
41
41
 
42
42
  it "should match based on one full name" do
43
- outcome = SearchAccounts.call('full_name:"Mary Mighty"').outputs.accounts.all
43
+ outcome = SearchAccounts.call('full_name:"Mary Mighty"').outputs.items
44
44
  expect(outcome).to eq [account_2]
45
45
  end
46
46
 
47
47
  it "should return all results if the query is empty" do
48
- outcome = SearchAccounts.call("").outputs.accounts.all
48
+ outcome = SearchAccounts.call("").outputs.items
49
49
  expect(outcome).to eq [account_4, account_3, account_1, account_2]
50
50
  end
51
51
 
52
52
  it "should match any field when no prefix given" do
53
- outcome = SearchAccounts.call("jst").outputs.accounts.all
53
+ outcome = SearchAccounts.call("jst").outputs.items
54
54
  expect(outcome).to eq [account_4, account_3, account_1]
55
55
  end
56
56
 
57
57
  it "should match any field when no prefix given and intersect when prefix given" do
58
- outcome = SearchAccounts.call("jst username:jst").outputs.accounts.all
58
+ outcome = SearchAccounts.call("jst username:jst").outputs.items
59
59
  expect(outcome).to eq [account_3, account_1]
60
60
  end
61
61
 
62
- it "shouldn't allow accounts to add their own wildcards" do
63
- outcome = SearchAccounts.call("username:'%ar'").outputs.accounts.all
62
+ it "shouldn't allow users to add their own wildcards" do
63
+ outcome = SearchAccounts.call("username:'%ar'").outputs.items
64
64
  expect(outcome).to eq []
65
65
  end
66
66
 
67
- it "should gather space-separated unprefixed search terms" do
68
- outcome = SearchAccounts.call("john mighty").outputs.accounts.all
67
+ it "should gather comma-separated unprefixed search terms" do
68
+ outcome = SearchAccounts.call("john,mighty").outputs.items
69
69
  expect(outcome).to eq [account_3, account_1, account_2]
70
70
  end
71
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
+
72
77
  context "pagination and sorting" do
73
78
 
74
79
  let!(:billy_accounts) {
@@ -80,31 +85,26 @@ module OpenStax
80
85
  }
81
86
  }
82
87
 
83
- it "should return the first page of values by default in default order" do
84
- outcome = SearchAccounts.call("username:billy").outputs.accounts.all
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
85
90
  expect(outcome.length).to eq 20
86
91
  expect(outcome[0]).to eq Account.where{username.eq "billy_00"}.first
87
92
  expect(outcome[19]).to eq Account.where{username.eq "billy_19"}.first
88
93
  end
89
94
 
90
- it "should return the 2nd page when requested" do
91
- outcome = SearchAccounts.call("username:billy", page: 1).outputs.accounts.all
95
+ it "should return the second page when requested" do
96
+ outcome = SearchAccounts.call("username:billy", page: 2, per_page: 20).outputs.items
92
97
  expect(outcome.length).to eq 20
93
98
  expect(outcome[0]).to eq Account.where{username.eq "billy_20"}.first
94
99
  expect(outcome[19]).to eq Account.where{username.eq "billy_39"}.first
95
100
  end
96
101
 
97
102
  it "should return the incomplete 3rd page when requested" do
98
- outcome = SearchAccounts.call("username:billy", page: 2).outputs.accounts.all
103
+ outcome = SearchAccounts.call("username:billy", page: 3, per_page: 20).outputs.items
99
104
  expect(outcome.length).to eq 6
100
105
  expect(outcome[5]).to eq Account.where{username.eq "billy_45"}.first
101
106
  end
102
107
 
103
- it "should return no results if the limit is exceeded" do
104
- outcome = SearchAccounts.call("").outputs.accounts.all
105
- expect(outcome).to be_empty
106
- end
107
-
108
108
  end
109
109
 
110
110
  context "sorting" do
@@ -114,10 +114,10 @@ module OpenStax
114
114
  let!(:tim_jones) { FactoryGirl.create :openstax_accounts_account, first_name: "Tim", last_name: "Jones", username: "foo_tj" }
115
115
 
116
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.accounts.all
117
+ outcome = SearchAccounts.call("username:foo", order_by: "first_name, last_name DESC").outputs.items
118
118
  expect(outcome).to eq [bob_jones, bob_brown, tim_jones]
119
119
 
120
- outcome = SearchAccounts.call("username:foo", order_by: "first_name, last_name ASC").outputs.accounts.all
120
+ outcome = SearchAccounts.call("username:foo", order_by: "first_name, last_name ASC").outputs.items
121
121
  expect(outcome).to eq [bob_brown, bob_jones, tim_jones]
122
122
  end
123
123