Introduction
Introduction Statistics Contact Development Disclaimer Help
added specs for ResultSet and ResultSet class itself - reportable - Fork of rep…
Log
Files
Refs
README
---
commit 9b6f36fede4867bc4942797ae213df70084cbdbc
parent bd7abefecd4586413307561c5ff84c683870058f
Author: Marco Otte-Witte <[email protected]>
Date: Wed, 21 Apr 2010 16:01:03 +0200
added specs for ResultSet and ResultSet class itself
Diffstat:
A lib/saulabs/reportable/result_set.… | 40 +++++++++++++++++++++++++++…
M spec/other/report_method_spec.rb | 23 +++++++++++++++++++++++
2 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/lib/saulabs/reportable/result_set.rb b/lib/saulabs/reportable/resu…
@@ -0,0 +1,40 @@
+module Saulabs
+
+ module Reportable
+
+ # A result set as it is returned by the report methods.
+ # This is basically a subclass of +Array+ that adds two
+ # attributes, +model_name+ and +report_name+ that store
+ # the name of the model and the report the result set
+ # was generated from.
+ #
+ class ResultSet < ::Array
+
+ # the name of the model the result set is based on
+ #
+ attr_reader :model_name
+
+ # the name of the report the result is based on
+ #
+ attr_reader :report_name
+
+ # Initializes a new result set.
+ #
+ # @param [Array] array
+ # the array that is the actual result
+ # @param [String] model_name
+ # the name of the model the result set is based on
+ # @param [String] report_name
+ # the name of the report the result is based on
+ #
+ def initialize(array, model_name, report_name)
+ super(array)
+ @model_name = model_name
+ @report_name = report_name.to_s
+ end
+
+ end
+
+ end
+
+end
diff --git a/spec/other/report_method_spec.rb b/spec/other/report_method_spec.rb
@@ -2,6 +2,23 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
describe Saulabs::Reportable do
+ before(:all) do
+ User.create!(:login => 'test 1', :created_at => Time.now - 1.days, :profi…
+ User.create!(:login => 'test 2', :created_at => Time.now - 2.days, :profil…
+ end
+
+ it 'should return a Saulabs::Reportable::ResultSet' do
+ User.registrations_report.should be_instance_of(Saulabs::Reportable::Resul…
+ end
+
+ it 'should return a result set that stores the name of the model the report …
+ User.registrations_report.model_name.should == User.name
+ end
+
+ it 'should return a result set that stores the name of the report that was i…
+ User.registrations_report.report_name.should == 'registrations'
+ end
+
describe 'for inherited models' do
before(:all) do
@@ -10,6 +27,10 @@ describe Saulabs::Reportable do
SpecialUser.create!(:login => 'test 3', :created_at => Time.now - 2.days…
end
+ it 'should return a result set that stores the model the report was invoke…
+ SpecialUser.registrations_report.model_name.should == SpecialUser.name
+ end
+
it 'should include all data when invoked on the base model class' do
result = User.registrations_report.to_a
@@ -38,7 +59,9 @@ describe Saulabs::Reportable do
end
class User < ActiveRecord::Base
+
reportable :registrations, :limit => 10
+
end
class SpecialUser < User; 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.