propel_api 0.3.1.1 → 0.3.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0678229260f4bf549c0400eb94198b37474caf360b1abf8812fbd126b5b99ab2'
4
- data.tar.gz: db237ccf7c112fe8ed510236e2eba216e3cc8cb3fa1529b1d549f9fe00e6200f
3
+ metadata.gz: 9e5a2cb9edf143dc6d0f7582e01e51abe3c1ea0cf7e37c0ba9077fe38be5c9fb
4
+ data.tar.gz: c13fe800d5804bb1fc9846c35baff955e38680ea099e8167b5c00fa66309c6ce
5
5
  SHA512:
6
- metadata.gz: 7e4d691dfc7ddcb82c9bac1991aabf43d77a8d0b03f5604744e1c07fac90a122c2baf1667e0ea753bcf71dfde57e8aa45513b1bfc55aed34f9aca4b0694f6d44
7
- data.tar.gz: 776098346e44a9b1aa68d28507d9cb0e4dbffdea4ebd08711c66d1906501d372020107ba877fbce8ab32469c745f7c540362b7b015fee249eec25db4388e8e78
6
+ metadata.gz: 53fea1d7c31195a2411974a1a3149e2757b77574824639616a8af0b1f80b8e5234b6dead7663f46c84575b07a8ad7560d53ea06fca1dd328f31e0a15214620e9
7
+ data.tar.gz: e635decc36265a721ca638ff706383cce7e55b87a0bcef1f64c7bf3c6a549facc7845d5aaf29579914264a0ec2ba08493f159b65972ccb20b28fe4952b3fe200
data/CHANGELOG.md CHANGED
@@ -10,9 +10,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
  ### Planned Features
11
11
  - GraphQL adapter support
12
12
 
13
+ ## [0.3.1.2] - 2025-09-11
14
+
15
+ ### 🎉 New Features
16
+ - **Automatic JSON Field Defaults**: Added intelligent default values for JSON/JSONB fields in migrations
17
+ - Generated migrations now automatically add `default: '{}'` to JSON/JSONB fields
18
+ - Prevents nil values and makes JSON fields more predictable across PostgreSQL, SQLite, and MySQL
19
+ - Configurable via `PropelApi.configuration.json_field_defaults = true/false`
20
+ - Per-generator override with `--json-defaults` or `--no-json-defaults` command-line flags
21
+ - Eliminates need for manual migration patches to add JSON field defaults
22
+ - Smart detection: only adds defaults to fields that don't already have them
23
+
24
+ ### 🔧 Configuration Enhancements
25
+ - **Enhanced PropelApi Configuration**: Extended configuration system with JSON field defaults
26
+ - New `json_field_defaults` configuration option with comprehensive documentation
27
+ - Command-line flag support for per-generator control
28
+ - Backward compatible with existing configurations
29
+
30
+ ### 🐛 Bug Fixes
31
+ - **Polymorphic Association Facet Includes**: Fixed facet includes for polymorphic associations in model templates
32
+ - Polymorphic associations are now properly included in `details` facet for eager loading
33
+ - Enhanced model template to handle polymorphic associations in facet includes correctly
34
+ - Fixed Schedule model and similar polymorphic association issues
35
+ - **Data Integrity Test Fixes**: Improved model test template for more reliable data integrity tests
36
+ - Fixed hardcoded test expectations to match actual test data creation
37
+ - Better handling of polymorphic associations in integrity tests
38
+ - Enhanced test data generation for name/title fields to use realistic values
39
+ - Added proper JSON/JSONB field testing support
40
+ - **HTTP Status Code Consistency**: Fixed tokens controller to use consistent HTTP status codes
41
+ - Changed validation errors from `:unprocessable_content` (422) to `:bad_request` (400)
42
+ - Better alignment with standard HTTP parameter validation practices
43
+ - Improved error handling consistency across authentication endpoints
44
+
13
45
  ## [0.3.1.1] - 2025-09-11
14
46
 
15
47
  ### 🐛 Bug Fixes
