dossier 2.8.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/app/controllers/dossier/reports_controller.rb +2 -2
  4. data/app/views/dossier/reports/multi.html.haml +5 -5
  5. data/app/views/dossier/reports/show.html.haml +1 -1
  6. data/lib/dossier/multi_report.rb +16 -0
  7. data/lib/dossier/report.rb +4 -0
  8. data/lib/dossier/responder.rb +11 -0
  9. data/lib/dossier/result.rb +16 -12
  10. data/lib/dossier/version.rb +1 -1
  11. data/spec/dossier/responder_spec.rb +1 -1
  12. data/spec/dossier/result_spec.rb +24 -1
  13. data/spec/dummy/app/reports/employee_with_custom_view_report.rb +1 -1
  14. data/spec/dummy/db/test.sqlite3 +0 -0
  15. data/spec/dummy/log/test.log +266 -46790
  16. data/spec/features/combination_report_spec.rb +3 -0
  17. data/spec/features/employee_spec.rb +8 -0
  18. data/spec/fixtures/db/mysql2.yml +1 -1
  19. data/spec/fixtures/db/mysql2.yml.example +1 -1
  20. metadata +3 -35
  21. data/spec/dummy/log/development.log +0 -4378
  22. data/spec/dummy/tmp/cache/assets/C35/BF0/sprockets%2F64292e0008108df585a755f2876c7869 +0 -0
  23. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  24. data/spec/dummy/tmp/cache/assets/CEA/5A0/sprockets%2Fc0534884cbc43494a05d9e957ea1298d +0 -0
  25. data/spec/dummy/tmp/cache/assets/D00/EF0/sprockets%2F4e1e8b85785ee1929c8e355c96902e9c +0 -0
  26. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  27. data/spec/dummy/tmp/cache/assets/D40/0D0/sprockets%2F15a6bb0a1346b6d7fe859c14bf729a49 +0 -0
  28. data/spec/dummy/tmp/cache/assets/D45/6A0/sprockets%2F22f3562bf7d5e640880df2a5d683f2fc +0 -0
  29. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  30. data/spec/dummy/tmp/cache/assets/D51/510/sprockets%2Fca0353abc266080173bbc3c13efa935a +0 -0
  31. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  32. data/spec/dummy/tmp/cache/assets/D6C/400/sprockets%2F7fa180a6e05c7ca4346ef58c54bb30f8 +0 -0
  33. data/spec/dummy/tmp/cache/assets/DCF/420/sprockets%2F9f127ea0ab7236994d1ceaa7bbea86c8 +0 -0
  34. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  35. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  36. data/spec/dummy/tmp/restart.txt +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b964aa00e953df017cd8772cd0ed975301b841bd
4
- data.tar.gz: c8faa33c28dec8b77a253918d089eea36d41c06d
3
+ metadata.gz: 654b5bc958cd0b8226eb0f4048c88540fa3024db
4
+ data.tar.gz: 4dd0180bd6e67e797fc003342b13c9fbc093d138
5
5
  SHA512:
6
- metadata.gz: 4557b660e38d7b8a6b8aeb4bd7a7579ae0bc5eeea214bf3a6a02bd45330b95bd120bacb8cf9905cf5c4bf47922f6f37f7d57ba2ffff6bc8e660867556e02653a
7
- data.tar.gz: 27c413936b6b22c1c4f977eb7546419b92f8804df1908e6346b82ce3f3f74e0bdcc42b182d7300a799b2f43c0658a25d7d12c8c869455036ef0b0ae6e292c1a4
6
+ metadata.gz: 5b53a3128c5e0042ee01621f49dc931c1f9cd5480b1b3e7a66517f8fa6b05b97797accded6927604da3e8e28ed7c3b2650b15fbab33ea120ae37c60f166985f6
7
+ data.tar.gz: a92771615847f0460bdb3fdca9e43730e9d14ccfa440b51fc73379f97964f0cf380a714620da2324a2547e11e77f0c214799397455169722e19a940a90ca3f6b
data/README.md CHANGED
@@ -272,6 +272,7 @@ See the referenced gems for more documentation on using them.
272
272
  Note: when you run the tests, Dossier will **make and/or truncate** some tables in the `dossier_test` database.
273
273
 
274
274
  - Run `bundle`
275
+ - `RAILS_ENV=test rake db:create`
275
276
  - `cp spec/dummy/config/database.yml{.example,}` and edit it so that it can connect to the test database.
276
277
  - `cp spec/fixtures/db/mysql2.yml{.example,}`
277
278
  - `cp spec/fixtures/db/sqlite3.yml{.example,}`
@@ -4,14 +4,14 @@ module Dossier
4
4
 
5
5
  self.responder = Dossier::Responder
6
6
 
7
- respond_to :html, :json, :csv, :xls, only: :show
7
+ respond_to :html, :json, :csv, :xls
8
8
 
9
9
  def show
10
10
  respond_with(report)
11
11
  end
12
12
 
13
13
  def multi
14
- render template: 'dossier/reports/multi', locals: {multi: report}
14
+ respond_with(report)
15
15
  end
16
16
 
17
17
  private
@@ -1,8 +1,8 @@
1
- %div{id: multi.dom_id}
1
+ %div{id: report.dom_id}
2
2
  %h1.dossier-multi-header
3
- = multi.formatted_title
3
+ = report.formatted_title
4
4
 
5
- = render_options(multi)
5
+ = render_options(report)
6
6
 
7
- - multi.reports.each do |report|
8
- = report.render layout: false
7
+ - report.reports.each do |r|
8
+ = r.render layout: false
@@ -8,7 +8,7 @@
8
8
  %thead
9
9
  %tr
10
10
  - report.results.headers.each do |header|
