dossier 2.5.2 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/dossier/reports_controller.rb +20 -3
- data/app/views/dossier/reports/multi.html.haml +3 -0
- data/config/routes.rb +2 -1
- data/lib/dossier/adapter/active_record.rb +1 -0
- data/lib/dossier/multi_report.rb +29 -0
- data/lib/dossier/version.rb +1 -1
- data/lib/dossier.rb +1 -0
- data/spec/dossier/multi_report_spec.rb +11 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +109 -0
- data/spec/features/combination_report_spec.rb +20 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/reports/combination_report.rb +8 -0
- data/spec/support/reports/hello_my_friends_report.rb +2 -1
- metadata +28 -4
@@ -1,9 +1,6 @@
|
|
1
1
|
module Dossier
|
2
2
|
class ReportsController < ApplicationController
|
3
3
|
def show
|
4
|
-
report = report_class.new(params[:options] || {})
|
5
|
-
report.run
|
6
|
-
|
7
4
|
respond_to do |format|
|
8
5
|
format.html do
|
9
6
|
begin
|
@@ -29,6 +26,18 @@ module Dossier
|
|
29
26
|
end
|
30
27
|
end
|
31
28
|
|
29
|
+
def multi
|
30
|
+
respond_to do |format|
|
31
|
+
format.html do
|
32
|
+
begin
|
33
|
+
render template: "dossier/reports/#{report_class.report_name}", locals: {multi: report}
|
34
|
+
rescue ActionView::MissingTemplate => e
|
35
|
+
render template: 'dossier/reports/multi', locals: {multi: report}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
32
41
|
private
|
33
42
|
|
34
43
|
def report_class
|
@@ -39,5 +48,13 @@ module Dossier
|
|
39
48
|
headers["Content-Disposition"] = %[attachment;filename=#{params[:report]}-report_#{Time.now.strftime('%m-%d-%Y_%H-%M-%S')}.#{params[:format]}]
|
40
49
|
end
|
41
50
|
|
51
|
+
def report
|
52
|
+
@report ||= report_class.new(options_params)
|
53
|
+
end
|
54
|
+
|
55
|
+
def options_params
|
56
|
+
params[:options].presence || {}
|
57
|
+
end
|
58
|
+
|
42
59
|
end
|
43
60
|
end
|
data/config/routes.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
|
3
|
-
|
3
|
+
get "reports/:report", to: 'dossier/reports#show', as: :dossier_report
|
4
|
+
get "multi/reports/:report", to: 'dossier/reports#multi', as: :multi_report
|
4
5
|
|
5
6
|
end
|
@@ -14,6 +14,7 @@ module Dossier
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def execute(query, report_name = nil)
|
17
|
+
# Ensure that SQL logs show name of report generating query
|
17
18
|
Result.new(connection.exec_query(*[query, report_name].compact))
|
18
19
|
rescue => e
|
19
20
|
raise Dossier::ExecuteError.new "#{e.message}\n\n#{query}"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Dossier::MultiReport
|
2
|
+
|
3
|
+
attr_accessor :options
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :reports
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.report_name
|
10
|
+
Dossier.class_to_name(self)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.combine(*reports)
|
14
|
+
self.reports = reports
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.report=(value)
|
18
|
+
value
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
self.options = options.dup.with_indifferent_access
|
23
|
+
end
|
24
|
+
|
25
|
+
def reports
|
26
|
+
@reports ||= self.class.reports.map(&:new)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/lib/dossier/version.rb
CHANGED
data/lib/dossier.rb
CHANGED
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/spec/dummy/log/test.log
CHANGED
@@ -2218,3 +2218,112 @@ Processing by SiteController#report as HTML
|
|
2218
2218
|
Completed 200 OK in 9ms (Views: 4.6ms | ActiveRecord: 0.4ms)
|
2219
2219
|
[1m[35mEmployeeReport (0.3ms)[0m SELECT * FROM employees WHERE 1=1
|
2220
2220
|
ORDER BY name ASC
|
2221
|
+
Connecting to database specified by database.yml
|
2222
|
+
[1m[36mFACTORY (3.4ms)[0m [1mCREATE DATABASE IF NOT EXISTS `dossier_test`[0m
|
2223
|
+
[1m[35mFACTORY (30.7ms)[0m DROP TABLE IF EXISTS `employees`
|
2224
|
+
[1m[36mFACTORY (18.6ms)[0m [1m CREATE TABLE `employees` (
|
2225
|
+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
2226
|
+
`name` varchar(255) NOT NULL,
|
2227
|
+
`division` varchar(255) NOT NULL,
|
2228
|
+
`salary` int(11) NOT NULL,
|
2229
|
+
`suspended` tinyint(1) NOT NULL DEFAULT 0,
|
2230
|
+
`hired_on` date NOT NULL,
|
2231
|
+
PRIMARY KEY (`id`)
|
2232
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
2233
|
+
[0m
|
2234
|
+
[1m[35mFACTORY (1.3ms)[0m TRUNCATE `employees`
|
2235
|
+
[1m[36mFACTORY (0.9ms)[0m [1m INSERT INTO
|
2236
|
+
`employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
|
2237
|
+
VALUES ('Moustafa McMann', '2010-10-02', false, 'Zany Inventions', 30000);
|
2238
|
+
[0m
|
2239
|
+
[1m[35mFACTORY (0.6ms)[0m INSERT INTO
|
2240
|
+
`employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
|
2241
|
+
VALUES ('Jimmy Jackalope, Jr.', '2013-01-11', true, 'Tedious Toiling', 20000);
|
2242
|
+
|
2243
|
+
[1m[36mFACTORY (0.7ms)[0m [1m INSERT INTO
|
2244
|
+
`employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
|
2245
|
+
VALUES ('Elise Elderberry', '2013-01-11', false, 'Corporate Malfeasance', 99000);
|
2246
|
+
[0m
|
2247
|
+
[1m[35mFACTORY (10.2ms)[0m DROP TABLE IF EXISTS `employees`
|
2248
|
+
[1m[36mFACTORY (2.0ms)[0m [1m CREATE TABLE `employees` (
|
2249
|
+
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
2250
|
+
`name` TEXT NOT NULL,
|
2251
|
+
`division` TEXT NOT NULL,
|
2252
|
+
`salary` INTEGER NOT NULL,
|
2253
|
+
`suspended` TINYINT NOT NULL DEFAULT 0,
|
2254
|
+
`hired_on` DATE NOT NULL
|
2255
|
+
);
|
2256
|
+
[0m
|
2257
|
+
[1m[35mFACTORY (0.9ms)[0m DELETE FROM `employees`
|
2258
|
+
[1m[36mFACTORY (0.9ms)[0m [1m INSERT INTO
|
2259
|
+
`employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
|
2260
|
+
VALUES ('MOUSTAFA MCMANN', '2010-10-02', 0, 'Zany Inventions', 30000);
|
2261
|
+
[0m
|
2262
|
+
[1m[35mFACTORY (1.0ms)[0m INSERT INTO
|
2263
|
+
`employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
|
2264
|
+
VALUES ('JIMMY JACKALOPE, JR.', '2013-01-11', 1, 'Tedious Toiling', 20000);
|
2265
|
+
|
2266
|
+
[1m[36mFACTORY (0.8ms)[0m [1m INSERT INTO
|
2267
|
+
`employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
|
2268
|
+
VALUES ('ELISE ELDERBERRY', '2013-01-11', 0, 'Corporate Malfeasance', 99000);
|
2269
|
+
[0m
|
2270
|
+
Started GET "/multi/reports/combination" for 127.0.0.1 at 2013-05-21 13:30:44 -0400
|
2271
|
+
Processing by Dossier::ReportsController#multi as HTML
|
2272
|
+
Parameters: {"report"=>"combination"}
|
2273
|
+
[1m[35mEmployeeReport (0.3ms)[0m SELECT * FROM employees WHERE 1=1
|
2274
|
+
ORDER BY name ASC
|
2275
|
+
Rendered /Users/adamhunter/Studio/adamhunter/dossier/app/views/dossier/reports/show.html.haml (19.7ms)
|
2276
|
+
[1m[36mEmployeeWithCustomViewReport (0.3ms)[0m [1mSELECT * FROM employees WHERE suspended = true[0m
|
2277
|
+
Rendered /Users/adamhunter/Studio/adamhunter/dossier/app/views/dossier/reports/show.html.haml (2.5ms)
|
2278
|
+
Rendered /Users/adamhunter/Studio/adamhunter/dossier/app/views/dossier/reports/multi.html.haml within layouts/application (29.2ms)
|
2279
|
+
Completed 200 OK in 90ms (Views: 33.5ms | ActiveRecord: 0.6ms)
|
2280
|
+
Started GET "/employee_report_custom_controller" for 127.0.0.1 at 2013-05-21 13:30:44 -0400
|
2281
|
+
Processing by SiteController#report as HTML
|
2282
|
+
[1m[35mEmployeeReport (0.3ms)[0m SELECT * FROM employees WHERE 1=1
|
2283
|
+
ORDER BY name ASC
|
2284
|
+
Rendered /Users/adamhunter/Studio/adamhunter/dossier/app/views/dossier/reports/show.html.haml within layouts/application (2.4ms)
|
2285
|
+
Completed 200 OK in 9ms (Views: 5.2ms | ActiveRecord: 0.3ms)
|
2286
|
+
[1m[36mEmployeeReport (0.3ms)[0m [1mSELECT * FROM employees WHERE 1=1
|
2287
|
+
ORDER BY name ASC[0m
|
2288
|
+
Started GET "/reports/employee.xls" for 127.0.0.1 at 2013-05-21 13:30:44 -0400
|
2289
|
+
Processing by Dossier::ReportsController#show as XLS
|
2290
|
+
Parameters: {"report"=>"employee"}
|
2291
|
+
[1m[35mEmployeeReport (0.3ms)[0m SELECT * FROM employees WHERE 1=1
|
2292
|
+
ORDER BY name ASC
|
2293
|
+
Completed 200 OK in 5ms (ActiveRecord: 0.3ms)
|
2294
|
+
Started GET "/reports/employee.csv" for 127.0.0.1 at 2013-05-21 13:30:44 -0400
|
2295
|
+
Processing by Dossier::ReportsController#show as CSV
|
2296
|
+
Parameters: {"report"=>"employee"}
|
2297
|
+
[1m[36mEmployeeReport (0.3ms)[0m [1mSELECT * FROM employees WHERE 1=1
|
2298
|
+
ORDER BY name ASC[0m
|
2299
|
+
Completed 200 OK in 3ms (ActiveRecord: 0.3ms)
|
2300
|
+
Started GET "/reports/employee_with_custom_view" for 127.0.0.1 at 2013-05-21 13:30:44 -0400
|
2301
|
+
Processing by Dossier::ReportsController#show as HTML
|
2302
|
+
Parameters: {"report"=>"employee_with_custom_view"}
|
2303
|
+
Completed 200 OK in 4ms (Views: 3.5ms | ActiveRecord: 0.0ms)
|
2304
|
+
Started GET "/reports/employee?options[footer]=1" for 127.0.0.1 at 2013-05-21 13:30:44 -0400
|
2305
|
+
Processing by Dossier::ReportsController#show as HTML
|
2306
|
+
Parameters: {"options"=>{"footer"=>"1"}, "report"=>"employee"}
|
2307
|
+
[1m[35mEmployeeReport (0.3ms)[0m SELECT * FROM employees WHERE 1=1
|
2308
|
+
ORDER BY name ASC
|
2309
|
+
Completed 200 OK in 12ms (Views: 9.0ms | ActiveRecord: 0.3ms)
|
2310
|
+
Started GET "/reports/employee?options[salary]=true&options[order]=desc&options[names][]=Jimmy+Jackalope&options[names][]=Moustafa+McMann&options[divisions][]=Tedious+Toiling" for 127.0.0.1 at 2013-05-21 13:30:44 -0400
|
2311
|
+
Processing by Dossier::ReportsController#show as HTML
|
2312
|
+
Parameters: {"options"=>{"salary"=>"true", "order"=>"desc", "names"=>["Jimmy Jackalope", "Moustafa McMann"], "divisions"=>["Tedious Toiling"]}, "report"=>"employee"}
|
2313
|
+
[1m[36mEmployeeReport (0.4ms)[0m [1mSELECT * FROM employees WHERE 1=1
|
2314
|
+
AND division in (('Tedious Toiling'))
|
2315
|
+
AND salary > 10000
|
2316
|
+
AND (name like '%Moustafa McMann%' or name like '%Jimmy Jackalope%')
|
2317
|
+
ORDER BY name DESC[0m
|
2318
|
+
Completed 200 OK in 16ms (Views: 15.1ms | ActiveRecord: 0.4ms)
|
2319
|
+
Started GET "/reports/employee" for 127.0.0.1 at 2013-05-21 13:30:44 -0400
|
2320
|
+
Processing by Dossier::ReportsController#show as HTML
|
2321
|
+
Parameters: {"report"=>"employee"}
|
2322
|
+
[1m[35mEmployeeReport (0.3ms)[0m SELECT * FROM employees WHERE 1=1
|
2323
|
+
ORDER BY name ASC
|
2324
|
+
Completed 200 OK in 11ms (Views: 9.4ms | ActiveRecord: 0.3ms)
|
2325
|
+
Started GET "/reports/employee_with_custom_client" for 127.0.0.1 at 2013-05-21 13:30:44 -0400
|
2326
|
+
Processing by Dossier::ReportsController#show as HTML
|
2327
|
+
Parameters: {"report"=>"employee_with_custom_client"}
|
2328
|
+
[1m[36mEmployeeWithCustomClientReport (0.4ms)[0m [1mSELECT * FROM `employees`[0m
|
2329
|
+
Completed 200 OK in 6ms (Views: 4.0ms | ActiveRecord: 0.4ms)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "combination report" do
|
4
|
+
|
5
|
+
describe "rendering html" do
|
6
|
+
|
7
|
+
context "when no custom view exists" do
|
8
|
+
|
9
|
+
it "displays the correct html" do
|
10
|
+
visit '/multi/reports/combination'
|
11
|
+
expect(page).to have_content('Employee Report')
|
12
|
+
expect(page).to have_content('Employee With Custom View Report')
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dossier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-05-
|
14
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: arel
|
@@ -189,6 +189,22 @@ dependencies:
|
|
189
189
|
- - ~>
|
190
190
|
- !ruby/object:Gem::Version
|
191
191
|
version: 0.2.7
|
192
|
+
- !ruby/object:Gem::Dependency
|
193
|
+
name: capybara
|
194
|
+
requirement: !ruby/object:Gem::Requirement
|
195
|
+
none: false
|
196
|
+
requirements:
|
197
|
+
- - ~>
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: 2.1.0
|
200
|
+
type: :development
|
201
|
+
prerelease: false
|
202
|
+
version_requirements: !ruby/object:Gem::Requirement
|
203
|
+
none: false
|
204
|
+
requirements:
|
205
|
+
- - ~>
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: 2.1.0
|
192
208
|
description: Easy SQL based report generation with the ability to accept request parameters
|
193
209
|
and render multiple formats.
|
194
210
|
email:
|
@@ -204,6 +220,7 @@ files:
|
|
204
220
|
- app/controllers/dossier/application_controller.rb
|
205
221
|
- app/controllers/dossier/reports_controller.rb
|
206
222
|
- app/helpers/dossier/application_helper.rb
|
223
|
+
- app/views/dossier/reports/multi.html.haml
|
207
224
|
- app/views/dossier/reports/show.html.haml
|
208
225
|
- config/initializers/mime_types.rb
|
209
226
|
- config/routes.rb
|
@@ -213,6 +230,7 @@ files:
|
|
213
230
|
- lib/dossier/configuration.rb
|
214
231
|
- lib/dossier/engine.rb
|
215
232
|
- lib/dossier/formatter.rb
|
233
|
+
- lib/dossier/multi_report.rb
|
216
234
|
- lib/dossier/query.rb
|
217
235
|
- lib/dossier/report.rb
|
218
236
|
- lib/dossier/result.rb
|
@@ -231,6 +249,7 @@ files:
|
|
231
249
|
- spec/dossier/client_spec.rb
|
232
250
|
- spec/dossier/configuration_spec.rb
|
233
251
|
- spec/dossier/formatter_spec.rb
|
252
|
+
- spec/dossier/multi_report_spec.rb
|
234
253
|
- spec/dossier/query_spec.rb
|
235
254
|
- spec/dossier/report_spec.rb
|
236
255
|
- spec/dossier/result_spec.rb
|
@@ -282,6 +301,7 @@ files:
|
|
282
301
|
- spec/dummy/tmp/cache/assets/DCF/420/sprockets%2F9f127ea0ab7236994d1ceaa7bbea86c8
|
283
302
|
- spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
|
284
303
|
- spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
|
304
|
+
- spec/features/combination_report_spec.rb
|
285
305
|
- spec/fixtures/db/mysql2.yml
|
286
306
|
- spec/fixtures/db/mysql2.yml.example
|
287
307
|
- spec/fixtures/db/sqlite3.yml
|
@@ -300,6 +320,7 @@ files:
|
|
300
320
|
- spec/routing/dossier_routes_spec.rb
|
301
321
|
- spec/spec_helper.rb
|
302
322
|
- spec/support/factory.rb
|
323
|
+
- spec/support/reports/combination_report.rb
|
303
324
|
- spec/support/reports/employee_report.rb
|
304
325
|
- spec/support/reports/employee_with_custom_client_report.rb
|
305
326
|
- spec/support/reports/employee_with_custom_view_report.rb
|
@@ -319,7 +340,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
319
340
|
version: '0'
|
320
341
|
segments:
|
321
342
|
- 0
|
322
|
-
hash:
|
343
|
+
hash: -3969565327804791987
|
323
344
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
324
345
|
none: false
|
325
346
|
requirements:
|
@@ -328,7 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
328
349
|
version: '0'
|
329
350
|
segments:
|
330
351
|
- 0
|
331
|
-
hash:
|
352
|
+
hash: -3969565327804791987
|
332
353
|
requirements: []
|
333
354
|
rubyforge_project:
|
334
355
|
rubygems_version: 1.8.23
|
@@ -341,6 +362,7 @@ test_files:
|
|
341
362
|
- spec/dossier/client_spec.rb
|
342
363
|
- spec/dossier/configuration_spec.rb
|
343
364
|
- spec/dossier/formatter_spec.rb
|
365
|
+
- spec/dossier/multi_report_spec.rb
|
344
366
|
- spec/dossier/query_spec.rb
|
345
367
|
- spec/dossier/report_spec.rb
|
346
368
|
- spec/dossier/result_spec.rb
|
@@ -392,6 +414,7 @@ test_files:
|
|
392
414
|
- spec/dummy/tmp/cache/assets/DCF/420/sprockets%2F9f127ea0ab7236994d1ceaa7bbea86c8
|
393
415
|
- spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
|
394
416
|
- spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
|
417
|
+
- spec/features/combination_report_spec.rb
|
395
418
|
- spec/fixtures/db/mysql2.yml
|
396
419
|
- spec/fixtures/db/mysql2.yml.example
|
397
420
|
- spec/fixtures/db/sqlite3.yml
|
@@ -410,6 +433,7 @@ test_files:
|
|
410
433
|
- spec/routing/dossier_routes_spec.rb
|
411
434
|
- spec/spec_helper.rb
|
412
435
|
- spec/support/factory.rb
|
436
|
+
- spec/support/reports/combination_report.rb
|
413
437
|
- spec/support/reports/employee_report.rb
|
414
438
|
- spec/support/reports/employee_with_custom_client_report.rb
|
415
439
|
- spec/support/reports/employee_with_custom_view_report.rb
|