Permalink
Browse files

All tests passing.

  • Loading branch information...
1 parent 3e70fbe commit 1a2876650ccce1f39065a9dfd8cdedae0ed280b7 @wayneeseguin committed Jul 1, 2009
@@ -24,7 +24,13 @@ class << self
# Views setter and accessor.
def views(*array)
@views ||= ["#{File::dirname(File::expand_path(__FILE__))}/views/"]
- array ? @views += array : @views
+ unless array.empty?
+ @views.unshift(array)
+ @views.flatten!
+ @views.uniq!
+ else
+ @views
+ end
end
# class level options accessor
@@ -100,7 +106,11 @@ def class_name(value = nil)
# OrdersReport.template # => :orders
#
def template(value = nil)
- value ? options[:template] = value : options[:template]
+ if value
+ @template = value
+ options[:template] = @template
+ end
+ @template ||= nil
end
# Accessor for columns
@@ -201,10 +211,15 @@ def on(records)
def initialize(records, *new_options)
new_options = new_options.shift || {}
@records = records
- @views = []
- @views << new_options.delete(:views) if new_options[:views]
- @views += self.class.views
+
+ @views = self.class.views
+ @views.unshift(new_options.delete(:views)) if new_options[:views]
+ @views.flatten!
+ @views.uniq!
+
+ @template = self.class.template
@template = new_options.delete(:template) if new_options[:template]
+
@options = self.class.options.merge!(new_options)
@options.each_pair do |key,value|
if key == "chart"
@@ -233,6 +248,7 @@ def to_html(*options)
options = (options.shift || {}).merge!(@options || {})
# todo: if rails is loaded set the default engine: dynamicreports::report.default_engine
engine = options.delete(:engine) || @@default_engine
+ options[:template] = self.class.template
view.__send__("#{engine}", options)
end
@@ -4,7 +4,6 @@ class ChartsTest < Test::Unit::TestCase
class TheReport < DynamicReports::Report
chart :the_chart_name, :an => "option", :another => "option" do
title "awesome report!"
- sub_title "you won't need another!"
type :svg
height "350"
width "250"
@@ -17,7 +16,19 @@ class TheReport < DynamicReports::Report
end
end
- teardown do
+ should "allow specification of options to the chart beyond it's attributes." do
+ hash = {
+ :name => :the_chart_name,
+ :an => "option",
+ :type => :svg,
+ :another => "option",
+ :title=>"awesome report!",
+ :height=>"350",
+ :width=>"250",
+ :columns=>[:pageviews],
+ :label_column => "created_at"
+ }
+ assert_equal hash, TheReport.chart_with_name(:the_chart_name).options
end
should "allow setting their name" do
@@ -40,20 +51,6 @@ class TheReport < DynamicReports::Report
assert_equal "350", TheReport.chart_with_name(:the_chart_name).height
end
-
- should "allow specification of options to the chart beyond it's attributes." do
- hash = {
- :name => :the_chart_name,
- :an => "option",
- :another => "option",
- :title=>"awesome report!",
- :height=>"350",
- :width=>"250",
- :columns=>[:pageviews]
- }
- assert_equal hash, TheReport.chart_with_name(:the_chart_name).options
- end
-
should "allow definition of multiple charts" do
#require "ruby-debug" ; debugger
assert_contains TheReport.charts[0].name, :the_chart_name
@@ -18,9 +18,6 @@ class TheReport < DynamicReports::Report
@object_records = DynamicReports::Test::ObjectRecords.generate(TheReport, :count => 10)
end
- teardown do
- end
-
should "allow setting the title of a report" do
assert_equal "Daily Report", TheReport.title
end
@@ -29,10 +26,6 @@ class TheReport < DynamicReports::Report
assert_equal "Happens every day, ya!", TheReport.sub_title
end
- #should "allow setting the report template base (not type/extension)" do
- # assert_equal TheReport.template, "my_special_template"
- #end
-
should "allow setting the columns to report on" do
assert_equal [:recorded_at, :viewed_on, :pageviews_count, :visits_count, :conversions_count], TheReport.columns
end
@@ -50,7 +43,7 @@ class TheReport < DynamicReports::Report
assert_match(/class="report_charts"/, TheReport.on(@array_records).to_html)
end
- context "Report with template specified" do
+ context "Report with templates and views specified" do
setup do
class SpecificTemplateReport < DynamicReports::Report
name "A report with specified template!"
@@ -64,9 +57,6 @@ class SpecificTemplateReport < DynamicReports::Report
@object_records = DynamicReports::Test::ObjectRecords.generate(SpecificTemplateReport, :count => 10)
end
- teardown do
- end
-
should "allow setting of the views directories" do
assert_contains SpecificTemplateReport.views,
"#{File::dirname(File::expand_path(__FILE__))}/views/"
@@ -1,27 +1,5 @@
class ReportsTest < Test::Unit::TestCase
- context "Views" do
-
- setup do
- class ViewTestReport < DynamicReports::Report
- name "Report for testing views."
- title "Test la views!"
- columns :recorded_at, :viewed_on, :pageviews_count, :visits_count, :conversions_count
- template :specific_template
- views "#{File::dirname(File::expand_path(__FILE__))}/views/"
- end
- @array_records = DynamicReports::Test::ArrayRecords.generate(ViewTestReport, :count => 10)
- @report = ViewTestReport.on(@array_records)
- @view = DynamicReports::View.new(@report)
- end
-
- should "have the same views path as the report object it is called with" do
- assert_equal @report.views, @view.views
- end
-
- should "render a specific_template when specified" do
- assert_equal "This is the specified template!",
- @view.__send__("#{:erb}", ViewTestReport.options).strip
- end
+ context "View" do
end
end

0 comments on commit 1a28766

Please sign in to comment.