hot-glue 0.5.17 → 0.5.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b466a03ce8d764332b3f3d8673bc29b6071308cb976706632a70713b6efb53b4
4
- data.tar.gz: 03f8580d7266c767b1bed6a1e325c515bc09a5d9886356250ed9a4d936bab452
3
+ metadata.gz: a492a1e3528a8f8cbe485fe6e2c489896740184e55b8a910312bbaaeb9439e72
4
+ data.tar.gz: e935b8bb498f464b978a34d9714603f41bc7af3d530a9844b560693184344bf0
5
5
  SHA512:
6
- metadata.gz: 3e0b66aa6cbab6a813a810f6bee04503c0f7437f53dc2a7a2f27aadad8b09a559a1d540f7c6ce850c5a25f641ab847edeb6c5b26fc83c6b6728bb52278bbc3bb
7
- data.tar.gz: 5bcc706e9ad0a620c33a5815fc5160fe7afef6b9468d1d920032d1daffbfc3bc304816dc661d1c359b1002fdc854d1757869844e7afe1efa2f0eb021df408827
6
+ metadata.gz: aa2d1676222bc0a91b945654bd93d452a5c102625068f5ab6acbca3eb250f79b6e3030fdcaf2b3a61672d143d8813fc39280581542c8bb2e4d94760d0f0ad944
7
+ data.tar.gz: b048a9fb6f22d24f10920da6f67297aa8c1e57ccea6850ee442d6fe27f85be4ceeba76f86c5fdc2f79afd2691b0bbdc6f897738dc63a0857076824d15d1e332c
data/.circleci/config.yml CHANGED
@@ -3,7 +3,7 @@ version: 2.1
3
3
 
4
4
  orbs:
5
5
  ruby: circleci/ruby@1.0
6
- browser-tools: circleci/browser-tools@1.4.1
6
+ browser-tools: circleci/browser-tools@1.4.4
7
7
 
8
8
  jobs:
9
9
  build:
@@ -47,7 +47,15 @@ jobs:
47
47
  RAILS_ENV: test
48
48
 
49
49
  steps:
50
- - browser-tools/install-chrome
50
+ - run: sudo apt-get update
51
+ - browser-tools/install-browser-tools:
52
+ chrome-version: 116.0.5845.96 # TODO: remove when chromedriver downloads are fixed
53
+ replace-existing-chrome: true
54
+ - browser-tools/install-chrome:
55
+ # TODO remove following line when fixed https://github.com/CircleCI-Public/browser-tools-orb/issues/90
56
+ chrome-version: 116.0.5845.96
57
+ replace-existing: true
58
+
51
59
  - browser-tools/install-chromedriver
52
60
  - checkout
53
61
  - ruby/install-deps
@@ -0,0 +1,46 @@
1
+ # This workflow uses actions that are not certified by GitHub. They are
2
+ # provided by a third-party and are governed by separate terms of service,
3
+ # privacy policy, and support documentation.
4
+ #
5
+ # This workflow will install a prebuilt Ruby version, install dependencies, and
6
+ # run tests and linters.
7
+ name: "Test Suite"
8
+ on:
9
+ push:
10
+ branches: [ "main" ]
11
+ pull_request:
12
+ branches: [ "main" ]
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+ services:
17
+ postgres:
18
+ image: postgres:11-alpine
19
+ ports:
20
+ - "5432:5432"
21
+ env:
22
+ POSTGRES_DB: rails_test
23
+ POSTGRES_USER: rails
24
+ POSTGRES_PASSWORD: password
25
+ chrome:
26
+ image: selenium/standalone-chrome:latest
27
+ ports:
28
+ - 4444:4444
29
+ env:
30
+ RAILS_ENV: test
31
+ DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test"
32
+
33
+
34
+ steps:
35
+ - name: Checkout code
36
+ uses: actions/checkout@v3
37
+ - name: Install Ruby and gems
38
+ uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
39
+ with:
40
+ bundler-cache: true
41
+
42
+ - name: internal tests
43
+ run: bundle exec rspec
44
+ - name: system tests
45
+ run: script/test
46
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot-glue (0.5.16)
4
+ hot-glue (0.5.17)
5
5
  ffaker (~> 2.16)
