No helps today
write_attribute and “type inference”: By default, in AR property assignment calls write_attribute which performs some nice type inference that can be very handy. If you override property assignment you have to call this explicitly if you want that behavior. Note that type inference inference is not available for hashed attribute assignment.
As a motivating example, consider checkboxes. From the form the value is represented as “0″ or “1″ (String). Assuming you use automatic property assignment, write_attribute is called and it will convert “0″ to false and “1″ to true. If you override the assignment and don’t call write_attribute, or try to use hash-based attribute access, it will view both “0″ and “1″ as true values; it only considers the empty string or a nil value as false.
View paths in RSpec Helper tests: Note that view paths are not present in the load path in RSpec Helper Tests. Therefore, if you’re testing a helper that attempts to render a page or a partial, you’ll get an exception. There are at least 2 solutions to this.
- Mock out your render method
- Return the string for the page/partial from the helper and test that value