From 67a00173f836aa295115b4c0be2bdb049b4531c5 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 15 Aug 2020 12:26:59 +0100 Subject: [PATCH] Replace one-letter-variables in old spec and wrap long lines --- .../open_food_network/packing_report_spec.rb | 85 +++++++++++-------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/spec/lib/open_food_network/packing_report_spec.rb b/spec/lib/open_food_network/packing_report_spec.rb index f7b02923e1..7b01f8aee9 100644 --- a/spec/lib/open_food_network/packing_report_spec.rb +++ b/spec/lib/open_food_network/packing_report_spec.rb @@ -6,27 +6,29 @@ include AuthenticationWorkflow module OpenFoodNetwork describe PackingReport do describe "fetching orders" do - let(:d1) { create(:distributor_enterprise) } - let(:oc1) { create(:simple_order_cycle) } - let(:o1) { create(:order, completed_at: 1.day.ago, order_cycle: oc1, distributor: d1) } - let(:li1) { build(:line_item_with_shipment) } + let(:distributor) { create(:distributor_enterprise) } + let(:order_cycle) { create(:simple_order_cycle) } + let(:order) { + create(:order, completed_at: 1.day.ago, order_cycle: order_cycle, distributor: distributor) + } + let(:line_item) { build(:line_item_with_shipment) } - before { o1.line_items << li1 } + before { order.line_items << line_item } context "as a site admin" do let(:user) { create(:admin_user) } subject { PackingReport.new user, {}, true } it "fetches completed orders" do - o2 = create(:order) - o2.line_items << build(:line_item) - expect(subject.table_items).to eq([li1]) + order2 = create(:order) + order2.line_items << build(:line_item) + expect(subject.table_items).to eq([line_item]) end it "does not show cancelled orders" do - o2 = create(:order, state: "canceled", completed_at: 1.day.ago) - o2.line_items << build(:line_item_with_shipment) - expect(subject.table_items).to eq([li1]) + order2 = create(:order, state: "canceled", completed_at: 1.day.ago) + order2.line_items << build(:line_item_with_shipment) + expect(subject.table_items).to eq([line_item]) end end @@ -34,45 +36,56 @@ module OpenFoodNetwork let!(:user) { create(:user) } subject { PackingReport.new user, {}, true } - let(:s1) { create(:supplier_enterprise) } + let(:supplier) { create(:supplier_enterprise) } before do - s1.enterprise_roles.create!(user: user) + supplier.enterprise_roles.create!(user: user) end context "that has granted P-OC to the distributor" do - let(:o2) { create(:order, distributor: d1, completed_at: 1.day.ago, bill_address: create(:address), ship_address: create(:address)) } - let(:li2) { build(:line_item_with_shipment, product: create(:simple_product, supplier: s1)) } + let(:order2) { + create(:order, distributor: distributor, completed_at: 1.day.ago, + bill_address: create(:address), ship_address: create(:address)) + } + let(:line_item2) { + build(:line_item_with_shipment, product: create(:simple_product, supplier: supplier)) + } before do - o2.line_items << li2 - create(:enterprise_relationship, parent: s1, child: d1, permissions_list: [:add_to_order_cycle]) + order2.line_items << line_item2 + create(:enterprise_relationship, parent: supplier, child: distributor, + permissions_list: [:add_to_order_cycle]) end it "shows line items supplied by my producers, with names hidden" do - expect(subject.table_items).to eq([li2]) + expect(subject.table_items).to eq([line_item2]) expect(subject.table_items.first.order.bill_address.firstname).to eq("HIDDEN") end context "where the distributor allows suppliers to see customer names" do before do - d1.preferred_show_customer_names_to_suppliers = true + distributor.preferred_show_customer_names_to_suppliers = true end it "shows line items supplied by my producers, with names shown" do - expect(subject.table_items).to eq([li2]) + expect(subject.table_items).to eq([line_item2]) expect(subject.table_items.first.order.bill_address.firstname). - to eq(o2.bill_address.firstname) + to eq(order2.bill_address.firstname) end end end context "that has not granted P-OC to the distributor" do - let(:o2) { create(:order, distributor: d1, completed_at: 1.day.ago, bill_address: create(:address), ship_address: create(:address)) } - let(:li2) { build(:line_item_with_shipment, product: create(:simple_product, supplier: s1)) } + let(:order2) { + create(:order, distributor: distributor, completed_at: 1.day.ago, + bill_address: create(:address), ship_address: create(:address)) + } + let(:line_item2) { + build(:line_item_with_shipment, product: create(:simple_product, supplier: supplier)) + } before do - o2.line_items << li2 + order2.line_items << line_item2 end it "does not show line items supplied by my producers" do @@ -81,7 +94,7 @@ module OpenFoodNetwork context "where the distributor allows suppliers to see customer names" do before do - d1.preferred_show_customer_names_to_suppliers = true + distributor.preferred_show_customer_names_to_suppliers = true end it "does not show line items supplied by my producers" do @@ -96,23 +109,23 @@ module OpenFoodNetwork subject { PackingReport.new user, {}, true } before do - d1.enterprise_roles.create!(user: user) + distributor.enterprise_roles.create!(user: user) end it "only shows line items distributed by enterprises managed by the current user" do - d2 = create(:distributor_enterprise) - d2.enterprise_roles.create!(user: create(:user)) - o2 = create(:order, distributor: d2, completed_at: 1.day.ago) - o2.line_items << build(:line_item_with_shipment) - expect(subject.table_items).to eq([li1]) + distributor2 = create(:distributor_enterprise) + distributor2.enterprise_roles.create!(user: create(:user)) + order2 = create(:order, distributor: distributor2, completed_at: 1.day.ago) + order2.line_items << build(:line_item_with_shipment) + expect(subject.table_items).to eq([line_item]) end it "only shows the selected order cycle" do - oc2 = create(:simple_order_cycle) - o2 = create(:order, distributor: d1, order_cycle: oc2) - o2.line_items << build(:line_item) - allow(subject).to receive(:params).and_return(order_cycle_id_in: oc1.id) - expect(subject.table_items).to eq([li1]) + order_cycle2 = create(:simple_order_cycle) + order2 = create(:order, distributor: distributor, order_cycle: order_cycle2) + order2.line_items << build(:line_item) + allow(subject).to receive(:params).and_return(order_cycle_id_in: order_cycle.id) + expect(subject.table_items).to eq([line_item]) end end end