Skip to content

Instantly share code, notes, and snippets.

@davidbegin
Created July 22, 2013 06:57
Show Gist options
  • Save davidbegin/6051797 to your computer and use it in GitHub Desktop.
Save davidbegin/6051797 to your computer and use it in GitHub Desktop.
require 'factory_girl'
FactoryGirl.define do
factory :user do
name 'Pete'
end
factory :registration do
title 'Summer Class'
end
factory :user_registration do
user
registration
end
end
require 'spec_helper'
describe "Connecting Users to Registrations through 2 Factories" do
before :each do
@user = create(:user)
@registration = create(:registration)
@user.registrations << @registration
end
it "should associate the user with the registration" do
expect(@user.name).to eq 'Pete'
expect(@registration.title).to eq 'Summer Class'
expect(@user.registrations.length).to eq 1
end
describe "Connecting Users to Registrations through 1 Factory" do
before :each do
@user_and_registration = create(:user_registration)
end
it "should create a new user and new registration and associate them" do
expect(@user_and_registration.user.name).to eq 'Pete'
expect(@user_and_registration.registration.title).to eq 'Summer Class'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment