clark_kent 0.7.1 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/clark_kent/report_filters_controller.rb +2 -2
  3. data/app/controllers/clark_kent/reports_controller.rb +1 -1
  4. data/app/models/clark_kent/report_column.rb +13 -3
  5. data/app/models/clark_kent/reportable.rb +1 -1
  6. data/app/validators/clark_kent/report_column_validator.rb +7 -0
  7. data/app/views/clark_kent/report_columns/_form.html.erb +1 -1
  8. data/lib/clark_kent/version.rb +1 -1
  9. data/test/controllers/clark_kent/report_filters_controller_test.rb +11 -10
  10. data/test/controllers/clark_kent/reports_controller_test.rb +32 -31
  11. data/test/dummy/db/test.sqlite3 +0 -0
  12. data/test/dummy/log/test.log +7139 -0
  13. data/test/dummy/tmp/cache/assets/sprockets/v3.0/-p/-p0yY-ZfSq2z3p93_-pQ37fG8LHtag_WTxyycFtpfYg.cache +1 -0
  14. data/test/dummy/tmp/cache/assets/sprockets/v3.0/0T/0T4f7V-gjBT3v8qDpXeOYY75WyxL2aodqWk7MiOc0jI.cache +0 -0
  15. data/test/dummy/tmp/cache/assets/sprockets/v3.0/5k/5k7OtUEslUWi1MkCA5Kmc7rHAU0hWPFaSUcq7j8-doc.cache +1 -0
  16. data/test/dummy/tmp/cache/assets/sprockets/v3.0/DK/DKA8K2AVy7t5pWF88wjHwvc8mVvBXaieFbJ68r_5nkc.cache +1 -0
  17. data/test/dummy/tmp/cache/assets/sprockets/v3.0/EF/EFH19OQ02-sMAQJznIN5z49e_78IV0E143KKlj9u2qo.cache +0 -0
  18. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Hu/HuyKNAYEnPs4OFAHZ6YQZ3VSrTaxZe0Ra_fNZLbeXDw.cache +1 -0
  19. data/test/dummy/tmp/cache/assets/sprockets/v3.0/IS/ISN9Hxq36D1ejVxS38niQNl373tRMSHSIDxyFE7cPXM.cache +0 -0
  20. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Jb/JbcAACpMmVlknG104wCtLY73aNeelGB5NNPiF4uDf5s.cache +2 -0
  21. data/test/dummy/tmp/cache/assets/sprockets/v3.0/LN/LNv9fieEzShvj0fy3fulj6rLRJrSie5o91QhOEPDCf4.cache +1 -0
  22. data/test/dummy/tmp/cache/assets/sprockets/v3.0/O8/O8akbUwAbmIKY-AhITimq-JDQ6IgsO3Hvq2v5etufFw.cache +2 -0
  23. data/test/dummy/tmp/cache/assets/sprockets/v3.0/UV/UVeH93rELRBawlPCnRGGJP4tRFjy_dH7wicU_ZbrCDM.cache +1 -0
  24. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Ur/UrvBNsTYTsrqJWZ8m86kNZY4jILmqjRZMyHUy-3iYDY.cache +0 -0
  25. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Uw/UwMFS8rJmeOVTOPUAsy5rBsPqe-mwJgvTSCg-8xwSK8.cache +2 -0
  26. data/test/dummy/tmp/cache/assets/sprockets/v3.0/XG/XGAUd4zdycHNjgugiwtNoIzH7Rye3BmjHFqOL3pkrhg.cache +0 -0
  27. data/test/dummy/tmp/cache/assets/sprockets/v3.0/c0/c0fZzpmetAbdlEG8jam5O6N3N3wiVzKXR_lCIY6kCTA.cache +0 -0
  28. data/test/dummy/tmp/cache/assets/sprockets/v3.0/fH/fHWyzePKbils7mC23jWPCevjAzyBfo8j01idOorqDT0.cache +0 -0
  29. data/test/dummy/tmp/cache/assets/sprockets/v3.0/hj/hj8Ir9wcVSy1KYrnWu9bpD24vDhCG3tvt-nKbNxb1Wg.cache +2 -0
  30. data/test/dummy/tmp/cache/assets/sprockets/v3.0/iD/iDxOcLQhAs-zS2-4AShuzHEtsbcdSQPBmTI5BP1WfwM.cache +0 -0
  31. data/test/dummy/tmp/cache/assets/sprockets/v3.0/kx/kxkWN7_XTUQXY0Jl_27tQE9bqJGPvb8jdSFi36PgCcE.cache +1 -0
  32. data/test/dummy/tmp/cache/assets/sprockets/v3.0/oC/oCsZTGZyV4kH8Y4OeSDUdrwfkJFPzTODZjuBKZB8oGQ.cache +2 -0
  33. data/test/dummy/tmp/cache/assets/sprockets/v3.0/oU/oUDjXYmDJ26HtNPmg5Ys5Qsbv1KJ8gFj4UjHSno6Nz4.cache +1 -0
  34. data/test/dummy/tmp/cache/assets/sprockets/v3.0/qO/qOsXW8q70wL7_ono3kwb4IhdpIs0QYgSGrD77JrlGyo.cache +1 -0
  35. data/test/dummy/tmp/cache/assets/sprockets/v3.0/tP/tPF6H9NRpGO3whu2y5_e_R_1EACKdCwu5437D83qJT0.cache +2 -0
  36. data/test/dummy/tmp/cache/assets/sprockets/v3.0/x1/x1pNHYQUCVLQm2-2eBri2T7gxgLTBDez3d7ao8etFX4.cache +0 -0
  37. data/test/models/clark_kent/report_column_test.rb +12 -0
  38. data/test/models/clark_kent/reportable_test.rb +9 -2
  39. data/test/test_helper.rb +5 -3
  40. metadata +77 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea08eca7b36b019e73199ff6a74672024c788687
