diff --git a/promotions/app/models/solidus_friendly_promotions/discountable/line_item.rb b/promotions/app/models/solidus_friendly_promotions/discountable/line_item.rb deleted file mode 100644 index f732710d..00000000 --- a/promotions/app/models/solidus_friendly_promotions/discountable/line_item.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -module SolidusFriendlyPromotions - module Discountable - class LineItem < SimpleDelegator - attr_reader :discounts, :order - - def initialize(line_item, order:) - super(line_item) - @order = order - @discounts = [] - end - - def line_item - __getobj__ - end - - def discountable_amount - amount + discounts.sum(&:amount) - end - end - end -end diff --git a/promotions/app/models/solidus_friendly_promotions/discountable/order.rb b/promotions/app/models/solidus_friendly_promotions/discountable/order.rb deleted file mode 100644 index ef2bd8c1..00000000 --- a/promotions/app/models/solidus_friendly_promotions/discountable/order.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -module SolidusFriendlyPromotions - module Discountable - class Order < SimpleDelegator - attr_reader :line_items, :shipments - - def initialize(order) - super - @line_items = order.line_items.map { |line_item| LineItem.new(line_item, order: self) } - @shipments = order.shipments.map { |shipment| Shipment.new(shipment, order: self) } - end - - def order - __getobj__ - end - end - end -end diff --git a/promotions/app/models/solidus_friendly_promotions/discountable/shipment.rb b/promotions/app/models/solidus_friendly_promotions/discountable/shipment.rb deleted file mode 100644 index e16c5a96..00000000 --- a/promotions/app/models/solidus_friendly_promotions/discountable/shipment.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module SolidusFriendlyPromotions - module Discountable - class Shipment < SimpleDelegator - attr_reader :discounts, :shipping_rates, :order - - def initialize(shipment, order:) - super(shipment) - @order = order - @discounts = [] - @shipping_rates = shipment.shipping_rates.map { |shipping_rate| ShippingRate.new(shipping_rate, shipment: self) } - end - - def shipment - __getobj__ - end - - def discountable_amount - amount + discounts.sum(&:amount) - end - end - end -end diff --git a/promotions/app/models/solidus_friendly_promotions/discountable/shipping_rate.rb b/promotions/app/models/solidus_friendly_promotions/discountable/shipping_rate.rb deleted file mode 100644 index 77a6ca46..00000000 --- a/promotions/app/models/solidus_friendly_promotions/discountable/shipping_rate.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -module SolidusFriendlyPromotions - module Discountable - class ShippingRate < SimpleDelegator - attr_reader :discounts, :shipment - - def initialize(shipping_rate, shipment:) - super(shipping_rate) - @shipment = shipment - @discounts = [] - end - - def shipping_rate - __getobj__ - end - - def discountable_amount - amount + discounts.sum(&:amount) - end - end - end -end diff --git a/promotions/spec/models/solidus_friendly_promotions/discountable/line_item_spec.rb b/promotions/spec/models/solidus_friendly_promotions/discountable/line_item_spec.rb deleted file mode 100644 index c107b821..00000000 --- a/promotions/spec/models/solidus_friendly_promotions/discountable/line_item_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe SolidusFriendlyPromotions::Discountable::LineItem do - let(:discountable_order) { double(SolidusFriendlyPromotions::Discountable::Order) } - let(:spree_line_item) { build(:line_item, price: 10, quantity: 2) } - - subject(:discountable_line_item) { described_class.new(spree_line_item, order: discountable_order) } - - describe "#order" do - subject { discountable_line_item.order } - - it { is_expected.to eq(discountable_order) } - end - - describe "#discountable_amount" do - subject(:discountable_amount) { discountable_line_item.discountable_amount } - - context "with no discounts" do - it { is_expected.to eq(20) } - end - - context "with discounts" do - let(:discount) { SolidusFriendlyPromotions::ItemDiscount.new(amount: -4) } - - before do - discountable_line_item.discounts << discount - end - - it { is_expected.to eq(16) } - end - end -end diff --git a/promotions/spec/models/solidus_friendly_promotions/discountable/order_spec.rb b/promotions/spec/models/solidus_friendly_promotions/discountable/order_spec.rb deleted file mode 100644 index 637b8a05..00000000 --- a/promotions/spec/models/solidus_friendly_promotions/discountable/order_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe SolidusFriendlyPromotions::Discountable::Order do - subject(:discountable_order) { described_class.new(spree_order) } - - let(:spree_order) { Spree::Order.new } - - describe "#line_items" do - let(:spree_order) { create(:order_with_line_items) } - subject(:line_items) { discountable_order.line_items } - - specify "are converted into Discountable Line Items" do - line_items.each do |line_item| - expect(line_item).to be_a(SolidusFriendlyPromotions::Discountable::LineItem) - end - end - end - - describe "#shipments" do - let(:spree_order) { create(:order_ready_to_ship) } - subject(:shipments) { discountable_order.shipments } - - specify "are converted into Discountable Shipments" do - shipments.each do |shipment| - expect(shipment).to be_a(SolidusFriendlyPromotions::Discountable::Shipment) - end - end - end - - describe "delegation" do - let(:spree_order) { Spree::Order.new(email: "yoda@example.com") } - - it "forwards order attributes" do - expect(subject.email).to eq("yoda@example.com") - end - end -end diff --git a/promotions/spec/models/solidus_friendly_promotions/discountable/shipment_spec.rb b/promotions/spec/models/solidus_friendly_promotions/discountable/shipment_spec.rb deleted file mode 100644 index 96e58f1f..00000000 --- a/promotions/spec/models/solidus_friendly_promotions/discountable/shipment_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe SolidusFriendlyPromotions::Discountable::Shipment do - let(:discountable_order) { double(SolidusFriendlyPromotions::Discountable::Order) } - - let(:spree_shipment) { build(:shipment, amount: 20) } - - subject(:discountable_shipment) { described_class.new(spree_shipment, order: discountable_order) } - - describe "#order" do - subject { discountable_shipment.order } - - it { is_expected.to eq(discountable_order) } - end - - describe "#discountable_amount" do - subject(:discountable_amount) { discountable_shipment.discountable_amount } - - context "with no discounts" do - it { is_expected.to eq(20) } - end - - context "with discounts" do - let(:discount) { SolidusFriendlyPromotions::ItemDiscount.new(amount: -4) } - - before do - discountable_shipment.discounts << discount - end - - it { is_expected.to eq(16) } - end - end - - describe "#shipping_rates" do - subject(:shipping_rates) { discountable_shipment.shipping_rates } - - specify "are converted into Discountable Shipments" do - shipping_rates.each do |shipping_rate| - expect(shipping_rate).to be_a(SolidusFriendlyPromotions::Discountable::ShippingRate) - end - end - end -end diff --git a/promotions/spec/models/solidus_friendly_promotions/discountable/shipping_rate_spec.rb b/promotions/spec/models/solidus_friendly_promotions/discountable/shipping_rate_spec.rb deleted file mode 100644 index f6c6d778..00000000 --- a/promotions/spec/models/solidus_friendly_promotions/discountable/shipping_rate_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe SolidusFriendlyPromotions::Discountable::ShippingRate do - let(:discountable_shipment) { double(SolidusFriendlyPromotions::Discountable::Shipment) } - - let(:spree_shipping_rate) { build(:shipping_rate, amount: 20) } - - subject(:discountable_shipping_rate) { described_class.new(spree_shipping_rate, shipment: discountable_shipment) } - - describe "#shipment" do - subject { discountable_shipping_rate.shipment } - - it { is_expected.to eq(discountable_shipment) } - end - - describe "#discountable_amount" do - subject(:discountable_amount) { discountable_shipping_rate.discountable_amount } - - context "with no discounts" do - it { is_expected.to eq(20) } - end - - context "with discounts" do - let(:discount) { SolidusFriendlyPromotions::ItemDiscount.new(amount: -4) } - - before do - discountable_shipping_rate.discounts << discount - end - - it { is_expected.to eq(16) } - end - end -end