dossier 2.5.2 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,3 @@
1
+ %h1= multi.class.report_name
2
+ - multi.reports.each do |report|
3
+ = render template: 'dossier/reports/show', locals: {report: report}
data/config/routes.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
- match "reports/:report", :to => 'dossier/reports#show', :as => :dossier_report, via: :get
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
@@ -1,3 +1,3 @@
1
1
  module Dossier
2
- VERSION = "2.5.2"
2
+ VERSION = "2.6.0"
3
3
  end
data/lib/dossier.rb CHANGED
@@ -34,6 +34,7 @@ require "dossier/adapter/active_record/result"
34
34
  require "dossier/client"
35
35
  require "dossier/configuration"
36
36
  require "dossier/formatter"
37
+ require "dossier/multi_report"
37
38
  require "dossier/query"
38
39
  require "dossier/report"
39
40
  require "dossier/result"
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dossier::MultiReport do
4
+
5
+ let(:combined_report) {CombinationReport}
6
+
7
+ it 'knows its sub reports' do
8
+ expect(combined_report.reports).to eq([EmployeeReport, EmployeeWithCustomViewReport])
9
+ end
10
+
11
+ end
Binary file
@@ -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
  EmployeeReport (0.3ms) SELECT * FROM employees WHERE 1=1
2220
2220
  ORDER BY name ASC
2221
+ Connecting to database specified by database.yml
2222
+ FACTORY (3.4ms) CREATE DATABASE IF NOT EXISTS `dossier_test`
2223
+ FACTORY (30.7ms) DROP TABLE IF EXISTS `employees`
2224
+ FACTORY (18.6ms)  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
+ 
2234
+ FACTORY (1.3ms) TRUNCATE `employees`
2235
+ FACTORY (0.9ms)  INSERT INTO
2236
+ `employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
2237
+ VALUES ('Moustafa McMann', '2010-10-02', false, 'Zany Inventions', 30000);
2238
+ 
2239
+ FACTORY (0.6ms) INSERT INTO
2240
+ `employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
2241
+ VALUES ('Jimmy Jackalope, Jr.', '2013-01-11', true, 'Tedious Toiling', 20000);
2242
+
2243
+ FACTORY (0.7ms)  INSERT INTO
2244
+ `employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
2245
+ VALUES ('Elise Elderberry', '2013-01-11', false, 'Corporate Malfeasance', 99000);
2246
+ 
2247
+ FACTORY (10.2ms) DROP TABLE IF EXISTS `employees`
2248
+ FACTORY (2.0ms)  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
+ 
2257
+ FACTORY (0.9ms) DELETE FROM `employees`
2258
+ FACTORY (0.9ms)  INSERT INTO
2259
+ `employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
2260
+ VALUES ('MOUSTAFA MCMANN', '2010-10-02', 0, 'Zany Inventions', 30000);
2261
+ 
2262
+ FACTORY (1.0ms) INSERT INTO
2263
+ `employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
2264
+ VALUES ('JIMMY JACKALOPE, JR.', '2013-01-11', 1, 'Tedious Toiling', 20000);
2265
+
2266
+ FACTORY (0.8ms)  INSERT INTO
2267
+ `employees` (`name`, `hired_on`, `suspended`, `division`, `salary`)
2268
+ VALUES ('ELISE ELDERBERRY', '2013-01-11', 0, 'Corporate Malfeasance', 99000);
2269
+ 
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
+ EmployeeReport (0.3ms) 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
+ EmployeeWithCustomViewReport (0.3ms) SELECT * FROM employees WHERE suspended = true
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
+ EmployeeReport (0.3ms) 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
+ EmployeeReport (0.3ms) SELECT * FROM employees WHERE 1=1
2287
+ ORDER BY name ASC
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
+ EmployeeReport (0.3ms) 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
+ EmployeeReport (0.3ms) SELECT * FROM employees WHERE 1=1
2298
+ ORDER BY name ASC
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
+ EmployeeReport (0.3ms) 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
+ EmployeeReport (0.4ms) SELECT * 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
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
+ EmployeeReport (0.3ms) 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
+ EmployeeWithCustomClientReport (0.4ms) SELECT * FROM `employees`
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
@@ -6,6 +6,7 @@ require "rails/test_help"
6
6
  require 'rspec/rails'
7
7
  require 'pry'
8
8
  require 'genspec'
9
+ require 'capybara/rspec'
9
10
 
10
11
  Rails.backtrace_cleaner.remove_silencers!
11
12
 
@@ -0,0 +1,8 @@
1
+ require Rails.root.join(*%w[.. support reports employee_report])
2
+ require Rails.root.join(*%w[.. support reports employee_with_custom_view_report])
3
+
4
+ class CombinationReport < Dossier::MultiReport
5
+
6
+ combine EmployeeReport, EmployeeWithCustomViewReport
7
+
8
+ end
@@ -1,5 +1,6 @@
1
1
  class HelloMyFriendsReport < Dossier::Report
2
2
  def sql
3
- "select * from employees where friends = true and me = :self group by this is not a real query"
3
+ # Doesn't matter; not meant to be run.
4
+ "select * from employees"
4
5
  end
5
6
  end
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.5.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-06 00:00:00.000000000 Z
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: 573132527792046513
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: 573132527792046513
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