I've combined my user & shift factories to save space.
FactoryGirl.define do
factory :user do
name 'test'
password 'test'
phone_number '1-444-555-8888'
end
factory :shift do
user
end
end
This is my test. Fails on 'shifts = create_list(:shift, 20)'
require 'spec_helper'
describe MyFirebase do
let(:dummy_class) { Class.new { include MyFirebase } }
describe ".firebase_update_duration" do
it "should update total duration value in firebase", focus: true do
shifts = create_list(:shift, 20)
instance = dummy_class.new
duration = instance.firebase_update_duration
p "/" * 100
p duration
p "/" * 100
duration.should eq(Shift.shift_duration_total)
end
end
end
This is the error:
Failure/Error: shifts = create_list(:shift, 20)
ActiveRecord::RecordNotUnique:
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_users_on_phone_number"
DETAIL: Key (phone_number)=(1-444-555-8888) already exists.
How is there duplicate user records? I thought I was creating a list of shifts for a specific user (user one to many shifts association).