Permalink
Browse files

searching profiles also by user's login and searching only for active…

… users
  • Loading branch information...
1 parent 8375b26 commit 913eaf71621b19555dede9256be7d741cc2df21a @molpe molpe committed Nov 23, 2009
Showing with 38 additions and 6 deletions.
  1. +2 −0 CHANGELOG.md
  2. +2 −1 app/models/profile.rb
  3. +10 −0 test/test_helper.rb
  4. +24 −5 test/unit/profile_test.rb
View
@@ -5,6 +5,8 @@ Edge
* Acts_as_state_machine code replaced by AASM gem
* Better messages for bidirectional friendships
* Added translations for Brazilian Portuguese
+* Fixed: searching only active profiles
+* Set profile's first name == login by default
0.5.4
----
View
@@ -30,7 +30,8 @@ class Profile < ActiveRecord::Base
named_scope :active, :conditions => {'users.state' => 'active'}, :include => :user
def self.site_search(query, search_options={})
- Profile.find(:all, :conditions => ["first_name like ? or last_name like ?", "%#{query}%", "%#{query}%"])
+ q = "%#{query}%"
+ Profile.active.find(:all, :conditions => ["first_name like ? or last_name like ? or login like ?", q, q, q])
end
def network
View
@@ -31,4 +31,14 @@ def assert_no_difference(object, method, &block)
assert_difference object, method, 0, &block
end
+ def create_user(login)
+ Factory(:user, :login => login)
+ end
+
+ def create_active_user(login)
+ user = create_user(login)
+ user.activate!
+ user
+ end
+
end
View
@@ -3,11 +3,15 @@
class ProfileTest < ActiveSupport::TestCase
context "A Profile " do
setup do
- @user = Factory(:user, :login => 'chavez')
- @user2 = Factory(:user, :login => 'evo')
-
+ @user = create_active_user('chavez')
+ @user2 = create_active_user('evo')
+ @user3 = create_active_user('fidel')
+ @user4 = create_user('ghost')
+
@chavez = Factory(:profile, :first_name => 'Hugo', :last_name => 'Chavez', :user => @user)
- @evo = Factory(:profile, :first_name => 'Evo', :last_name => 'Morales', :user => @user2)
+ @evo = Factory(:profile, :first_name => 'Evo', :last_name => 'Morales', :user => @user2)
+ @fidel = Factory(:profile, :user => @user3)
+ @ghost = Factory(:profile, :first_name => 'Ghost', :user => @user4)
end
should "return full_name correctly base on first_name and last_name" do
@@ -105,11 +109,26 @@ class ProfileTest < ActiveSupport::TestCase
@chavez.remove_following @evo
@chavez.follows? @evo
end
-
+
should "treat a friendship as mutual follower relationship between the 2 profiles" do
@evo.add_friend(@chavez)
assert @evo.follows?(@chavez)
assert @chavez.follows?(@evo)
end
+
+ context "being searched " do
+ should "be found if using his first name" do
+ assert Profile.site_search('Hugo').include?(@chavez)
+ end
+ should "be found if using his last name" do
+ assert Profile.site_search('Morales').include?(@evo)
+ end
+ should "be found if using his login" do
+ assert Profile.site_search('fidel').include?(@fidel)
+ end
+ should "not be found if user is not active" do
+ assert !Profile.site_search('Ghost').include?(@ghost)
+ end
+ end
end
end

0 comments on commit 913eaf7

Please sign in to comment.