4
- data.tar.gz: 1d2966c55b6e1f6ba3eedd5ca0d340be91359821
3
+ metadata.gz: e63c1a037abbf2c2830ddad357e7239cfae00ca2
4
+ data.tar.gz: a3514ad0db2d2cd9e9a8020f78aea5e52ef9c011
5
5
  SHA512:
6
- metadata.gz: 89328622596263860bade995ec001e20454eccd838a57b954beb19df9125385dd2a251fe73909c50b84e62e71e9e793c2312ea267dda1aa57747c62fdeed7d68
7
- data.tar.gz: d71ee68a2f3f4089dad1bae18d3dace7a4574636d9191f68c6674e8493ebbd299ac8b91818e255775baec36768303890b650695d994a9a35bfdd10f7e41f540d
6
+ metadata.gz: ff06a601a8d74cd2de05815fb42635cd0325061112a9912fb25bd5350696c62b11bda5a25c4aad481c1b6b3cbe9d0f13d50268d38a1c0f62f8f4cdc9da6b9393
7
+ data.tar.gz: 8df55e3b836dd8f92b85535ef963a6354ba4a8b040092e7668687cd3745fe9d4039cba721dcd8fea1fbe7e38a95b043aa98f76209b436cf41595b73869c0c0f0
@@ -1,6 +1,6 @@
1
1
  class ClarkKent::ReportFiltersController < ClarkKent::ApplicationController
2
- before_filter :prepare_report_filter
3
- before_filter :prepare_report, :prepare_filters
2
+ before_action :prepare_report_filter
3
+ before_action :prepare_report, :prepare_filters
4
4
 
5
5
  def new
6
6
  @report_filter = ClarkKent::ReportFilter.new(filterable_id: @filterable.id, filterable_type: @filterable.class.name)
@@ -1,6 +1,6 @@
1
1
  class ClarkKent::ReportsController < ClarkKent::ApplicationController
2
2
  require 'csv'
3
- before_filter :get_these_params, :prepare_filters
3
+ before_action :get_these_params, :prepare_filters
4
4
 
5
5
  def set_manage_tab
6
6
  @manage_tab = 'reports'