48
+ - **PostgreSQL JSONB Support**: Added comprehensive JSONB type support for PostgreSQL compatibility
49
+ - Enhanced controller templates to handle both `:json` and `:jsonb` field types
50
+ - Updated test templates to properly generate test data for JSONB fields
51
+ - Fixed parameter handling in `named_base.rb` to support JSONB fields
52
+ - Improved strong parameters generation for both JSON and JSONB field types
16
53
  - **PostgreSQL Migration Generation**: Fixed migration generation bug that caused issues with PostgreSQL database constraints
17
54
  - Corrected polymorphic migration templates to use proper PostgreSQL-compatible syntax
18
55
  - Enhanced migration generation to handle PostgreSQL foreign key constraints correctly
@@ -27,6 +27,11 @@ module PropelApi
27
27
  type: :boolean,
28
28
  default: false,
29
29
  desc: "Automatically include all model attributes from file and/or database schema for existing models"
30
+
31
+ base.class_option :json_defaults,
32
+ type: :boolean,
33
+ default: nil,
34
+ desc: "Add default: '{}' to json/jsonb fields in migrations. Defaults to PropelApi configuration."
30
35
  end
31
36
 
32
37
  protected
@@ -175,7 +175,7 @@ module PropelApi
175
175
  elsif attr[:type] == :references
176
176
  # Convert association references to foreign key format for strong parameters
177
177
  "#{attr[:name]}_id" # Convert :organization to :organization_id for permitted_params
178
- elsif attr[:type] == :json
178
+ elsif attr[:type] == :json || attr[:type] == :jsonb
179
179
  # JSON/JSONB fields need hash syntax for Rails strong parameters to allow nested objects
180
180
  "#{attr[:name]}: {}"
181
181
  else
@@ -575,7 +575,20 @@ module PropelApi
575
575
  end
576
576
 
577
577
  def migration_timestamp
578
- Time.current.utc.strftime("%Y%m%d%H%M%S")
578
+ Time.current.utc.strftime("%Y%m%d%H%M%S")
579
+ end
580
+
581
+ def should_add_json_defaults?
582
+ # Check command line option first, then configuration, then default to true
583
+ return options[:json_defaults] if options[:json_defaults] != nil
584
+
585
+ # Try to use PropelApi configuration if available
586
+ if defined?(PropelApi) && PropelApi.respond_to?(:configuration)
587
+ return PropelApi.configuration.json_field_defaults
588
+ end
589
+
590
+ # Default to true for better developer experience
591
+ true
579
592
  end
580
593
 
581
594
  def update_migration_constraints
@@ -614,6 +627,18 @@ module PropelApi
614
627
  end
615
628
  end
616
629
 
630
+ # Third pass: Add default empty hash to JSON/JSONB fields (if enabled)
631
+ if should_add_json_defaults?
632
+ json_attrs = attributes.select { |attr| attr.type == :json || attr.type == :jsonb }
633
+ json_attrs.each do |attr|
634
+ # Look for the json/jsonb field declaration and add default: '{}'
635
+ json_field_pattern = /t\.#{attr.type} :#{attr.name}(?!\s*,\s*default:)/
636
+ if updated_content.match?(json_field_pattern)
637
+ updated_content = updated_content.gsub(json_field_pattern, "t.#{attr.type} :#{attr.name}, default: '{}'")
638
+ end
639
+ end
640
+ end
641
+
617
642
  # Write the updated migration back to file
618
643
  File.write(migration_file, updated_content)
619
644
  end
@@ -6,7 +6,7 @@
6
6
 
7
7
  module PropelApi
8
8
  class Configuration
9
- attr_accessor :adapter, :namespace, :version, :enforce_tenancy, :required_tenancy_attributes
9
+ attr_accessor :adapter, :namespace, :version, :enforce_tenancy, :required_tenancy_attributes, :json_field_defaults
10
10
  attr_reader :attribute_filter
11
11
 
12
12
  def initialize
@@ -19,6 +19,9 @@ module PropelApi
19
19
  @enforce_tenancy = true # true = enforce tenancy (default), false = no checking
