Skip to content

Commit

Permalink
Added namespace support for reports
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhunter committed May 28, 2013
1 parent 5e3c2b4 commit 5182583
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion 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'

Expand Down
4 changes: 2 additions & 2 deletions 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
3 changes: 2 additions & 1 deletion lib/dossier.rb
Expand Up @@ -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
Expand All @@ -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"
4 changes: 4 additions & 0 deletions lib/dossier/report.rb
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions spec/dossier/report_spec.rb
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/dossier_spec.rb
Expand Up @@ -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
9 changes: 9 additions & 0 deletions 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.