6
6
  kaminari (~> 1.2)
7
7
  rails (> 5.1)
data/README.md CHANGED
@@ -1159,13 +1159,13 @@ factory = AgentFactory.new(find_or_create_by_email: agent_company_params[:__look
1159
1159
  params: modified_params)
1160
1160
  ```
1161
1161
 
1162
- Here the new AgentFactory will recieve any variables by keyword argument, and since you're specifying the calling code here, Hot Glue does not dictate your factory's setup.
1162
+ Here the new AgentFactory will receive any variables by keyword argument, and since you're specifying the calling code here, Hot Glue does not dictate your factory's setup.
1163
1163
  However, two special variables are in scope which you can use in your calling code.
1164
1164
 
1165
1165
  `*_params` (where * is the name of the thing you are building)
1166
- `modified_params` a variable that has been transmogrified for the timezone aware input
1166
+ `modified_params`
1167
1167
 
1168
- Either one must be recieved by your factory for your factory to create data based off the inputted data.
1168
+ Either one must be received by your factory for your factory to create data based off the inputted data.
1169
1169
 
1170
1170
  Rememebr, `*_params` has the input params passed only the through the sanitizer, and modified_params has it passed through the timezone aware mechanism and other Hot Glue-specific defaults.
1171
1171
 
@@ -1179,14 +1179,14 @@ Always:
1179
1179
  Don't include this last line in your factory code.
1180
1180
 
1181
1181
  ## Nav Templates
1182
- At the namespace level, you can have a file called `_nav.html.erb` to create tabbed bootstrap nav (you'll need to create this file manually).
1182
+ At the namespace level, you can have a file called `_nav.html.erb` to create tabbed bootstrap nav
1183
1183
 
1184
- To create the default template, start by running
1184
+ To create the file for the first time (at each namespace), start by running
1185
1185
  ```
1186
1186
  bin/rails generate hot_glue:nav_template --namespace=xyz
1187
-
1188
1187
  ```
1189
- this will append the file `_nav.html.erb` to the views folder at `views/xyz`
1188
+
1189
+ This will append the file `_nav.html.erb` to the views folder at `views/xyz`. To begin, this file contains only the following:
1190
1190
 
1191
1191
  ```
1192
1192
  <ul class='nav nav-tabs'>
@@ -1195,19 +1195,18 @@ this will append the file `_nav.html.erb` to the views folder at `views/xyz`
1195
1195
 
1196
1196
  Once the file is present, any further builds in this namespace will:
1197
1197
 
1198
- 1) Append to the `_nav.html.erb` file, adding a tab for the new built scaffold
1199
- 2) Add render to the list view of the built scaffold to include the partial:
1198
+ 1) Append to this `_nav.html.erb` file, adding a tab for the new built scaffold
1199
+ 2) On the list view of the scaffold being built, it will include a render to the _nav partial, passing the name of the currently-viewed thing as the local variable `nav` (this is how the nav template knows which tab to make active).
1200
1200
  ```
1201
1201
  <%= render partial: "owner/nav", locals: {nav: "things"} %>
1202
1202
  ```
1203
- (in this example `owner/` is the namespace and `things` is the name of the scaffold being built)
1203
+ (In this example `owner/` is the namespace and `things` is the name of the scaffold being built)
1204
1204
 
1205
1205
  ## Automatic Base Controller
1206
1206
 
1207
- HotGlue will copy a file named base_controller.rb to the same folder where it tries to create any controller, unless such a file exists there already.
1208
-
1209
- The created controller will always have this base controller as its subclass. You are encouraged to implement functionality common to the *namespace* (shared between the controllers in the namespace) using this technique.
1207
+ Hot Glue will copy a file named `base_controller.rb` to the same folder where it tries to create any controller (so to the namespace), unless such a file exists there already.
1210
1208
 
1209
+ The created controller will always have this base controller as its subclass. You are encouraged to implement functionality common to all the controllers in the *namespace* in the base class. For example, authorizing your user to access that part of the app.
1211
1210
 
1212
1211
  ## Special Table Labels
1213
1212
 
