Sha256: 05dd46e273e9b23316f78216880233ccba30f3ee6f6246081cb95aa82e16034d

Contents?: true

Size: 899 Bytes

Versions: 5

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

require 'rails_helper'

module Spree
  RSpec.describe Spree::PromotionRule, type: :model do
    class BadTestRule < Spree::PromotionRule; end

    class TestRule < Spree::PromotionRule
      def eligible?(_promotable, _options = {})
        true
      end
    end

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

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

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
solidus_core-2.10.5 spec/models/spree/promotion_rule_spec.rb
solidus_core-2.10.3 spec/models/spree/promotion_rule_spec.rb
solidus_core-2.10.2 spec/models/spree/promotion_rule_spec.rb
solidus_core-2.10.1 spec/models/spree/promotion_rule_spec.rb
solidus_core-2.10.0 spec/models/spree/promotion_rule_spec.rb