20
20
  @required_tenancy_attributes = [:organization, :agency] # Required when enforce_tenancy is true
21
21
 
22
+ # JSON field defaults - automatically add default: '{}' to json/jsonb fields in migrations
23
+ @json_field_defaults = true # true = add default: '{}', false = leave as default nil
24
+
22
25
  # Initialize the configurable attribute filter
23
26
  @attribute_filter = PropelApi::AttributeFilter.new
24
27
  end
@@ -143,6 +146,17 @@ PropelApi.configure do |config|
143
146
  # Define which tenancy attributes are required for your system
144
147
  config.required_tenancy_attributes = [:organization, :agency] # Both required by default
145
148
 
149
+ # JSON field defaults configuration
150
+ # Automatically adds default: '{}' to json/jsonb fields in generated migrations
151
+ # This prevents nil values and makes JSON fields more predictable
152
+ config.json_field_defaults = true # Default: true (add default: '{}' to JSON fields)
153
+
154
+ # To disable JSON defaults globally:
155
+ # config.json_field_defaults = false
156
+ #
157
+ # You can also override this per-generator with:
158
+ # rails generate propel_api:resource Model field:json --no-json-defaults
159
+
146
160
  # Examples of different tenancy configurations:
147
161
  #
148
162
  # Organization-only tenancy:
@@ -17,7 +17,7 @@ class <%= controller_class_name_with_namespace %>Controller < <%= api_controller
17
17
 
18
18
  # Add attribute-based params using polymorphic support
19
19
  attributes.each do |attr|
20
- if attr.type == :json
20
+ if attr.type == :json || attr.type == :jsonb
21
21
  json_params << "#{attr.name}: {}"
22
22
  elsif attr.type == :references
23
23
  # Use Rails' built-in polymorphic detection
@@ -174,13 +174,19 @@ json_facet :details, fields: [:id<%
174
174
  all_fields.to_a.sort.each do |field| -%>, :<%= field %><% end -%>]<%
175
175
 
176
176
  # Generate include for nested objects (reference associations)
177
- reference_associations = detail_attributes.select { |attr| attr.type == :references }.map(&:name)
177
+ reference_associations = detail_attributes.select { |attr| attr.type == :references && (!attr.respond_to?(:polymorphic?) || !attr.polymorphic?) }.map(&:name)
178
178
  if has_organization_reference?
179
179
  reference_associations += %w[organization]
180
180
  end
181
181
  if has_agency_reference?
182
182
  reference_associations += %w[agency]
183
183
  end
184
+
185
+ # Add polymorphic associations to includes (they can be included for eager loading)
186
+ polymorphic_associations.each do |poly_attr|
187
+ reference_associations << poly_attr.name
188
+ end
189
+
184
190
  reference_associations.uniq!
185
191
 
186
192
  if reference_associations.any?
@@ -128,6 +128,8 @@ class <%= controller_class_name_with_namespace %>ControllerTest < ActionDispatch
128
128
  <%= attribute.name %>: "other@example.com"<%= ',' if index < attributes.length - 1 %>
129
129
  <% elsif attribute.name.to_s.match?(/password/) -%>
130
130
  <%= attribute.name %>: "password123"<%= ',' if index < attributes.length - 1 %>
131
+ <% elsif attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
132
+ <%= attribute.name %>: "https://other-org.example.com"<%= ',' if index < attributes.length - 1 %>
131
133
  <% else -%>
132
134
  <%= attribute.name %>: "Other Org <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
133
135
  <% end -%>
@@ -141,7 +143,7 @@ class <%= controller_class_name_with_namespace %>ControllerTest < ActionDispatch
141
143
  <%= attribute.name %>: 99.99<%= ',' if index < attributes.length - 1 %>
142
144
  <% elsif attribute.type == :datetime -%>
143
145
  <%= attribute.name %>: Time.current<%= ',' if index < attributes.length - 1 %>
144
- <% elsif attribute.type == :json -%>
146
+ <% elsif attribute.type == :json || attribute.type == :jsonb -%>
145
147
  <%= attribute.name %>: {}<%= ',' if index < attributes.length - 1 %>
