Skip to content

Commit

Permalink
update factory girl syntax style to avoid deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski committed Apr 4, 2012
1 parent 9c503b6 commit 842f4a3
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source "http://rubygems.org"
gemspec

gem "capybara", "~> 1.1.1"
gem "factory_girl_rails"
gem "factory_girl_rails", "1.7.0"
gem "shoulda-matchers", :git => "git://github.com/thoughtbot/shoulda-matchers.git"
gem "database_cleaner"
gem "launchy"
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ GEM
railties
diff-lcs (1.1.3)
erubis (2.7.0)
factory_girl (2.5.0)
activesupport
factory_girl_rails (1.6.0)
factory_girl (~> 2.5.0)
factory_girl (2.6.4)
activesupport (>= 2.3.9)
factory_girl_rails (1.7.0)
factory_girl (~> 2.6.0)
railties (>= 3.0.0)
ffi (1.0.11)
gherkin (2.7.6)
Expand Down Expand Up @@ -178,7 +178,7 @@ DEPENDENCIES
clearance!
cucumber-rails (~> 1.1.1)
database_cleaner
factory_girl_rails
factory_girl_rails (= 1.7.0)
launchy
rspec-rails (~> 2.9.0)
shoulda-matchers!
Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/engine/clearance_steps.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Existing users

Given /^(?:I am|I have|I) signed up (?:as|with) "(.*)"$/ do |email|
Factory(:user, :email => email)
FactoryGirl.create(:user, :email => email)
end

Given /^a user "([^"]*)" exists without a salt, remember token, or password$/ do |email|
user = Factory(:user, :email => email)
user = FactoryGirl.create(:user, :email => email)
sql = "update users set salt = NULL, encrypted_password = NULL, remember_token = NULL where id = #{user.id}"
ActiveRecord::Base.connection.update(sql)
end
Expand Down
6 changes: 3 additions & 3 deletions gemfiles/3.0.12.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

source "http://rubygems.org"

gem "rails", "3.0.12"
gem "capybara", "~> 1.1.1"
gem "factory_girl_rails"
gem "shoulda-matchers", :git=>"git://github.com/thoughtbot/shoulda-matchers.git"
gem "database_cleaner"
gem "launchy"
gem "aruba", "~> 0.4.2"
gem "rails", "3.0.12"
gem "factory_girl_rails", "1.7.0"
gem "launchy"

gemspec :path=>"../"
10 changes: 5 additions & 5 deletions gemfiles/3.0.12.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ GEM
diff-lcs (1.1.3)
erubis (2.6.6)
abstract (>= 1.0.0)
factory_girl (3.0.0)
activesupport (>= 3.0.0)
factory_girl_rails (3.0.0)
factory_girl (~> 3.0.0)
factory_girl (2.6.4)
activesupport (>= 2.3.9)
factory_girl_rails (1.7.0)
factory_girl (~> 2.6.0)
railties (>= 3.0.0)
ffi (1.0.11)
gherkin (2.9.3)
Expand Down Expand Up @@ -167,7 +167,7 @@ DEPENDENCIES
clearance!
cucumber-rails (~> 1.1.1)
database_cleaner
factory_girl_rails
factory_girl_rails (= 1.7.0)
launchy
rails (= 3.0.12)
rspec-rails (~> 2.9.0)
Expand Down
6 changes: 3 additions & 3 deletions gemfiles/3.1.4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

source "http://rubygems.org"

gem "rails", "3.1.4"
gem "capybara", "~> 1.1.1"
gem "factory_girl_rails"
gem "shoulda-matchers", :git=>"git://github.com/thoughtbot/shoulda-matchers.git"
gem "database_cleaner"
gem "launchy"
gem "aruba", "~> 0.4.2"
gem "rails", "3.1.4"
gem "factory_girl_rails", "1.7.0"
gem "launchy"

