Update factory girl to last version

This commit is contained in:
Thibault Jouan 2014-04-01 05:04:27 +00:00
parent d2b332215e
commit eda2f3fbee
28 changed files with 56 additions and 56 deletions

View File

@ -9,7 +9,7 @@ gem 'rabl', '~> 0.6'
group :development, :test do group :development, :test do
gem 'rspec-rails', '~> 2.6' gem 'rspec-rails', '~> 2.6'
gem 'capybara', '~> 1.1' gem 'capybara', '~> 1.1'
gem 'factory_girl_rails', '~> 1.2' gem 'factory_girl_rails', '~> 4.4'
gem 'shoulda-matchers', '~> 1.0' gem 'shoulda-matchers', '~> 1.0'
end end

View File

@ -11,8 +11,8 @@ describe API::PlaylistsController do
render_views render_views
before do before do
playlist_1 = Factory.create(:playlist, :name => 'Playlist 1') playlist_1 = FactoryGirl.create(:playlist, :name => 'Playlist 1')
playlist_2 = Factory.create(:playlist, :name => 'Playlist 2') playlist_2 = FactoryGirl.create(:playlist, :name => 'Playlist 2')
end end
def do_get def do_get
@ -37,7 +37,7 @@ describe API::PlaylistsController do
def do_create def do_create
post :create, post :create,
:format => :json, :format => :json,
:playlist => Factory.attributes_for(:playlist) :playlist => FactoryGirl.attributes_for(:playlist)
end end
it 'creates a new playlist for the current user' do it 'creates a new playlist for the current user' do

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe API::SessionsController do describe API::SessionsController do
describe 'POST create' do describe 'POST create' do
let(:user) { Factory.create(:user) } let(:user) { FactoryGirl.create(:user) }
def do_create def do_create
post :create, :format => :json, :session => { post :create, :format => :json, :session => {

View File

@ -11,8 +11,8 @@ describe API::TracksController do
render_views render_views
before do before do
Factory.create(:track_with_sound) FactoryGirl.create(:track_with_sound)
Factory.create(:track_with_sound) FactoryGirl.create(:track_with_sound)
end end
def do_get def do_get

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe ApplicationController do describe ApplicationController do
let(:user) { Factory.create(:user) } let(:user) { FactoryGirl.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

View File

@ -9,14 +9,14 @@ describe HomeController do
describe 'GET index' do describe 'GET index' do
it 'assigns all playlists as @playlists' do it 'assigns all playlists as @playlists' do
playlist = Factory.create(:playlist) playlist = FactoryGirl.create(:playlist)
get :index get :index
assigns[:playlists].should == [playlist] assigns[:playlists].should == [playlist]
end end
it 'assigns latest tracks as @tracks' do it 'assigns latest tracks as @tracks' do
track1 = Factory.create(:track, :created_at => '2011-07-27 19:13:42') track1 = FactoryGirl.create(:track, :created_at => '2011-07-27 19:13:42')
track2 = Factory.create(:track, :created_at => '2011-07-27 19:58:57') track2 = FactoryGirl.create(:track, :created_at => '2011-07-27 19:58:57')
get :index get :index
assigns[:tracks].should == Track.latest assigns[:tracks].should == Track.latest
end end

View File

@ -9,7 +9,7 @@ describe PlaylistsController do
describe 'GET index' do describe 'GET index' do
it 'assigns all playlists as @playlists' do it 'assigns all playlists as @playlists' do
playlist = Factory.create(:playlist) playlist = FactoryGirl.create(:playlist)
get :index get :index
assigns[:playlists].should == [playlist] assigns[:playlists].should == [playlist]
end end
@ -24,7 +24,7 @@ describe PlaylistsController do
describe 'GET edit' do describe 'GET edit' do
it 'assigns the requested playlist as @playlist' do it 'assigns the requested playlist as @playlist' do
playlist = Factory.create(:playlist) playlist = FactoryGirl.create(:playlist)
get :edit, :id => playlist.id.to_s get :edit, :id => playlist.id.to_s
assigns[:playlist].should == playlist assigns[:playlist].should == playlist
end end
@ -32,7 +32,7 @@ describe PlaylistsController do
describe 'POST create' do describe 'POST create' do
def do_create def do_create
post :create, :playlist => Factory.attributes_for(:playlist) post :create, :playlist => FactoryGirl.attributes_for(:playlist)
end end
context 'whith valid params' do context 'whith valid params' do
@ -64,7 +64,7 @@ describe PlaylistsController do
end end
describe 'PUT update' do describe 'PUT update' do
let (:playlist) { Factory.create(:playlist) } let (:playlist) { FactoryGirl.create(:playlist) }
def do_update def do_update
put :update, :id => playlist.id.to_s, :playlist => { :name => 'Rock' } put :update, :id => playlist.id.to_s, :playlist => { :name => 'Rock' }

View File

@ -8,7 +8,7 @@ describe SessionsController do
end end
describe 'POST create' do describe 'POST create' do
let(:user) { Factory.create(:user) } let(:user) { FactoryGirl.create(:user) }
def do_create def do_create
post :create, :session => { post :create, :session => {

View File

@ -8,7 +8,7 @@ describe SoundsController do
end end
describe 'GET show' do describe 'GET show' do
let(:sound) { Factory.create(:sound) } let(:sound) { FactoryGirl.create(:sound) }
def do_show def do_show
get :show, :id => sound.id get :show, :id => sound.id

View File

@ -9,7 +9,7 @@ describe TracksController do
describe 'GET show' do describe 'GET show' do
it 'assigns the requested track as @track' do it 'assigns the requested track as @track' do
track = Factory.create(:track) track = FactoryGirl.create(:track)
get :show, :id => track.id.to_s get :show, :id => track.id.to_s
assigns[:track].should == track assigns[:track].should == track
end end
@ -24,7 +24,7 @@ describe TracksController do
describe 'POST create new' do describe 'POST create new' do
def do_create def do_create
post :create, :track => Factory.attributes_for(:track).merge({ post :create, :track => FactoryGirl.attributes_for(:track).merge({
:file => fixture_file_upload( :file => fixture_file_upload(
"#{Rails.root}/spec/fixtures/test.mp3", "#{Rails.root}/spec/fixtures/test.mp3",
'audio/mpeg' 'audio/mpeg'

View File

@ -12,17 +12,17 @@ describe UsersController do
context 'whith valid params' do context 'whith valid params' do
it 'creates a new user' do it 'creates a new user' do
expect { expect {
post :create, :user => Factory.attributes_for(:user) post :create, :user => FactoryGirl.attributes_for(:user)
}.to change(User, :count).by(1) }.to change(User, :count).by(1)
end end
it 'signs the user in' do it 'signs the user in' do
post :create, :user => Factory.attributes_for(:user) post :create, :user => FactoryGirl.attributes_for(:user)
controller.current_user.should_not be_nil controller.current_user.should_not be_nil
end end
it 'redirects to the home page' do it 'redirects to the home page' do
post :create, :user => Factory.attributes_for(:user) post :create, :user => FactoryGirl.attributes_for(:user)
response.should redirect_to(:root) response.should redirect_to(:root)
end end
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
feature 'API sign in' do feature 'API sign in' do
let(:user) { Factory.create(:user) } let(:user) { FactoryGirl.create(:user) }
def do_create def do_create
post api_sessions_path, :format => :json, :session => { post api_sessions_path, :format => :json, :session => {

View File

@ -3,7 +3,7 @@ require 'spec_helper'
feature 'API cross origin request' do feature 'API cross origin request' do
include UserIntegrationHelpers include UserIntegrationHelpers
let(:user) { Factory.create(:user) } let(:user) { FactoryGirl.create(:user) }
let(:origin) { 'http://origin.example/' } let(:origin) { 'http://origin.example/' }
background do background do

View File

@ -8,7 +8,7 @@ feature 'API playlists' do
end end
scenario 'creates playlist' do scenario 'creates playlist' do
playlist = Factory.attributes_for :playlist playlist = FactoryGirl.attributes_for :playlist
post api_playlists_path, post api_playlists_path,
:format => :json, :format => :json,

View File

@ -8,8 +8,8 @@ feature 'API tracks' do
end end
scenario 'lists tracks' do scenario 'lists tracks' do
track_1 = Factory.create(:track_with_sound, :name => 'Track 1') track_1 = FactoryGirl.create(:track_with_sound, :name => 'Track 1')
track_2 = Factory.create(:track, :name => 'Track 2') track_2 = FactoryGirl.create(:track, :name => 'Track 2')
get api_tracks_path, :format => :json get api_tracks_path, :format => :json

View File

@ -8,7 +8,7 @@ feature 'Home page' do
end end
scenario 'displays playlists' do scenario 'displays playlists' do
playlist = Factory.create(:playlist, :name => 'Electro') playlist = FactoryGirl.create(:playlist, :name => 'Electro')
visit root_path visit root_path
@ -16,11 +16,11 @@ feature 'Home page' do
end end
scenario 'displays last track added' do scenario 'displays last track added' do
Factory.create(:track, FactoryGirl.create(:track,
:name => 'Mega song 1', :name => 'Mega song 1',
:created_at => '2011-07-27 19:13:42' :created_at => '2011-07-27 19:13:42'
) )
Factory.create(:track, FactoryGirl.create(:track,
:name => 'Mega song 2', :name => 'Mega song 2',
:created_at => '2011-07-27 19:58:57' :created_at => '2011-07-27 19:58:57'
) )

View File

@ -8,8 +8,8 @@ feature 'Playlists' do
end end
scenario 'lists playlists' do scenario 'lists playlists' do
Factory.create(:playlist, :name => 'Electro') FactoryGirl.create(:playlist, :name => 'Electro')
Factory.create(:playlist, :name => 'Reggae') FactoryGirl.create(:playlist, :name => 'Reggae')
visit playlists_path visit playlists_path
@ -28,7 +28,7 @@ feature 'Playlists' do
end end
scenario 'edits playlist' do scenario 'edits playlist' do
Factory.create(:playlist, :name => 'Electro') FactoryGirl.create(:playlist, :name => 'Electro')
visit playlists_path visit playlists_path
click_link 'Electro' click_link 'Electro'

View File

@ -8,7 +8,7 @@ feature 'Tracks' do
end end
scenario 'shows track' do scenario 'shows track' do
track = Factory.create(:track, :name => 'Mega song') track = FactoryGirl.create(:track, :name => 'Mega song')
visit track_path(track) visit track_path(track)
@ -28,7 +28,7 @@ feature 'Tracks' do
end end
scenario 'plays track' do scenario 'plays track' do
track = Factory.create(:track_with_sound) track = FactoryGirl.create(:track_with_sound)
visit track_path(track) visit track_path(track)

View File

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

View File

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

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Playlist do describe Playlist do
subject { playlist } subject { playlist }
let(:playlist) { Factory.build(:playlist) } let(:playlist) { FactoryGirl.build(:playlist) }
it { should be_valid } it { should be_valid }
it { should belong_to :user } it { should belong_to :user }

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Sound do describe Sound do
subject { sound } subject { sound }
let(:sound) { Factory.build(:sound) } let(:sound) { FactoryGirl.build(:sound) }
it { should be_valid } it { should be_valid }
it { should belong_to :track } it { should belong_to :track }
@ -20,7 +20,7 @@ describe Sound do
end end
describe '#file=' do describe '#file=' do
let (:file) { Factory.attributes_for(:sound)[:file] } let (:file) { FactoryGirl.attributes_for(:sound)[:file] }
it 'saves the file SHA256 digest' do it 'saves the file SHA256 digest' do
sound.sha256.should == Digest::SHA256.file(file.path).hexdigest sound.sha256.should == Digest::SHA256.file(file.path).hexdigest

View File

@ -2,8 +2,8 @@ require 'spec_helper'
describe Track do describe Track do
subject { track } subject { track }
let(:track) { Factory.build(:track) } let(:track) { FactoryGirl.build(:track) }
let(:file) { Factory.attributes_for(:track_with_sound)[:file] } let(:file) { FactoryGirl.attributes_for(:track_with_sound)[:file] }
it { should be_valid } it { should be_valid }
it { should have_many :sounds } it { should have_many :sounds }
@ -34,7 +34,7 @@ describe Track do
describe '#sound' do describe '#sound' do
context 'with a sound' do context 'with a sound' do
before do before do
track.sounds << Factory.create(:sound) track.sounds << FactoryGirl.create(:sound)
end end
it 'returns a sound' do it 'returns a sound' do
@ -52,7 +52,7 @@ describe Track do
context 'with a sound' do context 'with a sound' do
before do before do
track.sounds << Factory.create(:sound) track.sounds << FactoryGirl.create(:sound)
end end
it 'returns true' do it 'returns true' do
@ -63,8 +63,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 = Factory.create(:track, :created_at => '2011-07-27 19:13:42') track1 = FactoryGirl.create(:track, :created_at => '2011-07-27 19:13:42')
track2 = Factory.create(:track, :created_at => '2011-07-27 19:58:57') track2 = FactoryGirl.create(:track, :created_at => '2011-07-27 19:58:57')
Track.latest.should == [track2, track1] Track.latest.should == [track2, track1]
end end
end end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe User do describe User do
subject { user } subject { user }
let(:user) { Factory.build(:user) } let(:user) { FactoryGirl.build(:user) }
it { should be_valid } it { should be_valid }
it { should have_many :playlists } it { should have_many :playlists }
@ -12,8 +12,8 @@ describe User do
it { should_not allow_mass_assignment_of :password_hash } it { should_not allow_mass_assignment_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) { Factory.create(:user, :email => 'unique@example.net') } let(:old_user) { FactoryGirl.create(:user, :email => 'unique@example.net') }
subject { Factory.build(:user, :email => old_user.email) } subject { FactoryGirl.build(:user, :email => old_user.email) }
it { should_not be_valid } it { should_not be_valid }

View File

@ -1,5 +1,5 @@
module UserControllerHelpers module UserControllerHelpers
def sign_in def sign_in
controller.current_user = Factory.create(:user) controller.current_user = FactoryGirl.create(:user)
end end
end end

View File

@ -1,6 +1,6 @@
module UserIntegrationHelpers module UserIntegrationHelpers
def sign_in def sign_in
user = Factory.create(:user) user = FactoryGirl.create(:user)
visit new_session_path visit new_session_path
fill_in 'Email', :with => user.email fill_in 'Email', :with => user.email
fill_in 'Password', :with => user.password fill_in 'Password', :with => user.password
@ -8,7 +8,7 @@ module UserIntegrationHelpers
end end
def api_sign_in def api_sign_in
user = Factory.create :user user = FactoryGirl.create :user
post api_sessions_path, :format => :json, :session => { post api_sessions_path, :format => :json, :session => {
:email => user.email, :email => user.email,

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'tracks/show' do describe 'tracks/show' do
let(:track) { Factory.create(:track) } let(:track) { FactoryGirl.create(:track) }
before do before do
assign :track, track assign :track, track
@ -13,7 +13,7 @@ describe 'tracks/show' do
end end
context 'when track has a sound' do context 'when track has a sound' do
let(:track) { Factory.create(:track_with_sound) } let(:track) { FactoryGirl.create(:track_with_sound) }
it 'provides an audio stream for the track' do it 'provides an audio stream for the track' do
render render

View File

@ -48,8 +48,8 @@ describe 'users/new' do
context 'when the user has some validation errors' do context 'when the user has some validation errors' do
it 'on the email address uniqueness' do it 'on the email address uniqueness' do
user = Factory.create(:user, :email => 'unique@example.net') user = FactoryGirl.create(:user, :email => 'unique@example.net')
new_user = Factory.build(:user, :email => user.email) new_user = FactoryGirl.build(:user, :email => user.email)
new_user.save new_user.save
assign :user, new_user assign :user, new_user
render render