Skip to content

Commit

Permalink
Add with_action trait
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielePalombo committed Aug 31, 2020
1 parent 85a3e30 commit 68c4148
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
describe Spree::Admin::PromotionsController, type: :controller do
stub_authorization!

let!(:promotion1) { create(:promotion, name: "name1", code: "code1", path: "path1") }
let!(:promotion2) { create(:promotion, name: "name2", code: "code2", path: "path2") }
let!(:promotion3) { create(:promotion, name: "name2", code: "code3", path: "path3", expires_at: Date.yesterday) }
let!(:promotion1) { create(:promotion, :with_action, name: "name1", code: "code1", path: "path1") }
let!(:promotion2) { create(:promotion, :with_action, name: "name2", code: "code2", path: "path2") }
let!(:promotion3) do
create(:promotion, :with_action, name: "name2", code: "code3", path: "path3", expires_at: Date.yesterday)
end
let!(:category) { create :promotion_category }

describe "#show" do
Expand Down
6 changes: 6 additions & 0 deletions core/lib/spree/testing_support/factories/promotion_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
end
end

trait :with_action do
after(:create) do |promotion, _evaluator|
promotion.actions << Spree::Promotion::Actions::CreateAdjustment.new
end
end

trait :with_line_item_adjustment do
transient do
adjustment_rate { 10 }
Expand Down
7 changes: 1 addition & 6 deletions core/spec/models/spree/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,18 +456,13 @@ class Extension < Spree::Base

# Regression test for https://github.com/spree/spree/issues/4416
context "#possible_promotions" do
let!(:promotion) do
create(:promotion, advertise: true, starts_at: 1.day.ago)
end
let!(:promotion) { create(:promotion, :with_action, advertise: true, starts_at: 1.day.ago) }
let!(:rule) do
Spree::Promotion::Rules::Product.create(
promotion: promotion,
products: [product]
)
end
before do
promotion.actions << Spree::Promotion::Actions::CreateAdjustment.new
end

it "lists the promotion as a possible promotion" do
expect(product.possible_promotions).to include(promotion)
Expand Down

0 comments on commit 68c4148

Please sign in to comment.