spec/timespan/mongoid/mongoid_timespan_spec.rb in timespan-0.5.1 vs spec/timespan/mongoid/mongoid_timespan_spec.rb in timespan-0.5.2
- old
+ new
@@ -5,13 +5,21 @@
describe TimeSpan do
subject { account }
def tomorrow
- Date.today + 1.day
+ @tmrw ||= today + 1.day
end
+ def today
+ @today ||= Date.today
+ end
+
+ def format_date date
+ DateTime.parse(date.to_s).strftime('%d %b %Y')
+ end
+
let(:from) { Chronic.parse("1 day ago") }
let(:to) { Time.now }
context 'factory method #from' do
describe ':today' do
@@ -27,11 +35,11 @@
end
end
describe '.start_date' do
it 'should default to today' do
- DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
+ format_date(subject.period.start_date).should == format_date(today)
end
end
describe '.duration' do
it 'should be 5 days' do
@@ -39,47 +47,23 @@
end
end
describe '.end_date' do
it 'should be 5 days from today' do
- DateTime.parse(subject.period.end_date.to_s).strftime('%d %b %Y').should == (Date.today + 5.days).strftime('%d %b %Y')
+ format_date(subject.period.end_date).should == format_date(today + 5.days)
end
end
end
- describe ':asap' do
- let(:account) do
- Account.create period: Timespan.from(:asap, 5.days)
- end
-
- describe '.start_date' do
- it 'should default to today' do
- DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
- end
- end
-
- describe '.duration' do
- it 'should be 5 days' do
- subject.period.to_days.should == 5
- end
- end
-
- describe '.end_date' do
- it 'should be 5 days from today' do
- DateTime.parse(subject.period.end_date.to_s).strftime('%d %b %Y').should == (Date.today + 5.days).strftime('%d %b %Y')
- end
- end
- end
-
describe ':tomorrow' do
let(:account) do
Account.create period: Timespan.from(:tomorrow, 5.days)
end
describe '.start_date' do
it 'should be tomorrow' do
- DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.tomorrow.strftime('%d %b %Y')
+ format_date(subject.period.start_date).should == format_date(Date.tomorrow)
end
end
describe '.duration' do
it 'should be 5 days' do
@@ -87,11 +71,11 @@
end
end
describe '.end_date' do
it 'should be 5 days from tomorrow' do
- DateTime.parse(subject.period.end_date.to_s).strftime('%d %b %Y').should == (Date.tomorrow + 5.days).strftime('%d %b %Y')
+ format_date(subject.period.end_date).should == format_date(Date.tomorrow + 5.days)
end
end
end
describe ':next_week' do
@@ -99,11 +83,11 @@
Account.create period: Timespan.from(:next_week, 5.days)
end
describe '.start_date' do
it 'should be 1 week from today' do
- DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.next_week.strftime('%d %b %Y')
+ format_date(subject.period.start_date).should == format_date(Date.next_week)
end
end
describe '.duration' do
it 'should be 5 days' do
@@ -111,11 +95,11 @@
end
end
describe '.end_date' do
it 'should be 5 days from next week' do
- DateTime.parse(subject.period.end_date.to_s).strftime('%d %b %Y').should == (Date.next_week + 5.days).strftime('%d %b %Y')
+ format_date(subject.period.end_date).should == format_date(Date.next_week + 5.days)
end
end
end
end
@@ -124,11 +108,11 @@
Account.create_it! '2 days'
end
describe '.start_date' do
it 'should default to today' do
- DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
+ format_date(subject.period.start_date).should == format_date(Date.today)
end
end
end
context '2 days duration using Timespan' do
@@ -136,11 +120,11 @@
Account.create :period => Timespan.new(:duration => 2.days)
end
describe '.start_date' do
it 'should default to today' do
- DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
+ format_date(subject.period.start_date).should == format_date(Date.today)
end
end
end
context '2 days using integer via ActiveSupport::Duration' do
@@ -148,11 +132,11 @@
Account.create :period => Timespan.new(2.days)
end
describe '.start_date' do
it 'should default to today' do
- DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
+ format_date(subject.period.start_date).should == format_date(Date.today)
end
end
end
context 'Setters and delegates' do
@@ -168,11 +152,11 @@
subject.time_period.dates_end = tomorrow + 3.days
subject.end_date = tomorrow + 3.days
end
specify do
- Date.parse(subject.time_period.end_date.to_s).should == tomorrow + 3.days
+ format_date(subject.time_period.end_date).should == format_date(tomorrow + 3.days)
end
specify do
subject.period.should be_a Timespan
end
@@ -184,10 +168,10 @@
specify do
subject.end_date.should == subject.period.end_date
end
specify do
- Date.parse(subject.start_date.to_s).should == tomorrow
+ format_date(subject.start_date).should == format_date(tomorrow)
end
end
end
end
\ No newline at end of file