<commit_before>require 'spec_helper'

describe Event do
  subject {build(:event)}
  describe "validations" do
    context "when start time is less than end time" do
      it {should be_valid}
    end
    context "when start time is greater than end time" do
      subject {build(:event, start_time: Time.current.tomorrow.midnight)}
      it {should_not be_valid}
    end
    context "when start time is equal to end time" do
      subject {build(:event, start_time: Time.current.midnight, end_time: Time.current.midnight)}
      it {should_not be_valid}
    end
  end

  describe "payload method access" do
    context "when there is no payload" do
      it "should raise on undefined methods" do
        expect{subject.blabla}.to raise_error
      end
    end
    context "when there is a payload" do
      let(:object) {
        o = double("object")
        o.stub(:blabla).and_return("bla")
        return o
      }
      subject{build(:event, object: object)}
      it "should raise on the payload's undefined method" do
        expect{subject.not_exist}.to raise_error
      end
      it "should delegate to payload if method doesn't exist" do
        expect(subject.blabla).to eq "bla"
      end
      it "should prefer the event's return value" do
        subject.stub(:blabla).and_return("monkey")
        expect(subject.blabla).to eq "monkey"
      end
      it "should be able to access the payload via .payload" do
        subject.stub(:blabla).and_return("monkey")
        expect(subject.payload.blabla).to eq "bla"
      end
    end
  end
end<commit_msg>Fixed event spec.<commit_after>require 'spec_helper'

describe Event do
  subject {build(:event)}
  describe "validations" do
    context "when start time is less than end time" do
      it {should be_valid}
    end
    context "when start time is greater than end time" do
      subject {build(:event, start_time: Time.current.tomorrow.midnight, end_time: Time.current.midnight)}
      it {should_not be_valid}
    end
    context "when start time is equal to end time" do
      subject {build(:event, start_time: Time.current.midnight, end_time: Time.current.midnight)}
      it {should_not be_valid}
    end
  end

  describe "payload method access" do
    context "when there is no payload" do
      it "should raise on undefined methods" do
        expect{subject.blabla}.to raise_error
      end
    end
    context "when there is a payload" do
      let(:object) {
        o = double("object")
        o.stub(:blabla).and_return("bla")
        return o
      }
      subject{build(:event, object: object)}
      it "should raise on the payload's undefined method" do
        expect{subject.not_exist}.to raise_error
      end
      it "should delegate to payload if method doesn't exist" do
        expect(subject.blabla).to eq "bla"
      end
      it "should prefer the event's return value" do
        subject.stub(:blabla).and_return("monkey")
        expect(subject.blabla).to eq "monkey"
      end
      it "should be able to access the payload via .payload" do
        subject.stub(:blabla).and_return("monkey")
        expect(subject.payload.blabla).to eq "bla"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08861557868180385, 'fraction_numerical': 0.0, 'mean_word_length': 2.679814385150812, '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': '5752418', 'n_tokens_mistral': 946, 'n_tokens_neox': 921, 'n_words': 323}