clark_kent 0.7.1 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/clark_kent/report_filters_controller.rb +2 -2
- data/app/controllers/clark_kent/reports_controller.rb +1 -1
- data/app/models/clark_kent/report_column.rb +13 -3
- data/app/models/clark_kent/reportable.rb +1 -1
- data/app/validators/clark_kent/report_column_validator.rb +7 -0
- data/app/views/clark_kent/report_columns/_form.html.erb +1 -1
- data/lib/clark_kent/version.rb +1 -1
- data/test/controllers/clark_kent/report_filters_controller_test.rb +11 -10
- data/test/controllers/clark_kent/reports_controller_test.rb +32 -31
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +7139 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/-p/-p0yY-ZfSq2z3p93_-pQ37fG8LHtag_WTxyycFtpfYg.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/0T/0T4f7V-gjBT3v8qDpXeOYY75WyxL2aodqWk7MiOc0jI.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/5k/5k7OtUEslUWi1MkCA5Kmc7rHAU0hWPFaSUcq7j8-doc.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/DK/DKA8K2AVy7t5pWF88wjHwvc8mVvBXaieFbJ68r_5nkc.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/EF/EFH19OQ02-sMAQJznIN5z49e_78IV0E143KKlj9u2qo.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Hu/HuyKNAYEnPs4OFAHZ6YQZ3VSrTaxZe0Ra_fNZLbeXDw.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/IS/ISN9Hxq36D1ejVxS38niQNl373tRMSHSIDxyFE7cPXM.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Jb/JbcAACpMmVlknG104wCtLY73aNeelGB5NNPiF4uDf5s.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/LN/LNv9fieEzShvj0fy3fulj6rLRJrSie5o91QhOEPDCf4.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/O8/O8akbUwAbmIKY-AhITimq-JDQ6IgsO3Hvq2v5etufFw.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/UV/UVeH93rELRBawlPCnRGGJP4tRFjy_dH7wicU_ZbrCDM.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Ur/UrvBNsTYTsrqJWZ8m86kNZY4jILmqjRZMyHUy-3iYDY.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Uw/UwMFS8rJmeOVTOPUAsy5rBsPqe-mwJgvTSCg-8xwSK8.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/XG/XGAUd4zdycHNjgugiwtNoIzH7Rye3BmjHFqOL3pkrhg.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/c0/c0fZzpmetAbdlEG8jam5O6N3N3wiVzKXR_lCIY6kCTA.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/fH/fHWyzePKbils7mC23jWPCevjAzyBfo8j01idOorqDT0.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/hj/hj8Ir9wcVSy1KYrnWu9bpD24vDhCG3tvt-nKbNxb1Wg.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/iD/iDxOcLQhAs-zS2-4AShuzHEtsbcdSQPBmTI5BP1WfwM.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/kx/kxkWN7_XTUQXY0Jl_27tQE9bqJGPvb8jdSFi36PgCcE.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/oC/oCsZTGZyV4kH8Y4OeSDUdrwfkJFPzTODZjuBKZB8oGQ.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/oU/oUDjXYmDJ26HtNPmg5Ys5Qsbv1KJ8gFj4UjHSno6Nz4.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/qO/qOsXW8q70wL7_ono3kwb4IhdpIs0QYgSGrD77JrlGyo.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/tP/tPF6H9NRpGO3whu2y5_e_R_1EACKdCwu5437D83qJT0.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/x1/x1pNHYQUCVLQm2-2eBri2T7gxgLTBDez3d7ao8etFX4.cache +0 -0
- data/test/models/clark_kent/report_column_test.rb +12 -0
- data/test/models/clark_kent/reportable_test.rb +9 -2
- data/test/test_helper.rb +5 -3
- metadata +77 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e63c1a037abbf2c2830ddad357e7239cfae00ca2
|
|
4
|
+
data.tar.gz: a3514ad0db2d2cd9e9a8020f78aea5e52ef9c011
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff06a601a8d74cd2de05815fb42635cd0325061112a9912fb25bd5350696c62b11bda5a25c4aad481c1b6b3cbe9d0f13d50268d38a1c0f62f8f4cdc9da6b9393
|
|
7
|
+
data.tar.gz: 8df55e3b836dd8f92b85535ef963a6354ba4a8b040092e7668687cd3745fe9d4039cba721dcd8fea1fbe7e38a95b043aa98f76209b436cf41595b73869c0c0f0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class ClarkKent::ReportFiltersController < ClarkKent::ApplicationController
|
|
2
|
-
|
|
3
|
-
|
|
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)
|
|
@@ -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
|
-
|
|
43
|
+
config_options.link
|
|
34
44
|
end
|
|
35
45
|
|
|
36
46
|
def time_zone_column
|
|
37
|
-
|
|
47
|
+
config_options.time_zone_column
|
|
38
48
|
end
|
|
39
49
|
|
|
40
50
|
def time_format
|
|
41
|
-
|
|
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?
|
|
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)
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
<% end %>
|
|
34
34
|
</div>
|
|
35
35
|
<div class="ih-span one-fifth">
|
|
36
|
-
<%
|
|
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>
|
data/lib/clark_kent/version.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
@
|
|
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
|
-
|
|
12
|
-
get :index, 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
|
-
|
|
17
|
-
get :new, 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
|
-
|
|
22
|
-
post :create,
|
|
23
|
-
report: {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
34
|
-
get :show, 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
|
-
|
|
39
|
-
get :show, id:
|
|
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
|
-
|
|
46
|
-
get :show, id:
|
|
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
|
-
|
|
52
|
-
get :edit, 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
|
-
|
|
57
|
-
patch :update, id:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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:
|
|
69
|
+
delete :destroy, params: {id: report, current_user_id: current_user.id}
|
|
69
70
|
end
|
|
70
71
|
|
|
71
72
|
assert_redirected_to reports_path
|
data/test/dummy/db/test.sqlite3
CHANGED
|
Binary file
|