开发者

Strange error with a simple test

this is what I'm testing:

model

scope :user_pending, l开发者_开发技巧ambda { |user|
where("jobs.available = 0 AND jobs.user_id = ?", user.id) }

test

it "should have the scope" do
  Job.should respond_to(:user_pending)
end

it "should return a list of jobs that are unavailable for the current_user" do
  @user = Factory(:user, :id => 1)
  @job = Factory(:job, :available => false, :user_id => @user)
  Job.user_pending(@user).should == @job
end

the first test is passing, but I can't pass on second. The following error message is returning:

Failures:


  1) Job Job :user_pending should return a list of jobs that are unavailable for the current_user
     Failure/Error: Job.user_pending(@user).should == @job
     expected: #<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para contato@test.com", locked: false, visits: 0>,
          got: [#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para contato@test.com", locked: false, visits: 0>] (using ==)
     Diff:
     @@ -1,2 +1,2 @@
     -#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para contato@test.com", locked: false, visits: 0>
     +[#<Job id: 6, title: "Contrata-se para fabrica de autos", location: "Aichi-ken, Toyohashi-shi", content: "Estamos contratando pessoas interessadas em trabalh...", user_id: 1, created_at: "2011-01-31 02:10:04", updated_at: "2011-01-31 02:10:04", available: false, company_name: "K.K. Test", company_website: "http://www.test.com", how_to_apply: "Enviar email para contato@test.com", locked: false, visits: 0>]
     # ./spec/models/job_spec.rb:91:in `block (3 levels) in <top (required)>'

what I missing? it's look all okay, right? I can't understand whats wrong there.


It appears that your scope is returning an array (which is what I would expect). Your test should probably look like:

Job.user_pending(@user).first.should == @job

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