dossier 2.10.0 → 2.11.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93987008f6194c281702669957217d7a95c69e58
4
- data.tar.gz: 9549de90bae8c4d2e92b0090670bd70a9b4b6b9c
3
+ metadata.gz: 5750b4e9b45d224d36b0781ac414430996424e5d
4
+ data.tar.gz: 82b8a612bf19b8b07244a7aa70ea7f7b0369f4ab
5
5
  SHA512:
6
- metadata.gz: abb7438d57a7d8f724054c371f5dc324773f63eeb783be4de9690206d24435199e24df268bb46b360120fc66f7aaf3f194ed567371f82f8ad0c2ae2d5edc3379
7
- data.tar.gz: 3bf60dc6132b439fe35b0f35115a253f20b7f56b7b12f0a4c0a77fee2a66eaea4dbf1983f94c507aed376e0b4f39449051c818dace505827c114cfd542c08b09
6
+ metadata.gz: cfdb1e481e2f1f3ff757f6a96a4203efc720665b71923ef56d3dae8d4afccc8e0ec9636d81b7a292316f6f4ba76a3d25aa831a3486fdd85b3a74fe9ce23ad56a
7
+ data.tar.gz: 19a70f10f3d8d60f0df04da43cdb18aa370c0f83961c2845d09f64935bcc2d16e29e31fa9299822ec9590c4dd129279c373d50e4e700bb8a56610090e00fa4bc
@@ -13,12 +13,12 @@ module Dossier
13
13
 
14
14
  def to_csv
15
15
  set_content_disposition!
16
- controller.response_body = StreamCSV.new(report.raw_results.arrays)
16
+ controller.response_body = StreamCSV.new(*collection_and_headers(report.raw_results.arrays))
17
17
  end
18
18
 
19
19
  def to_xls
20
20
  set_content_disposition!
21
- controller.response_body = Xls.new(report.raw_results.arrays)
21
+ controller.response_body = Xls.new(*collection_and_headers(report.raw_results.arrays))
22
22
  end
23
23
 
24
24
  def respond
@@ -31,6 +31,11 @@ module Dossier
31
31
  def set_content_disposition!
32
32
  controller.headers["Content-Disposition"] = %[attachment;filename=#{filename}]
33
33
  end
34
+
35
+ def collection_and_headers(collection)
36
+ headers = collection.shift.map { |header| report.format_header(header) }
37
+ [collection, headers]
38
+ end
34
39
 
35
40
  def filename
36
41
  "#{report.class.filename}.#{format}"
@@ -10,7 +10,7 @@ module Dossier
10
10
  end
11
11
 
12
12
  def each
13
- yield headers.map { |header| Dossier::Formatter.titleize(header) }.to_csv if headers?
13
+ yield headers.to_csv if headers?
14
14
  collection.each do |record|
15
15
  yield record.to_csv
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Dossier
2
- VERSION = "2.10.0"
2
+ VERSION = "2.11.0"
3
3
  end
data/lib/dossier/xls.rb CHANGED
@@ -11,7 +11,7 @@ module Dossier
11
11
 
12
12
  def each
13
13
  yield HEADER
14
- yield headers_as_row
14
+ yield as_row(@headers)
15
15
  @collection.each { |record| yield as_row(record) }
16
16
  yield FOOTER
17
17
  end
@@ -26,9 +26,5 @@ module Dossier
26
26
  my_array = array.map{|a| as_cell(a)}.join("\n")
27
27
  "<Row>\n" + my_array + "\n</Row>\n"
28
28
  end
29
-
30
- def headers_as_row
31
- as_row(@headers.map { |header| Dossier::Formatter.titleize(header) })
32
- end
33
29
  end
34
30
  end
@@ -10,7 +10,7 @@ describe Dossier::Adapter::ActiveRecord::Result do
10
10
  let(:fake_columns) { %[foo bar] }
11
11
 
12
12
  it "calls `columns` on its connection_results" do
13
- ar_connection_results.should_receive(:columns)
13
+ expect(ar_connection_results).to receive(:columns)
14
14
  result.headers
15
15
  end
16
16
 
@@ -11,7 +11,7 @@ describe Dossier::Adapter::ActiveRecord do
11
11
  let(:clean_value) { "'Robert\\'); DROP TABLE Students;--'" }
12
12
 
13
13
  it "delegates to the connection" do
14
- ar_connection.should_receive(:quote).with(dirty_value)
14
+ expect(ar_connection).to receive(:quote).with(dirty_value)
15
15
  adapter.escape(dirty_value)
16
16
  end
17
17
 
@@ -29,13 +29,13 @@ describe Dossier::Adapter::ActiveRecord do
29
29
  let(:adapter_result_class) { Dossier::Adapter::ActiveRecord::Result}
30
30
 
31
31
  it "delegates to the connection" do
32
- ar_connection.should_receive(:exec_query).with("\n#{query}")
32
+ expect(ar_connection).to receive(:exec_query).with("\n#{query}")
33
33
  adapter.execute(query)
34
34
  end
35
35
 
36
36
  it "builds an adapter result" do
37
37
  ar_connection.stub(:exec_query).and_return(connection_results)
38
- adapter_result_class.should_receive(:new).with(connection_results)
38
+ expect(adapter_result_class).to receive(:new).with(connection_results)
39
39
  adapter.execute(:query)
40
40
  end
41
41
 
@@ -31,7 +31,7 @@ describe Dossier::Client do
31
31
  end
32
32
 
33
33
  it "uses an adapter by that name" do
34
- Dossier::Adapter::SpecAdapter.should_receive(:new).with(username: 'Timmy')
34
+ expect(Dossier::Adapter::SpecAdapter).to receive(:new).with(username: 'Timmy')
35
35
  described_class.new(dossier_adapter: 'spec_adapter', username: 'Timmy')
36
36
  end
37
37
 
@@ -48,7 +48,7 @@ describe Dossier::Client do
48
48
  end
49
49
 
50
50
  it "uses that ORM's adapter" do
51
- Dossier::Adapter::ActiveRecord.should_receive(:new).with(username: 'Jimmy')
51
+ expect(Dossier::Adapter::ActiveRecord).to receive(:new).with(username: 'Jimmy')
52
52
  described_class.new(username: 'Jimmy')
53
53
  end
54
54
 
@@ -94,12 +94,12 @@ describe Dossier::Client do
94
94
  end
95
95
 
96
96
  it "delegates `escape` to its adapter" do
97
- adapter.should_receive(:escape).with('Bobby Tables')
97
+ expect(adapter).to receive(:escape).with('Bobby Tables')
98
98
  client.escape('Bobby Tables')
99
99
  end
100
100
 
101
101
  it "delegates `execute` to its adapter" do
102
- adapter.should_receive(:execute).with('SELECT * FROM `primes`') # It's OK, it's in the cloud!
102
+ expect(adapter).to receive(:execute).with('SELECT * FROM `primes`') # It's OK, it's in the cloud!
103
103
  client.execute('SELECT * FROM `primes`')
104
104
  end
105
105
 
@@ -16,7 +16,7 @@ describe Dossier::Configuration do
16
16
  describe "client" do
17
17
  it "uses config/dossier.yml to setup the client" do
18
18
  options = YAML.load_file(Rails.root.join('config', 'dossier.yml'))[Rails.env].symbolize_keys
19
- Dossier::Client.should_receive(:new).with(options)
19
+ expect(Dossier::Client).to receive(:new).with(options)
20
20
  Dossier.configure
21
21
  end
22
22
 
@@ -12,7 +12,7 @@ describe Dossier::MultiReport do
12
12
 
13
13
  it "passes options to the sub reports" do
14
14
  combined_report.reports.each do |report|
15
- report.should_receive(:new).with(options).and_call_original
15
+ expect(report).to receive(:new).with(options).and_call_original
16
16
  end
17
17
 
18
18
  report.reports
@@ -24,9 +24,9 @@ describe Dossier::Query do
24
24
  end
25
25
 
26
26
  it "escapes the values" do
27
- query.should_receive(:escape).with(92)
28
- query.should_receive(:escape).with(3.14)
29
- query.should_receive(:escape).with('2013-03-29')
27
+ expect(query).to receive(:escape).with(92)
28
+ expect(query).to receive(:escape).with(3.14)
29
+ expect(query).to receive(:escape).with('2013-03-29')
30
30
  query.to_s
31
31
  end
32
32
 
@@ -44,10 +44,10 @@ describe Dossier::Query do
44
44
  end
45
45
 
46
46
  it "escapes each value in the array" do
47
- Dossier.client.should_receive(:escape).with(38)
48
- Dossier.client.should_receive(:escape).with('blue')
49
- Dossier.client.should_receive(:escape).with('mandible')
50
- Dossier.client.should_receive(:escape).with(2)
47
+ expect(Dossier.client).to receive(:escape).with(38)
48
+ expect(Dossier.client).to receive(:escape).with('blue')
49
+ expect(Dossier.client).to receive(:escape).with('mandible')
50
+ expect(Dossier.client).to receive(:escape).with(2)
51
51
  query.to_s
52
52
  end
53
53
 
@@ -14,7 +14,7 @@ describe Dossier::Renderer do
14
14
  let(:template) { report.report_name }
15
15
 
16
16
  it "renders the custom view" do
17
- engine.should_receive(:render).with(options)
17
+ expect(engine).to receive(:render).with(options)
18
18
  end
19
19
  end
20
20
 
@@ -22,8 +22,8 @@ describe Dossier::Renderer do
22
22
  let(:template) { 'show' }
23
23
 
24
24
  it "renders show" do
25
- engine.should_receive(:render).with(options.merge(template: 'dossier/reports/employee')).and_call_original
26
- engine.should_receive(:render).with(options)
25
+ expect(engine).to receive(:render).with(options.merge(template: 'dossier/reports/employee')).and_call_original
26
+ expect(engine).to receive(:render).with(options)
27
27
  end
28
28
  end
29
29
 
@@ -57,14 +57,14 @@ describe Dossier::Report do
57
57
  end
58
58
 
59
59
  it "has callbacks for build_query" do
60
- report.should_receive(:before_test_for_build_query)
60
+ expect(report).to receive(:before_test_for_build_query)
61
61
  report.query
62
62
  end
63
63
 
64
64
  it "has callbacks for execute" do
65
65
  Dossier.client.stub(:execute).and_return([])
66
66
  report.stub(:before_test_for_build_query)
67
- report.should_receive(:after_test_for_execute)
67
+ expect(report).to receive(:after_test_for_execute)
68
68
  report.run
69
69
  end
70
70
 
@@ -79,7 +79,7 @@ describe Dossier::Report do
79
79
  describe "run" do
80
80
  it "will execute the generated sql query" do
81
81
  report = EmployeeReport.new
82
- Dossier.client.should_receive(:execute).with(report.query, 'EmployeeReport').and_return([])
82
+ expect(Dossier.client).to receive(:execute).with(report.query, 'EmployeeReport').and_return([])
83
83
  report.run
84
84
  end
85
85
 
@@ -98,7 +98,7 @@ describe Dossier::Report do
98
98
  end
99
99
 
100
100
  it "delegates render to the renderer" do
101
- report.renderer.should_receive(:render)
101
+ expect(report.renderer).to receive(:render)
102
102
  report.render
103
103
  end
104
104
  end
@@ -9,7 +9,7 @@ describe Dossier::Responder do
9
9
  }