gemspec :path=>"../"
10 changes: 5 additions & 5 deletions gemfiles/3.1.4.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ GEM
railties
diff-lcs (1.1.3)
erubis (2.7.0)
factory_girl (3.0.0)
activesupport (>= 3.0.0)
factory_girl_rails (3.0.0)
factory_girl (~> 3.0.0)
factory_girl (2.6.4)
activesupport (>= 2.3.9)
factory_girl_rails (1.7.0)
factory_girl (~> 2.6.0)
railties (>= 3.0.0)
ffi (1.0.11)
gherkin (2.9.3)
Expand Down Expand Up @@ -177,7 +177,7 @@ DEPENDENCIES
clearance!
cucumber-rails (~> 1.1.1)
database_cleaner
factory_girl_rails
factory_girl_rails (= 1.7.0)
launchy
rails (= 3.1.4)
rspec-rails (~> 2.9.0)
Expand Down
2 changes: 1 addition & 1 deletion lib/clearance/testing/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def sign_in_as(user)
end

def sign_in
sign_in_as Factory(:user)
sign_in_as FactoryGirl.create(:user)
end

def sign_out
Expand Down
12 changes: 6 additions & 6 deletions spec/clearance/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
after { Timecop.return }

it "finds a user from a cookie" do
user = Factory(:user)
user = create(:user)
env = env_with_remember_token(user.remember_token)

session = Clearance::Session.new(env)
Expand All @@ -14,7 +14,7 @@
end

it "returns nil for an unknown user" do
user = Factory(:user)
user = create(:user)
env = env_with_remember_token("bogus")

session = Clearance::Session.new(env)
Expand All @@ -30,14 +30,14 @@
end

it "signs in a given user" do
user = Factory(:user)
user = create(:user)
session = Clearance::Session.new(env_without_remember_token)
session.sign_in user
session.current_user.should == user
end

it "sets a remember token cookie with a default expiration of 1 year from now" do
user = Factory(:user)
user = create(:user)
headers = {}
session = Clearance::Session.new(env_without_remember_token)
session.sign_in user
Expand All @@ -48,7 +48,7 @@
it "sets a remember token cookie with a custom expiration" do
custom_expiration = 1.day.from_now
with_custom_expiration 1.day.from_now do
user = Factory(:user)
user = create(:user)
headers = {}
session = Clearance::Session.new(env_without_remember_token)
session.sign_in user
Expand All @@ -66,7 +66,7 @@
end

it "signs out a user" do
user = Factory(:user)
user = create(:user)
old_remember_token = user.remember_token
env = env_with_remember_token(old_remember_token)

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/forgeries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def create
match 'sign_in' => 'clearance/sessions#new', :as => 'sign_in'
end

@user = Factory(:user)
@user = create(:user)
@user.update_attribute(:remember_token, "old-token")
@request.cookies["remember_token"] = "old-token"
@request.session[:_csrf_token] = "golden-ticket"
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/passwords_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

describe "a signed up user" do
before do
@user = Factory(:user)
@user = create(:user)
end

describe "on GET to #new" do
Expand Down Expand Up @@ -60,7 +60,7 @@

describe "a signed up user and forgotten password" do
before do
@user = Factory(:user)
@user = create(:user)
@user.forgot_password!
end

Expand Down Expand Up @@ -157,8 +157,8 @@

describe "given two users and user one signs in" do
before do
@user_one = Factory(:user)
@user_two = Factory(:user)
@user_one = create(:user)
@user_two = create(:user)
sign_in_as @user_one
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