@@ -8,6 +8,8 @@ module ClarkKent
8
8
 
9
9
  scope :sorted, -> { order("clark_kent_report_columns.column_order") }
10
10
 
11
+ validates_with ReportColumnValidator
12
+
11
13
  def report_sort_pretty
12
14
  {'ascending' => 'A->Z','descending' => 'Z->A'}[self.report_sort]
13
15
  end
@@ -21,6 +23,10 @@ module ClarkKent
21
23
  report.column_options_for(self.column_name.to_sym).summarizable
22
24
  end
23
25
 
26
+ def sortable?
27
+ config_options.order_sql.present?
28
+ end
29
+
24
30
  def calculator
25
31
  ('ClarkKent::' + summary_method.camelcase + 'Calculator').constantize
26
32
  end
@@ -29,16 +35,20 @@ module ClarkKent
29
35
  column_name
30
36
  end
31
37
 
38
+ def config_options
39
+ report.column_options_for(self.name.to_sym)
40
+ end
41
+
32
42
  def link
33
- report.column_options_for(self.name.to_sym).link
43
+ config_options.link
34
44
  end
35
45
 
36
46
  def time_zone_column
37
- report.column_options_for(self.name.to_sym).time_zone_column
47
+ config_options.time_zone_column
38
48
  end
39
49
 
40
50
  def time_format
41
- report.column_options_for(self.name.to_sym).time_format
51
+ config_options.time_format
42
52
  end
43
53
  end
44
54
 
@@ -163,7 +163,7 @@ module ClarkKent
163
163
  order_column, order_direction = match_value.split('-')
164
164
  end
165
165
  column_info = column_options_for(order_column.to_sym)
166
- if column_info.respond_to? :order_sql
166
+ if column_info.respond_to?(:order_sql) && column_info.order_sql.present?
167
167
  order_sql = column_info.order_sql
168
168
  order_sql = "#{order_sql} #{order_direction}"
169
169
  query = query.order(order_sql)
@@ -0,0 +1,7 @@
1
+ module ClarkKent
2
+ class ReportColumnValidator < ActiveModel::Validator
3
+ def validate(record)
4
+ record.errors[:report_sort] << "This column is not sortable." unless record.sortable?
5
+ end
6
+ end
7
+ end
@@ -33,7 +33,7 @@
33
33
  <% end %>
34
34
  </div>
35
35
  <div class="ih-span one-fifth">
36
- <% unless report_column.report.sort_column.present? and report_column.report.sort_column != report_column %>
36
+ <% if report_column.report.sort_column.blank? || report_column.report.sort_column == report_column %>
37
37
  <%= f.input :report_sort, collection: [['A->Z','ascending'],['Z->A','descending']], include_blank: true %>
38
38
  <% end %>
39
39
  </div>
@@ -1,3 +1,3 @@
1
1
  module ClarkKent
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.1"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
- describe ClarkKent::ReportFiltersController do
3
+ class ClarkKent::ReportFiltersControllerTest < ControllerTest
4
+
4
5
  setup do
5
6
  @routes = ClarkKent::Engine.routes
6
7
  @report = ClarkKent::Report.first
@@ -9,21 +10,21 @@ describe ClarkKent::ReportFiltersController do
9
10
  end
10
11
 
11
12
  test "it should create a report filter" do
12
- post :create, report_filter: {filterable_id: @report.id, filterable_type: "ClarkKent::Report", filter_name: "user_email", filter_value: "taproot@gmail.com"}
13
+ post :create, params: {report_filter: {filterable_id: @report.id, filterable_type: "ClarkKent::Report", filter_name: "user_email", filter_value: "taproot@gmail.com"}}
13
14
  assert_response :success
14
15
  report_filter = ClarkKent::ReportFilter.order(id: :desc).first
15
16
  report_filter.type.must_equal 'ClarkKent::ReportStringFilter'
16
17
  end
17
18
 
18
19
  test "it should create an object report filter" do
