Files
openfoodnetwork/spec/controllers/shops_controller_spec.rb
Pau Perez 7b2d4f10ee Cover #distributed_properties \w a controller spec
This exercises the controller and the serializer ensuring the
integration works allowing to confidently refactor things further.
2019-02-26 11:36:36 +01:00

40 lines
1.2 KiB
Ruby

require 'spec_helper'
describe ShopsController, type: :controller do
render_views
let!(:distributor) { create(:distributor_enterprise) }
let!(:invisible_distributor) { create(:distributor_enterprise, visible: false) }
before do
allow(Enterprise).to receive_message_chain(:distributors_with_active_order_cycles, :ready_for_checkout) { [distributor] }
end
# Exclusion from actual rendered view handled in features/consumer/home
it "shows JSON for invisible hubs" do
get :index
expect(response.body).to have_content(invisible_distributor.name)
end
it 'renders distributed properties' do
duplicate_property = create(:property, presentation: 'dairy')
producer = create(:supplier_enterprise, properties: [duplicate_property])
property = create(:property, presentation: 'dairy')
product = create(:product, properties: [property])
producer.supplied_products << product
create(
:simple_order_cycle,
coordinator: distributor,
suppliers: [producer],
distributors: [distributor],
variants: [product.variants]
)
get :index
expect(response.body)
.to match(/"distributed_properties":\[{"id":\d+,"name":"dairy","presentation":"dairy"}\]/)
end
end