11
- %th= report.format_header(header)
11
+ %th= header
12
12
  %tbody
13
13
  - report.results.body.each do |row|
14
14
  %tr
@@ -34,4 +34,20 @@ class Dossier::MultiReport
34
34
  def dom_id
35
35
  nil
36
36
  end
37
+
38
+ def template
39
+ 'multi'
40
+ end
41
+
42
+ def renderer
43
+ @renderer ||= Dossier::Renderer.new(self)
44
+ end
45
+
46
+ delegate :render, to: :renderer
47
+
48
+ class UnsupportedFormatError < StandardError
49
+ def initialize(format)
50
+ super "Dossier::MultiReport only supports rendering in HTML format (you tried #{format})"
51
+ end
52
+ end
37
53
  end
@@ -55,6 +55,10 @@ module Dossier
55
55
  formatter.titleize(header.to_s)
56
56
  end
57
57
 
58
+ def format_column(column, value)
59
+ value
60
+ end
61
+
58
62
  def dossier_client
59
63
  Dossier.client
60
64
  end
@@ -20,6 +20,11 @@ module Dossier
20
20
  set_content_disposition!
21
21
  controller.response_body = Xls.new(report.raw_results.arrays)
22
22
  end
23
+
24
+ def respond
25
+ multi_report_html_only!
26
+ super
27
+ end
23
28
 
24
29
  private
25
30
 
@@ -30,5 +35,11 @@ module Dossier
30
35
  def filename
31
36
  "#{report.class.filename}.#{format}"
32
37
  end
38
+
39
+ def multi_report_html_only!
40
+ if report.is_a?(Dossier::MultiReport) and format.to_s != 'html'
41
+ raise Dossier::MultiReport::UnsupportedFormatError.new(format)
42
+ end
43
+ end
33
44
  end
34
45
  end
@@ -43,6 +43,13 @@ module Dossier
43
43
  end
44
44
 
45
45
  class Formatted < Result
46
+
47
+ alias :raw_headers :headers
48
+
49
+ def headers
50
+ @formatted_headers ||= super.map { |h| report.format_header(h) }
51
+ end
52
+
46
53
  def each
47
54
  adapter_results.rows.each { |row| yield format(row) }
48
55
  end
@@ -52,20 +59,17 @@ module Dossier
52
59
  raise ArgumentError.new("#{row.inspect} must be a kind of Enumerable")
53
60
  end
54
61
 
55
- row.each_with_index.map do |field, i|
56
- method_name = "format_#{headers[i]}"
57
-
58
- if report.respond_to?(method_name)
59
-
60
- # Provide the row as context if the formatter takes two arguments
61
- if report.method(method_name).arity == 2
62
- report.public_send(method_name, field, row_hash(row))
63
- else
64
- report.public_send(method_name, field)
65
- end
62
+ row.each_with_index.map do |value, i|
63
+ column = raw_headers.at(i)
64
+ method = "format_#{column}"
66
65
 
66
+ if report.respond_to?(method)
67
+ args = [method, value]
68
+ # Provide the row as context if the formatter takes two arguments
69
+ args << row_hash(row) if report.method(method).arity == 2
70
+ report.public_send(*args)
67
71
  else
68
- field
72
+ report.format_column(column, value)
69
73
  end
70
74
  end
71
75
  end
@@ -1,3 +1,3 @@
1
1
  module Dossier
2
- VERSION = "2.8.0"
2
+ VERSION = "2.9.0"
3
3
  end
@@ -9,7 +9,7 @@ describe Dossier::Responder do
9
9
  }
10
10
  end
11
11
 
12
- let(:results) { mock(arrays: [[]], hashes: [{}]) }
12
+ let(:results) { double(arrays: [[]], hashes: [{}]) }
13
13
  let(:report) { EmployeeReport.new }
14
14
  let(:reports) { [stub_out_report_results(report)] }
15
15
  let(:controller) {
@@ -56,6 +56,13 @@ describe Dossier::Result do
56
56
 
57
57
  let(:result) { Dossier::Result::Formatted.new(adapter_result, report) }
58
58
 
59
+ describe "headers" do
60
+ it "formats the headers by calling format_header" do
61
+ adapter_result.headers.each { |h| result.report.should_receive(:format_header).with(h) }
62
+ result.headers
63
+ end
64
+ end
65
+
59
66
  describe "each" do
60
67
 
61
68
  it "calls :each on on its adapter's results" do
@@ -71,11 +78,27 @@ describe Dossier::Result do
71
78
  end
72
79
 
73
80
  describe "format" do
81
+ let(:report) {
82
+ Class.new(Dossier::Report) {
83
+ def format_mascot(value); value.upcase; end
84
+ }.new
85
+ }
86
+
87
+ let(:row) { result_row.values }
74
88
 
75
- it "it raises unless its argument responds to :[]" do
89
+ it "raises unless its argument responds to :[]" do
76
90
  expect {result.format(Object.new)}.to raise_error(ArgumentError)
77
91
  end
78
92
 
93
+ it "calls a custom formatter method if available" do
94
+ result.report.should_receive(:format_mascot).with('platapus')
95
+ result.format(row)
96
+ end
97
+
98
+ it "calls the default format_column method otherwise" do
99
+ result.report.should_receive(:format_column).with('cheese', 'bleu')
100
+ result.format(row)
101
+ end
79
102
  end
80
103
 
81
104
  describe "footer" do
@@ -18,7 +18,7 @@ class EmployeeWithCustomViewReport < Dossier::Report
18
18
  end
19
19
 
20
20
  module CustomFormatter
21
- include Dossier::Formatter
21
+ extend Dossier::Formatter
22
22
  def margery_butts(word)
23
23
  "Margery Butts #{word}"
24
24
  end
Binary file