Permalink
Browse files

multi report using renderer

  • Loading branch information...
1 parent fba10b4 commit 7036000bd995f88697babb6419bdd0b2fa7a1721 @RodneyTurnham RodneyTurnham committed Jul 30, 2013
@@ -4,8 +4,7 @@ class ReportsController < ApplicationController
self.responder = Dossier::Responder
- respond_to :html, :json, :csv, :xls, only: :show
- respond_to :html, only: :multi
+ respond_to :html, :json, :csv, :xls
def show
respond_with(report)
@@ -44,4 +44,10 @@ def renderer
end
delegate :render, to: :renderer
+
+ class UnsupportedFormatError < StandardError
+ def initialize(format)
+ super "Dossier::MultiReport only supports rendering in HTML format (you tried #{format})"
+ end
+ end
end
View
@@ -20,6 +20,11 @@ def to_xls
set_content_disposition!
controller.response_body = Xls.new(report.raw_results.arrays)
end
+
+ def respond
+ multi_report_html_only!
+ super
+ end
private
@@ -30,5 +35,11 @@ def set_content_disposition!
def filename
"#{report.class.filename}.#{format}"
end
+
+ def multi_report_html_only!
+ if report.is_a?(Dossier::MultiReport) and format.to_s != 'html'
+ raise Dossier::MultiReport::UnsupportedFormatError.new(format)
+ end
+ end
end
end
@@ -19,5 +19,8 @@
expect(page).to_not have_content('options be here matey!')
end
+ it "raises an UnsupportedFormatError when trying something besides HTML" do
+ expect { visit "#{path}.csv" }.to raise_error(Dossier::MultiReport::UnsupportedFormatError, /you tried csv/)
+ end
end

1 comment on commit 7036000

Contributor

nathanl commented on 7036000 Jul 31, 2013

Woo, @RodneyTurnham contributes to open source! And the crowd goes wild!

Please sign in to comment.