Skip to content

Commit

Permalink
Added spec to test that the manager will get the users ordered by amo…
Browse files Browse the repository at this point in the history
…unt of search matches
  • Loading branch information
RafaFP committed Nov 7, 2016
1 parent 03efcca commit e0938ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def self.find_first_by_auth_conditions(warden_conditions)

scope :search_by_terms, -> (words, include_private=false) {
query = joins(:profile).includes(:profile)
puts words.inspect

if words.present?
words ||= []
words = [words] unless words.is_a?(Array)
Expand Down
15 changes: 15 additions & 0 deletions spec/controllers/manage_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@
it { assigns(:users)[3].should eql(@u1) }
end

context "on a search_by_terms orders @users by more hits" do
before {
@u1 = FactoryGirl.create(:user, :_full_name => 'First user created')
@u2 = user
@u2.profile.update_attributes(:full_name => 'Second user created')
@u3 = FactoryGirl.create(:user, :_full_name => 'A user starting with letter A')
@u4 = FactoryGirl.create(:user, :_full_name => 'Being someone starting with B')
}
before(:each) { get :users, :q => 'second user' }
it { assigns(:users).count.should be(3) }
it ("On top the user with 2 matches") { assigns(:users)[0].should eql(@u2) }
it ("Then another user with 1 match and has higher alphabetical order") { assigns(:users)[1].should eql(@u3) }
it ("Then another user with 1 match and has lower alphabetical order") { assigns(:users)[2].should eql(@u1) }
end

context "paginates the list of users" do
before {
45.times { FactoryGirl.create(:user) }
Expand Down

0 comments on commit e0938ef

Please sign in to comment.