<commit_before>require 'spec_helper'

describe Spree::OptionValue, :type => :model do
  context "touching" do
    let!(:variant) do
      Timecop.freeze(1.day.ago) do
        create(:variant)
      end
    end
    let(:option_value) { variant.option_values.first }

    it "should touch a variant" do
      Timecop.freeze do
        option_value.touch
        expect(variant.reload.updated_at).to eq(Time.now)
      end
    end

    context "from the after_save hook" do
      it "should not touch the variant if there are no changes" do
        Timecop.freeze 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
        Timecop.freeze do
          option_value.name += "--1"
          option_value.save!
          expect(variant.reload.updated_at).to eq(Time.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<commit_msg>Be more tolerant with timestamps in the spec<commit_after>require 'spec_helper'

describe Spree::OptionValue, :type => :model do
  context "touching" do
    let!(:variant) do
      Timecop.freeze(1.day.ago) do
        create(:variant)
      end
    end
    let(:option_value) { variant.option_values.first }

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

    context "from the after_save hook" do
      it "should not touch the variant if there are no changes" do
        Timecop.freeze 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
        Timecop.freeze do
          option_value.name += "--1"
          option_value.save!
          expect(variant.reload.updated_at).to be_within(1.second).of(Time.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
{'fraction_non_alphanumeric': 0.08660461351679483, 'fraction_numerical': 0.003237555645487657, 'mean_word_length': 2.3863013698630136, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7309780', 'n_tokens_mistral': 767, 'n_tokens_neox': 747, 'n_words': 210}