Created
July 22, 2013 06:57
-
-
Save davidbegin/6051797 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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