10
10
  end
11
11
 
12
- let(:results) { double(arrays: [[]], hashes: [{}]) }
12
+ let(:results) { double(arrays: [%w[hi], %w[there]], hashes: [{hi: 'there'}]) }
13
13
  let(:report) { EmployeeReport.new }
14
14
  let(:reports) { [stub_out_report_results(report)] }
15
15
  let(:controller) {
@@ -19,21 +19,21 @@ describe Dossier::Responder do
19
19
 
20
20
  describe "to_html" do
21
21
  it "calls render on the report" do
22
- report.should_receive(:render)
22
+ expect(report).to receive(:render)
23
23
  responder.to_html
24
24
  end
25
25
  end
26
26
 
27
27
  describe "to_json" do
28
28
  it "renders the report as json" do
29
- controller.should_receive(:render).with(json: results.hashes)
29
+ expect(controller).to receive(:render).with(json: results.hashes)
30
30
  responder.to_json
31
31
  end
32
32
  end
33
33
 
34
34
  describe "to_csv" do
35
35
  it "sets the content disposition" do
36
- responder.should_receive(:set_content_disposition!)
36
+ expect(responder).to receive(:set_content_disposition!)
37
37
  responder.to_csv
38
38
  end
39
39
 
@@ -41,11 +41,16 @@ describe Dossier::Responder do
41
41
  responder.to_csv
42
42
  expect(responder.controller.response_body).to be_a(Dossier::StreamCSV)
43
43
  end
44
+
45
+ it "formats the headers that are passed to Dossier::StreamCSV" do
46
+ expect(report).to receive(:format_header).with('hi')
47
+ responder.to_csv
48
+ end
44
49
  end
45
50
 
46
51
  describe "to_xls" do
47
52
  it "sets the content disposition" do
48
- responder.should_receive(:set_content_disposition!)
53
+ expect(responder).to receive(:set_content_disposition!)
49
54
  responder.to_xls
50
55
  end
51
56
 
@@ -53,6 +58,11 @@ describe Dossier::Responder do
53
58
  responder.to_xls
54
59
  expect(responder.controller.response_body).to be_a(Dossier::Xls)
55
60
  end
61
+
62
+ it "formats the headers that are passed to Dossier::Xls" do
63
+ expect(report).to receive(:format_header).with('hi')
64
+ responder.to_csv
65
+ end
56
66
  end
57
67
 
58
68
  end
@@ -35,12 +35,12 @@ describe Dossier::Result do
35
35
  end
36
36
 
37
37
  it "can extract the fields queried" do
38
- adapter_result.should_receive(:headers).and_return([])
38
+ expect(adapter_result).to receive(:headers).and_return([])
39
39
  result.headers
40
40
  end
41
41
 
42
42
  it "can extract the values from the adapter results" do
43
- result.should_receive(:to_a)
43
+ expect(result).to receive(:to_a)
44
44
  result.rows
45
45
  end
46
46
 
@@ -67,7 +67,7 @@ describe Dossier::Result do
67
67
 
68
68
  describe "headers" do
69
69
  it "formats the headers by calling format_header" do
70
- adapter_result.headers.each { |h| result.report.should_receive(:format_header).with(h) }
70
+ adapter_result.headers.each { |h| expect(result.report).to receive(:format_header).with(h) }
71
71
  result.headers
72
72
  end
73
73
  end
@@ -82,12 +82,12 @@ describe Dossier::Result do
82
82
  describe "each" do
83
83
 
84
84
  it "calls :each on on its adapter's results" do
85
- adapter_result.rows.should_receive(:each)
85
+ expect(adapter_result.rows).to receive(:each)
86
86
  result.each { |result| }
87
87
  end
88
88
 
89
89
  it "formats each of the adapter's results" do
90
- result.should_receive(:format).with(result_row.values)
90
+ expect(result).to receive(:format).with(result_row.values)
91
91
  result.each { |result| }
92
92
  end
93
93
 
@@ -107,12 +107,12 @@ describe Dossier::Result do
107
107
  end
108
108
 
109
109
  it "calls a custom formatter method if available" do
110
- result.report.should_receive(:format_mascot).with('platapus')
110
+ expect(result.report).to receive(:format_mascot).with('platapus')
111
111
  result.format(row)
112
112
  end
113
113
 
114
114
  it "calls the default format_column method otherwise" do
115
- result.report.should_receive(:format_column).with('cheese', 'bleu')
115
+ expect(result.report).to receive(:format_column).with('cheese', 'bleu')
116
116
  result.format(row)
117
117
  end
118
118
  end
@@ -152,7 +152,7 @@ describe Dossier::Result do
152
152
  describe "each" do
153
153
 
154
154
  it "calls :each on on its adapter's results" do
155
- adapter_result.rows.should_receive(:each)
155
+ expect(adapter_result.rows).to receive(:each)
156
156
  result.each { |result| }
157
157
  end
158
158
 
@@ -15,10 +15,10 @@ describe Dossier::StreamCSV do
15
15
  expect(streamer.headers).to eq headers
16
16
  end
17
17
 
18
- it "formats the headers when streamed" do
18
+ it "does not format the headers when streamed" do
19
19
  formatted = nil
20
20
  streamer.each { |r| formatted = r; break }
21
- expect(formatted).to eq %w[W1 W2 W3 W4 W5 W6].to_csv
21
+ expect(formatted).to eq %w[w1 w2 w3 w4 w5 w6].to_csv
22
22
  end
23
23
 
24
24
  describe "using the first element of the collection for headers" do
@@ -50,7 +50,7 @@ describe Dossier::StreamCSV do
50
50
  end
51
51
 
52
52
  it "calls to csv on each member of the collection" do
53
- collection.each { |row| row.should_receive(:to_csv) }
53
+ collection.each { |row| expect(row).to receive(:to_csv) }
54
54
  streamer.each {}
55
55
  end
56
56
 
@@ -68,7 +68,7 @@ describe Dossier::StreamCSV do
68
68
  it "provides a simple error if not a local request" do
69
69
  Rails.application.config.stub(:consider_all_requests_local).and_return(false)
70
70
  streamer.each { |line| output << line }
71
- expect(output).to match /something went wrong/
71
+ expect(output).to match(/something went wrong/)
72
72
  end
73
73
  end
74
74
 
data/spec/dossier_spec.rb CHANGED
@@ -25,7 +25,7 @@ describe Dossier do
25
25
 
26
26
  it "exposes the configurations client via Dossier.client" do
27
27
  Dossier.configure
28
- Dossier.configuration.should_receive(:client)
28
+ expect(Dossier.configuration).to receive(:client)
29
29
  Dossier.client
30
30
  end
31
31
  end
@@ -34,4 +34,6 @@ Dummy::Application.configure do
34
34
 
35
35
  # Expands the lines which load the assets
36
36
  config.assets.debug = true
37
+
38
+ config.eager_load = false
37
39
  end
@@ -64,4 +64,6 @@ Dummy::Application.configure do
64
64
  # Log the query plan for queries taking more than this (works
65
65
  # with SQLite, MySQL, and PostgreSQL)
66
66
  # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
+
68
+ config.eager_load = true
67
69
  end
@@ -34,4 +34,6 @@ Dummy::Application.configure do
34
34
 
35
35
  # Print deprecation notices to the stderr
36
36
  config.active_support.deprecation = :stderr
37
+
38
+ config.eager_load = false
37
39
  end
Binary file