Forum: RSpec Verify Order

Posted by Frank Lakatos (Guest)
on 2010-03-04 07:06
(Received via mailing list)
I may be missing something obvious, but how do I verify sort order?

I have

class Project < ActiveRecord::Base
   has_many :tasks, :order => "position"
end


I create a project, and 2 tasks: one with position = 1 and the other
with position = 2. I want to verify that Project.tasks orders the
tasks so that the task with position = 1 comes before the task with
position = 2.

Little push would be great, thanks

Frank
Posted by Nicolás Sanguinetti (Guest)
on 2010-03-04 07:32
(Received via mailing list)
Assuming Project.tasks has :order => 'position ASC' then:

describe Project do
  before do
    @project = Project.create
    @first_task = @project.tasks.create(:position => 1)
    @last_task = @project.tasks.create(:position => 2)
  end

  it "returns its tasks in order" do
    @project.tasks.should == [@first_task, @last_task]
  end
end

Will check that they are ordered.

Cheers,
-foca
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.