For testing accepts_nested_attributes_for there are convenient shoulda sockets for creating gems, but you mentioned that you do not want to use other gems. Thus, using only Rspec, the idea is to set an hash of attributes that will include the required Tester attributes and a nested hash called skill_attributes that will include the required Skill attributes; then pass it to the create method of the Tester and see if it changes the number of Testers and the number of Skills . Something like that:
class Tester < Person has_one :company accepts_nested_attributes_for :skill
Your tests:
# spec/models/tester_spec.rb ...... describe "creating Tester with valid attributes and nested Skill attributes" do before(:each) do
Hash syntax may vary. Also, if you have any uniqueness checks, make sure you generate dynamic @attrs dynamically before each test. Hi helper.
source share