[rspec-users] having trouble specing an ajax request

4 views
Skip to first unread message

Namrata Tiwari

unread,
Mar 5, 2008, 5:25:05 AM3/5/08
to rspec...@rubyforge.org
Do I need to spec an AR. If yes, what is the best way to spec this.
here is the code -

def index
@deals = Deal.paginate(:all, :conditions =>
prepare_search_conditions, :order
=> 'created_at DESC', :page => params[:page]
)
if request.xhr?
render :update do |page|
page.replace_html "table", :partial => "/deals/front/listing"
end
end

I am new to Rspec. Is this the right way?

it "should list all deals" do
controller.stub!(:prepare_search_conditions).and_return(true)
Deal.should_receive(:paginate).with(:all, {:conditions=>true,
:order=>"created_at DESC",
:page=>nil}).and_return(@deals)
get :list
controller.expect_render(:partial => '/deals/cms/list')
end

Thanks,
Namrata.
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Namrata Tiwari

unread,
Mar 5, 2008, 5:27:49 AM3/5/08
to rspec...@rubyforge.org
Sorry I pasted the wrong spec.
Here is correct one -

it "should show deals listing" do
controller.stub!(:prepare_search_conditions).and_return(true)
Deal.should_receive(:paginate).and_return(@deals)

get :index
controller.expect_render(:partial => '/deals/front/listing')

Ben Mabey

unread,
Mar 5, 2008, 1:18:37 PM3/5/08
to rspec...@rubyforge.org
Namrata Tiwari wrote:
> Sorry I pasted the wrong spec.
> Here is correct one -
>
> it "should show deals listing" do
> controller.stub!(:prepare_search_conditions).and_return(true)
> Deal.should_receive(:paginate).and_return(@deals)
>
> get :index
> controller.expect_render(:partial => '/deals/front/listing')
> end
>
>
>> Thanks,
>> Namrata.
>>
>
>
Try setting your headers before your get request.. Like so:

@request.env["HTTP_ACCEPT"] = "application/javascript"

-Ben

Harm Aarts

unread,
Mar 6, 2008, 3:16:50 AM3/6/08
to rspec...@rubyforge.org
Hi Namrata,

I recently ran into the same problem as well. The trick was to do
something like:
response.should have_rjs(some_arguments)
The 'some_arguments' threw me off for a while but I believe you
need :chained_replace_html.
I wrote a little piece on it here: http://www.rubytutorials.net/2008/02/29/small-rspec-revelations-rjs/
Hope you find it helpful.

With kind regards,
Harm

Reply all
Reply to author
Forward
0 new messages