require 'spec_helper'

describe Event do

  it "should be creatable" do
    FactoryGirl.create(:event)
  end

  it "should not have duplicate slugs" do
    event1 = FactoryGirl.create(:event)
    dup = FactoryGirl.build(:event, slug: event1.slug)
    dup.save.should be_false
    dup.errors[:slug].should == ["has already been taken"]
  end

  it "can have associated event session, then destroy it by destroying event" do
    event = FactoryGirl.create(:event)
    event_session = FactoryGirl.create(:event_session, event: event)
    event.reload
    event.event_sessions.length.should == 1
    event_session.event.should == event
    event.destroy
    EventSession.find_by_id(event_session.id).should be_nil
  end
end
