Skip to content

Commit

Permalink
Merge pull request #8 from friendlycart/fix-promotion-rule-spec
Browse files Browse the repository at this point in the history
Fix standardrb error in promotion rule spec
  • Loading branch information
mamhoff authored Oct 4, 2023
2 parents 7507a71 + 740a590 commit 904c07e
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
require "spec_helper"

RSpec.describe SolidusFriendlyPromotions::PromotionRule do
class BadTestRule < SolidusFriendlyPromotions::PromotionRule; end

class TestRule < SolidusFriendlyPromotions::PromotionRule
def eligible?(_promotable, _options = {})
true
let(:bad_test_rule_class) { Class.new(SolidusFriendlyPromotions::PromotionRule) }
let(:test_rule_class) do
Class.new(SolidusFriendlyPromotions::PromotionRule) do
def self.model_name
ActiveModel::Name.new(self, nil, "test_rule")
end

def eligible?(_promotable, _options = {})
true
end
end
end

Expand All @@ -18,21 +23,22 @@ def eligible?(_promotable, _options = {})
end

it "forces developer to implement eligible? method" do
expect { BadTestRule.new.eligible?("promotable") }.to raise_error NotImplementedError
expect { bad_test_rule_class.new.eligible?("promotable") }.to raise_error NotImplementedError
expect { test_rule_class.new.eligible?("promotable") }.not_to raise_error NotImplementedError
end

it "validates unique rules for a promotion" do
promotion_one = TestRule.new
promotion_one = test_rule_class.new
promotion_one.promotion_id = 1
promotion_one.save

promotion_two = TestRule.new
promotion_two = test_rule_class.new
promotion_two.promotion_id = 1
expect(promotion_two).not_to be_valid
end

it "generates its own partial path" do
rule = TestRule.new
rule = test_rule_class.new
expect(rule.to_partial_path).to eq "solidus_friendly_promotions/admin/promotion_rules/rules/test_rule"
end
end

0 comments on commit 904c07e

Please sign in to comment.