From e40c1c08ca075f85ddc74e60e80942ea854a3b9f Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 26 Nov 2018 17:32:32 +0100 Subject: [PATCH] Refactor spec to not stub the class under test This also relies on ActiveRecord which will come in handy as we move on the refactor. --- .../api/cached_enterprise_serializer_spec.rb | 32 ++++++------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/spec/serializers/api/cached_enterprise_serializer_spec.rb b/spec/serializers/api/cached_enterprise_serializer_spec.rb index 017403de65..dbef516df5 100644 --- a/spec/serializers/api/cached_enterprise_serializer_spec.rb +++ b/spec/serializers/api/cached_enterprise_serializer_spec.rb @@ -32,32 +32,18 @@ describe Api::CachedEnterpriseSerializer do let(:duplicate_property) { create(:property, presentation: 'One') } let(:different_property) { create(:property, presentation: 'Two') } - describe "merging Spree::Properties" do - it "merges properties" do - allow(cached_enterprise_serializer) - .to receive(:product_properties) { [property] } - allow(cached_enterprise_serializer) - .to receive(:producer_properties) { [duplicate_property, different_property] } - - merge = cached_enterprise_serializer.supplied_properties - expect(merge).to eq([property, different_property]) - end + let(:enterprise) do + create(:enterprise, properties: [duplicate_property, different_property]) end - describe "merging ProducerProperties and Spree::ProductProperties" do - let(:product_property) { create(:product_property, property: property) } - let(:duplicate_product_property) { create(:producer_property, property: duplicate_property) } - let(:producer_property) { create(:producer_property, property: different_property) } + before do + product = create(:product, properties: [property]) + enterprise.supplied_products << product + end - it "merges properties" do - allow(cached_enterprise_serializer) - .to receive(:product_properties) { [product_property] } - allow(cached_enterprise_serializer) - .to receive(:producer_properties) { [duplicate_product_property, producer_property] } - - merge = cached_enterprise_serializer.supplied_properties - expect(merge).to eq([product_property, producer_property]) - end + it "removes duplicate product and producer properties" do + merge = cached_enterprise_serializer.supplied_properties + expect(merge).to eq([property, different_property]) end end end