Created
May 6, 2009 06:30
-
-
Save joshski/107391 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec' | |
# i have an option box that stores text ("day", "week" or "month" - | |
# representing the accuracy of a date) to a database that is then used | |
# when displaying the date (i.e. decides what accuracy to show it to). | |
class Event | |
attr_accessor :date, :accuracy | |
def to_s | |
case @accuracy | |
when "day" | |
date.strftime("%A %d %B %Y") | |
when "week" | |
date.strftime("Week %U, %Y") | |
when "month" | |
date.strftime("%B %Y") | |
end | |
end | |
end | |
describe Event do | |
before do | |
@event = Event.new | |
end | |
describe "with day accuracy" do | |
before do | |
@event.accuracy = "day" | |
end | |
it "should render string '<day> <date> <month> <year>'" do | |
@event.date = Date.parse("2006/01/01") | |
@event.to_s.should == "Sunday 01 January 2006" | |
end | |
end | |
describe "with week accuracy" do | |
before do | |
@event.accuracy = "week" | |
end | |
it "should render string 'Week <week>, <year>'" do | |
@event.date = Date.parse("2006/09/09") | |
@event.to_s.should == "Week 36, 2006" | |
end | |
end | |
describe "with month accuracy" do | |
before do | |
@event.accuracy = "month" | |
end | |
it "should render string '<month> <year>'" do | |
@event.date = Date.parse("2006/03/03") | |
@event.to_s.should == "March 2006" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment