Created
September 26, 2011 23:44
-
-
Save batasrki/1243788 to your computer and use it in GitHub Desktop.
Example model search spec
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
describe Job do | |
before :each do | |
@mock_client = mock_model(Client, {:name => "Test Client"}) | |
@job = Job.new(:name => "test job", :client => @mock_client, | |
:category => @mock_job_category) | |
end | |
describe "search" do | |
before :each do | |
@category = JobCategory.create!(:name => "Testing search") | |
end | |
it "should search for a term without a join" do | |
@job.save | |
Job.search("jobs.name like '%test%'", 1, "client_id in (#{@mock_client.id})", nil).should include(@job) | |
end | |
it "should search for a term without a join and a condition" do | |
@job.save | |
Job.search("jobs.name like '%test%'", 1, nil, nil).should include(@job) | |
end | |
it "should search for a term with a join" do | |
@job.category = @category | |
@job.save | |
Job.search("jobs.name like '%test%'", 1, "client_id in (#{@mock_client.id})", :category).should include(@job) | |
end | |
it "should return the right order of jobs when searching for a term with a join and condition" do | |
@job.category = @category | |
@job.save | |
Job.create!(:name =>"Before the other test one", :client => @mock_client, :category => @category, :users => [@mock_member]) | |
found = Job.search("jobs.name like '%test%'", 1, "client_id in (#{@mock_client.id})", :category) | |
found.size.should == 2 | |
found.first.name.should match(/^Before/) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment