Refactor factory girl usage in specs

This commit is contained in:
Thibault Jouan 2015-05-01 15:21:41 +00:00
parent 3247dd0934
commit 00fe9bf258
9 changed files with 17 additions and 17 deletions

View File

@ -1,5 +1,5 @@
describe ApplicationController do
let(:user) { FactoryGirl.create(:user) }
let(:user) { create :user }
describe '#current_user=' do
it 'stores the user id in the session as :user_id' do

View File

@ -6,7 +6,7 @@ feature 'User sign in' do
end
scenario 'signs the user in' do
user = FactoryGirl.create(:user)
user = create :user
visit new_session_path
fill_in 'Email', with: user.email

View File

@ -1,5 +1,5 @@
feature 'User sign up' do
let(:user) { FactoryGirl.build(:user) }
let(:user) { build :user }
background do
visit new_user_path

View File

@ -4,7 +4,7 @@ feature 'Tracks player' do
background { sign_in }
scenario 'includes a player in track page' do
track = FactoryGirl.create(:track_with_sound)
track = create :track_with_sound
visit track_path(track)

View File

@ -1,7 +1,7 @@
describe 'API cross origin request' do
include AcceptanceHelpers
let(:user) { FactoryGirl.create(:user) }
let(:user) { create :user }
let(:origin) { 'http://origin.example/' }
before do

View File

@ -1,6 +1,6 @@
describe Playlist do
subject { playlist }
let(:playlist) { FactoryGirl.build(:playlist) }
let(:playlist) { build :playlist }
it { is_expected.to be_valid }
it { is_expected.to belong_to :user }

View File

@ -1,6 +1,6 @@
describe Sound do
subject { sound }
let(:sound) { FactoryGirl.build(:sound) }
let(:sound) { build :sound }
it { is_expected.to be_valid }
it { is_expected.to belong_to :track }
@ -19,7 +19,7 @@ describe Sound do
end
describe '#file=' do
let(:file) { FactoryGirl.attributes_for(:sound)[:file] }
let(:file) { attributes_for(:sound)[:file] }
it 'saves the file SHA256 digest' do
expect(sound.sha256).to eq Digest::SHA256.file(file.path).hexdigest

View File

@ -1,7 +1,7 @@
describe Track do
subject { track }
let(:track) { FactoryGirl.build(:track) }
let(:file) { FactoryGirl.attributes_for(:track_with_sound)[:file] }
let(:track) { build :track }
let(:file) { attributes_for(:track_with_sound)[:file] }
it { is_expected.to be_valid }
it { is_expected.to have_many :sounds }
@ -30,7 +30,7 @@ describe Track do
describe '#sound' do
context 'with a sound' do
before { track.sounds << FactoryGirl.create(:sound) }
before { track.sounds << create(:sound) }
it 'returns a sound' do
expect(track.sound).to be_a Sound
@ -46,7 +46,7 @@ describe Track do
end
context 'with a sound' do
before { track.sounds << FactoryGirl.create(:sound) }
before { track.sounds << create(:sound) }
it 'returns true' do
expect(track.sound?).to be true
@ -56,8 +56,8 @@ describe Track do
describe '.latest' do
it 'returns latest tracks in descending creation date order' do
track1 = FactoryGirl.create(:track, created_at: '2011-07-27 19:13:42')
track2 = FactoryGirl.create(:track, created_at: '2011-07-27 19:58:57')
track1 = create :track, created_at: '2011-07-27 19:13:42'
track2 = create :track, created_at: '2011-07-27 19:58:57'
expect(Track.latest).to eq [track2, track1]
end
end

View File

@ -1,5 +1,5 @@
describe User do
subject(:user) { FactoryGirl.build(:user) }
subject(:user) { build :user }
it { is_expected.to be_valid }
it { is_expected.to have_many :playlists }
@ -8,8 +8,8 @@ describe User do
it { is_expected.to validate_presence_of :password_hash }
context 'when a user with the same email address already exists' do
let(:old_user) { FactoryGirl.create(:user, email: 'unique@example.net') }
subject(:user) { FactoryGirl.build(:user, email: old_user.email) }
let(:old_user) { create :user, email: 'unique@example.net' }
subject(:user) { build :user, email: old_user.email }
it { is_expected.to_not be_valid }