19
- post :create, report_filter: {filterable_id: @report.id, filterable_type: "ClarkKent::Report", filter_name: "user_id", filter_value: @current_user.id}
20
+ post :create, params: {report_filter: {filterable_id: @report.id, filterable_type: "ClarkKent::Report", filter_name: "user_id", filter_value: @current_user.id}}
20
21
  assert_response :success
21
22
  report_filter = ClarkKent::ReportFilter.order(id: :desc).first
22
23
  report_filter.type.must_equal 'ClarkKent::ReportObjectFilter'
23
24
  end
24
25
 
25
26
  test "it should create a date report filter" do
26
- post :create, report_filter: {filterable_id: @report_email.id, filterable_type: "ClarkKent::Report", filter_name: 'created_at', duration: 'week', kind_of_day: 'Monday', offset: 'last_week'}
27
+ post :create, params: {report_filter: {filterable_id: @report_email.id, filterable_type: "ClarkKent::Report", filter_name: 'created_at', duration: 'week', kind_of_day: 'Monday', offset: 'last_week'}}
27
28
  assert_response :success
28
29
  report_filter = ClarkKent::ReportFilter.order(id: :desc).first
29
30
  report_filter.type.must_equal 'ClarkKent::ReportDateFilter'
@@ -31,37 +32,37 @@ describe ClarkKent::ReportFiltersController do
31
32
 
32
33
  test "should get the edit form for a string filter" do
33
34
  filter = @report_email.report_filters.create(type: 'ClarkKent::ReportStringFilter', filter_name: "user_email", filter_value: "taproot@gmail.com")
34
- get :edit, id: filter.id
35
+ get :edit, params: {id: filter.id}
35
36
  assert_response :success
36
37
  end
37
38
 
38
39
  test "should get the edit form for an object filter" do
39
40
  filter = @report_email.report_filters.create(type: 'ClarkKent::ReportObjectFilter', filter_name: "user_id", filter_value: @current_user.id)
40
- get :edit, id: filter.id
41
+ get :edit, params: {id: filter.id}
41
42
  assert_response :success
42
43
  end
43
44
 
44
45
  test "should get the edit form for a date filter" do
45
46
  filter = @report_email.report_filters.create(type: 'ClarkKent::ReportDateFilter', filter_name: 'created_at', duration: 'week', kind_of_day: 'Monday', offset: 'last_week')
46
- get :edit, id: filter.id
47
+ get :edit, params: {id: filter.id}
47
48
  assert_response :success
48
49
  end
49
50
 
50
51
  test "should get the show view for a string filter" do
51
52
  filter = @report_email.report_filters.create(type: 'ClarkKent::ReportStringFilter', filter_name: "user_email", filter_value: "taproot@gmail.com")
52
- get :show, id: filter.id
53
+ get :show, params: {id: filter.id}
53
54
  assert_response :success
54
55
  end
55
56
 
56
57
  test "should get the show view for an object filter" do
57
58
  filter = @report_email.report_filters.create(type: 'ClarkKent::ReportObjectFilter', filter_name: "user_id", filter_value: @current_user.id)
58
- get :show, id: filter.id
59
+ get :show, params: {id: filter.id}
59
60
  assert_response :success
60
61
  end
61
62
 
62
63
  test "should get the show view for a date filter" do
63
64
  filter = @report_email.report_filters.create(type: 'ClarkKent::ReportDateFilter', filter_name: 'created_at', duration: 'week', kind_of_day: 'Monday', offset: 'last_week')
64
- get :show, id: filter.id
65
+ get :show, params: {id: filter.id}
65
66
  assert_response :success
66
67
  end
67
68
  end
@@ -1,71 +1,72 @@
1
1
  require 'test_helper'
2
2
 
3
- describe ClarkKent::ReportsController do
3
+ class ClarkKent::ReportsControllerTest < ControllerTest
4
+
5
+ let(:report) {ClarkKent::Report.first}
6
+ let(:current_user) {User.first}
7
+
4
8
  setup do
5
9
  @routes = ClarkKent::Engine.routes
