Permalink
Browse files

Added namespace support for reports

  • Loading branch information...
1 parent 5e3c2b4 commit 5182583cba0abd25c1c123569bef10c98875bd97 @adamhunter adamhunter committed May 28, 2013
View
6 CHANGELOG.md
@@ -2,6 +2,12 @@
Dossier does its best to use [semantic versioning](http://semver.org).
+## Unreleased
+- Support namespaces for report names (`cats/are/super_fun` => `Cats::Are::SuperRunReport`
+
+## v2.7.0
+- Added `formatted_dossier_report_path` helper method
+
## v2.6.0
- Support ability to combine reports into a macro report using the Dossier::MultiReport class
View
2 app/views/dossier/reports/show.html.haml
@@ -1,4 +1,4 @@
-%h1= report.class.name.titleize
+%h1= report.formatted_title
= link_to 'Download CSV', dossier_report_path(format: 'csv', options: report.options, report: report.class.report_name), class: 'download-csv'
View
4 config/routes.rb
@@ -1,6 +1,6 @@
Rails.application.routes.draw do
- get "reports/:report", to: 'dossier/reports#show', as: :dossier_report
- get "multi/reports/:report", to: 'dossier/reports#multi', as: :dossier_multi_report
+ get "reports/*report", to: 'dossier/reports#show', as: :dossier_report
+ get "multi/reports/*report", to: 'dossier/reports#multi', as: :dossier_multi_report
end
View
3 lib/dossier.rb
@@ -23,7 +23,7 @@ def class_to_name(klass)
end
def name_to_class(name)
- "#{name.split('_').map(&:capitalize).join}Report".constantize
+ "#{name}_report".classify.constantize
end
class ExecuteError < StandardError; end
@@ -37,6 +37,7 @@ class ExecuteError < StandardError; end
require "dossier/multi_report"
require "dossier/query"
require "dossier/report"
+require "dossier/responder"
require "dossier/result"
require "dossier/stream_csv"
require "dossier/xls"
View
4 lib/dossier/report.rb
@@ -46,6 +46,10 @@ def format_header(header)
formatter.titleize(header.to_s)
end
+ def formatted_title
+ format_header("#{self.class.report_name.gsub('/', ' ')} Report")
+ end
+
def dossier_client
Dossier.client
end
View
6 spec/dossier/report_spec.rb
@@ -20,18 +20,20 @@ def format_header(header)
end
it "takes options when initializing" do
- report = TestReport.new(:foo => 'bar')
report.options.should eq('foo' => 'bar')
end
it 'generates column headers' do
- report = TestReport.new(:foo => 'bar')
report.format_header('Foo').should eq 'Foo'
end
it 'allows for column header customization' do
report_with_custom_header.format_header(:generic).should eq 'customized'
end
+
+ it "has a formatted title" do
+ expect(report.formatted_title).to eq 'Test Report'
+ end
end
describe "callbacks" do
View
13 spec/dossier_spec.rb
@@ -40,5 +40,18 @@
it "converting a report name to a report class" do
expect(Dossier.name_to_class(name)).to eq(klass)
end
+
+ describe "with namespaces" do
+ let(:klass) { Cats::Are::SuperFunReport }
+ let(:name) { 'cats/are/super_fun' }
+
+ it "converts a report class to a report name" do
+ expect(Dossier.class_to_name klass).to eq name
+ end
+
+ it "converts a report name to a report class" do
+ expect(Dossier.name_to_class name).to eq klass
+ end
+ end
end
end
View
9 spec/support/reports/cats/are/super_fun_report.rb
@@ -0,0 +1,9 @@
+module Cats
+ module Are
+ class SuperFunReport < Dossier::Report
+ def sql
+ "select * from cats where fun = true" # Doesn't matter; not meant to be run.
+ end
+ end
+ end
+end

0 comments on commit 5182583

Please sign in to comment.