146
148
  <% else -%>
147
149
  <%= attribute.name %>: "other_value"<%= ',' if index < attributes.length - 1 %>
@@ -198,6 +200,8 @@ class <%= controller_class_name_with_namespace %>ControllerTest < ActionDispatch
198
200
  <%= attribute.name %>: "other@example.com"<%= ',' if index < attributes.length - 1 %>
199
201
  <% elsif attribute.name.to_s.match?(/password/) -%>
200
202
  <%= attribute.name %>: "password123"<%= ',' if index < attributes.length - 1 %>
203
+ <% elsif attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
204
+ <%= attribute.name %>: "https://other-org.example.com"<%= ',' if index < attributes.length - 1 %>
201
205
  <% else -%>
202
206
  <%= attribute.name %>: "Other Org <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
203
207
  <% end -%>
@@ -211,7 +215,7 @@ class <%= controller_class_name_with_namespace %>ControllerTest < ActionDispatch
211
215
  <%= attribute.name %>: 99.99<%= ',' if index < attributes.length - 1 %>
212
216
  <% elsif attribute.type == :datetime -%>
213
217
  <%= attribute.name %>: Time.current<%= ',' if index < attributes.length - 1 %>
214
- <% elsif attribute.type == :json -%>
218
+ <% elsif attribute.type == :json || attribute.type == :jsonb -%>
215
219
  <%= attribute.name %>: {}<%= ',' if index < attributes.length - 1 %>
216
220
  <% else -%>
217
221
  <%= attribute.name %>: "other_value"<%= ',' if index < attributes.length - 1 %>
@@ -466,6 +470,8 @@ class <%= controller_class_name_with_namespace %>ControllerTest < ActionDispatch
466
470
  <%= attribute.name %>: "other@example.com"<%= ',' if index < attributes.length - 1 %>
467
471
  <% elsif attribute.name.to_s.match?(/password/) -%>
468
472
  <%= attribute.name %>: "password123"<%= ',' if index < attributes.length - 1 %>
473
+ <% elsif attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
474
+ <%= attribute.name %>: "https://other-org.example.com"<%= ',' if index < attributes.length - 1 %>
469
475
  <% else -%>
470
476
  <%= attribute.name %>: "Other Org <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
471
477
  <% end -%>
@@ -479,7 +485,7 @@ class <%= controller_class_name_with_namespace %>ControllerTest < ActionDispatch
479
485
  <%= attribute.name %>: 99.99<%= ',' if index < attributes.length - 1 %>
480
486
  <% elsif attribute.type == :datetime -%>
481
487
  <%= attribute.name %>: Time.current<%= ',' if index < attributes.length - 1 %>
482
- <% elsif attribute.type == :json -%>
488
+ <% elsif attribute.type == :json || attribute.type == :jsonb -%>
483
489
  <%= attribute.name %>: {}<%= ',' if index < attributes.length - 1 %>
484
490
  <% else -%>
485
491
  <%= attribute.name %>: "other_value"<%= ',' if index < attributes.length - 1 %>
@@ -523,6 +529,8 @@ class <%= controller_class_name_with_namespace %>ControllerTest < ActionDispatch
523
529
  <%= attribute.name %>: "other@example.com"<%= ',' if index < attributes.length - 1 %>
524
530
  <% elsif attribute.name.to_s.match?(/password/) -%>
525
531
  <%= attribute.name %>: "password123"<%= ',' if index < attributes.length - 1 %>
532
+ <% elsif attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
533
+ <%= attribute.name %>: "https://other-org.example.com"<%= ',' if index < attributes.length - 1 %>
526
534
  <% else -%>
527
535
  <%= attribute.name %>: "Other Org <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
528
536
  <% end -%>
@@ -536,7 +544,7 @@ class <%= controller_class_name_with_namespace %>ControllerTest < ActionDispatch
536
544
  <%= attribute.name %>: 99.99<%= ',' if index < attributes.length - 1 %>
537
545
  <% elsif attribute.type == :datetime -%>
538
546
  <%= attribute.name %>: Time.current<%= ',' if index < attributes.length - 1 %>
