Skip to content

Commit

Permalink
Replace factory girl with factory bot (#1243)
Browse files Browse the repository at this point in the history
* Replace FactoryGirl with FactoryBot (gem was renamed)

* Fix alignment due to renaming FactoryGirl to FactoryBot
  • Loading branch information
rdunlop authored and meara committed Dec 20, 2017
1 parent f7d8a01 commit f62c1b7
Show file tree
Hide file tree
Showing 228 changed files with 1,813 additions and 1,813 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -96,7 +96,7 @@ end

group :development, :test do
gem "awesome_print", "1.8.0"
gem "factory_girl_rails", "~> 4.9.0"
gem "factory_bot_rails"
gem "guard-rspec", require: false
gem "guard-teaspoon", require: false
gem "pry-rails", "~> 0.3.6"
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Expand Up @@ -238,10 +238,10 @@ GEM
eye-patch (0.4.2)
chronic_duration
eye (>= 0.6.2)
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)
ffi (1.9.17)
fog-aws (0.9.4)
Expand Down Expand Up @@ -608,7 +608,7 @@ DEPENDENCIES
dynamic_form (~> 1.1.4)
exception_notification (~> 4.0.1)
eye-patch
factory_girl_rails (~> 4.9.0)
factory_bot_rails
fine_uploader!
fog-aws
font-awesome-rails (~> 4.7.0)
Expand Down
2 changes: 1 addition & 1 deletion config/spring.rb
@@ -1 +1 @@
Spring.after_fork { FactoryGirl.reload }
Spring.after_fork { FactoryBot.reload }
40 changes: 20 additions & 20 deletions doc/FACTORIES.md
Expand Up @@ -6,61 +6,61 @@ Since the upgrade from Factory Girl 1, we've set up a new series of factories fo

## Facilities

`FactoryGirl.create :setup_facility`
`FactoryBot.create :setup_facility`
Creates a facility and all the necessary accounts and price groups to begin using.

## Products

### Items and Services

`FactoryGirl.create :setup_item` and `FactoryGirl.create :setup_service` will create all the necessary dependencies including the facility.
`FactoryBot.create :setup_item` and `FactoryBot.create :setup_service` will create all the necessary dependencies including the facility.

For putting multiple products on a facility, use:

facility = FactoryGirl.create :facility
item1 = FactoryGirl.create :setup_item, facility: facility
item2 = FactoryGirl.create :setup_item, facility: facility
facility = FactoryBot.create :facility
item1 = FactoryBot.create :setup_item, facility: facility
item2 = FactoryBot.create :setup_item, facility: facility

### Instruments

`FactoryGirl.create :setup_instrument`
`FactoryBot.create :setup_instrument`

#### Shared schedules

schedule = FactoryGirl.create :schedule # Will create the facility if not specified
instrument1 = FactoryGirl.create :setup_instrument, schedule: schedule
instrument2 = FactoryGirl.create :setup_instrument, schedule: schedule
schedule = FactoryBot.create :schedule # Will create the facility if not specified
instrument1 = FactoryBot.create :setup_instrument, schedule: schedule
instrument2 = FactoryBot.create :setup_instrument, schedule: schedule

## Orders

`FactoryGirl.create :setup_order` will setup an order including accounts and users if not specified. It will also create an order detail if you specify a product.
`FactoryBot.create :setup_order` will setup an order including accounts and users if not specified. It will also create an order detail if you specify a product.

item1 = FactoryGirl.create :setup_item
order = FactoryGirl.create :setup_order, product: item1 # Facility is taken from the product
item1 = FactoryBot.create :setup_item
order = FactoryBot.create :setup_order, product: item1 # Facility is taken from the product
order.order_details.first # Contains an order detail of item1 with quantity 1

## Reservations

This will create a reservation, a new instrument on a new facility, with a new order. The order is not purchased.

reservation = FactoryGirl.create :setup_reservation
reservation = FactoryBot.create :setup_reservation

This will allow you to place a reservation on an already existing order detail:

instrument = FactoryGirl.create :setup_instrument
order = FactoryGirl.create :setup_order, product: instrument
reservation = FactoryGirl.create :setup_reservation, order_detail: order.order_details.first
instrument = FactoryBot.create :setup_instrument
order = FactoryBot.create :setup_order, product: instrument
reservation = FactoryBot.create :setup_reservation, order_detail: order.order_details.first

