From 83d8889699eca568095bc708580ce9763fd68080 Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 30 May 2020 13:59:54 -0500 Subject: [PATCH] Add factory_bot lint test to core Adds a test that lints FactoryBot. Also makes changes to two tests to conform to the lint - store_credit_event_factory needs to have an action, even if the action is replaced with one of the sub factories. store_credit_reason_factory tripped the linter because of a uniqueness contraint for the name - should not come up in normal testing, but I added a sequencer to account for it in the linter anyway. The linter ignores just one factory - customer_return_without_return_items this factory is intentionally invalid (see: /core/spec/lib/spree/core/testing_support/factories/customer_return_factory_spec.rb#L37 ) --- .../factories/store_credit_event_factory.rb | 1 + .../factories/store_credit_reason_factory.rb | 4 +++- core/spec/lib/factory_spec.rb | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 core/spec/lib/factory_spec.rb diff --git a/core/lib/spree/testing_support/factories/store_credit_event_factory.rb b/core/lib/spree/testing_support/factories/store_credit_event_factory.rb index ed0f77e11a7..b43332f5cd7 100644 --- a/core/lib/spree/testing_support/factories/store_credit_event_factory.rb +++ b/core/lib/spree/testing_support/factories/store_credit_event_factory.rb @@ -8,6 +8,7 @@ store_credit amount { 100.00 } authorization_code { "#{store_credit.id}-SC-20140602164814476128" } + action { Spree::StoreCredit::AUTHORIZE_ACTION } factory :store_credit_auth_event, class: 'Spree::StoreCreditEvent' do action { Spree::StoreCredit::AUTHORIZE_ACTION } diff --git a/core/lib/spree/testing_support/factories/store_credit_reason_factory.rb b/core/lib/spree/testing_support/factories/store_credit_reason_factory.rb index 31fc0686394..24cad21deba 100644 --- a/core/lib/spree/testing_support/factories/store_credit_reason_factory.rb +++ b/core/lib/spree/testing_support/factories/store_credit_reason_factory.rb @@ -2,6 +2,8 @@ FactoryBot.define do factory :store_credit_reason, class: 'Spree::StoreCreditReason' do - name { "Input error" } + sequence :name do |n| + "Input error #{n}" + end end end diff --git a/core/spec/lib/factory_spec.rb b/core/spec/lib/factory_spec.rb new file mode 100644 index 00000000000..bc50f1b81e7 --- /dev/null +++ b/core/spec/lib/factory_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe FactoryBot do + it { FactoryBot.lint(FactoryBot.factories.reject{ |f| f.name == :customer_return_without_return_items }) } +end