6
- @report = ClarkKent::Report.first
7
- @report_email = @report.report_emails.create(when_to_send: 'Monday', name: 'Owner Arrival')
8
- @current_user = User.first
10
+ @report_email = report.report_emails.create(when_to_send: 'Monday', name: 'Owner Arrival')
9
11
  end
10
12
 
11
- test "should get index" do
12
- get :index, current_user_id: @current_user.id
13
+ it "should get index" do
14
+ get :index, params: {current_user_id: current_user.id}
13
15
  assert_response :success
14
16
  end
15
17
 
16
- test "should get new" do
17
- get :new, current_user_id: @current_user.id
18
+ it "should get new" do
19
+ get :new, params: {current_user_id: current_user.id}
18
20
  assert_response :success
19
21
  end
20
22
 
21
- test "should create report" do
22
- post :create,
23
- report: {
24
- name: 'delete me', resource_type: @report.resource_type,
25
- sharing_scope_id: @report.sharing_scope_id, sharing_scope_type: @report.sharing_scope_type },
26
- current_user_id: @current_user.id
23
+ it "should create report" do
24
+ post :create, params:
25
+ {report: {
26
+ name: 'delete me', resource_type: report.resource_type,
27
+ sharing_scope_id: report.sharing_scope_id, sharing_scope_type: report.sharing_scope_type },
28
+ current_user_id: current_user.id}
27
29
  report = ClarkKent::Report.find_by(name: 'delete me')
28
30
  report.wont_be_nil
29
31
  report.destroy
30
32
  assert_response :success
31
33
  end
32
34
 
33
- test "should show report" do
34
- get :show, id: @report, current_user_id: @current_user.id
35
+ it "should show report" do
36
+ get :show, params: {id: report, current_user_id: current_user.id}
35
37
  assert_response :success
36
38
  end
37
39
 
38
- test "should show report results" do
39
- get :show, id: @report, current_user_id: @current_user.id, run_report: true, created_at_until: Date.today, created_at_from: Date.yesterday
40
+ it "should show report results" do
41
+ get :show, params: {id: report, current_user_id: current_user.id, run_report: true, created_at_until: Date.today, created_at_from: Date.yesterday}
40
42
  assert_response :success
41
- assert_not_nil assigns(:rows)
42
43
  @response.body.must_match 'Guitar strings'
43
44
  end
44
45
 
45
- test "should show report run errors" do
46
- get :show, id: @report, current_user_id: @current_user.id, run_report: true
46
+ it "should show report run errors" do
47
+ get :show, params: {id: report, current_user_id: current_user.id, run_report: true}
47
48
  assert_response :success
48
49
  @response.body.must_match 'At least one date range is required.'
49
50
  end
50
51
 
51
- test "should get edit" do
52
- get :edit, id: @report, current_user_id: @current_user.id
52
+ it "should get edit" do
53
+ get :edit, params: {id: report, current_user_id: current_user.id}
53
54
  assert_response :success
54
55
  end
55
56
 
56
- test "should update report" do
57
- patch :update, id: @report,
58
- report: {
59
- name: @report.name, resource_type: @report.resource_type,
60
- sharing_scope_id: @report.sharing_scope_id, sharing_scope_type: @report.sharing_scope_type },
61
- current_user_id: @current_user.id
57
+ it "should update report" do
58
+ patch :update, params: {id: report,
59
+ report: {
60
+ name: report.name, resource_type: report.resource_type,
61
+ sharing_scope_id: report.sharing_scope_id, sharing_scope_type: report.sharing_scope_type },
62
+ current_user_id: current_user.id}
62
63
  assert_response :success
63
64
  end
64
65
 
65
- test "should destroy report" do
66
+ it "should destroy report" do
66
67
  report = ClarkKent::Report.create(name: 'delete me', resource_type: 'Order')
67
68
  assert_difference('ClarkKent::Report.count', -1) do
68
- delete :destroy, id: report, current_user_id: @current_user.id
69
+ delete :destroy, params: {id: report, current_user_id: current_user.id}
69
70
  end
70
71
 
71
72
  assert_redirected_to reports_path
Binary file