539
- <% elsif attribute.type == :json -%>
547
+ <% elsif attribute.type == :json || attribute.type == :jsonb -%>
540
548
  <%= attribute.name %>: {}<%= ',' if index < attributes.length - 1 %>
541
549
  <% else -%>
542
550
  <%= attribute.name %>: "other_value"<%= ',' if index < attributes.length - 1 %>
@@ -717,7 +725,7 @@ class <%= controller_class_name_with_namespace %>ControllerTest < ActionDispatch
717
725
  <%= attribute.name %>: 123.45<%= ',' if index < attributes.length - 1 %>
718
726
  <% elsif attribute.type == :datetime -%>
719
727
  <%= attribute.name %>: Time.current<%= ',' if index < attributes.length - 1 %>
720
- <% elsif attribute.type == :json -%>
728
+ <% elsif attribute.type == :json || attribute.type == :jsonb -%>
721
729
  <%= attribute.name %>: {}<%= ',' if index < attributes.length - 1 %>
722
730
  <% elsif !reference_names.include?(attribute.name) -%>
723
731
  <%= attribute.name %>: "test_value"<%= ',' if index < attributes.length - 1 %>
@@ -24,16 +24,6 @@ one:
24
24
  <% elsif attribute.type == :references && is_polymorphic -%>
25
25
  <% # Polymorphic references are handled above, skip them here -%>
26
26
  <% elsif attribute.type == :string -%>
27
- <% if attribute.name == 'organization' -%>
28
- <%= attribute.name %>: acme_org
29
- <% elsif attribute.name == 'user' -%>
30
- <%= attribute.name %>: john_user
31
- <% elsif attribute.name == 'agency' -%>
32
- <%= attribute.name %>: marketing_agency
33
- <% else -%>
34
- <%= attribute.name %>: one
35
- <% end -%>
36
- <% elsif attribute.type == :string -%>
37
27
  <% if attribute.name.to_s.match?(/\A(email|email_address)\z/i) -%>
38
28
  <%= attribute.name %>: test1@example.com
39
29
  <% elsif attribute.name.to_s.match?(/\A(username)\z/i) -%>
@@ -48,6 +38,12 @@ one:
48
38
  <%= attribute.name %>: "test-<%= singular_table_name %>-one"
49
39
  <% elsif attribute.name.to_s.match?(/\A(status|state)\z/i) -%>
50
40
  <%= attribute.name %>: "active"
41
+ <% elsif attribute.name == 'organization' -%>
42
+ <%= attribute.name %>: acme_org
43
+ <% elsif attribute.name == 'user' -%>
44
+ <%= attribute.name %>: john_user
45
+ <% elsif attribute.name == 'agency' -%>
46
+ <%= attribute.name %>: marketing_agency
51
47
  <% else -%>
52
48
  <%= attribute.name %>: "Test <%= attribute.name.humanize %> One"
53
49
  <% end -%>
@@ -93,7 +93,11 @@ class <%= class_name %>Test < ActiveSupport::TestCase
93
93
  <% if attribute.type == :references -%>
94
94
  <%= attribute.name %>: @<%= attribute.name %><%= ',' if index < attributes.length - 1 %>
95
95
  <% elsif attribute.type == :string -%>
96
+ <% if attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
97
+ <%= attribute.name %>: "https://test-example.com"<%= ',' if index < attributes.length - 1 %>
98
+ <% else -%>
96
99
  <%= attribute.name %>: "Test <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
100
+ <% end -%>
97
101
  <% elsif attribute.type == :text -%>
98
102
  <%= attribute.name %>: "Test <%= attribute.name.humanize %> content"<%= ',' if index < attributes.length - 1 %>
99
103
  <% elsif attribute.type == :integer -%>
@@ -103,7 +107,7 @@ class <%= class_name %>Test < ActiveSupport::TestCase
103
107
  <% elsif attribute.type == :decimal || attribute.type == :float -%>
104
108
  <%= attribute.name %>: <%= (index + 1) * 10.5 %><%= ',' if index < attributes.length - 1 %>
