report_method_spec.rb - reportable - Fork of reportable required by WarVox, from hdm/reportable.
(HTM) git clone git://jay.scot/reportable
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
report_method_spec.rb (1987B)
---
1 require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))),'spec_helper')
2
3 describe Saulabs::Reportable do
4
5 ActiveRecord::Base.class_eval do
6 include Saulabs::Reportable::RailsAdapter
7 end
8
9 class User < ActiveRecord::Base
10 reportable :registrations, :limit => 10
11 end
12
13 class SpecialUser < User; end
14
15 before(:all) do
16 User.create!(:login => 'test 1', :created_at => Time.now - 1.days, :profile_visits => 1)
17 User.create!(:login => 'test 2', :created_at => Time.now - 2.days, :profile_visits => 2)
18 end
19
20 it 'should return a Saulabs::Reportable::ResultSet' do
21 User.registrations_report.should be_instance_of(Saulabs::Reportable::ResultSet)
22 end
23
24 it 'should return a result set that stores the name of the model the report was invoked on' do
25 User.registrations_report.model_name.should == User.name
26 end
27
28 it 'should return a result set that stores the name of the report that was invoked' do
29 User.registrations_report.report_name.should == 'registrations'
30 end
31
32 describe 'for inherited models' do
33
34 before(:all) do
35 SpecialUser.create!(:login => 'test 3', :created_at => Time.now - 2.days, :profile_visits => 3)
36 end
37
38 it 'should return a result set that stores the model the report was invoked on' do
39 SpecialUser.registrations_report.model_name.should == SpecialUser.name
40 end
41
42 it 'should include all data when invoked on the base model class' do
43 result = User.registrations_report.to_a
44
45 result[9][1].should == 1.0
46 result[8][1].should == 2.0
47 end
48
49 it 'should include only data for instances of the inherited model when invoked on the inherited model class' do
50 result = SpecialUser.registrations_report.to_a
51
52 result[9][1].should == 0.0
53 result[8][1].should == 1.0
54 end
55
56 after(:all) do
57 SpecialUser.destroy_all
58 end
59
60 end
61
62 after do
63 Saulabs::Reportable::ReportCache.destroy_all
64 end
65
66 after(:all) do
67 User.destroy_all
68 end
69
70 end
71