For the ultimate in setup, you can create a purchased reservation. This alone will create all the dependencies you need.

reservation = FactoryGirl.create :purchased_reservation
reservation = FactoryBot.create :purchased_reservation

If you want to specify the dependencies, you'll need to create them first and pass them in.

instrument = FactoryGirl.create :setup_instrument
reservation1 = FactoryGirl.create :purchased_reservation, product: instrument
instrument = FactoryBot.create :setup_instrument
reservation1 = FactoryBot.create :purchased_reservation, product: instrument
# Need to specify :reserve_start_at and :reserve_end_at so as not to
# conflict with reservation1
reservation2 = FactoryGirl.create :purchased_reservation, product: instrument, reserve_start_at: reservation1.reserve_end_at, reserve_end_at: reservation1.reserve_end_at + 1.hour
reservation2 = FactoryBot.create :purchased_reservation, product: instrument, reserve_start_at: reservation1.reserve_end_at, reserve_end_at: reservation1.reserve_end_at + 1.hour


4 changes: 2 additions & 2 deletions spec/account_builder_shared_examples.rb
@@ -1,8 +1,8 @@
RSpec.shared_examples_for "AccountBuilder#build" do
subject(:account) { builder.build }
let(:builder) { described_class.new(options) }
let(:facility) { FactoryGirl.build_stubbed(:facility) }
let(:user) { FactoryGirl.build_stubbed(:user) }
let(:facility) { FactoryBot.build_stubbed(:facility) }
let(:user) { FactoryBot.build_stubbed(:user) }

context "when the affiliate_id param is set" do
let(:affiliate) { Affiliate.create!(name: "New Affiliate") }
Expand Down
10 changes: 5 additions & 5 deletions spec/app_support/notification_sender_spec.rb
Expand Up @@ -5,23 +5,23 @@

let(:accounts) do
account_owners.map do |user|
FactoryGirl.create_list(:setup_account, 2, owner: user, facility_id: facility.id)
FactoryBot.create_list(:setup_account, 2, owner: user, facility_id: facility.id)
end.flatten
end
let(:account_ids) { accounts.map(&:id) }
let(:delivery) { OpenStruct.new(deliver_now: true) }
let(:facility) { item.facility }
let(:item) { FactoryGirl.create(:setup_item, :with_facility_account) }
let(:item) { FactoryBot.create(:setup_item, :with_facility_account) }
let!(:order_details) do
accounts.map do |account|
FactoryGirl.create(:account_user, :purchaser, user_id: purchaser.id, account_id: account.id)
FactoryBot.create(:account_user, :purchaser, user_id: purchaser.id, account_id: account.id)
Array.new(3) { place_product_order(purchaser, facility, item, account) }
end.flatten
end
let(:order_detail_ids) { order_details.map(&:id) }
let(:price_policy) { item.price_policies.first }
let(:account_owners) { FactoryGirl.create_list(:user, 2) }
let(:purchaser) { FactoryGirl.create(:user) }
let(:account_owners) { FactoryBot.create_list(:user, 2) }
let(:purchaser) { FactoryBot.create(:user) }

before(:each) do
# This feature only gets used when there is a review period, so go ahead and enable it.
Expand Down
10 changes: 5 additions & 5 deletions spec/app_support/reservation_instrument_switcher_spec.rb
@@ -1,8 +1,8 @@
require "rails_helper"

RSpec.describe ReservationInstrumentSwitcher do
let(:instrument) { FactoryGirl.create(:setup_instrument, relay: create(:relay_syna)) }
let(:reservation) { FactoryGirl.create(:purchased_reservation, product: instrument) }
let(:instrument) { FactoryBot.create(:setup_instrument, relay: create(:relay_syna)) }
let(:reservation) { FactoryBot.create(:purchased_reservation, product: instrument) }
let(:action) { described_class.new(reservation) }

describe '#switch_on!' do
Expand All @@ -21,15 +21,15 @@ def do_action
end

context "with a long running reservation" do
let!(:running_reservation) { FactoryGirl.create(:purchased_reservation, :long_running, product: instrument) }
let!(:running_reservation) { FactoryBot.create(:purchased_reservation, :long_running, product: instrument) }