105
109
  <% else -%>
106
- <%= attribute.name %>: "test_value"<%= ',' if index < attributes.length - 1 %>
110
+ <%= attribute.name %>: "Test <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
107
111
  <% end -%>
108
112
  <% end -%>
109
113
  )
@@ -119,7 +123,11 @@ class <%= class_name %>Test < ActiveSupport::TestCase
119
123
  <% if attribute.type == :references -%>
120
124
  <%= attribute.name %>: @<%= attribute.name %><%= ',' if index < attributes.length - 1 %>
121
125
  <% elsif attribute.type == :string -%>
126
+ <% if attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
127
+ <%= attribute.name %>: "https://new-test-example.com"<%= ',' if index < attributes.length - 1 %>
128
+ <% else -%>
122
129
  <%= attribute.name %>: "New Test <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
130
+ <% end -%>
123
131
  <% elsif attribute.type == :text -%>
124
132
  <%= attribute.name %>: "New test <%= attribute.name.humanize %> content"<%= ',' if index < attributes.length - 1 %>
125
133
  <% elsif attribute.type == :integer -%>
@@ -129,7 +137,7 @@ class <%= class_name %>Test < ActiveSupport::TestCase
129
137
  <% elsif attribute.type == :decimal || attribute.type == :float -%>
130
138
  <%= attribute.name %>: 99.99<%= ',' if index < attributes.length - 1 %>
131
139
  <% else -%>
132
- <%= attribute.name %>: "new_test_value"<%= ',' if index < attributes.length - 1 %>
140
+ <%= attribute.name %>: "New Test <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
133
141
  <% end -%>
134
142
  <% end -%>
135
143
  )
@@ -246,12 +254,24 @@ class <%= class_name %>Test < ActiveSupport::TestCase
246
254
 
247
255
  test "should maintain data integrity" do
248
256
  # Test that saved data matches what was set
