dossier 2.10.0 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dossier/responder.rb +7 -2
- data/lib/dossier/stream_csv.rb +1 -1
- data/lib/dossier/version.rb +1 -1
- data/lib/dossier/xls.rb +1 -5
- data/spec/dossier/adapter/active_record/result_spec.rb +1 -1
- data/spec/dossier/adapter/active_record_spec.rb +3 -3
- data/spec/dossier/client_spec.rb +4 -4
- data/spec/dossier/configuration_spec.rb +1 -1
- data/spec/dossier/multi_report_spec.rb +1 -1
- data/spec/dossier/query_spec.rb +7 -7
- data/spec/dossier/renderer_spec.rb +3 -3
- data/spec/dossier/report_spec.rb +4 -4
- data/spec/dossier/responder_spec.rb +15 -5
- data/spec/dossier/result_spec.rb +8 -8
- data/spec/dossier/stream_csv_spec.rb +4 -4
- data/spec/dossier_spec.rb +1 -1
- data/spec/dummy/config/environments/development.rb +2 -0
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/environments/test.rb +2 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +4189 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5750b4e9b45d224d36b0781ac414430996424e5d
|
4
|
+
data.tar.gz: 82b8a612bf19b8b07244a7aa70ea7f7b0369f4ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfdb1e481e2f1f3ff757f6a96a4203efc720665b71923ef56d3dae8d4afccc8e0ec9636d81b7a292316f6f4ba76a3d25aa831a3486fdd85b3a74fe9ce23ad56a
|
7
|
+
data.tar.gz: 19a70f10f3d8d60f0df04da43cdb18aa370c0f83961c2845d09f64935bcc2d16e29e31fa9299822ec9590c4dd129279c373d50e4e700bb8a56610090e00fa4bc
|
data/lib/dossier/responder.rb
CHANGED
@@ -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}"
|
data/lib/dossier/stream_csv.rb
CHANGED
data/lib/dossier/version.rb
CHANGED
data/lib/dossier/xls.rb
CHANGED
@@ -11,7 +11,7 @@ module Dossier
|
|
11
11
|
|
12
12
|
def each
|
13
13
|
yield HEADER
|
14
|
-
yield
|
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.
|
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.
|
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.
|
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.
|
38
|
+
expect(adapter_result_class).to receive(:new).with(connection_results)
|
39
39
|
adapter.execute(:query)
|
40
40
|
end
|
41
41
|
|
data/spec/dossier/client_spec.rb
CHANGED
@@ -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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
15
|
+
expect(report).to receive(:new).with(options).and_call_original
|
16
16
|
end
|
17
17
|
|
18
18
|
report.reports
|
data/spec/dossier/query_spec.rb
CHANGED
@@ -24,9 +24,9 @@ describe Dossier::Query do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "escapes the values" do
|
27
|
-
query.
|
28
|
-
query.
|
29
|
-
query.
|
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.
|
48
|
-
Dossier.client.
|
49
|
-
Dossier.client.
|
50
|
-
Dossier.client.
|
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.
|
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.
|
26
|
-
engine.
|
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
|
|
data/spec/dossier/report_spec.rb
CHANGED
@@ -57,14 +57,14 @@ describe Dossier::Report do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "has callbacks for build_query" do
|
60
|
-
report.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
data/spec/dossier/result_spec.rb
CHANGED
@@ -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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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 "
|
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[
|
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.
|
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
|
71
|
+
expect(output).to match(/something went wrong/)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
data/spec/dossier_spec.rb
CHANGED
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|