Introduction
Introduction Statistics Contact Development Disclaimer Help
cleaned up specs - reportable - Fork of reportable required by WarVox, from hdm…
Log
Files
Refs
README
---
commit 302078c74c8857b4e0aab259fc7d2c79489d7d73
parent 1a5f067f3b860469357f8a05db8efcbc2ca3ca0a
Author: Marco Otte-Witte <[email protected]>
Date: Tue, 13 Jan 2009 23:34:05 +0800
cleaned up specs
Signed-off-by: Marco Otte-Witte <[email protected]>
Diffstat:
A spec/classes/cumulated_report_spec… | 117 +++++++++++++++++++++++++++…
A spec/classes/date_time_spec.rb | 16 ++++++++++++++++
A spec/classes/grouping_spec.rb | 152 +++++++++++++++++++++++++++++…
R spec/other/report_cache_spec.rb ->… | 0
A spec/classes/report_spec.rb | 237 +++++++++++++++++++++++++++++…
A spec/classes/reporting_period_spec… | 201 +++++++++++++++++++++++++++…
D spec/models/report_method_spec.rb | 45 -----------------------------…
D spec/other/cumulated_report_spec.rb | 117 -----------------------------…
D spec/other/date_time_spec.rb | 16 ----------------
D spec/other/grouping_spec.rb | 152 -----------------------------…
A spec/other/report_method_spec.rb | 45 +++++++++++++++++++++++++++++…
D spec/other/report_spec.rb | 237 -----------------------------…
D spec/other/reporting_period_spec.rb | 201 ------------------------------
13 files changed, 768 insertions(+), 768 deletions(-)
---
diff --git a/spec/classes/cumulated_report_spec.rb b/spec/classes/cumulated_rep…
@@ -0,0 +1,117 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe Kvlr::ReportsAsSparkline::CumulatedReport do
+
+ before do
+ @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :cumulated_r…
+ end
+
+ describe '#run' do
+
+ it 'should cumulate the data' do
+ @report.should_receive(:cumulate).once
+
+ @report.run
+ end
+
+ it 'should return an array of the same length as the specified limit' do
+ @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :cumulated…
+
+ @report.run.length.should == 10
+ end
+
+ for grouping in [:hour, :day, :week, :month] do
+
+ describe "for grouping #{grouping.to_s}" do
+
+ before(:all) do
+ User.create!(:login => 'test 1', :created_at => Time.now - 1.send(gr…
+ User.create!(:login => 'test 2', :created_at => Time.now - 3.send(gr…
+ User.create!(:login => 'test 3', :created_at => Time.now - 3.send(gr…
+ end
+
+ describe do
+
+ before do
+ @grouping = Kvlr::ReportsAsSparkline::Grouping.new(grouping)
+ @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :cum…
+ @result = @report.run
+ end
+
+ it "should return an array starting reporting period (Time.now - (li…
+ @result.first[0].should == Kvlr::ReportsAsSparkline::ReportingPeri…
+ end
+
+ it "should return data ending with with the current reporting period…
+ @result.last[0].should == Kvlr::ReportsAsSparkline::ReportingPerio…
+ end
+
+ end
+
+ it 'should return correct data for aggregation :count' do
+ @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :regis…
+ result = @report.run
+
+ result[9][1].should == 3.0
+ result[8][1].should == 3.0
+ result[7][1].should == 2.0
+ result[6][1].should == 2.0
+ end
+
+ it 'should return correct data for aggregation :sum' do
+ @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :regis…
+ result = @report.run()
+
+ result[9][1].should == 6.0
+ result[8][1].should == 6.0
+ result[7][1].should == 5.0
+ result[6][1].should == 5.0
+ end
+
+ it 'should return correct data for aggregation :count when custom cond…
+ @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :regis…
+ result = @report.run(:conditions => ['login IN (?)', ['test 1', 'tes…
+
+ result[9][1].should == 2.0
+ result[8][1].should == 2.0
+ result[7][1].should == 1.0
+ result[6][1].should == 1.0
+ end
+
+ it 'should return correct data for aggregation :sum when custom condit…
+ @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :regis…
+ result = @report.run(:conditions => ['login IN (?)', ['test 1', 'tes…
+
+ result[9][1].should == 3.0
+ result[8][1].should == 3.0
+ result[7][1].should == 2.0
+ result[6][1].should == 2.0
+ end
+
+ after(:all) do
+ User.destroy_all
+ end
+
+ end
+
+ after(:each) do
+ Kvlr::ReportsAsSparkline::ReportCache.destroy_all
+ end
+
+ end
+
+ end
+
+ describe '#cumulate' do
+
+ it 'should correctly cumulate the given data' do
+ first = (Time.now - 1.week).to_s
+ second = Time.now.to_s
+ data = [[first, 1], [second, 2]]
+
+ @report.send(:cumulate, data).should == [[first, 1.0], [second, 3.0]]
+ end
+
+ end
+
+end
diff --git a/spec/classes/date_time_spec.rb b/spec/classes/date_time_spec.rb
@@ -0,0 +1,16 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe DateTime do
+
+ describe '#to_reporting_period' do
+
+ it 'should return a reporting period for the specified grouping and instan…
+ date_time = DateTime.now
+ grouping = Kvlr::ReportsAsSparkline::Grouping.new(:hour)
+
+ date_time.to_reporting_period(grouping).should == Kvlr::ReportsAsSparkli…
+ end
+
+ end
+
+end
diff --git a/spec/classes/grouping_spec.rb b/spec/classes/grouping_spec.rb
@@ -0,0 +1,152 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe Kvlr::ReportsAsSparkline::Grouping do
+
+ describe '#new' do
+
+ it 'should raise an error if an unsupported grouping is specified' do
+ lambda { Kvlr::ReportsAsSparkline::Grouping.new(:unsupported) }.should r…
+ end
+
+ end
+
+ describe '#to_sql' do
+
+ describe 'for MySQL' do
+
+ before do
+ ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
+ end
+
+ it 'should use DATE_FORMAT with format string "%Y/%m/%d/%H" for grouping…
+ Kvlr::ReportsAsSparkline::Grouping.new(:hour).send(:to_sql, 'created_a…
+ end
+
+ it 'should use DATE_FORMAT with format string "%Y/%m/%d" for grouping :d…
+ Kvlr::ReportsAsSparkline::Grouping.new(:day).send(:to_sql, 'created_at…
+ end
+
+ it 'should use DATE_FORMAT with format string "%Y/%u" for grouping :week…
+ Kvlr::ReportsAsSparkline::Grouping.new(:week).send(:to_sql, 'created_a…
+ end
+
+ it 'should use DATE_FORMAT with format string "%Y/%m" for grouping :mont…
+ Kvlr::ReportsAsSparkline::Grouping.new(:month).send(:to_sql, 'created_…
+ end
+
+ end
+
+ describe 'for PostgreSQL' do
+
+ before do
+ ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
+ end
+
+ for grouping in [:hour, :day, :week, :month] do
+
+ it "should use date_trunc with truncation identifier \"#{grouping.to_s…
+ Kvlr::ReportsAsSparkline::Grouping.new(grouping).send(:to_sql, 'crea…
+ end
+
+ end
+
+ end
+
+ describe 'for SQLite3' do
+
+ before do
+ ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
+ end
+
+ it 'should use strftime with format string "%Y/%m/%d/%H" for grouping :h…
+ Kvlr::ReportsAsSparkline::Grouping.new(:hour).send(:to_sql, 'created_a…
+ end
+
+ it 'should use strftime with format string "%Y/%m/%d" for grouping :day'…
+ Kvlr::ReportsAsSparkline::Grouping.new(:day).send(:to_sql, 'created_at…
+ end
+
+ it 'should use strftime with format string "%Y/%W" for grouping :week' do
+ Kvlr::ReportsAsSparkline::Grouping.new(:week).send(:to_sql, 'created_a…
+ end
+
+ it 'should use strftime with format string "%Y/%m" for grouping :month' …
+ Kvlr::ReportsAsSparkline::Grouping.new(:month).send(:to_sql, 'created_…
+ end
+
+ end
+
+ end
+
+ describe '#date_parts_from_db_string' do
+
+ describe 'for SQLite3' do
+
+ before do
+ ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
+ end
+
+ for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:month…
+
+ it "should split the string with '/' for grouping :#{grouping[0].to_s}…
+ Kvlr::ReportsAsSparkline::Grouping.new(grouping[0]).date_parts_from_…
+ end
+
+ end
+
+ it 'should split the string with "/" and increment the week by 1 for gro…
+ db_string = '2008/2'
+ expected = [2008, 3]
+
+ Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_strin…
+ end
+
+ end
+
+ describe 'for PostgreSQL' do
+
+ before do
+ ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
+ end
+
+ it 'should split the date part of the string with "-" and read out the h…
+ Kvlr::ReportsAsSparkline::Grouping.new(:hour).date_parts_from_db_strin…
+ end
+
+ it 'should split the date part of the string with "-" for grouping :day'…
+ Kvlr::ReportsAsSparkline::Grouping.new(:day).date_parts_from_db_string…
+ end
+
+ it 'should split the date part of the string with "-" for grouping :week…
+ Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_strin…
+ end
+
+ it 'should split the date part of the string with "-" and return year an…
+ Kvlr::ReportsAsSparkline::Grouping.new(:month).date_parts_from_db_stri…
+ end
+
+ end
+
+ describe 'for MySQL' do
+
+ before do
+ ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
+ end
+
+ for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:week,…
+
+ it "should split the string with '/' for grouping :#{grouping[0].to_s}…
+ Kvlr::ReportsAsSparkline::Grouping.new(grouping[0]).date_parts_from_…
+ end
+
+ end
+
+ end
+
+ end
+
+end
+
+class ActiveRecord::ConnectionAdapters::MysqlAdapter; end
+class ActiveRecord::ConnectionAdapters::SQLite3Adapter; end
+class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter; end
diff --git a/spec/other/report_cache_spec.rb b/spec/classes/report_cache_spec.rb
diff --git a/spec/classes/report_spec.rb b/spec/classes/report_spec.rb
@@ -0,0 +1,237 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe Kvlr::ReportsAsSparkline::Report do
+
+ before do
+ @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations)
+ end
+
+ describe '#run' do
+
+ it 'should process the data with the report cache' do
+ Kvlr::ReportsAsSparkline::ReportCache.should_receive(:process).once.with…
+
+ @report.run
+ end
+
+ it 'should process the data with the report cache and specify no_cache whe…
+ Kvlr::ReportsAsSparkline::ReportCache.should_receive(:process).once.with…
+
+ @report.run(:conditions => { :some => :condition })
+ end
+
+ it 'should validate the specified options for the :run context' do
+ @report.should_receive(:ensure_valid_options).once.with({ :limit => 3 },…
+
+ result = @report.run(:limit => 3)
+ end
+
+ for grouping in [:hour, :day, :week, :month] do
+
+ describe "for grouping #{grouping.to_s}" do
+
+ before(:all) do
+ User.create!(:login => 'test 1', :created_at => Time.now - 1.send(gr…
+ User.create!(:login => 'test 2', :created_at => Time.now - 3.send(gr…
+ User.create!(:login => 'test 3', :created_at => Time.now - 3.send(gr…
+ end
+
+ describe do
+
+ before do
+ @grouping = Kvlr::ReportsAsSparkline::Grouping.new(grouping)
+ @report = Kvlr::ReportsAsSparkline::Report.new(User, :registration…
+ @result = @report.run
+ end
+
+ it "should return an array starting reporting period (Time.now - (li…
+ @result.first[0].should == Kvlr::ReportsAsSparkline::ReportingPeri…
+ end
+
+ it "should return data ending with with the current reporting period…
+ @result.last[0].should == Kvlr::ReportsAsSparkline::ReportingPerio…
+ end
+
+ end
+
+ it 'should return correct data for aggregation :count' do
+ @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,…
+ result = @report.run.to_a
+
+ result[9][1].should == 0.0
+ result[8][1].should == 1.0
+ result[7][1].should == 0.0
+ result[6][1].should == 2.0
+ end
+
+ it 'should return correct data for aggregation :sum' do
+ @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,…
+ result = @report.run().to_a
+
+ result[9][1].should == 0.0
+ result[8][1].should == 1.0
+ result[7][1].should == 0.0
+ result[6][1].should == 5.0
+ end
+
+ it 'should return correct data for aggregation :count when custom cond…
+ @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,…
+ result = @report.run(:conditions => ['login IN (?)', ['test 1', 'tes…
+
+ result[9][1].should == 0.0
+ result[8][1].should == 1.0
+ result[7][1].should == 0.0
+ result[6][1].should == 1.0
+ end
+
+ it 'should return correct data for aggregation :sum when custom condit…
+ @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,…
+ result = @report.run(:conditions => ['login IN (?)', ['test 1', 'tes…
+
+ result[9][1].should == 0.0
+ result[8][1].should == 1.0
+ result[7][1].should == 0.0
+ result[6][1].should == 2.0
+ end
+
+ after(:all) do
+ User.destroy_all
+ end
+
+ after(:each) do
+ Kvlr::ReportsAsSparkline::ReportCache.destroy_all
+ end
+
+ end
+
+ end
+
+ end
+
+ describe '#read_data' do
+
+ it 'should invoke the aggregation method on the model' do
+ @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, :ag…
+ User.should_receive(:count).once.and_return([])
+
+ @report.send(:read_data, Time.now)
+ end
+
+ it 'should setup the conditions' do
+ @report.should_receive(:setup_conditions).once.and_return([])
+
+ @report.send(:read_data, Time.now)
+ end
+
+ end
+
+ describe '#setup_conditions' do
+
+ it 'should return conditions for date_column >= begin_at only when no cust…
+ begin_at = Time.now
+
+ @report.send(:setup_conditions, begin_at).should == ['created_at >= ?', …
+ end
+
+ it 'should return conditions for date_column >= begin_at only when an empt…
+ begin_at = Time.now
+
+ @report.send(:setup_conditions, begin_at, {}).should == ['created_at >= …
+ end
+
+ it 'should return conditions for date_column >= begin_at only when an empt…
+ begin_at = Time.now
+
+ @report.send(:setup_conditions, begin_at, []).should == ['created_at >= …
+ end
+
+ it 'should correctly include custom conditions if they are specified as a …
+ begin_at = Time.now
+ custom_conditions = { :first_name => 'first name', :last_name => 'last n…
+
+ conditions = @report.send(:setup_conditions, begin_at, custom_conditions)
+ #cannot check for equality of complete conditions array since hashes are…
+ conditions[0].should include('first_name = ?')
+ conditions[0].should include('last_name = ?')
+ conditions[0].should include('created_at >= ?')
+ conditions.should include('first name')
+ conditions.should include('last name')
+ conditions.should include(begin_at)
+ end
+
+ it 'should correctly include custom conditions if they are specified as an…
+ begin_at = Time.now
+ custom_conditions = ['first_name = ? AND last_name = ?', 'first name', '…
+
+ @report.send(:setup_conditions, begin_at, custom_conditions).should == [
+ 'first_name = ? AND last_name = ? AND created_at >= ?',
+ 'first name',
+ 'last name',
+ begin_at
+ ]
+ end
+
+ end
+
+ describe '#ensure_valid_options' do
+
+ it 'should raise an error if malformed conditions are specified' do
+ lambda { @report.send(:ensure_valid_options, { :conditions => 1 }) }.sho…
+ end
+
+ it 'should not raise an error if conditions are specified as an Array' do
+ lambda { @report.send(:ensure_valid_options, { :conditions => ['first_na…
+ end
+
+ it 'should not raise an error if conditions are specified as a Hash' do
+ lambda { @report.send(:ensure_valid_options, { :conditions => { :first_n…
+ end
+
+ describe 'for context :initialize' do
+
+ it 'should not raise an error if valid options are specified' do
+ lambda { @report.send(:ensure_valid_options, {
+ :limit => 100,
+ :aggregation => :count,
+ :grouping => :day,
+ :date_column => :created_at,
+ :value_column => :id,
+ :conditions => []
+ })
+ }.should_not raise_error(ArgumentError)
+ end
+
+ it 'should raise an error if an unsupported option is specified' do
+ lambda { @report.send(:ensure_valid_options, { :invalid => :option }) …
+ end
+
+ it 'should raise an error if an invalid aggregation is specified' do
+ lambda { @report.send(:ensure_valid_options, { :aggregation => :invali…
+ end
+
+ it 'should raise an error if an invalid grouping is specified' do
+ lambda { @report.send(:ensure_valid_options, { :grouping => :decade })…
+ end
+
+ it 'should raise an error if aggregation :sum is spesicied but no :value…
+ lambda { @report.send(:ensure_valid_options, { :aggregation => :sum })…
+ end
+
+ end
+
+ describe 'for context :run' do
+
+ it 'should not raise an error if valid options are specified' do
+ lambda { @report.send(:ensure_valid_options, { :limit => 100, :conditi…
+ }.should_not raise_error(ArgumentError)
+ end
+
+ it 'should raise an error if an unsupported option is specified' do
+ lambda { @report.send(:ensure_valid_options, { :aggregation => :sum },…
+ end
+
+ end
+
+ end
+
+end
diff --git a/spec/classes/reporting_period_spec.rb b/spec/classes/reporting_per…
@@ -0,0 +1,201 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe Kvlr::ReportsAsSparkline::ReportingPeriod do
+
+ describe '#date_time' do
+
+ it 'should return the date and time with minutes = seconds = 0 for groupin…
+ date_time = DateTime.now
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
+
+ reporting_period.date_time.should == DateTime.new(date_time.year, date_t…
+ end
+
+ it 'should return the date part only for grouping :day' do
+ date_time = DateTime.now
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
+
+ reporting_period.date_time.should == date_time.to_date
+ end
+
+ describe 'for grouping :week' do
+
+ it 'should return the date of the monday of the week date_time is in for…
+ date_time = DateTime.new(2008, 11, 27)
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:…
+
+ reporting_period.date_time.should == Date.new(date_time.year, date_tim…
+ end
+
+ it 'should return the date of the monday of the week date_time is in whe…
+ date_time = DateTime.new(2008, 11, 24) #this is a monday already, shou…
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:…
+
+ reporting_period.date_time.should == Date.new(date_time.year, date_tim…
+ end
+
+ it 'should return the date of the monday of the week date_time is in whe…
+ date_time = DateTime.new(2008, 11, 1) #this is a saturday
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:…
+
+ reporting_period.date_time.should == Date.new(2008, 10, 27) # expect t…
+ end
+
+ it 'should return the date of the monday of the week date_time is in whe…
+ date_time = DateTime.new(2009, 1, 1) #this is a thursday
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:…
+
+ reporting_period.date_time.should == Date.new(2008, 12, 29) # expect t…
+ end
+
+ end
+
+ it 'should return the date with day = 1 for grouping :month' do
+ date_time = Time.now
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
+
+ reporting_period.date_time.should == Date.new(date_time.year, date_time.…
+ end
+
+ end
+
+ describe '.from_db_string' do
+
+ it 'should return a reporting period with the correct date and time and wi…
+ grouping = Kvlr::ReportsAsSparkline::Grouping.new(:hour)
+ grouping.stub!(:date_parts_from_db_string).and_return([2008, 1, 1, 12])
+
+ Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d…
+ end
+
+ it 'should return a reporting period with the date part only for grouping …
+ grouping = Kvlr::ReportsAsSparkline::Grouping.new(:day)
+ grouping.stub!(:date_parts_from_db_string).and_return([2008, 1, 1])
+
+ Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d…
+ end
+
+ it 'should return a reporting period with the date part of the monday of t…
+ grouping = Kvlr::ReportsAsSparkline::Grouping.new(:week)
+ grouping.stub!(:date_parts_from_db_string).and_return([2008, 1])
+
+ Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d…
+ end
+
+ it 'should return a reporting period with the correct date and with day = …
+ grouping = Kvlr::ReportsAsSparkline::Grouping.new(:month)
+ grouping.stub!(:date_parts_from_db_string).and_return([2008, 1])
+
+ Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d…
+ end
+
+ end
+
+ describe '#next' do
+
+ it 'should return a reporting period with date and time one hour after the…
+ now = Time.now
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
+ expected = now + 1.hour
+
+ reporting_period.next.date_time.should == DateTime.new(expected.year, ex…
+ end
+
+ it 'should return a reporting period with date one day after the current p…
+ now = Time.now
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
+ expected = now + 1.day
+
+ reporting_period.next.date_time.should == Date.new(expected.year, expect…
+ end
+
+ it 'should return a reporting period with date one week after the current …
+ now = DateTime.now
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
+ expected = reporting_period.date_time + 1.week
+
+ reporting_period.next.date_time.should == Date.new(expected.year, expect…
+ end
+
+ it 'should return a reporting period with date of the first day in the mon…
+ now = Time.now
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
+ expected = reporting_period.date_time + 1.month
+
+ reporting_period.next.date_time.should == Date.new(expected.year, expect…
+ end
+
+ end
+
+ describe '#==' do
+
+ it 'should return true for 2 reporting periods with the same date_time and…
+ now = DateTime.now
+ reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
+ reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
+
+ (reporting_period1 == reporting_period2).should == true
+ end
+
+ it 'should return false for 2 reporting periods with the same date_time bu…
+ now = Time.now
+ reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
+ reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
+
+ (reporting_period1 == reporting_period2).should == false
+ end
+
+ it 'should return true for 2 reporting periods with the same grouping but …
+ reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
+ reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
+
+ (reporting_period1 == reporting_period2).should == true
+ end
+
+ it 'should return false for 2 reporting periods with the same grouping but…
+ reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
+ reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
+
+ (reporting_period1 == reporting_period2).should == false
+ end
+
+ end
+
+ describe '.first' do
+
+ before do
+ @now = DateTime.now
+ DateTime.stub!(:now).and_return(@now)
+ end
+
+ it 'should return a reporting period with the date part of (DateTime.now -…
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:…
+ expected = @now - 2.hours
+
+ reporting_period.date_time.should == DateTime.new(expected.year, expecte…
+ end
+
+ it 'should return a reporting period with the date part of (DateTime.now -…
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:…
+ expected = @now - 2.days
+
+ reporting_period.date_time.should == Date.new(expected.year, expected.mo…
+ end
+
+ it 'should return a reporting period with the date of the first day of the…
+ DateTime.stub!(:now).and_return(DateTime.new(2008, 12, 31, 0, 0, 0))
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:…
+
+ reporting_period.date_time.should == DateTime.new(2008, 10, 1)
+ end
+
+ it 'should return a reporting period with the date of the monday of the we…
+ DateTime.stub!(:now).and_return(DateTime.new(2008, 12, 31, 0, 0, 0)) #we…
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:…
+
+ reporting_period.date_time.should == DateTime.new(2008, 12, 15) #the mon…
+ end
+
+ end
+
+end
diff --git a/spec/models/report_method_spec.rb b/spec/models/report_method_spec…
@@ -1,45 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe Kvlr::ReportsAsSparkline do
-
- describe 'for inherited models' do
-
- before(:all) do
- User.create!(:login => 'test 1', :created_at => Time.now - 1.days, :pro…
- User.create!(:login => 'test 2', :created_at => Time.now - 2.days, :prof…
- SpecialUser.create!(:login => 'test 3', :created_at => Time.now - 2.days…
- end
-
- it 'should include all data when invoked on the base model class' do
- result = User.registrations_report.to_a
-puts result.inspect
- result.length.should == 10
- result[8][1].should == 1.0
- result[7][1].should == 2.0
- end
-
- it 'should include only data for instances of the inherited model when inv…
- result = SpecialUser.registrations_report.to_a
-
- result.length.should == 10
- result[7][1].should == 1.0
- end
-
- after(:all) do
- User.destroy_all
- SpecialUser.destroy_all
- end
-
- end
-
- after do
- Kvlr::ReportsAsSparkline::ReportCache.destroy_all
- end
-
-end
-
-class User < ActiveRecord::Base
- reports_as_sparkline :registrations, :limit => 10
-end
-
-class SpecialUser < User; end
diff --git a/spec/other/cumulated_report_spec.rb b/spec/other/cumulated_report_…
@@ -1,117 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe Kvlr::ReportsAsSparkline::CumulatedReport do
-
- before do
- @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :cumulated_r…
- end
-
- describe '.run' do
-
- it 'should cumulate the data' do
- @report.should_receive(:cumulate).once
-
- @report.run
- end
-
- it 'should return an array of the same length as the specified limit' do
- @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :cumulated…
-
- @report.run.length.should == 10
- end
-
- for grouping in [:hour, :day, :week, :month] do
-
- describe "for grouping #{grouping.to_s}" do
-
- before(:all) do
- User.create!(:login => 'test 1', :created_at => Time.now - 1.send(gr…
- User.create!(:login => 'test 2', :created_at => Time.now - 3.send(gr…
- User.create!(:login => 'test 3', :created_at => Time.now - 3.send(gr…
- end
-
- describe do
-
- before do
- @grouping = Kvlr::ReportsAsSparkline::Grouping.new(grouping)
- @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :cum…
- @result = @report.run
- end
-
- it "should return an array starting reporting period (Time.now - (li…
- @result.first[0].should == Kvlr::ReportsAsSparkline::ReportingPeri…
- end
-
- it "should return data ending with with the current reporting period…
- @result.last[0].should == Kvlr::ReportsAsSparkline::ReportingPerio…
- end
-
- end
-
- it 'should return correct data for aggregation :count' do
- @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :regis…
- result = @report.run
-
- result[9][1].should == 3.0
- result[8][1].should == 3.0
- result[7][1].should == 2.0
- result[6][1].should == 2.0
- end
-
- it 'should return correct data for aggregation :sum' do
- @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :regis…
- result = @report.run()
-
- result[9][1].should == 6.0
- result[8][1].should == 6.0
- result[7][1].should == 5.0
- result[6][1].should == 5.0
- end
-
- it 'should return correct data for aggregation :count when custom cond…
- @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :regis…
- result = @report.run(:conditions => ['login IN (?)', ['test 1', 'tes…
-
- result[9][1].should == 2.0
- result[8][1].should == 2.0
- result[7][1].should == 1.0
- result[6][1].should == 1.0
- end
-
- it 'should return correct data for aggregation :sum when custom condit…
- @report = Kvlr::ReportsAsSparkline::CumulatedReport.new(User, :regis…
- result = @report.run(:conditions => ['login IN (?)', ['test 1', 'tes…
-
- result[9][1].should == 3.0
- result[8][1].should == 3.0
- result[7][1].should == 2.0
- result[6][1].should == 2.0
- end
-
- after(:all) do
- User.destroy_all
- end
-
- end
-
- after(:each) do
- Kvlr::ReportsAsSparkline::ReportCache.destroy_all
- end
-
- end
-
- end
-
- describe '.cumulate' do
-
- it 'should correctly cumulate the given data' do
- first = (Time.now - 1.week).to_s
- second = Time.now.to_s
- data = [[first, 1], [second, 2]]
-
- @report.send(:cumulate, data).should == [[first, 1.0], [second, 3.0]]
- end
-
- end
-
-end
diff --git a/spec/other/date_time_spec.rb b/spec/other/date_time_spec.rb
@@ -1,16 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe DateTime do
-
- describe '.to_reporting_period' do
-
- it 'should return a reporting period for the specified grouping and instan…
- date_time = DateTime.now
- grouping = Kvlr::ReportsAsSparkline::Grouping.new(:hour)
-
- date_time.to_reporting_period(grouping).should == Kvlr::ReportsAsSparkli…
- end
-
- end
-
-end
diff --git a/spec/other/grouping_spec.rb b/spec/other/grouping_spec.rb
@@ -1,152 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe Kvlr::ReportsAsSparkline::Grouping do
-
- describe '#new' do
-
- it 'should raise an error if an unsupported grouping is specified' do
- lambda { Kvlr::ReportsAsSparkline::Grouping.new(:unsupported) }.should r…
- end
-
- end
-
- describe '.to_sql' do
-
- describe 'for MySQL' do
-
- before do
- ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
- end
-
- it 'should use DATE_FORMAT with format string "%Y/%m/%d/%H" for grouping…
- Kvlr::ReportsAsSparkline::Grouping.new(:hour).send(:to_sql, 'created_a…
- end
-
- it 'should use DATE_FORMAT with format string "%Y/%m/%d" for grouping :d…
- Kvlr::ReportsAsSparkline::Grouping.new(:day).send(:to_sql, 'created_at…
- end
-
- it 'should use DATE_FORMAT with format string "%Y/%u" for grouping :week…
- Kvlr::ReportsAsSparkline::Grouping.new(:week).send(:to_sql, 'created_a…
- end
-
- it 'should use DATE_FORMAT with format string "%Y/%m" for grouping :mont…
- Kvlr::ReportsAsSparkline::Grouping.new(:month).send(:to_sql, 'created_…
- end
-
- end
-
- describe 'for PostgreSQL' do
-
- before do
- ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
- end
-
- for grouping in [:hour, :day, :week, :month] do
-
- it "should use date_trunc with truncation identifier \"#{grouping.to_s…
- Kvlr::ReportsAsSparkline::Grouping.new(grouping).send(:to_sql, 'crea…
- end
-
- end
-
- end
-
- describe 'for SQLite3' do
-
- before do
- ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
- end
-
- it 'should use strftime with format string "%Y/%m/%d/%H" for grouping :h…
- Kvlr::ReportsAsSparkline::Grouping.new(:hour).send(:to_sql, 'created_a…
- end
-
- it 'should use strftime with format string "%Y/%m/%d" for grouping :day'…
- Kvlr::ReportsAsSparkline::Grouping.new(:day).send(:to_sql, 'created_at…
- end
-
- it 'should use strftime with format string "%Y/%W" for grouping :week' do
- Kvlr::ReportsAsSparkline::Grouping.new(:week).send(:to_sql, 'created_a…
- end
-
- it 'should use strftime with format string "%Y/%m" for grouping :month' …
- Kvlr::ReportsAsSparkline::Grouping.new(:month).send(:to_sql, 'created_…
- end
-
- end
-
- end
-
- describe '#date_parts_from_db_string' do
-
- describe 'for SQLite3' do
-
- before do
- ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
- end
-
- for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:month…
-
- it "should split the string with '/' for grouping :#{grouping[0].to_s}…
- Kvlr::ReportsAsSparkline::Grouping.new(grouping[0]).date_parts_from_…
- end
-
- end
-
- it 'should split the string with "/" and increment the week by 1 for gro…
- db_string = '2008/2'
- expected = [2008, 3]
-
- Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_strin…
- end
-
- end
-
- describe 'for PostgreSQL' do
-
- before do
- ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
- end
-
- it 'should split the date part of the string with "-" and read out the h…
- Kvlr::ReportsAsSparkline::Grouping.new(:hour).date_parts_from_db_strin…
- end
-
- it 'should split the date part of the string with "-" for grouping :day'…
- Kvlr::ReportsAsSparkline::Grouping.new(:day).date_parts_from_db_string…
- end
-
- it 'should split the date part of the string with "-" for grouping :week…
- Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_strin…
- end
-
- it 'should split the date part of the string with "-" and return year an…
- Kvlr::ReportsAsSparkline::Grouping.new(:month).date_parts_from_db_stri…
- end
-
- end
-
- describe 'for MySQL' do
-
- before do
- ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C…
- end
-
- for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:week,…
-
- it "should split the string with '/' for grouping :#{grouping[0].to_s}…
- Kvlr::ReportsAsSparkline::Grouping.new(grouping[0]).date_parts_from_…
- end
-
- end
-
- end
-
- end
-
-end
-
-class ActiveRecord::ConnectionAdapters::MysqlAdapter; end
-class ActiveRecord::ConnectionAdapters::SQLite3Adapter; end
-class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter; end
diff --git a/spec/other/report_method_spec.rb b/spec/other/report_method_spec.rb
@@ -0,0 +1,45 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe Kvlr::ReportsAsSparkline do
+
+ describe 'for inherited models' do
+
+ before(:all) do
+ User.create!(:login => 'test 1', :created_at => Time.now - 1.days, :pro…
+ User.create!(:login => 'test 2', :created_at => Time.now - 2.days, :prof…
+ SpecialUser.create!(:login => 'test 3', :created_at => Time.now - 2.days…
+ end
+
+ it 'should include all data when invoked on the base model class' do
+ result = User.registrations_report.to_a
+
+ result.length.should == 10
+ result[8][1].should == 1.0
+ result[7][1].should == 2.0
+ end
+
+ it 'should include only data for instances of the inherited model when inv…
+ result = SpecialUser.registrations_report.to_a
+
+ result.length.should == 10
+ result[7][1].should == 1.0
+ end
+
+ after(:all) do
+ User.destroy_all
+ SpecialUser.destroy_all
+ end
+
+ end
+
+ after do
+ Kvlr::ReportsAsSparkline::ReportCache.destroy_all
+ end
+
+end
+
+class User < ActiveRecord::Base
+ reports_as_sparkline :registrations, :limit => 10
+end
+
+class SpecialUser < User; end
diff --git a/spec/other/report_spec.rb b/spec/other/report_spec.rb
@@ -1,237 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe Kvlr::ReportsAsSparkline::Report do
-
- before do
- @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations)
- end
-
- describe '.run' do
-
- it 'should process the data with the report cache' do
- Kvlr::ReportsAsSparkline::ReportCache.should_receive(:process).once.with…
-
- @report.run
- end
-
- it 'should process the data with the report cache and specify no_cache whe…
- Kvlr::ReportsAsSparkline::ReportCache.should_receive(:process).once.with…
-
- @report.run(:conditions => { :some => :condition })
- end
-
- it 'should validate the specified options for the :run context' do
- @report.should_receive(:ensure_valid_options).once.with({ :limit => 3 },…
-
- result = @report.run(:limit => 3)
- end
-
- for grouping in [:hour, :day, :week, :month] do
-
- describe "for grouping #{grouping.to_s}" do
-
- before(:all) do
- User.create!(:login => 'test 1', :created_at => Time.now - 1.send(gr…
- User.create!(:login => 'test 2', :created_at => Time.now - 3.send(gr…
- User.create!(:login => 'test 3', :created_at => Time.now - 3.send(gr…
- end
-
- describe do
-
- before do
- @grouping = Kvlr::ReportsAsSparkline::Grouping.new(grouping)
- @report = Kvlr::ReportsAsSparkline::Report.new(User, :registration…
- @result = @report.run
- end
-
- it "should return an array starting reporting period (Time.now - (li…
- @result.first[0].should == Kvlr::ReportsAsSparkline::ReportingPeri…
- end
-
- it "should return data ending with with the current reporting period…
- @result.last[0].should == Kvlr::ReportsAsSparkline::ReportingPerio…
- end
-
- end
-
- it 'should return correct data for aggregation :count' do
- @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,…
- result = @report.run.to_a
-
- result[9][1].should == 0.0
- result[8][1].should == 1.0
- result[7][1].should == 0.0
- result[6][1].should == 2.0
- end
-
- it 'should return correct data for aggregation :sum' do
- @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,…
- result = @report.run().to_a
-
- result[9][1].should == 0.0
- result[8][1].should == 1.0
- result[7][1].should == 0.0
- result[6][1].should == 5.0
- end
-
- it 'should return correct data for aggregation :count when custom cond…
- @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,…
- result = @report.run(:conditions => ['login IN (?)', ['test 1', 'tes…
-
- result[9][1].should == 0.0
- result[8][1].should == 1.0
- result[7][1].should == 0.0
- result[6][1].should == 1.0
- end
-
- it 'should return correct data for aggregation :sum when custom condit…
- @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,…
- result = @report.run(:conditions => ['login IN (?)', ['test 1', 'tes…
-
- result[9][1].should == 0.0
- result[8][1].should == 1.0
- result[7][1].should == 0.0
- result[6][1].should == 2.0
- end
-
- after(:all) do
- User.destroy_all
- end
-
- after(:each) do
- Kvlr::ReportsAsSparkline::ReportCache.destroy_all
- end
-
- end
-
- end
-
- end
-
- describe '.read_data' do
-
- it 'should invoke the aggregation method on the model' do
- @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, :ag…
- User.should_receive(:count).once.and_return([])
-
- @report.send(:read_data, Time.now)
- end
-
- it 'should setup the conditions' do
- @report.should_receive(:setup_conditions).once.and_return([])
-
- @report.send(:read_data, Time.now)
- end
-
- end
-
- describe '.setup_conditions' do
-
- it 'should return conditions for date_column >= begin_at only when no cust…
- begin_at = Time.now
-
- @report.send(:setup_conditions, begin_at).should == ['created_at >= ?', …
- end
-
- it 'should return conditions for date_column >= begin_at only when an empt…
- begin_at = Time.now
-
- @report.send(:setup_conditions, begin_at, {}).should == ['created_at >= …
- end
-
- it 'should return conditions for date_column >= begin_at only when an empt…
- begin_at = Time.now
-
- @report.send(:setup_conditions, begin_at, []).should == ['created_at >= …
- end
-
- it 'should correctly include custom conditions if they are specified as a …
- begin_at = Time.now
- custom_conditions = { :first_name => 'first name', :last_name => 'last n…
-
- conditions = @report.send(:setup_conditions, begin_at, custom_conditions)
- #cannot check for equality of complete conditions array since hashes are…
- conditions[0].should include('first_name = ?')
- conditions[0].should include('last_name = ?')
- conditions[0].should include('created_at >= ?')
- conditions.should include('first name')
- conditions.should include('last name')
- conditions.should include(begin_at)
- end
-
- it 'should correctly include custom conditions if they are specified as an…
- begin_at = Time.now
- custom_conditions = ['first_name = ? AND last_name = ?', 'first name', '…
-
- @report.send(:setup_conditions, begin_at, custom_conditions).should == [
- 'first_name = ? AND last_name = ? AND created_at >= ?',
- 'first name',
- 'last name',
- begin_at
- ]
- end
-
- end
-
- describe '.ensure_valid_options' do
-
- it 'should raise an error if malformed conditions are specified' do
- lambda { @report.send(:ensure_valid_options, { :conditions => 1 }) }.sho…
- end
-
- it 'should not raise an error if conditions are specified as an Array' do
- lambda { @report.send(:ensure_valid_options, { :conditions => ['first_na…
- end
-
- it 'should not raise an error if conditions are specified as a Hash' do
- lambda { @report.send(:ensure_valid_options, { :conditions => { :first_n…
- end
-
- describe 'for context :initialize' do
-
- it 'should not raise an error if valid options are specified' do
- lambda { @report.send(:ensure_valid_options, {
- :limit => 100,
- :aggregation => :count,
- :grouping => :day,
- :date_column => :created_at,
- :value_column => :id,
- :conditions => []
- })
- }.should_not raise_error(ArgumentError)
- end
-
- it 'should raise an error if an unsupported option is specified' do
- lambda { @report.send(:ensure_valid_options, { :invalid => :option }) …
- end
-
- it 'should raise an error if an invalid aggregation is specified' do
- lambda { @report.send(:ensure_valid_options, { :aggregation => :invali…
- end
-
- it 'should raise an error if an invalid grouping is specified' do
- lambda { @report.send(:ensure_valid_options, { :grouping => :decade })…
- end
-
- it 'should raise an error if aggregation :sum is spesicied but no :value…
- lambda { @report.send(:ensure_valid_options, { :aggregation => :sum })…
- end
-
- end
-
- describe 'for context :run' do
-
- it 'should not raise an error if valid options are specified' do
- lambda { @report.send(:ensure_valid_options, { :limit => 100, :conditi…
- }.should_not raise_error(ArgumentError)
- end
-
- it 'should raise an error if an unsupported option is specified' do
- lambda { @report.send(:ensure_valid_options, { :aggregation => :sum },…
- end
-
- end
-
- end
-
-end
diff --git a/spec/other/reporting_period_spec.rb b/spec/other/reporting_period_…
@@ -1,201 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-
-describe Kvlr::ReportsAsSparkline::ReportingPeriod do
-
- describe '.date_time' do
-
- it 'should return the date and time with minutes = seconds = 0 for groupin…
- date_time = DateTime.now
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
-
- reporting_period.date_time.should == DateTime.new(date_time.year, date_t…
- end
-
- it 'should return the date part only for grouping :day' do
- date_time = DateTime.now
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
-
- reporting_period.date_time.should == date_time.to_date
- end
-
- describe 'for grouping :week' do
-
- it 'should return the date of the monday of the week date_time is in for…
- date_time = DateTime.new(2008, 11, 27)
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:…
-
- reporting_period.date_time.should == Date.new(date_time.year, date_tim…
- end
-
- it 'should return the date of the monday of the week date_time is in whe…
- date_time = DateTime.new(2008, 11, 24) #this is a monday already, shou…
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:…
-
- reporting_period.date_time.should == Date.new(date_time.year, date_tim…
- end
-
- it 'should return the date of the monday of the week date_time is in whe…
- date_time = DateTime.new(2008, 11, 1) #this is a saturday
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:…
-
- reporting_period.date_time.should == Date.new(2008, 10, 27) # expect t…
- end
-
- it 'should return the date of the monday of the week date_time is in whe…
- date_time = DateTime.new(2009, 1, 1) #this is a thursday
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr:…
-
- reporting_period.date_time.should == Date.new(2008, 12, 29) # expect t…
- end
-
- end
-
- it 'should return the date with day = 1 for grouping :month' do
- date_time = Time.now
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
-
- reporting_period.date_time.should == Date.new(date_time.year, date_time.…
- end
-
- end
-
- describe '#from_db_string' do
-
- it 'should return a reporting period with the correct date and time and wi…
- grouping = Kvlr::ReportsAsSparkline::Grouping.new(:hour)
- grouping.stub!(:date_parts_from_db_string).and_return([2008, 1, 1, 12])
-
- Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d…
- end
-
- it 'should return a reporting period with the date part only for grouping …
- grouping = Kvlr::ReportsAsSparkline::Grouping.new(:day)
- grouping.stub!(:date_parts_from_db_string).and_return([2008, 1, 1])
-
- Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d…
- end
-
- it 'should return a reporting period with the date part of the monday of t…
- grouping = Kvlr::ReportsAsSparkline::Grouping.new(:week)
- grouping.stub!(:date_parts_from_db_string).and_return([2008, 1])
-
- Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d…
- end
-
- it 'should return a reporting period with the correct date and with day = …
- grouping = Kvlr::ReportsAsSparkline::Grouping.new(:month)
- grouping.stub!(:date_parts_from_db_string).and_return([2008, 1])
-
- Kvlr::ReportsAsSparkline::ReportingPeriod.from_db_string(grouping, '').d…
- end
-
- end
-
- describe '.next' do
-
- it 'should return a reporting period with date and time one hour after the…
- now = Time.now
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
- expected = now + 1.hour
-
- reporting_period.next.date_time.should == DateTime.new(expected.year, ex…
- end
-
- it 'should return a reporting period with date one day after the current p…
- now = Time.now
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
- expected = now + 1.day
-
- reporting_period.next.date_time.should == Date.new(expected.year, expect…
- end
-
- it 'should return a reporting period with date one week after the current …
- now = DateTime.now
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
- expected = reporting_period.date_time + 1.week
-
- reporting_period.next.date_time.should == Date.new(expected.year, expect…
- end
-
- it 'should return a reporting period with date of the first day in the mon…
- now = Time.now
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::R…
- expected = reporting_period.date_time + 1.month
-
- reporting_period.next.date_time.should == Date.new(expected.year, expect…
- end
-
- end
-
- describe '.==' do
-
- it 'should return true for 2 reporting periods with the same date_time and…
- now = DateTime.now
- reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
- reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
-
- (reporting_period1 == reporting_period2).should == true
- end
-
- it 'should return false for 2 reporting periods with the same date_time bu…
- now = Time.now
- reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
- reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
-
- (reporting_period1 == reporting_period2).should == false
- end
-
- it 'should return true for 2 reporting periods with the same grouping but …
- reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
- reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
-
- (reporting_period1 == reporting_period2).should == true
- end
-
- it 'should return false for 2 reporting periods with the same grouping but…
- reporting_period1 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
- reporting_period2 = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::…
-
- (reporting_period1 == reporting_period2).should == false
- end
-
- end
-
- describe '.first' do
-
- before do
- @now = DateTime.now
- DateTime.stub!(:now).and_return(@now)
- end
-
- it 'should return a reporting period with the date part of (DateTime.now -…
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:…
- expected = @now - 2.hours
-
- reporting_period.date_time.should == DateTime.new(expected.year, expecte…
- end
-
- it 'should return a reporting period with the date part of (DateTime.now -…
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:…
- expected = @now - 2.days
-
- reporting_period.date_time.should == Date.new(expected.year, expected.mo…
- end
-
- it 'should return a reporting period with the date of the first day of the…
- DateTime.stub!(:now).and_return(DateTime.new(2008, 12, 31, 0, 0, 0))
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:…
-
- reporting_period.date_time.should == DateTime.new(2008, 10, 1)
- end
-
- it 'should return a reporting period with the date of the monday of the we…
- DateTime.stub!(:now).and_return(DateTime.new(2008, 12, 31, 0, 0, 0)) #we…
- reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.first(Kvlr:…
-
- reporting_period.date_time.should == DateTime.new(2008, 12, 15) #the mon…
- end
-
- end
-
-end
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.