mint_reporter 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +34 -0
  3. data/app/controllers/admin/reports_controller.rb +3 -0
  4. data/app/models/report.rb +86 -0
  5. data/app/views/admin/reports/_form.html.erb +40 -0
  6. data/app/views/admin/reports/edit.html.erb +14 -0
  7. data/app/views/admin/reports/index.html.erb +96 -0
  8. data/app/views/admin/reports/new.html.erb +13 -0
  9. data/app/views/admin/reports/show.html.erb +51 -0
  10. data/app/workers/csv_generation_worker.rb +8 -0
  11. data/config/initializers/mime_types.rb +1 -0
  12. data/config/routes.rb +5 -0
  13. data/db/migrate/20140703143528_create_reports.rb +16 -0
  14. data/lib/generators/mint_report/USAGE +8 -0
  15. data/lib/generators/mint_report/mint_report_generator.rb +7 -0
  16. data/lib/generators/mint_report/templates/mint_report.rb +9 -0
  17. data/lib/mint_reporter.rb +17 -0
  18. data/lib/mint_reporter/engine.rb +4 -0
  19. data/lib/mint_reporter/version.rb +3 -0
  20. data/lib/tasks/mint_reporter_tasks.rake +4 -0
  21. data/test/dummy/README.rdoc +28 -0
  22. data/test/dummy/Rakefile +6 -0
  23. data/test/dummy/app/assets/javascripts/admin.js +31 -0
  24. data/test/dummy/app/assets/javascripts/application.js +13 -0
  25. data/test/dummy/app/assets/stylesheets/admin.scss +11 -0
  26. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  27. data/test/dummy/app/controllers/admin/admin_controller.rb +3 -0
  28. data/test/dummy/app/controllers/application_controller.rb +7 -0
  29. data/test/dummy/app/helpers/application_helper.rb +8 -0
  30. data/test/dummy/app/models/user.rb +2 -0
  31. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/test/dummy/bin/bundle +3 -0
  33. data/test/dummy/bin/rails +4 -0
  34. data/test/dummy/bin/rake +4 -0
  35. data/test/dummy/config.ru +4 -0
  36. data/test/dummy/config/application.rb +23 -0
  37. data/test/dummy/config/boot.rb +7 -0
  38. data/test/dummy/config/database.yml +25 -0
  39. data/test/dummy/config/environment.rb +6 -0
  40. data/test/dummy/config/environments/development.rb +29 -0
  41. data/test/dummy/config/environments/production.rb +80 -0
  42. data/test/dummy/config/environments/test.rb +36 -0
  43. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  44. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  45. data/test/dummy/config/initializers/inflections.rb +16 -0
  46. data/test/dummy/config/initializers/mime_types.rb +5 -0
  47. data/test/dummy/config/initializers/secret_token.rb +12 -0
  48. data/test/dummy/config/initializers/session_store.rb +3 -0
  49. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  50. data/test/dummy/config/locales/en.yml +23 -0
  51. data/test/dummy/config/routes.rb +59 -0
  52. data/test/dummy/db/development.sqlite3 +0 -0
  53. data/test/dummy/db/migrate/20140716113109_create_users.rb +9 -0
  54. data/test/dummy/db/migrate/20140723162342_create_reports.mint_reporter_engine.rb +17 -0
  55. data/test/dummy/db/production.sqlite3 +0 -0
  56. data/test/dummy/db/schema.rb +35 -0
  57. data/test/dummy/db/test.sqlite3 +0 -0
  58. data/test/dummy/log/development.log +293 -0
  59. data/test/dummy/log/test.log +17259 -0
  60. data/test/dummy/public/404.html +58 -0
  61. data/test/dummy/public/422.html +58 -0
  62. data/test/dummy/public/500.html +57 -0
  63. data/test/dummy/public/favicon.ico +0 -0
  64. data/test/dummy/public/uploads/test/basic_reports/000/000/001/original.csv +3 -0
  65. data/test/dummy/test/factories/foos.rb +6 -0
  66. data/test/dummy/tmp/cache/assets/test/sass/051af4935d2ac60904721027c383dd9ffc9f7871/_admin-base.scssc +0 -0
  67. data/test/dummy/tmp/cache/assets/test/sass/7f5568ada10d673b8a1d203ce8b8c1dba7fbaf83/admin.scssc +0 -0
  68. data/test/dummy/tmp/cache/assets/test/sprockets/1935933f8fbe88236ef893016c1836bc +0 -0
  69. data/test/dummy/tmp/cache/assets/test/sprockets/27184889e78dc5a556f3c7567afbef63 +0 -0
  70. data/test/dummy/tmp/cache/assets/test/sprockets/37c7a190e68a7e26cf450e38ec190534 +0 -0
  71. data/test/dummy/tmp/cache/assets/test/sprockets/468917569b5c6af93b42fda1a68e426c +0 -0
  72. data/test/dummy/tmp/cache/assets/test/sprockets/638d4b299480bfa854367ae027ff66d0 +0 -0
  73. data/test/dummy/tmp/cache/assets/test/sprockets/6609ee9da4eaea9b8d8137fbcfce6fdd +0 -0
  74. data/test/dummy/tmp/cache/assets/test/sprockets/9d087e6fe6cf75adc1ebe34710cb71bc +0 -0
  75. data/test/dummy/tmp/cache/assets/test/sprockets/ac64f2f5da10d3fe34beec68afda56d4 +0 -0
  76. data/test/dummy/tmp/cache/assets/test/sprockets/b53da076920d68305d6582c3af250465 +0 -0
  77. data/test/dummy/tmp/cache/assets/test/sprockets/d875d477ab20a2e08531d775a5fea6f2 +0 -0
  78. data/test/dummy/tmp/cache/assets/test/sprockets/e017dd8f0cd2f98c7864918d2ba783b3 +0 -0
  79. data/test/dummy/tmp/cache/assets/test/sprockets/f8160f91b680b2f94df78cefd5abc06e +0 -0
  80. data/test/factories/reports.rb +8 -0
  81. data/test/factories/users.rb +5 -0
  82. data/test/fixtures/reports.yml +15 -0
  83. data/test/functional/reports_controller_test.rb +34 -0
  84. data/test/generators/mint_report_generator_test.rb +14 -0
  85. data/test/integration/configuration_test.rb +29 -0
  86. data/test/integration/create_report_test.rb +20 -0
  87. data/test/integration/mint_report_generator.rb +10 -0
  88. data/test/mint_reporter_test.rb +7 -0
  89. data/test/test_helper.rb +45 -0
  90. data/test/tmp/app/models/reports/foo_report.rb +9 -0
  91. data/test/unit/report_test.rb +69 -0
  92. metadata +330 -0
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,3 @@
1
+ col1,col2
2
+ one,two
3
+ a,b
@@ -0,0 +1,6 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :foo do
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ FactoryGirl.define do
2
+ factory :report do
3
+
4
+ trait :blank do
5
+ type "BlankReport"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :user do
3
+ sequence(:username) { |n| "user-#{n}" }
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ from_date: 2014-07-03 15:35:28
5
+ to_date: 2014-07-03 15:35:28
6
+ state: MyString
7
+ timestamp_field: MyString
8
+ parameters: MyText
9
+
10
+ two:
11
+ from_date: 2014-07-03 15:35:28
12
+ to_date: 2014-07-03 15:35:28
13
+ state: MyString
14
+ timestamp_field: MyString
15
+ parameters: MyText
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ class Admin::ReportsControllerTest < ActionController::TestCase
4
+ tests Admin::ReportsController
5
+
6
+ should 'get to #index' do
7
+ get :index
8
+ assert_response :success
9
+ end
10
+
11
+ should 'get to #new with report type' do
12
+ get :new
13
+ assert_response :success
14
+ end
15
+
16
+ should 'post to create' do
17
+ assert_difference("Report.count") do
18
+ post :create, "report" => {
19
+ "type" => "BasicReport",
20
+ "from_date(1i)" => "2014",
21
+ "from_date(2i)" => "7",
22
+ "from_date(3i)" => "17",
23
+ "from_date(4i)" => "13",
24
+ "from_date(5i)" => "39",
25
+ "to_date(1i)" => "2014",
26
+ "to_date(2i)" => "7",
27
+ "to_date(3i)" => "17",
28
+ "to_date(4i)" => "13",
29
+ "to_date(5i)" => "39"
30
+ }
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,14 @@
1
+ require "test_helper"
2
+ require "generators/mint_report/mint_report_generator"
3
+
4
+ class MintReportGeneratorTest < Rails::Generators::TestCase
5
+ tests MintReportGenerator
6
+
7
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
8
+ setup :prepare_destination
9
+
10
+ test "generate Report" do
11
+ run_generator %w(foo_report)
12
+ assert_file 'app/models/reports/foo_report.rb'
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < ActionDispatch::IntegrationTest
4
+ class FooPresenter
5
+ THINGS = %w[thing1 thing2 thing3]
6
+ end
7
+
8
+ setup do
9
+ MintReporter.config do |c|
10
+ c.paperclip_storage_options = {
11
+ :url => "http://example.com/uploads/:style.:extension",
12
+ :path => ":rails_root/public/uploads/:style.:extension"
13
+ }
14
+ c.reports = {:foo_presenter => {:fields => FooPresenter::THINGS}}
15
+ end
16
+ end
17
+
18
+ test "accepts paperclip config" do
19
+ paperclip_config = {}
20
+ paperclip_config[:url] = "http://example.com/uploads/:style.:extension"
21
+ paperclip_config[:path] = ":rails_root/public/uploads/:style.:extension"
22
+ assert_equal paperclip_config, MintReporter.config.paperclip_storage_options
23
+ end
24
+
25
+ test "accepts reports config" do
26
+ assert_equal FooPresenter::THINGS,
27
+ MintReporter.config.reports[:foo_presenter][:fields]
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class CreateReportTest < ActionDispatch::IntegrationTest
4
+ should "successfully create a report" do
5
+ records = [
6
+ OpenStruct.new(:one => 'one', :two => 'two'),
7
+ OpenStruct.new(:one => 'a', :two => 'b')
8
+ ]
9
+ flexmock(records).should_receive(:where).and_return(records)
10
+ flexmock(records).should_receive(:order).once.and_return(records)
11
+
12
+ report = BasicReport.create
13
+ flexmock(report).should_receive(:records).once.and_return(records)
14
+
15
+ report.generate_csv!
16
+ assert report.reload.csv.present?
17
+ file = File.open report.csv.path
18
+ assert_equal "col1,col2\none,two\na,b\n", file.read
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ class MintReportGeneratorTest < Rails::Generators::TestCase
2
+ tests MintReportGenerator
3
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
4
+
5
+ setup :prepare_destination
6
+
7
+ should "create Foo report" do
8
+ run_generator(['FooReport'])
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class MintReporterTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, MintReporter
6
+ end
7
+ end
@@ -0,0 +1,45 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+ require "rails/generators"
7
+ require "flexmock/test_unit"
8
+ require "factory_girl"
9
+ require "shoulda"
10
+ require "paperclip/matchers"
11
+
12
+ Rails.backtrace_cleaner.remove_silencers!
13
+
14
+ # Load support files
15
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
16
+
17
+ # Load factories
18
+ Dir["#{File.dirname(__FILE__)}/factories/*.rb"].each { |f| require f }
19
+
20
+ MintReporter.config do |c|
21
+ c.paperclip_storage_options = {
22
+ :url => "http://test.local/uploads/:class/:id_partition/:style.:extension",
23
+ :path => ":rails_root/public/uploads/test/:class/:id_partition/:style.:extension"
24
+ }
25
+ c.reports = %w[BasicReport BlankReport]
26
+ end
27
+
28
+ class BasicReport < Report
29
+ def csv_column_names
30
+ ['col1', 'col2']
31
+ end
32
+ def csv_row(record)
33
+ [record.one, record.two]
34
+ end
35
+ def records
36
+ [
37
+ OpenStruct.new(:one => 'one', :two => 'two'),
38
+ OpenStruct.new(:one => 'a', :two => 'b')
39
+ ]
40
+ end
41
+ end
42
+
43
+ class ActiveSupport::TestCase
44
+ extend Paperclip::Shoulda::Matchers
45
+ end
@@ -0,0 +1,9 @@
1
+ class FooReport < Report
2
+ def csv_column_names
3
+ super
4
+ end
5
+
6
+ def csv_row(record)
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class ReportTest < ActiveSupport::TestCase
4
+ should ensure_inclusion_of(:type).in_array(MintReporter.config.reports)
5
+ should have_attached_file(:csv)
6
+
7
+ context "with a basic report" do
8
+ setup { @report = BasicReport.create }
9
+
10
+ should "default to the pending state" do
11
+ assert_equal "pending", @report.state
12
+ end
13
+
14
+ should "add a task to the default queue after commit" do
15
+ flexmock(@report).should_receive(:generate_csv).once
16
+ @report.save
17
+ @report.run_callbacks(:commit)
18
+ end
19
+
20
+ should "enqueue CSV generation task" do
21
+ flexmock(CSVGenerationWorker).should_receive(:perform_async).
22
+ with(@report.id).once
23
+ @report.generate_csv
24
+ end
25
+
26
+ should "generate a csv" do
27
+ records = [
28
+ OpenStruct.new(:one => 'one', :two => 'two'),
29
+ OpenStruct.new(:one => 'a', :two => 'b')
30
+ ]
31
+ flexmock(records).should_receive(:where).
32
+ with(:created_at => @report.from_date..@report.to_date).
33
+ and_return(records)
34
+ flexmock(records).should_receive(:order).once.and_return(records)
35
+ flexmock(@report).should_receive(:records).once.and_return(records)
36
+
37
+ flexmock(@report).should_receive(:csv=).once
38
+ @report.generate_csv!
39
+ end
40
+ end
41
+
42
+ context "with a blank report" do
43
+ setup { @report = FactoryGirl.create(:report, :blank) }
44
+
45
+ should "raise an error on asking for csv column names" do
46
+ e = assert_raises(MintReporter::Undefined) do
47
+ @report.csv_column_names
48
+ end
49
+ assert_equal "Subclasses of Report must implement csv_column_names",
50
+ e.message
51
+ end
52
+
53
+ should "raise an error on asking for csv row" do
54
+ e = assert_raises(MintReporter::Undefined) do
55
+ @report.csv_row(nil)
56
+ end
57
+ assert_equal "Subclasses of Report must implement csv_row",
58
+ e.message
59
+ end
60
+
61
+ should "raise an error on asking for records" do
62
+ e = assert_raises(MintReporter::Undefined) do
63
+ @report.records
64
+ end
65
+ assert_equal "Subclasses of Report must implement records",
66
+ e.message
67
+ end
68
+ end
69
+ end