aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2014-05-01 15:10:38 +0100
committerGareth Rees <gareth@mysociety.org>2014-05-01 15:10:38 +0100
commit4d04209d29b76c997e5238d8546d7eb17ee2bd53 (patch)
treecb7862fadee1ab6849f20f90a14420c5e8af1159 /spec/lib
parent06c40e4d8fb546b315a4af3c82d5f891d4101c5f (diff)
parent6f5e975c65c4429b8a8a0040b7eb3405559acfd0 (diff)
Merge branch 'issues/1390-james-cheshire-infographic' into rails-3-develop
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/date_quarter_spec.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/lib/date_quarter_spec.rb b/spec/lib/date_quarter_spec.rb
new file mode 100644
index 000000000..29c2eb28d
--- /dev/null
+++ b/spec/lib/date_quarter_spec.rb
@@ -0,0 +1,29 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe DateQuarter do
+ include DateQuarter
+
+ describe :quarters_between do
+
+ it 'returns all the quarters in a year' do
+ # This is a bit of a convoluted spec, since we have to convert each
+ # Time in to an Integer to make a reasonable comparison
+ # See http://makandracards.com/makandra/1057-why-two-ruby-time-objects-are-not-equal-although-they-appear-to-be
+ start = Time.parse('2014-01-01')
+ finish = Time.parse('2014-12-31')
+
+ expected = [['Wed Jan 01 00:00:00 +0000 2014', 'Mon Mar 31 23:59:59 +0000 2014'],
+ ['Tue Apr 01 00:00:00 +0000 2014', 'Mon Jun 30 23:59:59 +0000 2014'],
+ ['Tue Jul 01 00:00:00 +0000 2014', 'Tue Sep 30 23:59:59 +0000 2014'],
+ ['Wed Oct 01 00:00:00 +0000 2014', 'Wed Dec 31 23:59:59 +0000 2014']].
+ map { |pair| [Time.parse(pair[0]).to_i, Time.parse(pair[1]).to_i] }
+
+ quarters_between(start, finish).each_with_index do |pair, i|
+ pair.map!(&:to_i)
+ pair.should == expected[i]
+ end
+ end
+
+ end
+
+end