Prawn has been and gone and updated itself - which is fair enough but damn it for eating up a good few hours while I tried to sort out a bug - that for once wasn't my fault.
Couple of things have changed
pdf.header has gone as has pdf.footer
Now replaced by pdf.repeat :all
That took a little bit of jiggery-pokery to sort out - but not too hard
Then the
can't dup Fixnum error kept cropping up.
This was simple - convert to a string
ie @job.id.to_s
Thursday, 20 May 2010
Monday, 17 May 2010
Why I love Rails
You get to write tests like this. What could be easier
it "should not allow timesheets to end before they start" do
@timesheet_item.start_time = 1.hour.from_now
@timesheet_item.should_not be_valid
end
it "should not allow timesheets to end before they start" do
@timesheet_item.start_time = 1.hour.from_now
@timesheet_item.should_not be_valid
end
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
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
Wednesday, 5 May 2010
Rspec and named routes
Have a job and a job has many pages. Setting that up for rspec was not as bad as I thought it was going to be
Here is the named route:
map.resources :jobs do |job|
job.resources :pages
end
Setting up the pages_controller_spec.rb was - after a bit of poking around - not too hard:
describe PagesController, " handling GET jobs/1/pages/1 for a job" do
before do
@job = mock_model(Job, {:id=>1})
@page = mock_model(Page)
Page.stub!(:find).and_return(@page)
Job.stub!(:find).and_return(@job)
end
Here is the named route:
map.resources :jobs do |job|
job.resources :pages
end
Setting up the pages_controller_spec.rb was - after a bit of poking around - not too hard:
describe PagesController, " handling GET jobs/1/pages/1 for a job" do
before do
@job = mock_model(Job, {:id=>1})
@page = mock_model(Page)
Page.stub!(:find).and_return(@page)
Job.stub!(:find).and_return(@job)
end
Subscribe to:
Posts (Atom)