-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5677 from mamhoff/promotion-finder
Add extension point: Promotion finder
- Loading branch information
Showing
10 changed files
with
96 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Spree | ||
module NullPromotionFinder | ||
def self.by_code_or_id(*) | ||
raise ActiveRecord::RecordNotFound, "No promotion system configured." | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Spree | ||
class PromotionFinder | ||
def self.by_code_or_id(coupon_code) | ||
Spree::Promotion.with_coupon_code(coupon_code.to_s) || Spree::Promotion.find(coupon_code) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Spree::NullPromotionFinder do | ||
describe ".by_code_or_id" do | ||
it "raises ActiveRecord::RecordNotFound" do | ||
expect { described_class.by_code_or_id("promo") }.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Spree::PromotionFinder do | ||
describe ".by_code_or_id" do | ||
let!(:promotion) { create(:promotion, code: "promo") } | ||
|
||
it "finds a promotion by its code" do | ||
expect(described_class.by_code_or_id("promo")).to eq promotion | ||
end | ||
|
||
it "finds a promotion by its ID" do | ||
expect(described_class.by_code_or_id(promotion.id)).to eq promotion | ||
end | ||
|
||
context "when the promotion does not exist" do | ||
it "raises an error" do | ||
expect { described_class.by_code_or_id("nonexistent") }.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
end | ||
end | ||
end |