@@ -1301,10 +1300,37 @@ end
1301
1300
  ```
1302
1301
 
1303
1302
 
1303
+ # VERSION HISTORY
1304
1304
 
1305
+ #### 2023-09-01 - v0.5.18
1306
+ - there three ways Hot Glue deals with Datetime fields:
1307
+ -
1308
+ - (1) with current users who have `timezone` method (field or method)
1309
+ - (2) without current user timezone and no global timezone set for your app
1310
+ - (3) without current user timezone and global timezone set for your app
1305
1311
 
1312
+ - For #1, previously this method returned a time zone offset (integer). After v0.5.18, the preferred return value is a Timezone string, but legacy implementation returning offset values will continue to work.
1313
+ Your user objects should have a field called `timezone` which should be a string.
1314
+ - Note that daylight savings time is accounted for in this implementation.
1315
+
1316
+ - For #2 (your user does not have a timezone field and you _have not_ set the timezone globally), all datetimes will display in UTC timezone.
1317
+
1318
+ - For #3 (your user does not have a timezone field but you _have_ set the timezone globally), your datetimes will display in the Rails-specified timezone.
1319
+
1320
+ - be sure to configure in `config/application.rb` this:
1321
+ ```
1322
+ config.time_zone = 'Eastern Time (US & Canada)'
1323
+ ```
1324
+ This should be your business's default timezone.
1325
+
1326
+
1327
+ (#93)
1328
+ fixes variables be more clear if they are TimeZone objects (https://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html) or are UTC offset (integers -/+ from UTC)
1329
+ - fixes spec assertions for DateTime and Time fields
1330
+ - removes randomness causing race conditions in the datetime object specs
1331
+ **- fixes issue where setting bootstrap-column-width was not preferred if… (#88)**
1332
+ - fixes flash notice output
1306
1333
 
1307
- # VERSION HISTORY
1308
1334
 
1309
1335
  #### 2023-08-18 - v0.5.17
1310
1336
 
@@ -5,10 +5,11 @@ module HotGlue
5
5
  (tz >= 0 ? "+" : "-") + sprintf('%02d',tz.abs) + ":00"
6
6
  end
7
7
 
8
- def datetime_field_localized(form_object, field_name, value, label, timezone = nil )
8
+ def datetime_field_localized(form_object, field_name, value, label )
9
+ current_timezone
9
10
  form_object.text_field(field_name, class: 'form-control',
10
11
  type: 'datetime-local',
11
- value: date_to_current_timezone(value, timezone)) + timezonize(timezone)
12
+ value: date_to_current_timezone(value, current_timezone)) + timezonize(current_timezone)
12
13
  end
13
14
 
14
15
 
@@ -18,53 +19,65 @@ module HotGlue
18
19
  value: value )
19
20
  end
20
21
 
21
- def time_field_localized(form_object, field_name, value, label, timezone = nil )
22
+ def time_field_localized(form_object, field_name, value, label )
23
+ current_timezone
22
24
  form_object.text_field(field_name, class: 'form-control',
23
25
  type: 'time',
24
- value: date_to_current_timezone(value, timezone)) + timezonize(timezone)
26
+ value: value && value.strftime("%H:%M"))
25
27
 
26
28
  end
27
29
 
28
30
  def current_timezone
31
+ # returns a TimeZone (https://apidock.com/rails/TimeZone) object
29
32
  if defined?(current_user)
30
33
  if current_user.try(:timezone)
31
- Time.now.in_time_zone(current_user.timezone.to_i).strftime("%z").to_i/100
34
+ current_user.timezone
35
+
36
+ # Time.now.in_time_zone(current_user.timezone.to_i).zone
32
37
  else
33
- server_timezone
38
+ Rails.application.config.time_zone
39
+ # Time.zone.name
34
40
  end
35
41
  else
36
- server_timezone
42
+ Rails.application.config.time_zone
43
+ # Time.zone.name
37
44
  end
38
45
  end
39
46
 
40
47
  def date_to_current_timezone(date, timezone = nil)
41
- # if the timezone is nil, use the server date'
42
-
43
- if timezone.nil?
44
- timezone = Time.now.strftime("%z").to_i/100
48
+ # used for displaying when in EDIT mode
49
+ # (this format is how the browser expectes to receive the value='' of the input field)
50
+ if date.nil?
51
+ return nil
52
+ else
53
+ return date.in_time_zone(timezone).strftime("%Y-%m-%dT%H:%M")
45
54
  end
46
-
47
- return nil if date.nil?
48
-
49
- return date.in_time_zone(timezone).strftime("%Y-%m-%dT%H:%M")
50
- # begin
51
- #
52
- # rescue
53
- # return nil
54
- # end
55
55
  end
56
56
 
57
- def modify_date_inputs_on_params(modified_params, current_user_object = nil)
58
-
59
- use_timezone = (current_user_object.try(:timezone)) || Time.now.strftime("%z")
57
+ def modify_date_inputs_on_params(modified_params, current_user_object = nil, field_list = nil)
58
+ use_offset = (current_user_object.try(:timezone)) || server_timezone_offset
60
59
 
61
60
  modified_params = modified_params.tap do |params|
62
61
  params.keys.each{|k|
63
- if k.ends_with?("_at") || k.ends_with?("_date")
64
62
 
65
- begin
66
- params[k] = DateTime.strptime("#{params[k]} #{use_timezone}", '%Y-%m-%dT%H:%M %z')
67
- rescue StandardError
63
+ if field_list.nil? # legacy pre v0.5.18 behavior
64
+ include_me = k.ends_with?("_at") || k.ends_with?("_date")
65
+ else
66
+ include_me = field_list.include?(k.to_sym)
67
+ end
68
+ if include_me
69
+ if use_offset != 0
70
+ puts "changing #{params[k]}"
71
+
72
+ if use_offset.is_a? String
73
+ puts "parsing #{use_offset}"
74
+ zone = DateTime.now.in_time_zone(use_offset).zone
75
+ params[k] = DateTime.parse(params[k].gsub("T", " ") + " #{zone}")
76
+ else
77
+ puts "parsing #{use_offset}"
78
+ params[k] = DateTime.strptime("#{params[k]} #{use_offset}", '%Y-%m-%dT%H:%M %z').new_offset(0)
79
+ end
80
+ puts "changed #{params[k]}"
68
81
 
69
82
  end
70
83
  end
@@ -73,7 +86,6 @@ module HotGlue
73
86
  modified_params
74
87
  end
75
88
 
76
-
77
89
  def hawk_params(hawk_schema, modified_params)
78
90
  @hawk_alarm = ""
79
91
  hawk_schema.each do |hawk_key,hawk_definition|
@@ -94,8 +106,8 @@ module HotGlue
94
106
 
95
107
  private
96
108
 
97
- def server_timezone
98
- Time.now.strftime("%z").to_i/100
109
+ def server_timezone_offset # returns integer of hours to add/subtract from UTC
110
+ Time.now.in_time_zone(Rails.application.config.time_zone).strftime("%z").to_i/100
99
111
  end
100
112
  end
101
113
  end
@@ -10,7 +10,7 @@ class DateField < Field
10
10
 
11
11
 
12
12
  def form_field_output
13
- "<%= date_field_localized(f, :#{name}, #{singular}.#{name}, '#{ name.to_s.humanize }', #{auth ? auth+'.timezone' : 'nil'}) %>"
13
+ "<%= date_field_localized(f, :#{name}, #{singular}.#{name}, '#{ name.to_s.humanize }') %>"
14
14
  end
15
15
 
16
16
  def line_field_output
@@ -4,21 +4,21 @@ class DateTimeField < Field
4
4
  end
5
5
 
6
6
  def spec_setup_and_change_act(which_partial = nil)
7
- " " + "new_#{name} = DateTime.current + (rand(100).days) \n" +
7
+ " " + "new_#{name} = DateTime.current + 1.year \n" +
8
8
  ' ' + "find(\"[name='#{testing_name}[#{ name.to_s }]']\").fill_in(with: new_#{name.to_s})"
9
9
 
10
10
  end
11
11
 
12
12
  def spec_make_assertion
13
13
  if !modify_binary?
14
- "expect(page).to have_content(new_#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone))"
14
+ "expect(page).to have_content(new_#{name}.in_time_zone(testing_timezone).strftime('%m/%d/%Y @ %l:%M %p %Z').gsub(' ', ' '))"
15
15
  else
16
16
  "expect(page).to have_content('#{modify[:binary][:truthy]}'"
17
17
  end
18
18
  end
19
19
 
20
20
  def spec_setup_let_arg
21
- "#{name}: DateTime.current + rand(1000).seconds"
21
+ "#{name}: DateTime.current + 1.day"
22
22
  end
23
23
 
24
24
  def spec_list_view_assertion
@@ -30,11 +30,11 @@ class DateTimeField < Field
30
30
  end
31
31
 
32
32
  def spec_list_view_natural_assertion
33
- "expect(page).to have_content(#{singular}#{1}.#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ').gsub(' ', ' ') + timezonize(current_timezone) )"
33
+ "expect(page).to have_content(#{singular}#{1}.#{name}.in_time_zone(testing_timezone).strftime('%m/%d/%Y @ %l:%M %p %Z').gsub(' ', ' '))"
34
34
  end
35
35
 
36
36
  def form_field_output
37
- "<%= datetime_field_localized(f, :#{name}, #{singular}.#{name}, '#{ name.to_s.humanize }', #{auth ? auth+'.timezone' : 'nil'}) %>"
37
+ "<%= datetime_field_localized(f, :#{name}, #{singular}.#{name}, '#{ name.to_s.humanize }') %>"
38
38
  end
39
39
 
40
40
  def line_field_output
@@ -42,7 +42,7 @@ class DateTimeField < Field
42
42
  modified_display_output
43
43
  else
44
44
  "<% unless #{singular}.#{name}.nil? %>
45
- <%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
45
+ <%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p %Z') %>
46
46
  <% else %>
47
47
  <span class='alert-danger'>MISSING</span>
48
48
  <% end %>"
@@ -5,22 +5,30 @@ class TimeField < Field
5
5
  end
6
6
 
7
7
  def form_field_output
8
- "<%= time_field_localized(f, :#{name}, #{singular}.#{name}, '#{ name.to_s.humanize }', #{auth ? auth+'.timezone' : 'nil'}) %>"
8
+ "<%= time_field_localized(f, :#{name}, #{singular}.#{name}, '#{ name.to_s.humanize }') %>"
9
9
  end
10
10
 
11
11
  def line_field_output
12
12
  "<% unless #{singular}.#{name}.nil? %>
13
- <%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone) %>
13
+ <%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%l:%M %p ') %>
14
14
  <% else %>
15
15
  <span class='alert-danger'>MISSING</span>
16
16
  <% end %>"
17
17
  end
18
18
 
19
+ def spec_setup_and_change_act(which_partial = nil)
20
+ " new_#{name} = Time.current + 5.seconds \n" +
21
+ ' ' + "find(\"[name='#{testing_name}[#{ name.to_s }]']\").fill_in(with: new_#{name.to_s})"
22
+
23
+ end
24
+
19
25
  def spec_make_assertion
20
- "#expect(page).to have_content(new_#{name} .in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone))"
26
+ "expect(page).to have_content(new_#{name}.strftime('%l:%M %p').strip)"
21
27
  end
22
28
 
23
29
  def spec_list_view_assertion
24
- "#expect(page).to have_content(#{singular}#{1}.#{name})"
30
+ # "expect(page).to have_content(#{singular}#{1}.#{name})"
25
31
  end
32
+
33
+
26
34
  end
@@ -115,7 +115,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
115
115
 
116
116
  @markup = get_default_from_config(key: :markup)
117
117
  @sample_file_path = get_default_from_config(key: :sample_file_path)
118
- @bootstrap_column_width ||= get_default_from_config(key: :bootstrap_column_width) || 2
118
+ @bootstrap_column_width ||= options['bootstrap_column_width'] ||
119
+ get_default_from_config(key: :bootstrap_column_width) || 2
119
120
 
120
121
  if options['layout']
121
122
  layout = options['layout']
@@ -154,6 +155,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
154
155
  @controller_build_folder_singular = singular
155
156
 
156
157
  @auth = options['auth'] || "current_user"
158
+
159
+ @god = options['god'] || options['gd'] || false
157
160
  @auth_identifier = options['auth_identifier'] || (!@god && @auth.gsub("current_", "")) || nil
158
161
 
159
162
  if options['nest']
@@ -256,7 +259,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
256
259
  raise HotGlue::Error, "You passed '#{@inline_list_labels}' as the setting for --inline-list-labels but the only allowed options are before, after, and omit (default)"
257
260
  end
258
261
 
259
- @god = options['god'] || options['gd'] || false
260
262
  @specs_only = options['specs_only'] || false
261
263
 
262
264
  @no_specs = options['no_specs'] || false
@@ -292,7 +294,6 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
292
294
  if @god
293
295
  @auth = nil
294
296
  end
295
-
296
297
  # when in self auth, the object is the same as the authenticated object
297
298
 
298
299
  if @auth && auth_identifier == @singular
@@ -645,9 +646,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
645
646
  end
646
647
  end
647
648
 
648
- def auth_root
649
- "authenticate_" + @auth_identifier.split(".")[0] + "!"
650
- end
649
+
651
650
 
652
651
  def formats
653
652
  [format]
@@ -818,6 +817,14 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
818
817
  nested_set: @nested_set)
819
818
  end
820
819
 
820
+ def datetime_fields_list
821
+ @columns.select do |col|
822
+ if @the_object.columns_hash[col.to_s]
823
+ @the_object.columns_hash[col.to_s].type == :datetime
824
+ end
825
+ end
826
+ end
827
+
821
828
  def form_path_new_helper
822
829
  HotGlue.optionalized_ternary(namespace: @namespace,
823
830
  target: @controller_build_folder,
@@ -951,6 +958,15 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
951
958
  @auth
952
959
  end
953
960
 
961
+ def current_user_object
962
+ default_current_user = options['auth'] || "current_user"
963
+ if eval("defined?(#{default_current_user})")
964
+ default_current_user
965
+ else
966
+ "nil"
967
+ end
968
+ end
969
+
954
970
  def no_devise_installed
955
971
  !Gem::Specification.sort_by { |g| [g.name.downcase, g.version] }.group_by { |g| g.name }['devise']
956
972
  end
@@ -5,7 +5,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
5
5
  helper :hot_glue
6
6
  include HotGlue::ControllerHelper
7
7
 
8
- <% unless @auth_identifier == '' || @god %>before_action :<%= auth_root %><% end %><% if any_nested? %>
8
+ <% unless @god %>before_action :<%= "authenticate_" + @auth_identifier.split(".")[0] + "!" %><% end %><% if any_nested? %>
9
9
  <% nest_chain = [] %> <% @nested_set.each { |arg|
10
10
 
11
11
  if auth_identifier == arg[:singular]
@@ -86,8 +86,16 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
86
86
  <% if @alt_lookups.any? %><%= @alt_lookups.collect{|key, data|
87
87
  " #{data[:assoc].downcase} = #{data[:assoc]}.#{data[:with_create] ? "find_or_create_by" : "find_by"}(#{data[:lookup_as]}: #{ singular_name }_params[:__lookup_#{data[:lookup_as]}])\n"
88
88
  }.join("/n") %><% end %> <% merge_lookups = @alt_lookups.collect{|key, data| "#{key.gsub("_id", "")}: #{key.gsub("_id", "")}" }.join(",") %>
89
- modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup<%= controller_update_params_tap_away_alt_lookups %><% if @object_owner_sym && eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>.merge!(<% if @object_owner_optional && any_nested? %><%= @object_owner_name %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}<% else %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)<% end %>)<%= ".merge(#{merge_lookups})" if !merge_lookups.empty? %><% if @hawk_keys.any? %>
90
- modified_params = hawk_params({<%= hawk_to_ruby %>}, modified_params)<% end %><%= controller_attachment_orig_filename_pickup_syntax %>
89
+ modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup<%= controller_update_params_tap_away_alt_lookups %>, <%= current_user_object %>, <%= datetime_fields_list %>) <% if @object_owner_sym && eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>
90
+ modified_params = modified_params.merge(<%= @object_owner_sym %>: <%= @object_owner_eval %>) <% elsif @object_owner_optional && any_nested? %>
91
+ modified_params = modified_params.merge(<%= @object_owner_name %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}) <% elsif !@object_owner_eval.empty? %>
92
+ modified_params = modified_params.merge(<%= @object_owner_eval %>) <% end %><% if !merge_lookups.empty? %>
93
+ modified_params = modified_params.merge(<%= merge_lookups %>)
94
+ <% end %>
95
+
96
+ <% if @hawk_keys.any? %>
97
+ modified_params = hawk_params({<%= hawk_to_ruby %>}, modified_params)<% end %>
98
+ <%= controller_attachment_orig_filename_pickup_syntax %>
91
99
  <%= creation_syntax %>
92
100
 
93
101
  if @<%= singular_name %>.save
@@ -112,7 +120,12 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
112
120
  }.join("\n") %><% end %> <% merge_lookups = @alt_lookups.filter{|key,d| ! @update_show_only.include?(key.to_sym) }.collect{|key, data| "#{key.gsub("_id", "")}: #{key.gsub("_id", "")}" }.join(",") %>
113
121
  <% @magic_buttons.each { |button| %>@<%= singular_name %>.<%= button %>! if <%= singular_name %>_params[:__<%= button %>]
114
122
  <% } %>
115
- modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup<% if @object_owner_sym && eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>.merge!(<% if @object_owner_optional && any_nested? %><%= @object_owner_name %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}<% else %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)<% end %>)<%= controller_update_params_tap_away_alt_lookups %><%= controller_update_params_tap_away_magic_buttons %><%= ".merge(#{merge_lookups})" if !merge_lookups.empty? %>
123
+ modified_params = modify_date_inputs_on_params(<%= singular_name %>_params.dup<%= controller_update_params_tap_away_alt_lookups %>, <%= current_user_object %>, <%= datetime_fields_list %>) <% if @object_owner_sym && eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>
124
+ modified_params = modified_params.merge(<%= @object_owner_sym %>: <%= @object_owner_eval %>) <% elsif @object_owner_optional && any_nested? %>
125
+ modified_params = modified_params.merge(<%= @object_owner_name %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}) <% elsif !@object_owner_eval.empty? %>
126
+ modified_params = modified_params.merge(<%= @object_owner_eval %>) <% end %><% if !merge_lookups.empty? %>
127
+ modified_params = modified_params.merge(<%= merge_lookups %>)
128
+ <% end %>
116
129
 
117
130
  <% if @hawk_keys.any? %> modified_params = hawk_params({<%= hawk_to_ruby %>}, modified_params)<% end %>
118
131
  <% if @alt_lookups.any? %><%= @alt_lookups.collect{|key, data|
@@ -125,7 +138,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
125
138
  }.join("/n") %><% end %><%= controller_attachment_orig_filename_pickup_syntax %>
126
139
  if @<%= singular_name %>.update(modified_params)
127
140
  <% if @display_list_after_update %> load_all_<%= plural %><% end %>
128
- flash[:notice] = "#{flash[:notice]} Saved \#{@<%= singular %>.<%= display_class %>}"
141
+ flash[:notice] = "#{flash[:notice]} Saved #{@<%= singular %>.<%= display_class %>}"
129
142
  flash[:alert] = @hawk_alarm if @hawk_alarm
130
143
  render :update
131
144
  else
@@ -19,8 +19,8 @@ describe 'interaction for <%= controller_class_name %>' do
19
19
  before do
20
20
  login_as(<%= @auth %>)
21
21
  end <% end %> <% if any_datetime_fields? %>
22
- let(:current_timezone) {
23
- <%= @auth_identifier %>.try(:timezone) || Time.now.strftime("%z").to_i/100
22
+ let(:testing_timezone) {
23
+ Rails.application.config.time_zone
24
24
  }<% end %>
25
25
  describe "index" do
26
26
  it "should show me the list" do
@@ -59,30 +59,14 @@ describe 'interaction for <%= controller_class_name %>' do
59
59
  <%= capybara_make_updates(:update) %>
60
60
  click_button "Save"
61
61
  within("turbo-frame#<%= @namespace %>__#{dom_id(<%= singular %>1)} ") do
62
- <%= ((@columns - @attachments.keys.collect(&:to_sym)) - (@show_only+@update_show_only)).map { |col|
63
- type = eval("#{singular_class}.columns_hash['#{col}']").type
64
-
65
- if type == :uuid || (type == :integer && col.to_s.ends_with?("_id"))
66
- assoc = col.to_s.gsub('_id', '')
67
- class_name = eval("#{@singular_class}.reflect_on_association(:#{assoc})").class_name
68
- " expect(page).to have_content(#{assoc}1.#{HotGlue.derrive_reference_name(class_name)})"
69
-
70
- elsif type == :boolean
71
- ' expect(page).to have_content(new_' + col.to_s + ' ? "YES" : "NO")'
72
-
73
- elsif type == :enum && eval("#{singular_class}.respond_to?(:#{col}_labels)")
74
- " expect(page).to have_content(#{singular_class}.#{col}_labels[new_#{col}])"
75
- elsif type == :string && eval("#{singular_class}.respond_to?(:devise_modules)") &&
76
- #devise confirmable makes email updates go into unconfirmed_email
77
- eval("#{singular_class}.devise_modules.include?(:confirmable)") && col.to_s == "email"
78
- " expect(page).to have_content(#{ singular }1.#{col.to_s})"
79
- elsif type == :datetime
80
- " expect(page).to have_content(new_#{col.to_s}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone))"
81
- else
82
- " expect(page).to have_content(new_#{col.to_s})"
83
- end
84
- }.compact.join("\n")
85
- %>
62
+ <%= " " + @columns_map.map{ |col, col_object|
63
+ if @attachments.keys.collect(&:to_sym).include?(col)
64
+ elsif @show_only.include?(col)
65
+ else
66
+ col_object.spec_make_assertion
67
+ end
68
+ }.compact.join("\n ")
69
+ %>
86
70
  end
87
71
  end
88
72
  end <% end %>
@@ -1,5 +1,5 @@
1
1
  module HotGlue
2
2
  class Version
3
- CURRENT = '0.5.17'
3
+ CURRENT = '0.5.18'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hot-glue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.17
4
+ version: 0.5.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-18 00:00:00.000000000 Z
11
+ date: 2023-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -61,7 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".circleci/config.yml"
63
63
  - ".github/FUNDING.yml"
64
- - ".github/workflows/test.yml"
64
+ - ".github/workflows/test_suite.yml"
65
65
  - ".gitignore"
66
66
  - ".ruby-version"
67
67
  - ".travis.yml"
@@ -1,49 +0,0 @@
1
- name: Test
2
- on: [ push, pull_request ]
3
-
4
- jobs:
5
- internal_tests:
6
- services:
7
- # Label used to access the service container
8
- postgres:
9
- # Docker Hub image
10
- image: postgres
11
- # Provide the password for postgres
12
- env:
13
- POSTGRES_USER: postgres
14
- POSTGRES_PASSWORD: postgres
15
- POSTGRES_DB: test_database_name
16
- ports:
17
- - 5432:5432
18
- # Set health checks to wait until postgres has started
19
- options: >-
20
- --health-cmd pg_isready
21
- --health-interval 10s
22
- --health-timeout 5s
23
- --health-retries 5
24
- runs-on: ubuntu-latest
25
- steps:
26
- - uses: actions/checkout@v3
27
- - name: Set up Ruby
28
- uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
29
- with:
30
- # Not needed with a .ruby-version file
31
- # runs 'bundle install' and caches installed gems automatically
32
- bundler-cache: true
33
- - name: bundle install
34
- run: cd dummy && bundle install && cd ..
35
-
36
- - name: run tests
37
- env:
38
- RUBYOPT: "-W:no-deprecated -W:no-experimental" # Suppress Rails 6 deprecation warnings for ruby 2.7
39
- RAILS_ENV: "test"
40
- DATABASE_URL: "postgres://postgres:postgres@localhost:5432/test_database_name"
41
-
42
- run: |
43
- cd dummy && bin/setup && cd ..
44
- bundle install
45
- bundle exec rspec --fail-fast --backtrace
46
-
47
-
48
-
49
-