Created
April 20, 2012 18:39
-
-
Save thedelchop/2430941 to your computer and use it in GitHub Desktop.
Basically and integration test
This file contains 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
PayableDecorator < ApplicationDecorator | |
decorates :payable | |
def due_date_in_words | |
if payable.due_date > Date.today | |
"#{due_date} (#{h.distance_of_time_in_words(payable.due_date, Date.today)} from now)" | |
elsif payable.due_date < Date.today | |
"#{due_date} (#{h.distance_of_time_in_words(payable.due_date, Date.today)} ago)" | |
else | |
"#{due_date} (today)" | |
end | |
end | |
end |
This file contains 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_helper' | |
describe PayableDecorator do | |
let(:payable) { mock 'Payable' } | |
subject { PayableDecorator.new payable } | |
describe '#due_date_in_words' do | |
it 'returns the date due and the number of days until it is due when the payable is due in future' do | |
Timecop.freeze( Chronic.parse("March 22, 2012")) do | |
payable.stub(:due_date).and_return 5.days.from_now.to_date | |
subject.due_date_in_words.should == "March 27, 2012 (5 days from now)" | |
end | |
end | |
it 'returns the date due and the number of days since it has been due if the payable is late' do | |
Timecop.freeze( Chronic.parse("March 22, 2012")) do | |
payable.stub(:due_date).and_return 5.days.ago.to_date | |
subject.due_date_in_words.should == "March 17, 2012 (5 days ago)" | |
end | |
end | |
it 'returns the date and the text "today" if the payable is due today' do | |
Timecop.freeze( Chronic.parse("March 22, 2012")) do | |
payable.stub(:due_date).and_return Date.today | |
subject.due_date_in_words.should == "March 22, 2012 (today)" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment