Refactor factory girl usage in specs
This commit is contained in:
parent
3247dd0934
commit
00fe9bf258
@ -1,5 +1,5 @@
|
|||||||
describe ApplicationController do
|
describe ApplicationController do
|
||||||
let(:user) { FactoryGirl.create(:user) }
|
let(:user) { create :user }
|
||||||
|
|
||||||
describe '#current_user=' do
|
describe '#current_user=' do
|
||||||
it 'stores the user id in the session as :user_id' do
|
it 'stores the user id in the session as :user_id' do
|
||||||
|
@ -6,7 +6,7 @@ feature 'User sign in' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario 'signs the user in' do
|
scenario 'signs the user in' do
|
||||||
user = FactoryGirl.create(:user)
|
user = create :user
|
||||||
|
|
||||||
visit new_session_path
|
visit new_session_path
|
||||||
fill_in 'Email', with: user.email
|
fill_in 'Email', with: user.email
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
feature 'User sign up' do
|
feature 'User sign up' do
|
||||||
let(:user) { FactoryGirl.build(:user) }
|
let(:user) { build :user }
|
||||||
|
|
||||||
background do
|
background do
|
||||||
visit new_user_path
|
visit new_user_path
|
||||||
|
@ -4,7 +4,7 @@ feature 'Tracks player' do
|
|||||||
background { sign_in }
|
background { sign_in }
|
||||||
|
|
||||||
scenario 'includes a player in track page' do
|
scenario 'includes a player in track page' do
|
||||||
track = FactoryGirl.create(:track_with_sound)
|
track = create :track_with_sound
|
||||||
|
|
||||||
visit track_path(track)
|
visit track_path(track)
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
describe 'API cross origin request' do
|
describe 'API cross origin request' do
|
||||||
include AcceptanceHelpers
|
include AcceptanceHelpers
|
||||||
|
|
||||||
let(:user) { FactoryGirl.create(:user) }
|
let(:user) { create :user }
|
||||||
let(:origin) { 'http://origin.example/' }
|
let(:origin) { 'http://origin.example/' }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
describe Playlist do
|
describe Playlist do
|
||||||
subject { playlist }
|
subject { playlist }
|
||||||
let(:playlist) { FactoryGirl.build(:playlist) }
|
let(:playlist) { build :playlist }
|
||||||
|
|
||||||
it { is_expected.to be_valid }
|
it { is_expected.to be_valid }
|
||||||
it { is_expected.to belong_to :user }
|
it { is_expected.to belong_to :user }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
describe Sound do
|
describe Sound do
|
||||||
subject { sound }
|
subject { sound }
|
||||||
let(:sound) { FactoryGirl.build(:sound) }
|
let(:sound) { build :sound }
|
||||||
|
|
||||||
it { is_expected.to be_valid }
|
it { is_expected.to be_valid }
|
||||||
it { is_expected.to belong_to :track }
|
it { is_expected.to belong_to :track }
|
||||||
@ -19,7 +19,7 @@ describe Sound do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#file=' do
|
describe '#file=' do
|
||||||
let(:file) { FactoryGirl.attributes_for(:sound)[:file] }
|
let(:file) { attributes_for(:sound)[:file] }
|
||||||
|
|
||||||
it 'saves the file SHA256 digest' do
|
it 'saves the file SHA256 digest' do
|
||||||
expect(sound.sha256).to eq Digest::SHA256.file(file.path).hexdigest
|
expect(sound.sha256).to eq Digest::SHA256.file(file.path).hexdigest
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
describe Track do
|
describe Track do
|
||||||
subject { track }
|
subject { track }
|
||||||
let(:track) { FactoryGirl.build(:track) }
|
let(:track) { build :track }
|
||||||
let(:file) { FactoryGirl.attributes_for(:track_with_sound)[:file] }
|
let(:file) { attributes_for(:track_with_sound)[:file] }
|
||||||
|
|
||||||
it { is_expected.to be_valid }
|
it { is_expected.to be_valid }
|
||||||
it { is_expected.to have_many :sounds }
|
it { is_expected.to have_many :sounds }
|
||||||
@ -30,7 +30,7 @@ describe Track do
|
|||||||
|
|
||||||
describe '#sound' do
|
describe '#sound' do
|
||||||
context 'with a sound' do
|
context 'with a sound' do
|
||||||
before { track.sounds << FactoryGirl.create(:sound) }
|
before { track.sounds << create(:sound) }
|
||||||
|
|
||||||
it 'returns a sound' do
|
it 'returns a sound' do
|
||||||
expect(track.sound).to be_a Sound
|
expect(track.sound).to be_a Sound
|
||||||
@ -46,7 +46,7 @@ describe Track do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'with a sound' do
|
context 'with a sound' do
|
||||||
before { track.sounds << FactoryGirl.create(:sound) }
|
before { track.sounds << create(:sound) }
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
expect(track.sound?).to be true
|
expect(track.sound?).to be true
|
||||||
@ -56,8 +56,8 @@ describe Track do
|
|||||||
|
|
||||||
describe '.latest' do
|
describe '.latest' do
|
||||||
it 'returns latest tracks in descending creation date order' do
|
it 'returns latest tracks in descending creation date order' do
|
||||||
track1 = FactoryGirl.create(:track, created_at: '2011-07-27 19:13:42')
|
track1 = create :track, created_at: '2011-07-27 19:13:42'
|
||||||
track2 = FactoryGirl.create(:track, created_at: '2011-07-27 19:58:57')
|
track2 = create :track, created_at: '2011-07-27 19:58:57'
|
||||||
expect(Track.latest).to eq [track2, track1]
|
expect(Track.latest).to eq [track2, track1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
describe User do
|
describe User do
|
||||||
subject(:user) { FactoryGirl.build(:user) }
|
subject(:user) { build :user }
|
||||||
|
|
||||||
it { is_expected.to be_valid }
|
it { is_expected.to be_valid }
|
||||||
it { is_expected.to have_many :playlists }
|
it { is_expected.to have_many :playlists }
|
||||||
@ -8,8 +8,8 @@ describe User do
|
|||||||
it { is_expected.to validate_presence_of :password_hash }
|
it { is_expected.to validate_presence_of :password_hash }
|
||||||
|
|
||||||
context 'when a user with the same email address already exists' do
|
context 'when a user with the same email address already exists' do
|
||||||
let(:old_user) { FactoryGirl.create(:user, email: 'unique@example.net') }
|
let(:old_user) { create :user, email: 'unique@example.net' }
|
||||||
subject(:user) { FactoryGirl.build(:user, email: old_user.email) }
|
subject(:user) { build :user, email: old_user.email }
|
||||||
|
|
||||||
it { is_expected.to_not be_valid }
|
it { is_expected.to_not be_valid }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user