Category Archives: Uncategorized

Rails Gotcha: Mocking/Stubbing on an Associated ActiveRecord Object

In RSpec it is still not possible to have mocks or stubs on all instances of a class, although this has been suggested and it is a feature of the Mocha framework. Stubbing or mocking an object returned by an ActiveRecord belongs_to association (i.e. article.author) won’t do what you expect. Instead of mocking the associated [...]

Rails Tip: Safe Usage of URI.parse

As documented already by Doug URI.parse will thrown an exception if your URL has a trailing space. It also throws an exception on invalid URLs in general. To avoid having URI.parse bomb on your pages you can use a construct like this:

acts_as_bitfield Plugin now Radio Button Compatible

I’ve patched the acts_as_bitfield plugin to recognize “true” as true so that now instead of having to write:
<%= f.radio_button(:email_activated, true, :checked => (”checked” if @item.email_activated?)) %> Yes
<%= f.radio_button(:email_activated, false, :checked => (”checked” unless @item.email_activated?)) %> No
you can omit the checked argument just like with ActiveRecord boolean attributes:
<%= f.radio_button(:email_activated, true) %> Yes

<%= f.radio_button(:email_activated, false) %> No

Committing to Rails Core

In our last post we talked about upgrading to Rails 2.3, and the issues we encountered. One bug we found was that multiple POST requests issued in a test didn’t reset the post parameters between requests. The patch Peter submitted is now part of the Rails core, and we are very happy about it.
Perhaps not [...]

A short introduction.

Welcome to the blog! I thought it would be appropriate to shortly present Newsdesk in a post before anything else.
If you don’t know about us (and chances are small you do, unless you’re living in Sweden), we are a Swedish equivalent to PRWeb, or PR Newswire in some ways.
We are an online visibility company. Corporations [...]