Skip to content

Commit

Permalink
Merge pull request eurucamp#54 from isleofruby/feature/factory_bot
Browse files Browse the repository at this point in the history
Switch to factory_bot (new name for factory_girl)
  • Loading branch information
myabc authored Apr 19, 2018
2 parents 72c75a7 + 487f289 commit 24398ac
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end

group :test, :development do
gem 'rspec-rails', '~> 3.3'
gem 'factory_girl_rails','~> 4.2'
gem 'factory_bot_rails', '~> 4.8'
end

group :test do
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ GEM
actionmailer (>= 3.0.4)
activesupport (>= 3.0.4)
execjs (2.7.0)
factory_girl (4.9.0)
factory_bot (4.8.2)
activesupport (>= 3.0.0)
factory_girl_rails (4.9.0)
factory_girl (~> 4.9.0)
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
Expand Down Expand Up @@ -337,7 +337,7 @@ DEPENDENCIES
dotenv-rails
draper (~> 3.0.0.pre1)
exception_notification (~> 4.0.1)
factory_girl_rails (~> 4.2)
factory_bot_rails (~> 4.8)
foreman
haml-rails
jbuilder (~> 2.5)
Expand Down
2 changes: 1 addition & 1 deletion spec/decorators/activity_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rails_helper'

RSpec.describe ActivityDecorator do
let (:activity) { FactoryGirl.build_stubbed(:activity, limit_of_participants: 20) }
let (:activity) { build_stubbed(:activity, limit_of_participants: 20) }
let (:decorator) { ActivityDecorator.new(activity) }

describe "#spots_left" do
Expand Down
6 changes: 3 additions & 3 deletions spec/factories/activities.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
# Read about factories at https://github.com/thoughtbot/factory_bot

FactoryGirl.define do
FactoryBot.define do
factory :activity do
name "Party!"
start_time "2013/12/12 18:00"
end_time "2013/12/13 03:00"
anytime false
location "Ballroom"
creator { FactoryGirl.create(:user) }
creator { FactoryBot.create(:user) }
event { Event.new("Some Conference", Time.parse("2013/12/10 18:00"), Time.parse("2013/12/18 18:00")) }
end
end
2 changes: 1 addition & 1 deletion spec/factories/authentications.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :authentication do
uid { generate(:uid) }
provider "Provider"
Expand Down
6 changes: 3 additions & 3 deletions spec/factories/participations.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
# Read about factories at https://github.com/thoughtbot/factory_bot

FactoryGirl.define do
FactoryBot.define do
factory :participation do
participant{ FactoryGirl.create(:user) }
participant{ FactoryBot.create(:user) }
activity
end
end
2 changes: 1 addition & 1 deletion spec/factories/sequences.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
sequence(:email) { |n| "person#{n}@example.com" }
sequence(:uid) { |n| "uid#{n}" }
end
4 changes: 2 additions & 2 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
# Read about factories at https://github.com/thoughtbot/factory_bot

FactoryGirl.define do
FactoryBot.define do
factory :user do
email { generate(:email) }
password "qweqweqwe"
Expand Down
4 changes: 2 additions & 2 deletions spec/models/activity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@
it { is_expected.not_to accept_values_for(:image_url, "http://com.co ge.gif", "ssh://com.com/image.gif", "blah")}

context "invalid time frame (wrong order)" do
subject { FactoryGirl.build(:activity, start_time: 10.days.ago.to_time, anytime: false) }
subject { build(:activity, start_time: 10.days.ago.to_time, anytime: false) }

it { is_expected.not_to accept_values_for(:end_time, 15.days.ago.to_time) }
end

context "invalid time frame (out of scope)" do
let(:event) { Event.new("A name", 2.days.ago.to_time, 2.days.from_now.to_time ) }
subject { FactoryGirl.build(:activity, event: event, start_time: 10.days.ago.to_time, anytime: false) }
subject { build(:activity, event: event, start_time: 10.days.ago.to_time, anytime: false) }

it { is_expected.to accept_values_for(:start_time, 1.days.ago.to_time) }
it { is_expected.not_to accept_values_for(:start_time, 15.days.ago.to_time) }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/participation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe "validations" do

specify { expect { FactoryGirl.create(:participation).dup.save! }.to raise_exception(ActiveRecord::RecordInvalid) }
specify { expect { create(:participation).dup.save! }.to raise_exception(ActiveRecord::RecordInvalid) }

it { is_expected.to accept_values_for(:user_id, 1 ) }
it { is_expected.not_to accept_values_for(:user_id, "", nil) }
Expand Down
8 changes: 4 additions & 4 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

describe "#no_oauth_connected?" do
subject { user.no_oauth_connected? }
let(:user) { FactoryGirl.create(:user) }
let(:user) { create(:user) }

context "account connected" do
context "password set" do
Expand All @@ -89,7 +89,7 @@

describe "#password_required?" do
subject { user.password_required? }
let(:user) { FactoryGirl.create(:user) }
let(:user) { create(:user) }

context "no account connected" do
it { is_expected.to eq(true) }
Expand All @@ -109,7 +109,7 @@

describe "#update_without_password" do
subject { user.update_without_password(params) }
let(:user) { FactoryGirl.create(:user) }
let(:user) { create(:user) }

context "no password provided" do
let(:params) { {name: "Zbigniew" } }
Expand All @@ -131,7 +131,7 @@

describe "#apply_omniauth" do
subject { user.apply_omniauth(params) }
let(:user) { FactoryGirl.create(:user, name: nil) }
let(:user) { create(:user, name: nil) }

context "no data provided" do
let(:params) { {} }
Expand Down
6 changes: 3 additions & 3 deletions spec/other/factories_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'rails_helper'

RSpec.describe 'validate FactoryGirl factories' do
FactoryGirl.factories.each do |factory|
RSpec.describe 'validate FactoryBot factories' do
FactoryBot.factories.each do |factory|
context "with factory for :#{factory.name}" do
subject { FactoryGirl.build(factory.name) }
subject { build(factory.name) }
it { is_expected.to be_valid, subject.errors.full_messages.join(", ") }
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/policies/activity_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'rails_helper'

RSpec.describe ActivityPolicy do
let(:activity) { FactoryGirl.build(:activity) }
let(:activity) { build(:activity) }
let(:activity_creator) { activity.creator }
let(:other_user) { FactoryGirl.build(:user) }
let(:other_user) { build(:user) }

subject { described_class }

Expand Down
4 changes: 2 additions & 2 deletions spec/policies/authentication_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'rails_helper'

RSpec.describe AuthenticationPolicy do
let(:authentication) { FactoryGirl.build(:authentication) }
let(:authentication) { build(:authentication) }
let(:authentication_user) { authentication.user }
let(:other_user) { FactoryGirl.build(:user) }
let(:other_user) { build(:user) }

subject { described_class }

Expand Down
4 changes: 2 additions & 2 deletions spec/policies/participation_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'rails_helper'

RSpec.describe ParticipationPolicy do
let(:participation) { FactoryGirl.build(:participation) }
let(:participation) { build(:participation) }
let(:participant) { participation.participant }
let(:other_user) { FactoryGirl.build(:user) }
let(:other_user) { build(:user) }

subject { described_class }

Expand Down
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def self.connection
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false

config.include FactoryBot::Syntax::Methods
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Warden::Test::Helpers
config.before :suite do
Expand Down

0 comments on commit 24398ac

Please sign in to comment.