diff --git a/spec/services/order_invoice_comparator_spec.rb b/spec/services/order_invoice_comparator_spec.rb index 4c05c814fa..af992e548d 100644 --- a/spec/services/order_invoice_comparator_spec.rb +++ b/spec/services/order_invoice_comparator_spec.rb @@ -17,94 +17,98 @@ describe OrderInvoiceComparator do } context "changes on the order object" do - it "returns false if the order didn't change" do - expect(subject).to be false - end + describe "detecting relevant attribute changes" do + it "returns true if a relevant attribute changes" do + Spree::Order.where(id: order.id).update_all(payment_total: order.payment_total + 10) + order.reload + expect(subject).to be true + end - it "returns true if a relevant attribute changes" do - Spree::Order.where(id: order.id).update_all(payment_total: order.payment_total + 10) - order.reload - expect(subject).to be true - end + it "returns true if a relevant attribute changes" do + Spree::Order.where(id: order.id).update_all(total: order.total + 10) + order.reload + expect(subject).to be true + end - it "returns true if a relevant attribute changes" do - Spree::Order.where(id: order.id).update_all(total: order.total + 10) - order.reload - expect(subject).to be true - end + it "returns true if a relevant attribute changes - order state: cancelled" do + order.cancel! + expect(subject).to be true + end - it "returns false if an attribute which should not change, changes" do - Spree::Order.where(id: order.id).update_all(number: 'R631504404') - order.reload - expect(subject).to be false - end + it "returns true if a relevant attribute changes - order state: resumed" do + order.cancel! + order.resume! + expect(subject).to be true + end - it "returns false if an attribute which should not change, changes" do - Spree::Order.where(id: order.id).update_all(currency: 'EUR') - order.reload - expect(subject).to be false - end + context "additional tax total changes" do + let(:order) do + create(:order_with_taxes, product_price: 110, tax_rate_amount: 0.1, + included_in_price: false) + .tap do |order| + order.create_tax_charge! + order.update_shipping_fees! + end + end - it "returns true if a relevant attribute changes - order state: cancelled" do - order.cancel! - expect(subject).to be true - end - - it "returns true if a relevant attribute changes - order state: resumed" do - order.cancel! - order.resume! - expect(subject).to be true - end - - it "returns false if a non-relevant attribute changes" do - order.update!(special_instructions: "A very special insctruction.") - expect(subject).to be false - end - - it "returns false if a non-relevant attribute changes" do - order.update!(note: "THIS IS A NEW NOTE") - expect(subject).to be false - end - - context "additional tax total changes" do - let(:order) do - create(:order_with_taxes, product_price: 110, tax_rate_amount: 0.1, - included_in_price: false) - .tap do |order| - order.create_tax_charge! - order.update_shipping_fees! + it "returns returns true" do + Spree::TaxRate.first.update!(amount: 0.15) + order.create_tax_charge! && order.save + expect(subject).to be true end end - it "returns returns true" do - Spree::TaxRate.first.update!(amount: 0.15) - order.create_tax_charge! && order.save - expect(subject).to be true - end - end + context "included tax total changes" do + let(:order) do + create(:order_with_taxes, product_price: 110, tax_rate_amount: 0.1, + included_in_price: true) + .tap do |order| + order.create_tax_charge! + order.update_shipping_fees! + end + end - context "included tax total changes" do - let(:order) do - create(:order_with_taxes, product_price: 110, tax_rate_amount: 0.1, - included_in_price: true) - .tap do |order| - order.create_tax_charge! - order.update_shipping_fees! + it "returns returns true" do + Spree::TaxRate.first.update!(amount: 0.15) + order.create_tax_charge! && order.save + expect(subject).to be true end end - it "returns returns true" do - Spree::TaxRate.first.update!(amount: 0.15) - order.create_tax_charge! && order.save - expect(subject).to be true + context "shipping method changes" do + let(:shipping_method) { create(:shipping_method) } + it "returns returns true" do + Spree::ShippingRate.first.update(shipping_method_id: shipping_method.id) + expect(subject).to be true + end end end - context "shipping method changes" do - let(:shipping_method) { create(:shipping_method) } - it "returns returns true" do - Spree::ShippingRate.first.update(shipping_method_id: shipping_method.id) - expect(subject).to be true + describe "ignoring non-relevant attribute changes" do + it "returns false if the order didn't change" do + expect(subject).to be false + end + + it "returns false if an attribute which should not change, changes" do + Spree::Order.where(id: order.id).update_all(number: 'R631504404') + order.reload + expect(subject).to be false + end + + it "returns false if an attribute which should not change, changes" do + Spree::Order.where(id: order.id).update_all(currency: 'EUR') + order.reload + expect(subject).to be false + end + + it "returns false if a non-relevant attribute changes" do + order.update!(special_instructions: "A very special insctruction.") + expect(subject).to be false + end + + it "returns false if a non-relevant attribute changes" do + order.update!(note: "THIS IS A NEW NOTE") + expect(subject).to be false end end end