Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: user directory returns staged users during search
- Loading branch information
Showing
5 changed files
with
90 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require 'rails_helper' | ||
|
||
describe DirectoryItemsController do | ||
let!(:user) { Fabricate(:user) } | ||
|
||
|
||
it "requires a `period` param" do | ||
expect do | ||
get '/directory_items.json' | ||
end.to raise_error(ActionController::ParameterMissing) | ||
end | ||
|
||
it "requires a proper `period` param" do | ||
get '/directory_items.json', params: { period: 'eviltrout' } | ||
expect(response).not_to be_success | ||
end | ||
|
||
context "without data" do | ||
|
||
context "and a logged in user" do | ||
before { sign_in(user) } | ||
|
||
it "succeeds" do | ||
get '/directory_items.json', params: { period: 'all' } | ||
expect(response).to be_success | ||
end | ||
end | ||
|
||
end | ||
|
||
context "with data" do | ||
before do | ||
Fabricate(:evil_trout) | ||
Fabricate(:walter_white) | ||
Fabricate(:staged, username: 'stage_user') | ||
|
||
DirectoryItem.refresh! | ||
end | ||
|
||
it "succeeds with a valid value" do | ||
get '/directory_items.json', params: { period: 'all' } | ||
expect(response).to be_success | ||
json = ::JSON.parse(response.body) | ||
|
||
expect(json).to be_present | ||
expect(json['directory_items']).to be_present | ||
expect(json['total_rows_directory_items']).to be_present | ||
expect(json['load_more_directory_items']).to be_present | ||
|
||
expect(json['directory_items'].length).to eq(4) | ||
expect(json['total_rows_directory_items']).to eq(4) | ||
end | ||
|
||
it "fails when the directory is disabled" do | ||
SiteSetting.enable_user_directory = false | ||
|
||
get '/directory_items.json', params: { period: 'all' } | ||
expect(response).not_to be_success | ||
end | ||
|
||
it "finds user by name" do | ||
get '/directory_items.json', params: { period: 'all', name: 'eviltrout' } | ||
expect(response).to be_success | ||
|
||
json = ::JSON.parse(response.body) | ||
expect(json).to be_present | ||
expect(json['directory_items'].length).to eq(1) | ||
expect(json['total_rows_directory_items']).to eq(1) | ||
expect(json['directory_items'][0]['user']['username']).to eq('eviltrout') | ||
end | ||
|
||
it "finds staged user by name" do | ||
get '/directory_items.json', params: { period: 'all', name: 'stage_user' } | ||
expect(response).to be_success | ||
|
||
json = ::JSON.parse(response.body) | ||
expect(json).to be_present | ||
expect(json['directory_items'].length).to eq(1) | ||
expect(json['total_rows_directory_items']).to eq(1) | ||
expect(json['directory_items'][0]['user']['username']).to eq('stage_user') | ||
end | ||
end | ||
end |
92a831b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should stated users show up in user search? Is this admin only?
92a831b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Staged users are always shown in the user directory. It was just not possible to search for them. It affects only the search on the user directory, not anywhere else. Sam requested it, but I can revert if we don't want this feature after all.
92a831b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's OK I was just curious about it. I am not sure staged users should show up in the user directory at all though? Sure on the admin side but on the user-facing side??