Files
openfoodnetwork/spec/services/variant_overrides_indexed_spec.rb
Luis Ramos 8a9dae0ee2 Run rubocop autocorrect
This is the result of bundle exec rubocop --auto-correct
2020-06-22 12:23:10 +01:00

64 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
describe VariantOverridesIndexed do
subject(:variant_overrides) { described_class.new([variant.id], [distributor.id]) }
let(:distributor) { create(:distributor_enterprise) }
let(:variant) { create(:variant) }
let!(:variant_override) do
create(
:variant_override,
hub: vo_distributor,
variant: vo_variant,
)
end
describe '#indexed' do
let(:result) { variant_overrides.indexed }
context 'when variant overrides exist for variants of specified variants' do
let(:vo_variant) { variant }
context 'when variant overrides apply to one of the specified distributors' do
let(:vo_distributor) { distributor }
it 'they are included in the mapping' do
expect(result).to eq(
distributor.id => { variant => variant_override }
)
end
end
context 'when variant overrides don\'t apply to one of the specified distributors' do
let(:vo_distributor) { create(:distributor_enterprise) }
it 'they are not included in the mapping' do
expect(result).to eq({})
end
end
end
context 'when variant overrides exist for other variants' do
let(:vo_variant) { create(:variant) }
context 'when variant overrides apply to one of the specified distributors' do
let(:vo_distributor) { distributor }
it 'they are not included in the mapping' do
expect(result).to eq({})
end
end
context 'when variant overrides don\'t apply to one of the specified distributors' do
let(:vo_distributor) { create(:distributor_enterprise) }
it 'they are not included in the mapping' do
expect(result).to eq({})
end
end
end
end
end