it "moves the running reservation to problem status" do
expect { do_action }.to change { running_reservation.order_detail.reload.problem }.from(false).to(true)
end
end

context "with a problem reservation that got canceled" do
let!(:running_reservation) { FactoryGirl.create(:purchased_reservation, :long_running, product: instrument) }
let!(:running_reservation) { FactoryBot.create(:purchased_reservation, :long_running, product: instrument) }
before { running_reservation.order_detail.update_order_status! running_reservation.user, OrderStatus.canceled, admin: true }

it "does not do anything to the canceled reservation" do
Expand All @@ -38,7 +38,7 @@ def do_action
end

context "with a problem reservation that got reconciled" do
let!(:running_reservation) { FactoryGirl.create(:purchased_reservation, :long_running, product: instrument) }
let!(:running_reservation) { FactoryBot.create(:purchased_reservation, :long_running, product: instrument) }
before do
running_reservation.order_detail.update_order_status! running_reservation.user, OrderStatus.complete, admin: true
running_reservation.order_detail.update_order_status! running_reservation.user, OrderStatus.reconciled, admin: true
Expand Down
2 changes: 1 addition & 1 deletion spec/app_support/reservations/rendering_spec.rb
Expand Up @@ -105,7 +105,7 @@
)
end

let(:user) { FactoryGirl.build(:user) }
let(:user) { FactoryBot.build(:user) }

context "with details requested" do
it "returns a hash without extra details about the order" do
Expand Down
18 changes: 9 additions & 9 deletions spec/controller_spec_helper.rb
Expand Up @@ -2,15 +2,15 @@
# Call this method in a before(:all) block at the top of your +describe+
def create_users
# TODO: Phase these out with "let" assignments, and use traits to assign roles
@admin = FactoryGirl.create(:user, :administrator, username: "admin")
@business_admin = FactoryGirl.create(:user, username: "business_admin")
@director = FactoryGirl.create(:user, username: "director")
@facility_admin = FactoryGirl.create(:user, username: "facility_admin")
@guest = FactoryGirl.create(:user, username: "guest")
@owner = FactoryGirl.create(:user, username: "owner")
@purchaser = FactoryGirl.create(:user, username: "purchaser")
@staff = FactoryGirl.create(:user, username: "staff")
@senior_staff = FactoryGirl.create(:user, username: "senior_staff")
@admin = FactoryBot.create(:user, :administrator, username: "admin")
@business_admin = FactoryBot.create(:user, username: "business_admin")
@director = FactoryBot.create(:user, username: "director")
@facility_admin = FactoryBot.create(:user, username: "facility_admin")
@guest = FactoryBot.create(:user, username: "guest")
@owner = FactoryBot.create(:user, username: "owner")
@purchaser = FactoryBot.create(:user, username: "purchaser")
@staff = FactoryBot.create(:user, username: "staff")
@senior_staff = FactoryBot.create(:user, username: "senior_staff")
end

#
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/accessories_controller_spec.rb
Expand Up @@ -49,7 +49,7 @@
auto_accessory
manual_accessory

sign_in FactoryGirl.create(:user, :facility_director, facility: facility)
sign_in FactoryBot.create(:user, :facility_director, facility: facility)
end

describe "a completed reservation" do
Expand Down
Expand Up @@ -5,12 +5,12 @@
render_views

let(:facility) { @authable }
let(:price_group) { FactoryGirl.create(:price_group, facility: facility) }
let(:price_group) { FactoryBot.create(:price_group, facility: facility) }

before(:all) { create_users }

before(:each) do
@authable = FactoryGirl.create(:facility)
@authable = FactoryBot.create(:facility)
end

shared_examples "facility price group restrictions" do
Expand All @@ -31,7 +31,7 @@

shared_examples "global price group restrictions" do
context "with a global price group" do
let(:price_group) { FactoryGirl.create(:price_group, :cancer_center) }
let(:price_group) { FactoryBot.create(:price_group, :cancer_center) }

it_should_allow :admin do
successful_action_expectations
Expand Down Expand Up @@ -119,7 +119,7 @@ def successful_action_expectations
end

context "search_results" do
let!(:account) { FactoryGirl.create(:account, :with_account_owner, account_number: "TESTING123") }
let!(:account) { FactoryBot.create(:account, :with_account_owner, account_number: "TESTING123") }

