This post originated from an RSS feed registered with Ruby Buzz
by Maxim Kulkin.
Original Post: Back to Rails
Feed Title: Software development
Feed URL: http://maximkulkin.blogspot.com/feeds/posts/full?alt=rss
Feed Description: Software development
Lately I wasn't doing any Rails development because I was busy re-learning C/C++ "the right way". Turns out it's not that painful as they say.
Then I had to do some Rails coding using latest and greatest Rails 2.2 and I find that that the simple things are broken (or somewhat obscure).
Case 1.
I was developing some general resource controller and wanted to spec out a redirect after #create action. My controller should not be bound to any specific resource url (as it is planned to bind many different resources with that controller), so I decided to make use of Rails' url rewriting. Spec was like this:
it "should redirect to #index after item creation" do
@model.stubs(:create!)
post :create
response.should redirect_to(:action => :index)
end
And this spec failed because of MethodNotAllowed: Only get and post requests are allowed.
WTF? It's the very basic functionality. Why does it fail to work ?
After half a day of investigation I found out that this is a bug in rspec-rails package and redirect_to matcher fails to handle hash-like url specifier.
Case 2.
I wanted to handle AR::RecordInvalid exceptions with one handler to DRY up controller code. I wrote corresponding "rescue_from" call in controller and wrote specs (in fact, the reverse order: specs then code). And those specs failed too.
The other several hours of investigation revealed hidden option: RSpec-rails overrides default Rails' error handling (which is based on ActiveSupport's #rescue_from feature) with pass-through exception handler, and you have to write following code to make YOUR exception handlers work:
before do
controller.use_rails_error_handling!
end
Yeah, Rails is nice, but upgrading to a new version is a pain.