Skip to content

Commit

Permalink
Add factory_bot lint test to core
Browse files Browse the repository at this point in the history
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
)
  • Loading branch information
seand7565 committed May 30, 2020
1 parent 1aa554f commit 83d8889
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions core/spec/lib/factory_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 83d8889

Please sign in to comment.