Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy Promotions: Move ransackable promo associations from core #5893

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CannotRebuildShipments < StandardError; end
go_to_state :confirm
end

self.allowed_ransackable_associations = %w[shipments user order_promotions promotions bill_address ship_address line_items]
self.allowed_ransackable_associations = %w[shipments user bill_address ship_address line_items]
self.allowed_ransackable_attributes = %w[completed_at created_at email number state payment_state shipment_state total store_id]

attr_reader :coupon_code
Expand Down
6 changes: 6 additions & 0 deletions core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
let(:user) { create(:user, email: "[email protected]") }
let(:order) { create(:order, user:, store:) }

describe ".ransackable_associations" do
subject { described_class.ransackable_associations }

it { is_expected.to contain_exactly("user", "line_items", "shipments", "bill_address", "ship_address") }
end

context '#store' do
it { is_expected.to respond_to(:store) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

module SolidusLegacyPromotions
module SpreeOrderDecorator
module ClassMethods
def allowed_ransackable_associations
super + ["promotions", "order_promotions"]
end
end

def self.prepended(base)
base.has_many :order_promotions, class_name: 'Spree::OrderPromotion', dependent: :destroy
base.has_many :promotions, through: :order_promotions
Expand All @@ -17,5 +23,6 @@ def shipping_discount
end

Spree::Order.prepend(self)
Spree::Order.singleton_class.prepend self::ClassMethods
end
end
6 changes: 6 additions & 0 deletions legacy_promotions/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
it { is_expected.to respond_to(:order_promotions) }
it { is_expected.to respond_to(:promotions) }

describe ".ransackable_associations" do
subject { described_class.ransackable_associations }

it { is_expected.to include("promotions", "order_promotions") }
end

context "#apply_shipping_promotions" do
let(:order) { build(:order) }

Expand Down
Loading