249
- original_<%= singular_table_name %> = <%= class_name %>.create!(
257
+ integrity_<%= singular_table_name %> = <%= class_name %>.create!(
250
258
  <% attributes.each_with_index do |attribute, index| -%>
251
259
  <% if attribute.type == :references -%>
260
+ <% if attribute.respond_to?(:polymorphic?) && attribute.polymorphic? -%>
261
+ <%= attribute.name %>: @<%= attribute.name %><%= ',' if index < attributes.length - 1 %>
262
+ <% else -%>
252
263
  <%= attribute.name %>: @<%= attribute.name %><%= ',' if index < attributes.length - 1 %>
264
+ <% end -%>
253
265
  <% elsif attribute.type == :string -%>
266
+ <% if attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
267
+ <%= attribute.name %>: "https://integrity-test-example.com"<%= ',' if index < attributes.length - 1 %>
268
+ <% elsif attribute.name.to_s.match?(/\A(email|email_address)\z/i) -%>
269
+ <%= attribute.name %>: "integrity.test@example.com"<%= ',' if index < attributes.length - 1 %>
270
+ <% elsif attribute.name.to_s.match?(/\A(name|title|label)\z/i) -%>
271
+ <%= attribute.name %>: "integrity_test"<%= ',' if index < attributes.length - 1 %>
272
+ <% else -%>
254
273
  <%= attribute.name %>: "Integrity Test <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
274
+ <% end -%>
255
275
  <% elsif attribute.type == :text -%>
256
276
  <%= attribute.name %>: "Integrity test <%= attribute.name.humanize %> content"<%= ',' if index < attributes.length - 1 %>
257
277
  <% elsif attribute.type == :integer -%>
@@ -260,20 +280,35 @@ class <%= class_name %>Test < ActiveSupport::TestCase
260
280
  <%= attribute.name %>: true<%= ',' if index < attributes.length - 1 %>
261
281
  <% elsif attribute.type == :decimal || attribute.type == :float -%>
262
282
  <%= attribute.name %>: 123.45<%= ',' if index < attributes.length - 1 %>
283
+ <% elsif attribute.type == :json || attribute.type == :jsonb -%>
284
+ <%= attribute.name %>: { "test_key" => "test_value" }<%= ',' if index < attributes.length - 1 %>
263
285
  <% else -%>
264
- <%= attribute.name %>: "integrity_test"<%= ',' if index < attributes.length - 1 %>
286
+ <%= attribute.name %>: "Integrity Test <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
265
287
  <% end -%>
266
288
  <% end -%>
267
289
  )
268
290
 
269
291
  # Reload from database and verify data integrity
270
- reloaded_<%= singular_table_name %> = <%= class_name %>.find(original_<%= singular_table_name %>.id)
292
+ reloaded_<%= singular_table_name %> = <%= class_name %>.find(integrity_<%= singular_table_name %>.id)
271
293
 
272
294
  <% attributes.each do |attribute| -%>
273
295
  <% if attribute.type == :references -%>
274
- assert_equal original_<%= singular_table_name %>.<%= attribute.name %>_id, reloaded_<%= singular_table_name %>.<%= attribute.name %>_id
296
+ <% if attribute.respond_to?(:polymorphic?) && attribute.polymorphic? -%>
297
+ assert_equal integrity_<%= singular_table_name %>.<%= attribute.name %>_id, reloaded_<%= singular_table_name %>.<%= attribute.name %>_id
298
+ assert_equal integrity_<%= singular_table_name %>.<%= attribute.name %>_type, reloaded_<%= singular_table_name %>.<%= attribute.name %>_type
299
+ <% else -%>
300
+ assert_equal integrity_<%= singular_table_name %>.<%= attribute.name %>_id, reloaded_<%= singular_table_name %>.<%= attribute.name %>_id
301
+ <% end -%>
275
302
  <% elsif attribute.type == :string -%>
303
+ <% if attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
304
+ assert_equal "https://integrity-test-example.com", reloaded_<%= singular_table_name %>.<%= attribute.name %>
305
+ <% elsif attribute.name.to_s.match?(/\A(email|email_address)\z/i) -%>
306
+ assert_equal "integrity.test@example.com", reloaded_<%= singular_table_name %>.<%= attribute.name %>
307
+ <% elsif attribute.name.to_s.match?(/\A(name|title|label)\z/i) -%>
308
+ assert_equal "integrity_test", reloaded_<%= singular_table_name %>.<%= attribute.name %>
309
+ <% else -%>
276
310
  assert_equal "Integrity Test <%= attribute.name.humanize %>", reloaded_<%= singular_table_name %>.<%= attribute.name %>
311
+ <% end -%>
277
312
  <% elsif attribute.type == :text -%>
278
313
  assert_equal "Integrity test <%= attribute.name.humanize %> content", reloaded_<%= singular_table_name %>.<%= attribute.name %>
279
314
  <% elsif attribute.type == :integer -%>
@@ -282,8 +317,10 @@ class <%= class_name %>Test < ActiveSupport::TestCase
282
317
  assert_equal true, reloaded_<%= singular_table_name %>.<%= attribute.name %>
283
318
  <% elsif attribute.type == :decimal || attribute.type == :float -%>
284
319
  assert_equal 123.45, reloaded_<%= singular_table_name %>.<%= attribute.name %>
320
+ <% elsif attribute.type == :json || attribute.type == :jsonb -%>
321
+ assert_equal({ "test_key" => "test_value" }, reloaded_<%= singular_table_name %>.<%= attribute.name %>)
285
322
  <% else -%>
286
- assert_equal "integrity_test", reloaded_<%= singular_table_name %>.<%= attribute.name %>
323
+ assert_equal "Integrity Test <%= attribute.name.humanize %>", reloaded_<%= singular_table_name %>.<%= attribute.name %>
287
324
  <% end -%>
288
325
  <% end -%>
289
326
  end
data/lib/propel_api.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PropelApi
2
- VERSION = "0.3.1.1"
2
+ VERSION = "0.3.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propel_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1.1
4
+ version: 0.3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Martin, Rafael Pivato, Chi Putera
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-09-11 00:00:00.000000000 Z
11
+ date: 2025-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails