dossier 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. data/app/controllers/dossier/reports_controller.rb +8 -4
  2. data/app/views/dossier/reports/show.html.haml +1 -1
  3. data/lib/dossier/report.rb +4 -4
  4. data/lib/dossier/version.rb +1 -1
  5. data/lib/dossier.rb +12 -3
  6. data/spec/dossier/report_spec.rb +4 -6
  7. data/spec/dossier_spec.rb +14 -1
  8. data/spec/dummy/app/controllers/site_controller.rb +6 -1
  9. data/spec/dummy/config/routes.rb +1 -2
  10. data/spec/dummy/config/setup_load_paths.rb +0 -3
  11. data/spec/dummy/db/test.sqlite3 +0 -0
  12. data/spec/dummy/log/development.log +512 -0
  13. data/spec/dummy/log/test.log +1376 -0
  14. data/spec/dummy/tmp/cache/assets/C35/BF0/sprockets%2F64292e0008108df585a755f2876c7869 +0 -0
  15. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  16. data/spec/dummy/tmp/cache/assets/D00/EF0/sprockets%2F4e1e8b85785ee1929c8e355c96902e9c +0 -0
  17. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  18. data/spec/dummy/tmp/cache/assets/D45/6A0/sprockets%2F22f3562bf7d5e640880df2a5d683f2fc +0 -0
  19. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  20. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  21. data/spec/dummy/tmp/cache/assets/DCF/420/sprockets%2F9f127ea0ab7236994d1ceaa7bbea86c8 +0 -0
  22. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  23. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  24. data/spec/fixtures/reports/employee.html +1 -1
  25. data/spec/fixtures/reports/employee_with_custom_client.html +1 -1
  26. data/spec/requests/employee_with_custom_controller_spec.rb +13 -0
  27. data/spec/support/reports/{employee.rb → employee_report.rb} +0 -0
  28. data/spec/support/reports/{employee_with_custom_client.rb → employee_with_custom_client_report.rb} +0 -0
  29. data/spec/support/reports/{employee_with_custom_view.rb → employee_with_custom_view_report.rb} +0 -0
  30. data/spec/support/reports/hello_my_friends_report.rb +5 -0
  31. data/spec/support/reports/{test.rb → test_report.rb} +0 -0
  32. metadata +36 -12
@@ -7,7 +7,7 @@ module Dossier
7
7
  respond_to do |format|
8
8
  format.html do
9
9
  begin
10
- render template: "dossier/reports/#{report.view}", locals: {report: report}
10
+ render template: "dossier/reports/#{report_class.report_name}", locals: {report: report}
11
11
  rescue ActionView::MissingTemplate => e
12
12
  render template: 'dossier/reports/show', locals: {report: report}
13
13
  end
@@ -18,12 +18,12 @@ module Dossier
18
18
  end
19
19
 
20
20
  format.csv do
