From e1dd0cf6be90562657f1d5aae6d7d415eef82d84 Mon Sep 17 00:00:00 2001 From: maxwell Date: Wed, 13 Oct 2010 23:49:13 -0700 Subject: [PATCH] Fixed pending people_controller spec; cleaned up person.search(this is ruby :D ); fyi, calling should_receive stubs that method, hence this test confusion --- Gemfile.lock | 21 ++++----------------- app/controllers/people_controller.rb | 1 - app/models/person.rb | 12 +++++------- spec/controllers/people_controller_spec.rb | 5 +++-- 4 files changed, 12 insertions(+), 27 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c92fae55d..41e008130 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -122,7 +122,6 @@ GEM selenium-webdriver (>= 0.0.3) childprocess (0.0.7) ffi (~> 0.6.3) - columnize (0.3.1) crack (0.1.8) cucumber (0.9.2) builder (~> 2.1.2) @@ -163,7 +162,6 @@ GEM i18n (0.4.1) json (1.4.6) json_pure (1.4.6) - linecache (0.43) mail (2.2.7) activesupport (>= 2.3.6) mime-types @@ -223,14 +221,8 @@ GEM rspec-mocks (2.0.0) rspec-core (= 2.0.0) rspec-expectations (= 2.0.0) - rspec-rails (2.0.0.beta.17) - rspec (>= 2.0.0.beta.14) - webrat (>= 0.7.0) - ruby-debug (0.10.3) - columnize (>= 0.1) - ruby-debug-base (~> 0.10.3.0) - ruby-debug-base (0.10.3) - linecache (>= 0.3) + rspec-rails (2.0.0) + rspec (= 2.0.0) rubyzip (0.9.4) selenium-webdriver (0.0.29) childprocess (>= 0.0.7) @@ -253,10 +245,6 @@ GEM webmock (1.3.5) addressable (>= 2.1.1) crack (>= 0.1.7) - webrat (0.7.1) - nokogiri (>= 1.2.0) - rack (>= 1.0) - rack-test (>= 0.5.3) will_paginate (3.0.pre2) xml-simple (1.0.12) @@ -290,9 +278,8 @@ DEPENDENCIES rails (= 3.0.0) redfinger! roxml! - rspec (>= 2.0.0.beta.17) - rspec-rails (= 2.0.0.beta.17) - ruby-debug + rspec (>= 2.0.0) + rspec-rails (>= 2.0.0) sprinkle! thin webmock diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 746877498..5503c2997 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -12,7 +12,6 @@ class PeopleController < ApplicationController @aspects_dropdown_array = current_user.aspects.collect{|x| [x.to_s, x.id]} @aspect = :all @people = Person.search(params[:q]).paginate :page => params[:page], :per_page => 25, :order => 'created_at DESC' - respond_with @people end diff --git a/app/models/person.rb b/app/models/person.rb index 8382c9d34..230ad20f1 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -35,19 +35,17 @@ class Person def self.search(query) return Person.all if query.to_s.empty? - qTokens = query.to_s.strip.split(" ") - fullQueryText = Regexp.escape( query.to_s.strip ) + query_tokens = query.to_s.strip.split(" ") + full_query_text = Regexp.escape( query.to_s.strip ) + p = [] - qTokens.each { - |token| - + query_tokens.each do |token| q = Regexp.escape( token.to_s.strip ) p = Person.all('profile.first_name' => /^#{q}/i) \ | Person.all('profile.last_name' => /^#{q}/i) \ | p - - } + end return p end diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index ab15625d0..26bf2a804 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -14,9 +14,10 @@ describe PeopleController do end it "index should yield search results for substring of person name" do - pending "wait, what???" - Person.should_receive(:search) + + eugene = Factory.create(:person, :profile => {:first_name => "Eugene", :last_name => "w"}) get :index, :q => "Eu" + assigns[:people].should include eugene end it 'should go to the current_user show page' do