Monday 10 May 2010

Rspec controller and respond_to with :js

Wanted to test that my controller was returning an array of ids when pinged by Ajax

respond_to do |format|
format.html # index.html.erb
format.js { render :text => @chart_entries.map {|x| '%' + x.id.to_s} }
format.xml { render :xml => @chart_entries }
end


After some googling and prodding it - came up withL

it "should return an array of ids if given the params[:co]" do
format = mock("format")
format.should_receive(:js).and_return(['%' + @chart_entry.id.to_s])
format.stub!(:html)
format.stub!(:xml)
controller.should_receive(:respond_to).and_yield(format)
get :index, :co=>1, :format=> 'js'
end

No comments:

Post a Comment