21
- headers["Content-Disposition"] = %[attachment;filename=#{params[:report]}-report_#{Time.now.strftime('%m-%d-%Y-%H%M%S')}.csv]
21
+ set_content_disposition!
22
22
  self.response_body = StreamCSV.new(report.raw_results.arrays)
23
23
  end
24
24
 
25
25
  format.xls do
26
- headers["Content-Disposition"] = %[attachment;filename=#{params[:report]}-report_#{Time.now.strftime('%m-%d-%Y-%H%M%S')}.xls]
26
+ set_content_disposition!
27
27
  self.response_body = Xls.new(report.raw_results.arrays)
28
28
  end
29
29
  end
@@ -32,7 +32,11 @@ module Dossier
32
32
  private
33
33
 
34
34
  def report_class
35
- "#{params[:report].split('_').map(&:capitalize).join}Report".constantize
35
+ Dossier.name_to_class(params[:report])
36
+ end
37
+
38
+ def set_content_disposition!
39
+ headers["Content-Disposition"] = %[attachment;filename=#{params[:report]}-report_#{Time.now.strftime('%m-%d-%Y_%H-%M-%S')}.#{params[:format]}]
36
40
  end
37
41
 
38
42
  end
@@ -18,4 +18,4 @@
18
18
  - row.each do |value|
19
19
  %th= value
20
20
 
21
- = link_to 'Download CSV', dossier_report_path(:format => 'csv', :options => params[:options]), :class => 'download-csv'
21
+ = link_to 'Download CSV', dossier_report_path(format: 'csv', options: report.options, report: report.class.report_name), class: 'download-csv'
@@ -7,6 +7,10 @@ module Dossier
7
7
 
8
8
  attr_reader :options
9
9
 
10
+ def self.report_name
11
+ Dossier.class_to_name(self)
12
+ end
13
+
10
14
  def initialize(options = {})
11
15
  @options = options.dup.with_indifferent_access
12
16
  end
@@ -34,10 +38,6 @@ module Dossier
34
38
  tap { execute }
35
39
  end
36
40
 
37
- def view
38
- self.class.name.sub(/Report\Z/, '').underscore
39
- end
40
-
41
41
  def formatter
42
42
  Dossier::Formatter
43
43
  end
@@ -1,3 +1,3 @@
1
1
  module Dossier
2
- VERSION = "2.2.0"
2
+ VERSION = "2.3.0"
3
3
  end
data/lib/dossier.rb CHANGED
@@ -2,21 +2,30 @@ require "dossier/engine"
2
2
  require "dossier/version"
3
3
 
4
4
  module Dossier
5
+ extend self
5
6
 
6
- def self.configuration
7
+ def configuration
7
8
  @configuration || configure
8
9
  end
9
10
 
10
- def self.configure
11
+ def configure
11
12
  @configuration = Configuration.new
12
13
  yield(@configuration) if block_given?
13
14
  @configuration
14
15
  end
15
16
 
16
- def self.client
17
+ def client
17
18
  configuration.client
18
19
  end
19
20
 
21
+ def class_to_name(klass)
22
+ klass.name.underscore[0..-8]
23
+ end
24
+
25
+ def name_to_class(name)
26
+ "#{name.split('_').map(&:capitalize).join}Report".constantize
27
+ end
28
+
20
29
  class ExecuteError < StandardError; end
21
30
  end
22
31
 
@@ -4,6 +4,10 @@ describe Dossier::Report do
4
4
 
5
5
  let(:report) { TestReport.new(:foo => 'bar') }
6
6
 
7
+ it "has a report name" do
8
+ TestReport.report_name.should eq('test')
9
+ end
10
+
7
11
  describe "report instances" do
8
12
  it "takes options when initializing" do
9
13
  report = TestReport.new(:foo => 'bar')
@@ -56,12 +60,6 @@ describe Dossier::Report do
56
60
  end
57
61
  end
58
62
 
59
- describe "view" do
60
- it "will infer its view name from the class name" do
61
- EmployeeReport.new.view.should eq("employee")
62
- end
63
- end
64
-
65
63
  end
66
64
 
67
65
  end
data/spec/dossier_spec.rb CHANGED
@@ -5,7 +5,7 @@ describe Dossier do
5
5
  Dossier.should be_a(Module)
6
6
  end
7
7
 
8
- it "is configuraable" do
8
+ it "is configurable" do
9
9
  Dossier.configure
10
10
  Dossier.configuration.should_not be_nil
11
11
  end
@@ -28,4 +28,17 @@ describe Dossier do
28
28
  Dossier.configuration.should_receive(:client)
29
29
  Dossier.client
30
30
  end
31
+
32
+ describe "report naming" do
33
+ let(:klass) { HelloMyFriendsReport }
34
+ let(:name) { 'hello_my_friends' }
35
+
36
+ it "converts a report class to a report name" do
37
+ expect(Dossier.class_to_name(klass)).to eq(name)
38
+ end
39
+
40
+ it "converting a report name to a report class" do
41
+ expect(Dossier.name_to_class(name)).to eq(klass)
42
+ end
43
+ end
31
44
  end
@@ -1,5 +1,10 @@
1
- class SiteController
1
+ class SiteController < ApplicationController
2
2
  def index
3
3
  render text: 'wooo!'
4
4
  end
5
+
6
+ def report
7
+ report = EmployeeReport.new
8
+ render template: 'dossier/reports/show', locals: {report: report.run}
9
+ end
5
10
  end
@@ -1,5 +1,4 @@
1
1
  Rails.application.routes.draw do
2
- mount Dossier::Engine => "/dossier"
3
-
4
2
  get 'woo' => 'site#index', as: 'woo'
3
+ get 'employee_report_custom_controller' => 'site#report', as: 'employee_report_custom_controller'
5
4
  end
@@ -1,8 +1,5 @@
1
1
  if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
2
2
  begin
3
- rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
4
- rvm_lib_path = File.join(rvm_path, 'lib')
5
- $LOAD_PATH.unshift rvm_lib_path
6
3
  require 'rvm'
7
4
  RVM.use_from_path! File.dirname(File.dirname(__FILE__))
8
5
  rescue LoadError
Binary file