describe "on POST to #create with good credentials" do
before do
@user = Factory(:user)
@user = create(:user)
@user.update_attribute(:remember_token, "old-token")
post :create, :session => {
:email => @user.email,
Expand All @@ -31,7 +31,7 @@

describe "on POST to #create with good credentials and a session return url" do
before do
@user = Factory(:user)
@user = create(:user)
@return_url = '/url_in_the_session'
@request.session[:return_to] = @return_url
post :create, :session => {
Expand All @@ -46,7 +46,7 @@

describe "on POST to #create with good credentials and a request return url" do
before do
@user = Factory(:user)
@user = create(:user)
@return_url = '/url_in_the_request'
post :create, :session => {
:email => @user.email,
Expand All @@ -61,7 +61,7 @@

describe "on POST to #create with good credentials and a session return url and request return url" do
before do
@user = Factory(:user)
@user = create(:user)
@return_url = '/url_in_the_session'
@request.session[:return_to] = @return_url
post :create, :session => {
Expand All @@ -85,7 +85,7 @@

describe "on DELETE to #destroy with a cookie" do
before do
@user = Factory(:user)
@user = create(:user)
@user.update_attribute(:remember_token, "old-token")
@request.cookies["remember_token"] = "old-token"
delete :destroy
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

describe "on POST to #create with valid attributes" do
before do
user_attributes = Factory.attributes_for(:user)
user_attributes = FactoryGirl.attributes_for(:user)
@old_user_count = User.count
post :create, :user => user_attributes
end
Expand All @@ -41,7 +41,7 @@

describe "on POST to #create with valid attributes and a session return url" do
before do
user_attributes = Factory.attributes_for(:user)
user_attributes = FactoryGirl.attributes_for(:user)
@old_user_count = User.count
@return_url = '/url_in_the_session'
@request.session[:return_to] = @return_url
Expand All @@ -60,7 +60,7 @@

describe "A signed-in user" do
before do
@user = Factory(:user)
@user = create(:user)
sign_in_as @user
end

Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/clearance_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe ClearanceMailer do
before do
@user = Factory(:user)
@user = create(:user)
@user.forgot_password!
@email = ClearanceMailer.change_password(@user)
end
Expand Down
20 changes: 10 additions & 10 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
it { should_not allow_value("example.com").for(:email) }

it "should store email in down case" do
user = Factory(:user, :email => "John.Doe@example.com")
user = create(:user, :email => "John.Doe@example.com")
user.email.should == "john.doe@example.com"
end
end

describe "When multiple users have signed up" do
before { Factory(:user) }
before { create(:user) }
it { should validate_uniqueness_of(:email) }
end

describe "A user" do
before do
@user = Factory(:user)
@user = create(:user)
@password = @user.password
end

Expand All @@ -50,7 +50,7 @@

describe "When resetting authentication with reset_remember_token!" do
before do
@user = Factory(:user)
@user = create(:user)
@user.remember_token = "old-token"
@user.reset_remember_token!
end
Expand All @@ -62,7 +62,7 @@

describe "An email confirmed user" do
before do
@user = Factory(:user)
@user = create(:user)
@old_encrypted_password = @user.encrypted_password
end

Expand All @@ -80,15 +80,15 @@
it "should not generate the same remember token for users with the same password at the same time" do
Time.stubs(:now => Time.now)
password = 'secret'
first_user = Factory(:user, :password => password)
second_user = Factory(:user, :password => password)
first_user = create(:user, :password => password)
second_user = create(:user, :password => password)

second_user.remember_token.should_not == first_user.remember_token
end

describe "An user" do
before do
@user = Factory(:user)
@user = create(:user)
@old_encrypted_password = @user.encrypted_password
end

Expand Down Expand Up @@ -168,13 +168,13 @@ def password_optional?

describe "user factory" do
it "should create a valid user with just an overridden password" do
Factory.build(:user, :password => "test").should be_valid
build(:user, :password => "test").should be_valid
end
end

describe "when user exists before Clearance was installed" do
before do
@user = Factory(:user)
@user = create(:user)
sql = "update users set salt = NULL, encrypted_password = NULL, remember_token = NULL where id = #{@user.id}"
ActiveRecord::Base.connection.update(sql)
@user.reload.salt.should be_nil
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
RSpec.configure do |config|
config.mock_with :mocha
config.use_transactional_fixtures = true
config.include FactoryGirl::Syntax::Methods
end

0 comments on commit 842f4a3

Please sign in to comment.