Testing nested attributes with RSpec

So I came across a situation today where I needed to have a particular model accept nested attributes for a related model – much like is demonstrated in the post on integrating advanced forms with Cocoon. Unfortunately, much to my dismay, RSpec doesn’t have any fancy convenience method for testing this. Intarwebz to the rescue!

I found this great little script for doing simple testing for nested attributes, including rejection and acceptance criteria. Just place the code from this gist in a file in your spec/support folder and you’ll magically gain access to a new should matcher – accept_nested_attributes_for.

it { should accept_nested_attributes_for(:association_name) }

Easy communication with Rails VirtualBox server

In a recent post I talked about how to setup a Ruby on Rails environment for Mac OS or Ubuntu by itself and in a VirtualBox. In using my VirtualBox Ubuntu server on my Windows laptop, I’ve been annoyed by the constantly changing IP address when networking is configured to Bridge Adapter, so after a little Google sleuthing I was able to find an easy to implement solution: port forwarding. Continue reading “Easy communication with Rails VirtualBox server”