glib-web 3.20.5 → 3.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/glib/json/libs.rb +38 -12
- data/app/helpers/glib/json_ui/action_builder/fields.rb +4 -0
- data/app/helpers/glib/json_ui/view_builder/panels.rb +3 -0
- data/app/helpers/glib/json_ui/view_builder.rb +1 -0
- data/app/views/json_ui/garage/forms/pickers.json.jbuilder +2 -1
- data/app/views/json_ui/garage/forms/selects.json.jbuilder +8 -0
- data/app/views/json_ui/garage/views/icons.json.jbuilder +4 -0
- data/lib/glib/mailer_tester.rb +94 -21
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61bf1dd4994bb6105fb043e7b7b0943cb44e4e418baf246556855816442d6293
|
4
|
+
data.tar.gz: 88902efc0cc5e18d925a1261106df0dca345f5880959dc2cbaca1a91938f83d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b86a31567e3e1eeb2252d5e3fa72796e563873ee7ff72f394e322227a876c31267bc4462383c323ebba40f302fa5fc16be86703569b86ebec3607cbc8caa967
|
7
|
+
data.tar.gz: ebdd87d23e46513bfce6804d6d1ed3fd6004cd00fa9c57b706aace77350d0c13b8603a8344b5e285535286b8fbb8e0b3bbdd23aeb227597ea289709736822e7f
|
@@ -68,6 +68,11 @@ module Glib::Json::Libs
|
|
68
68
|
redirect_to url
|
69
69
|
end
|
70
70
|
format.json do
|
71
|
+
if __json_ui_rendering?
|
72
|
+
redirect_to url
|
73
|
+
return
|
74
|
+
end
|
75
|
+
|
71
76
|
json_ui_redirect_to url
|
72
77
|
end
|
73
78
|
end
|
@@ -91,6 +96,10 @@ module Glib::Json::Libs
|
|
91
96
|
|
92
97
|
REDIRECT_BACK_KEY = :glib_return_to_url
|
93
98
|
|
99
|
+
def json_ui_save_return_url(url = nil)
|
100
|
+
session[REDIRECT_BACK_KEY] = url || url_for(params.to_unsafe_h.merge(format: nil))
|
101
|
+
end
|
102
|
+
|
94
103
|
def glib_handle_401(sign_in_url)
|
95
104
|
if !glib_json_dialog_mode? && request.get?
|
96
105
|
session[REDIRECT_BACK_KEY] = url_for(params.to_unsafe_h.merge(format: nil))
|
@@ -172,10 +181,29 @@ module Glib::Json::Libs
|
|
172
181
|
}
|
173
182
|
end
|
174
183
|
|
175
|
-
def glib_json_handle_500(exception)
|
176
|
-
if json_ui_activated?
|
177
|
-
|
178
|
-
|
184
|
+
def glib_json_handle_500(exception, preview_mode)
|
185
|
+
if json_ui_activated?
|
186
|
+
if Rails.env.production? || preview_mode
|
187
|
+
if defined?(Rollbar) && !preview_mode
|
188
|
+
Rollbar.error(exception, :use_exception_level_filters => true)
|
189
|
+
end
|
190
|
+
|
191
|
+
render file: Rails.root.join('public', '500.html'), status: :internal_server_error
|
192
|
+
else
|
193
|
+
raise exception
|
194
|
+
end
|
195
|
+
else
|
196
|
+
raise exception
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def glib_json_handle_404(exception, preview_mode)
|
201
|
+
if json_ui_activated?
|
202
|
+
if Rails.env.production? || preview_mode
|
203
|
+
render file: Rails.root.join('public', '404.html'), status: :not_found
|
204
|
+
else
|
205
|
+
raise exception
|
206
|
+
end
|
179
207
|
else
|
180
208
|
raise exception
|
181
209
|
end
|
@@ -262,18 +290,16 @@ module Glib::Json::Libs
|
|
262
290
|
|
263
291
|
# Call this before other rescues. Later rescue_from statements will take precedence, so more specific
|
264
292
|
# rescues have to be declared later.
|
265
|
-
def json_libs_rescue_500
|
293
|
+
def json_libs_rescue_500(preview_mode: false)
|
266
294
|
rescue_from StandardError do |exception|
|
267
|
-
glib_json_handle_500(exception)
|
295
|
+
glib_json_handle_500(exception, preview_mode)
|
268
296
|
end
|
269
297
|
end
|
270
298
|
|
271
|
-
def json_libs_rescue_404
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
# end
|
299
|
+
def json_libs_rescue_404(preview_mode: false)
|
300
|
+
rescue_from ActiveRecord::RecordNotFound do |exception|
|
301
|
+
glib_json_handle_404(exception, preview_mode)
|
302
|
+
end
|
276
303
|
end
|
277
|
-
|
278
304
|
end
|
279
305
|
end
|
@@ -277,18 +277,21 @@ class Glib::JsonUi::ViewBuilder
|
|
277
277
|
end
|
278
278
|
|
279
279
|
class Column < View
|
280
|
+
hash :xxl
|
280
281
|
hash :xl
|
281
282
|
hash :lg
|
282
283
|
hash :md
|
283
284
|
hash :sm
|
284
285
|
hash :xs
|
285
286
|
|
287
|
+
hash :xxlOnly
|
286
288
|
hash :xlOnly
|
287
289
|
hash :lgOnly
|
288
290
|
hash :mdOnly
|
289
291
|
hash :smOnly
|
290
292
|
hash :xsOnly
|
291
293
|
|
294
|
+
hash :xxlAndDown
|
292
295
|
hash :xlAndDown
|
293
296
|
hash :lgAndDown
|
294
297
|
hash :mdAndDown
|
@@ -82,7 +82,8 @@ page.form \
|
|
82
82
|
form.h2 text: 'Country'
|
83
83
|
form.spacer height: 6
|
84
84
|
region_field = { name: 'user[city]', label: 'City' }
|
85
|
-
form.fields_country name: 'user[country]', width: 'matchParent', label: 'Country', region:
|
85
|
+
form.fields_country name: 'user[country]', width: 'matchParent', label: 'Country', region: nil
|
86
|
+
form.fields_country name: 'user[country_with_region]', width: 'matchParent', label: 'Country with region', region: region_field
|
86
87
|
|
87
88
|
form.spacer height: 20
|
88
89
|
form.h2 text: 'Map'
|
@@ -72,6 +72,14 @@ page.form url: json_ui_garage_url(path: 'forms/generic_post'), method: 'post', p
|
|
72
72
|
end
|
73
73
|
accessory.footer padding: { x: 16, y: 10 }, childViews: ->(footer) do
|
74
74
|
footer.label text: 'Footer'
|
75
|
+
footer.spacer height: 14
|
76
|
+
footer.label text: 'Click me', onClick: ->(action) do
|
77
|
+
action.components_findClosest view: 'fields/select', onFind: ->(subaction) do
|
78
|
+
subaction.components_set data: { value: 'pt' }, onSet: ->(subsubaction) do
|
79
|
+
subsubaction.fields_blur
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
75
83
|
end
|
76
84
|
end
|
77
85
|
|
@@ -16,4 +16,8 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
|
|
16
16
|
scroll.spacer height: 20
|
17
17
|
scroll.h2 text: 'Icon with badge'
|
18
18
|
scroll.icon name: 'home', badge: { text: '22', backgroundColor: '#00ff00' }
|
19
|
+
|
20
|
+
scroll.spacer height: 20
|
21
|
+
scroll.h2 text: 'Icon with styleClasses'
|
22
|
+
scroll.icon name: 'home', styleClasses: ['small']
|
19
23
|
end
|
data/lib/glib/mailer_tester.rb
CHANGED
@@ -3,37 +3,110 @@ module Glib
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def generate_preview_tests
|
11
|
+
project_root = Rails.root
|
12
|
+
paths = Dir.glob(project_root + 'test/mailers/previews/*')
|
13
|
+
paths.each do |file|
|
14
|
+
require file
|
15
|
+
end
|
11
16
|
|
12
|
-
|
13
|
-
|
17
|
+
ActionMailer::Preview.subclasses.each do |preview_class|
|
18
|
+
preview = preview_class.new
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
20
|
+
preview_class.instance_methods(false).each do |mailer_method|
|
21
|
+
test "mailer for #{preview_class}##{mailer_method}" do
|
22
|
+
preview.send(mailer_method).deliver_now
|
18
23
|
|
19
|
-
|
20
|
-
|
24
|
+
# See TimeFreezableMailer
|
25
|
+
preview.try(:return_time_if_frozen)
|
21
26
|
|
22
|
-
|
27
|
+
_assert_last_mail_body_unchanged("#{preview_class.name.underscore}##{mailer_method}")
|
23
28
|
|
24
|
-
|
25
|
-
expected = File.exist?(logfile) ? File.read(logfile).rstrip : ''
|
26
|
-
last_delivery = ActionMailer::Base.deliveries.last
|
27
|
-
result = last_delivery.html_part.body.raw_source.rstrip
|
29
|
+
# logfile = File.join(log_dir, "#{preview_class.name.underscore}##{mailer_method}.txt")
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
# # Use rstrip to avoid trailing space issues
|
32
|
+
# expected = File.exist?(logfile) ? File.read(logfile).rstrip : ''
|
33
|
+
# # last_delivery = ActionMailer::Base.deliveries.last
|
34
|
+
# # result = last_delivery.html_part.body.raw_source.rstrip
|
32
35
|
|
33
|
-
|
36
|
+
# # result = mails.last.html_part.body.raw_source.rstrip
|
37
|
+
# result = last_mail_body
|
38
|
+
|
39
|
+
# logger = File.open(logfile, 'w')
|
40
|
+
# logger.puts result
|
41
|
+
# logger.close
|
42
|
+
|
43
|
+
# assert_equal expected, result, "Result mismatch! #{logfile.sub(/\.txt$/, '')}"
|
44
|
+
end
|
34
45
|
end
|
35
46
|
end
|
36
47
|
end
|
37
48
|
end
|
49
|
+
|
50
|
+
def log_root_dir
|
51
|
+
raise 'Implementation needed'
|
52
|
+
end
|
53
|
+
|
54
|
+
# Overridable
|
55
|
+
def log_dir
|
56
|
+
File.expand_path(File.join(log_root_dir, "results/#{class_name.underscore}/"))
|
57
|
+
end
|
58
|
+
|
59
|
+
def reset_mails
|
60
|
+
ActionMailer::Base.deliveries = []
|
61
|
+
end
|
62
|
+
|
63
|
+
def mails
|
64
|
+
@mails ||= ActionMailer::Base.deliveries
|
65
|
+
end
|
66
|
+
|
67
|
+
def last_mail
|
68
|
+
raise 'Last mail does not exist' unless (mail = mails.last)
|
69
|
+
|
70
|
+
mail
|
71
|
+
end
|
72
|
+
|
73
|
+
def assert_mails_unchanged
|
74
|
+
mails.each do |mail|
|
75
|
+
assert_mail_unchanged(mail)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# TODO: Remove test result files that are not relevant anymore
|
80
|
+
def assert_mail_unchanged(mail)
|
81
|
+
# `method_name` refers to the name of the current test method.
|
82
|
+
dir = File.join(log_dir, method_name)
|
83
|
+
unless File.directory?(dir)
|
84
|
+
FileUtils.mkdir_p(dir)
|
85
|
+
end
|
86
|
+
|
87
|
+
mail.to.each do |recipient|
|
88
|
+
_assert_mail_body_unchanged("#{method_name}/#{recipient}", mail)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# def assert_last_mail_body_unchanged
|
93
|
+
# # `method_name` refers to the name of the current test method.
|
94
|
+
# _assert_mail_body_unchanged(method_name, last_mail)
|
95
|
+
# end
|
96
|
+
|
97
|
+
private
|
98
|
+
def _assert_mail_body_unchanged(log_path, mail)
|
99
|
+
file = File.join(log_dir, "#{log_path}.txt")
|
100
|
+
|
101
|
+
# Use rstrip to avoid trailing space issues
|
102
|
+
expected = File.exist?(file) ? File.read(file).rstrip : ''
|
103
|
+
result = mail.html_part.body.raw_source.rstrip
|
104
|
+
|
105
|
+
logger = File.open(file, 'w')
|
106
|
+
logger.puts result
|
107
|
+
logger.close
|
108
|
+
|
109
|
+
assert_equal expected, result, "Result mismatch! #{file.sub(/\.txt$/, '')}"
|
110
|
+
end
|
38
111
|
end
|
39
112
|
end
|