before :each do
@method = :get
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/account_users_controller_spec.rb
Expand Up @@ -86,7 +86,7 @@
before :each do
@method = :delete
@action = :destroy
@account_user = FactoryGirl.create(
@account_user = FactoryBot.create(
:account_user, user_role: AccountUser::ACCOUNT_ADMINISTRATOR,
account_id: @authable.id, user_id: @staff.id,
created_by: @admin.id)
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/bundle_products_controller_spec.rb
Expand Up @@ -9,10 +9,10 @@
before(:all) { create_users }

before(:each) do
@authable = FactoryGirl.create(:facility)
@facility_account = FactoryGirl.create(:facility_account, facility: @authable)
@item = FactoryGirl.create(:item, facility_account: @facility_account, facility: @authable)
@bundle = FactoryGirl.create(:bundle, facility_account: @facility_account, facility: @authable)
@authable = FactoryBot.create(:facility)
@facility_account = FactoryBot.create(:facility_account, facility: @authable)
@item = FactoryBot.create(:item, facility_account: @facility_account, facility: @authable)
@bundle = FactoryBot.create(:bundle, facility_account: @facility_account, facility: @authable)
@bundle_product = BundleProduct.create!(bundle: @bundle, product: @item, quantity: 1)
end

Expand All @@ -38,7 +38,7 @@
before(:each) do
@method = :post
@action = :create
item2 = FactoryGirl.create(:item, facility_account: @facility_account, facility: @authable)
item2 = FactoryBot.create(:item, facility_account: @facility_account, facility: @authable)
@params = {
facility_id: @authable.url_name,
bundle_id: @bundle.url_name,
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/bundles_controller_spec.rb
Expand Up @@ -10,13 +10,13 @@
before(:all) { create_users }

before(:each) do
@authable = FactoryGirl.create(:facility)
@facility_account = FactoryGirl.create(:facility_account, facility: @authable)
@bundle = FactoryGirl.create(:bundle, facility_account: @facility_account, facility: @authable)
@authable = FactoryBot.create(:facility)
@facility_account = FactoryBot.create(:facility_account, facility: @authable)
@bundle = FactoryBot.create(:bundle, facility_account: @facility_account, facility: @authable)

# Create at least one item in the bundle, otherwise bundle.can_purchase? will return false
item = FactoryGirl.create(:item, facility_account: @facility_account, facility: @authable)
price_policy = item.item_price_policies.create(FactoryGirl.attributes_for(:item_price_policy, price_group: @nupg))
item = FactoryBot.create(:item, facility_account: @facility_account, facility: @authable)
price_policy = item.item_price_policies.create(FactoryBot.attributes_for(:item_price_policy, price_group: @nupg))
bundle_product = BundleProduct.new(bundle: @bundle, product: item, quantity: 1)
bundle_product.save!
end
Expand Down Expand Up @@ -207,7 +207,7 @@
before(:each) do
@method = :post
@action = :create
@params = { facility_id: @authable.url_name, bundle: FactoryGirl.attributes_for(:bundle) }
@params = { facility_id: @authable.url_name, bundle: FactoryBot.attributes_for(:bundle) }
end

it_should_require_login
Expand All @@ -229,7 +229,7 @@
@params = {
facility_id: @authable.url_name,
id: @bundle.url_name,
bundle: FactoryGirl.attributes_for(:bundle, url_name: @bundle.url_name),
bundle: FactoryBot.attributes_for(:bundle, url_name: @bundle.url_name),
}
end

Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/devise/sessions_controller_spec.rb
Expand Up @@ -5,7 +5,7 @@

describe "#create, aka logging in" do
describe "a user with the password in the database" do
let(:user) { FactoryGirl.create(:user, password: "password") }
let(:user) { FactoryBot.create(:user, password: "password") }

specify "can log in" do
post :create, user: { username: user.username, password: "password" }
Expand All @@ -14,7 +14,7 @@
end

describe "a deactived user" do
let(:user) { FactoryGirl.create(:user, password: "password", deactivated_at: 1.minute.ago) }
let(:user) { FactoryBot.create(:user, password: "password", deactivated_at: 1.minute.ago) }

specify "can not log in" do
post :create, user: { username: user.username, password: "password" }
Expand Down

0 comments on commit f62c1b7

Please sign in to comment.