<commit_before>require_relative '../test_helper'

describe Opening do
  let(:opening) do
    Opening.new(
      name: 'mon 00:00-01:00',
      day: 'mon',
      open: Time.now,
      close: Time.now + 1.hour
    )
  end

  subject { opening }

  describe 'attributes' do
    it { subject.must_respond_to :id }
    it { subject.must_respond_to :day }
    it { subject.must_respond_to :open }
    it { subject.must_respond_to :close }
    it { subject.must_respond_to :sort_value }
    it { subject.must_respond_to :created_at }
    it { subject.must_respond_to :updated_at }
  end

  describe 'validations' do
    describe 'always' do
      it { subject.must validate_presence_of :day }
      it { subject.must validate_presence_of :open }
      it { subject.must validate_uniqueness_of(:open).scoped_to([:day, :close]) }
      it { subject.must validate_presence_of :close }
      it { subject.must validate_uniqueness_of(:close).scoped_to([:day, :open]) }
    end
  end

  describe '::Base' do
    describe 'associations' do
      it { subject.must have_and_belong_to_many :offers }
    end
  end

  describe 'methods' do
    describe '#appointment?' do
      it 'should return false if opening and closing hour is present' do
        opening.appointment?.must_equal false
      end

      it 'should return true if neither open nor close is present' do
        opening.assign_attributes open: nil, close: nil
        opening.appointment?.must_equal true
      end
    end

    describe '#display_string' do
      it 'should output the open and close time' do
        opening.open = Time.parse '12:01:01'
        opening.close = Time.parse '13:02:02'

        opening.display_string.must_equal '12:01 Uhr - 13:02 Uhr'
      end

      it 'should output 24 instead of 00 for the closing time' do
        opening.open = Time.parse '14:00:00'
        opening.close = Time.parse '00:00:00'

        opening.display_string.must_equal '14:00 Uhr - 24:00 Uhr'
      end
    end
  end
end<commit_msg>for #306 - fix code coverage<commit_after>require_relative '../test_helper'

describe Opening do
  let(:opening) do
    Opening.new(
      name: 'mon 00:00-01:00',
      day: 'mon',
      open: Time.now,
      close: Time.now + 1.hour
    )
  end

  subject { opening }

  describe 'attributes' do
    it { subject.must_respond_to :id }
    it { subject.must_respond_to :day }
    it { subject.must_respond_to :open }
    it { subject.must_respond_to :close }
    it { subject.must_respond_to :sort_value }
    it { subject.must_respond_to :created_at }
    it { subject.must_respond_to :updated_at }
  end

  describe 'validations' do
    describe 'always' do
      it { subject.must validate_presence_of :day }
      it { subject.must validate_presence_of :open }
      it { subject.must validate_uniqueness_of(:open).scoped_to([:day, :close]) }
      it { subject.must validate_presence_of :close }
      it { subject.must validate_uniqueness_of(:close).scoped_to([:day, :open]) }
    end
  end

  describe '::Base' do
    describe 'associations' do
      it { subject.must have_and_belong_to_many :offers }
    end
  end

  describe 'methods' do
    describe '#appointment?' do
      it 'should return false if opening and closing hour is present' do
        opening.appointment?.must_equal false
      end

      it 'should return true if neither open nor close is present' do
        opening.assign_attributes open: nil, close: nil
        opening.appointment?.must_equal true
      end
    end

    describe '#display_string' do
      it 'should output the open and close time' do
        opening.open = Time.parse '12:01:01'
        opening.close = Time.parse '13:02:02'

        opening.display_string.must_equal '12:01 Uhr - 13:02 Uhr'
      end

      it 'should output a special string when there are no open/close times' do
        opening.close = nil
        opening.display_string.must_equal(
          I18n.t 'opening.display_string.appointment'
        )
      end

      it 'should output 24 instead of 00 for the closing time' do
        opening.open = Time.parse '14:00:00'
        opening.close = Time.parse '00:00:00'

        opening.display_string.must_equal '14:00 Uhr - 24:00 Uhr'
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09226401703335699, 'fraction_numerical': 0.0262597586941093, 'mean_word_length': 2.657439446366782, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7458498', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1321, 'n_words': 380}