Hi Rspec-Users,
I''m not sure if I am correctly specing my index since I''m
using
will_paginate.
params[:filter_by] will filter the paginate list accordingly.
Tickets Controller:
def index
@tickets = Ticket.filter_status_by(params[:filter_by],params[:page])
end
Ticket Model:
def self.filter_status_by(status, page, per_page = 10)
conditions = {:status => false} if status == "unsolved"
conditions = {:status => true} if status == "solved"
return Ticket.paginate(:page => page, :per_page => per_page, :conditions
=> conditions)
end
describe TicketsController, "handling GET /tickets" do
before do
@tickets = mock_model(Ticket)
Ticket.stub!(:find).and_return([@ticket])
end
def do_get
get :index
end
it "should be successful" do
do_get
response.should be_success
end
it "should render index template" do
do_get
response.should render_template(''index'')
end
it "should find all pagniated tickets" do
@tickets = Ticket.paginate :per_page => 10
Ticket.should_receive(:filter_status_by).with(nil,nil).and_return(@tickets)
do_get
end
it "should find solved pagniated tickets" do
@tickets = Ticket.paginate :per_page => 10, :conditions => {:status
=>
true}
Ticket.should_receive(:filter_status_by).with(''solved'',nil).and_return(@tickets)
get :index, :filter_by => ''solved''
end
it "should find unsolved pagniated tickets" do
@tickets = Ticket.paginate :per_page => 10, :conditions => {:status
=>
false}
Ticket.should_receive(:filter_status_by).with(''unsolved'',nil).and_return(@tickets)
get :index, :filter_by => ''unsolved''
end
it "should assign the found tickets for the view" do
do_get
assigns[:tickets].should == [@tickets]
end
end
1)
''TicketsController handling GET /tickets should assign the found
tickets for
the view'' FAILED
expected [#<Ticket:0x1aa340c @name="Ticket_1000">], got [nil]
(using ==)
./spec/controllers/tickets_controller_spec.rb:71:
script/spec:4:
Finished in 0.207992 seconds
13 examples, 1 failure
Any suggestions or criticisms about my rspec?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/rspec-users/attachments/20070614/e421636a/attachment.html