Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Move factories into factories.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
jhawthorn committed Nov 21, 2017
1 parent 2ac9769 commit ab99175
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
40 changes: 36 additions & 4 deletions lib/solidus_stock_transfers/factories.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
require 'spree/testing_support/factories'

# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
#
# Example adding this to your spec_helper will load these Factories for use:
# require 'solidus_stock_transfers/factories'

FactoryBot.define do
# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
#
# Example adding this to your spec_helper will load these Factories for use:
# require 'solidus_stock_transfers/factories'
sequence(:source_code) { |n| "SRC#{n}" }
sequence(:destination_code) { |n| "DEST#{n}" }

factory :stock_transfer, class: 'Spree::StockTransfer' do
source_location { Spree::StockLocation.create!(name: "Source Location", code: generate(:source_code), admin_name: "Source") }

factory :stock_transfer_with_items do
destination_location { Spree::StockLocation.create!(name: "Destination Location", code: generate(:destination_code), admin_name: "Destination") }

after(:create) do |stock_transfer, _evaluator|
variant_1 = create(:variant)
variant_2 = create(:variant)

variant_1.stock_items.find_by(stock_location: stock_transfer.source_location).set_count_on_hand(10)
variant_2.stock_items.find_by(stock_location: stock_transfer.source_location).set_count_on_hand(10)

stock_transfer.transfer_items.create(variant: variant_1, expected_quantity: 5)
stock_transfer.transfer_items.create(variant: variant_2, expected_quantity: 5)

stock_transfer.created_by = create(:admin_user)
stock_transfer.save!
end

factory :receivable_stock_transfer_with_items do
finalized_at { Time.current }
shipped_at { Time.current }
end
end
end
end
31 changes: 0 additions & 31 deletions lib/spree/testing_support/factories/stock_transfer_factory.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'spec_helper'
require 'spree/testing_support/factories/stock_transfer_factory'

RSpec.describe 'stock transfer factory' do
let(:factory_class) { Spree::StockTransfer }
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
require 'cancan/matchers'
require 'rspec/active_model/mocks'

require 'solidus_stock_transfers/factories'

Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|
config.infer_spec_type_from_file_location!

FactoryBot.find_definitions
end

0 comments on commit ab99175

Please sign in to comment.