Sha256: 66913475f19143281b4dedc5f47f117aaaf567f39238fe2ec842603b89d080f3

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

require 'rails_helper'

RSpec.describe Spree::OptionValue, type: :model do
  include ActiveSupport::Testing::TimeHelpers

  context "touching" do
    let!(:variant) do
      travel_to(1.day.ago) do
        create(:variant)
      end
    end
    let(:option_value) { variant.option_values.first }

    it "should touch a variant" do
      now = Time.current
      travel_to(now) do
        option_value.touch
        expect(variant.reload.updated_at).to be_within(1.second).of(now)
      end
    end

    context "from the after_save hook" do
      it "should not touch the variant if there are no changes" do
        now = Time.current
        travel_to(now) do
          option_value.save!
          expect(variant.reload.updated_at).to be <= 1.day.ago
        end
      end

      it "should touch the variant if there are changes" do
        now = Time.current
        travel_to(now) do
          option_value.name += "--1"
          option_value.save!
          expect(variant.reload.updated_at).to be_within(1.second).of(now)
        end
      end
    end
  end

  describe "#presentation_with_option_type" do
    let(:option_value) { build(:option_value) }
    subject { option_value.presentation_with_option_type }

    it "returns a string in the correct form" do
      expect(subject).to eq "Size - S"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
solidus_core-2.5.2 spec/models/spree/option_value_spec.rb
solidus_core-2.5.1 spec/models/spree/option_value_spec.rb
solidus_core-2.5.0 spec/models/spree/option_value_spec.rb
solidus_core-2.5.0.rc1 spec/models/spree/option_value_spec.rb
solidus_core-2.5.0.beta2 spec/models/spree/option_value_spec.rb
solidus_core-2.5.0.beta1 spec/models/spree/option_value_spec.rb