<commit_before># == Schema Information
#
# Table name: instances
#
#  id                :integer          not null, primary key
#  instructable_id   :integer
#  start_time        :datetime
#  end_time          :datetime
#  location          :string(255)
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#  override_location :boolean
#

require 'spec_helper'

describe Instance do
  describe "updates end time" do
    before :each do
      @instructable = create(:instructable, duration: 6)
      @instance = @instructable.instances.create!(start_time: get_date(1), location: "There")
    end

    it "updates end time on save" do
      @instance.end_time.to_s.should == get_date(1, 6.hours).to_s
      @instance.start_time = get_date(1, 1.hour)
      @instance.save!
      @instance.end_time.to_s.should == get_date(1, 7.hours).to_s
    end
  end

  it "rejects out of range dates" do
    instance = build(:instance, start_time: '2000-01-01')
    instance.should_not be_valid
    instance.errors[:start_time].should_not be_empty
  end

  describe '#formatted_location' do
    it "renders private camp correctly" do
      instructable = create(:instructable, location_type: 'private-camp', camp_reason: 'because', camp_address: 'N06', camp_name: 'Flarg')
      instance = instructable.instances.create
      instance.formatted_location.should == "Flarg (N06)"
    end

    it "renders merchant booth correctly" do
      instructable = create(:instructable, location_type: 'merchant-booth', camp_reason: 'because', camp_address: 'N06', camp_name: 'Flarg')
      instance = instructable.instances.create
      instance.formatted_location.should == "Flarg (N06)"
    end

    it "renders pennsic location correctly" do
      instructable = create(:instructable, location_type: 'track')
      instance = instructable.instances.create!(location: "Flarg")
      instance.formatted_location.should == "Flarg"
    end

    it "handles blank camp_address" do
      instructable = create(:instructable, location_type: 'private-camp', camp_reason: 'because', camp_name: 'Flarg')
      instance = instructable.instances.create
      instance.formatted_location.should == "Flarg"
    end

    it "handles blank location" do
      instructable = create(:instructable, location_type: 'track')<commit_msg>ensure times can be overridden<commit_after># == Schema Information
#
# Table name: instances
#
#  id                :integer          not null, primary key
#  instructable_id   :integer
#  start_time        :datetime
#  end_time          :datetime
#  location          :string(255)
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#  override_location :boolean
#

require 'spec_helper'

describe Instance do
  describe "updates end time" do
    before :each do
      @instructable = create(:instructable, duration: 6)
      @instance = @instructable.instances.create!(start_time: get_date(1), location: "There")
    end

    it "updates end time on save" do
      @instance.end_time.to_s.should == get_date(1, 6.hours).to_s
      @instance.start_time = get_date(1, 1.hour)
      @instance.save!
      @instance.end_time.to_s.should == get_date(1, 7.hours).to_s
    end
  end

  describe 'start date' do
    it "rejects out of range dates" do
      instance = build(:instance, start_time: '2000-01-01')
      instance.should_not be_valid
      instance.errors[:start_time].should_not be_empty
    end

    it "accepts bogus dates if overridden" do
      instance = build(:instance, override_location: true, start_time: '2000-01-01')
      instance.should be_valid
    end
  end

  describe '#formatted_location' do
    it "renders private camp correctly" do
      instructable = create(:instructable, location_type: 'private-camp', camp_reason: 'because', camp_address: 'N06', camp_name: 'Flarg')
      instance = instructable.instances.create
      instance.formatted_location.should == "Flarg (N06)"
    end

    it "renders merchant booth correctly" do
      instructable = create(:instructable, location_type: 'merchant-booth', camp_reason: 'because', camp_address: 'N06', camp_name: 'Flarg')
      instance = instructable.instances.create
      instance.formatted_location.should == "Flarg (N06)"
    end

    it "renders pennsic location correctly" do
      instructable = create(:instructable, location_type: 'track')
      instance = instructable.instances.create!(location: "Flarg")
      instance.formatted_location.should == "Flarg"
    end

    it "handles blank camp_address" do
      instructable = create(:instructable, location_type: 'private-camp', camp_reason: 'because', camp_name: 'Flarg')
      instance = instructable.instances.create
      instance.formatted_location.should == "Flarg"
    end

    it "handles blank location" do
      instructable = create(:instructable, location_type: 'track')
{'fraction_non_alphanumeric': 0.10263211589471537, 'fraction_numerical': 0.01265047949398082, 'mean_word_length': 3.326566637246249, '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': '2947495', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1480, 'n_words': 380}