Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: fd5c1e5b9b
Fetching contributors…

Cannot retrieve contributors at this time

113 lines (78 sloc) 2.602 kB
require 'spec_helper'
describe Event do
before(:each) do
@event = Event.new(title: 'Test Event', starts_at: Time.now, ends_at: 1.hour.from_now)
@event.section = stub_model(Section, course: stub_model(Course))
end
it "should be valid with given attributes" do
@event.should be_valid
end
it "should not be valid without title" do
@event.title = nil
@event.should_not be_valid
end
it "should not be valid without starts_at" do
@event.starts_at = nil
@event.should_not be_valid
end
it "should not be valid without ends_at" do
@event.ends_at = nil
@event.should_not be_valid
end
context "when the starts_at is more than an hour ago" do
before(:each) { @event.starts_at = 61.minutes.ago }
it "should not be valid" do
@event.should_not be_valid
end
end
context "when the ends_at is less than starts_at" do
before(:each) { @event.ends_at = 1.hour.ago }
it "should not be valid" do
@event.should_not be_valid
end
it "should add an error to the ends_at attribute" do
@event.should have(1).error_on(:ends_at)
end
end
context "when scoped by for" do
it "should only include events within the given date range" do
@new_event = @event.dup
@event.save
@new_event.starts_at = 10.days.from_now
@new_event.save
Event.for(Time.now.all_week).should == [@event]
end
end
describe "#full_title" do
it "should prepend 'DUE: ' if the event is an assignment" do
@event.assignment = true
@event.full_title.should == 'DUE: Test Event'
end
it "should not prepend 'DUE: ' if the event isn't an assignment" do
@event.assignment = false
@event.full_title.should == 'Test Event'
end
end
describe "#time" do
context "when the starts_at and ends_at are the same meridian indicator" do
it "should only display the meridian indicator once" do
@event.starts_at = Time.new(2012, 9, 24, 1)
@event.ends_at = Time.new(2012, 9, 24, 2)
@event.time.should == '1:00-2:00am'
end
end
context "when the starts_at and the ends_at are different meridian indicators" do
it "should display the meridian indicator twice" do
@event.starts_at = Time.new(2012, 9, 24, 1)
@event.ends_at = Time.new(2012, 9, 24, 13)
@event.time.should == '1:00am-1:00pm'
end
end
end
describe "#starts_on" do
it "should coerce starts_at to a date" do
@event.starts_at = Time.now
@event.starts_on.should == Date.today
end
end
end
Jump to Line
Something went wrong with that request. Please try again.