Skip to content

Instantly share code, notes, and snippets.

@thedelchop
Created April 20, 2012 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedelchop/2430941 to your computer and use it in GitHub Desktop.
Save thedelchop/2430941 to your computer and use it in GitHub Desktop.
Basically and integration test
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
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