Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

Friday 5/11 Standup: View Paths in RSpec Helper tests; write_attribute for "type inference"


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.

    1. Mock out your render method
    2. Return the string for the page/partial from the helper and test that value

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *