propel_api 0.3.1.1 → 0.3.1.3
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/CHANGELOG.md +36 -0
- data/lib/generators/propel_api/core/configuration_methods.rb +5 -0
- data/lib/generators/propel_api/core/named_base.rb +38 -8
- data/lib/generators/propel_api/resource/resource_generator.rb +26 -1
- data/lib/generators/propel_api/templates/config/propel_api.rb.tt +15 -1
- data/lib/generators/propel_api/templates/scaffold/facet_controller_template.rb.tt +1 -1
- data/lib/generators/propel_api/templates/scaffold/facet_model_template.rb.tt +7 -1
- data/lib/generators/propel_api/templates/tests/controller_test_template.rb.tt +13 -5
- data/lib/generators/propel_api/templates/tests/fixtures_template.yml.tt +12 -16
- data/lib/generators/propel_api/templates/tests/integration_test_template.rb.tt +133 -18
- data/lib/generators/propel_api/templates/tests/model_test_template.rb.tt +44 -7
- data/lib/propel_api.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bce938f1d94ec21c630795fd3732dc295d3555cb9b3907d9db74cfeac8ee59b
|
4
|
+
data.tar.gz: 15e9bec7ffc083869da29a883af7e5e9bdccbcf1e17c96a8ab8288f4dc7d37e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f76dd64b8ab5f5e6ec831f0e920e6b3d19502694a3c51ef8d01ef82524692c869c37bce68df5b813d5ebb64d24c5eb37cddca62608ae7edcd8ecbac06c247b21
|
7
|
+
data.tar.gz: c6a464ff6524bdcd2943dfbde5ee6f4624f9acac724ef9f508a22e66f4225d1b216259953a76e12f5a326b57f996873f8ba98225bfd85f182b23e36c108b9349
|
data/CHANGELOG.md
CHANGED
@@ -10,9 +10,45 @@ 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.3] - 2025-09-11
|
14
|
+
|
15
|
+
### 🐛 Bug Fixes
|
16
|
+
- **Polymorphic Association Facet Includes**: Fixed facet includes for polymorphic associations in model templates
|
17
|
+
- Polymorphic associations are now properly included in `details` facet for eager loading
|
18
|
+
- Enhanced model template to handle polymorphic associations in facet includes correctly
|
19
|
+
- Fixed Schedule model and similar polymorphic association issues
|
20
|
+
- **Data Integrity Test Fixes**: Improved model test template for more reliable data integrity tests
|
21
|
+
- Fixed hardcoded test expectations to match actual test data creation
|
22
|
+
- Better handling of polymorphic associations in integrity tests
|
23
|
+
- Enhanced test data generation for name/title fields to use realistic values (e.g., "integrity_test")
|
24
|
+
- Added proper JSON/JSONB field testing support
|
25
|
+
|
26
|
+
## [0.3.1.2] - 2025-09-11
|
27
|
+
|
28
|
+
### 🎉 New Features
|
29
|
+
- **Automatic JSON Field Defaults**: Added intelligent default values for JSON/JSONB fields in migrations
|
30
|
+
- Generated migrations now automatically add `default: '{}'` to JSON/JSONB fields
|
31
|
+
- Prevents nil values and makes JSON fields more predictable across PostgreSQL, SQLite, and MySQL
|
32
|
+
- Configurable via `PropelApi.configuration.json_field_defaults = true/false`
|
33
|
+
- Per-generator override with `--json-defaults` or `--no-json-defaults` command-line flags
|
34
|
+
- Eliminates need for manual migration patches to add JSON field defaults
|
35
|
+
- Smart detection: only adds defaults to fields that don't already have them
|
36
|
+
|
37
|
+
### 🔧 Configuration Enhancements
|
38
|
+
- **Enhanced PropelApi Configuration**: Extended configuration system with JSON field defaults
|
39
|
+
- New `json_field_defaults` configuration option with comprehensive documentation
|
40
|
+
- Command-line flag support for per-generator control
|
41
|
+
- Backward compatible with existing configurations
|
42
|
+
|
43
|
+
|
13
44
|
## [0.3.1.1] - 2025-09-11
|
14
45
|
|
15
46
|
### 🐛 Bug Fixes
|
47
|
+
- **PostgreSQL JSONB Support**: Added comprehensive JSONB type support for PostgreSQL compatibility
|
48
|
+
- Enhanced controller templates to handle both `:json` and `:jsonb` field types
|
49
|
+
- Updated test templates to properly generate test data for JSONB fields
|
50
|
+
- Fixed parameter handling in `named_base.rb` to support JSONB fields
|
51
|
+
- Improved strong parameters generation for both JSON and JSONB field types
|
16
52
|
- **PostgreSQL Migration Generation**: Fixed migration generation bug that caused issues with PostgreSQL database constraints
|
17
53
|
- Corrected polymorphic migration templates to use proper PostgreSQL-compatible syntax
|
18
54
|
- 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
|
@@ -544,7 +544,14 @@ module PropelApi
|
|
544
544
|
polymorphic_attrs = @attributes.select { |attr| attr.type == :references && attr.respond_to?(:polymorphic?) && attr.polymorphic? }
|
545
545
|
|
546
546
|
polymorphic_attrs.map do |attr|
|
547
|
-
parent_types = polymorphic_parent_types[attr.name.to_s] || discover_available_models.first(
|
547
|
+
parent_types = polymorphic_parent_types[attr.name.to_s] || discover_available_models.first(3)
|
548
|
+
|
549
|
+
# Fallback to User if no parent types specified and no models auto-discovered
|
550
|
+
if parent_types.empty?
|
551
|
+
say "Warning: No parent types specified for polymorphic association '#{attr.name}' and no models found to auto-discover.", :yellow
|
552
|
+
say "Falling back to 'User' as parent type. Use --parents ModelA,ModelB,ModelC to specify different parent types.", :yellow
|
553
|
+
parent_types = ['User']
|
554
|
+
end
|
548
555
|
|
549
556
|
# Create one association entry per polymorphic field with all parent types
|
550
557
|
{
|
@@ -554,7 +561,7 @@ module PropelApi
|
|
554
561
|
parent_types: parent_types,
|
555
562
|
# For fixture generation, we'll use the first parent type for fixture "one", second for "two", etc.
|
556
563
|
primary_parent_type: parent_types.first,
|
557
|
-
primary_parent_table: parent_types.first
|
564
|
+
primary_parent_table: parent_types.first&.underscore&.pluralize
|
558
565
|
}
|
559
566
|
end
|
560
567
|
end
|
@@ -572,6 +579,10 @@ module PropelApi
|
|
572
579
|
fixture_name = case parent_type.underscore
|
573
580
|
when 'agency'
|
574
581
|
['marketing_agency', 'tech_agency', 'sales_agency'][fixture_index] || 'marketing_agency'
|
582
|
+
when 'user'
|
583
|
+
['john_user', 'jane_user', 'confirmed_user'][fixture_index] || 'john_user'
|
584
|
+
when 'organization'
|
585
|
+
['acme_org', 'tech_startup', 'acme_org'][fixture_index] || 'acme_org'
|
575
586
|
else
|
576
587
|
['one', 'two', 'three'][fixture_index] || 'one'
|
577
588
|
end
|
@@ -588,27 +599,46 @@ module PropelApi
|
|
588
599
|
private
|
589
600
|
|
590
601
|
def parse_polymorphic_parent_types
|
591
|
-
return {} unless defined?(options) && options[:parents]
|
602
|
+
return {} unless defined?(options) && options[:parents] && !options[:parents].empty?
|
603
|
+
|
604
|
+
# With the simplified syntax, we apply the same parent types to all polymorphic associations
|
605
|
+
parent_types = options[:parents].map(&:strip).map(&:camelize)
|
592
606
|
|
607
|
+
# Debug: Show what we parsed
|
608
|
+
say "Debug: Parsed parent types from --parents: #{parent_types.inspect}", :cyan if parent_types.any?
|
609
|
+
|
610
|
+
# Find all polymorphic associations and apply the same parent types to each
|
593
611
|
parsed_types = {}
|
594
|
-
|
595
|
-
|
612
|
+
attrs = respond_to?(:attributes) ? attributes : (@attributes || [])
|
613
|
+
|
614
|
+
if attrs && !attrs.empty?
|
615
|
+
polymorphic_attrs = attrs.select { |attr| attr.type == :references && attr.respond_to?(:polymorphic?) && attr.polymorphic? }
|
616
|
+
polymorphic_attrs.each do |attr|
|
617
|
+
parsed_types[attr.name.to_s] = parent_types
|
618
|
+
say "Debug: Applied parent types #{parent_types.inspect} to polymorphic field '#{attr.name}'", :cyan
|
619
|
+
end
|
620
|
+
else
|
621
|
+
say "Debug: No attributes found when parsing polymorphic parent types", :yellow
|
596
622
|
end
|
623
|
+
|
597
624
|
parsed_types
|
598
625
|
end
|
599
626
|
|
600
627
|
def discover_available_models
|
601
628
|
# Auto-discover available models from app/models directory
|
602
629
|
models_dir = File.join(destination_root, 'app/models')
|
603
|
-
return [
|
630
|
+
return [] unless File.directory?(models_dir) # No fallback - return empty array
|
604
631
|
|
605
632
|
model_files = Dir[File.join(models_dir, '*.rb')]
|
606
|
-
model_files.map do |file|
|
633
|
+
models = model_files.map do |file|
|
607
634
|
File.basename(file, '.rb').camelize
|
608
635
|
end.reject do |model|
|
609
636
|
# Skip common non-domain models
|
610
637
|
%w[ApplicationRecord Concerns].include?(model)
|
611
638
|
end.sort
|
639
|
+
|
640
|
+
# Ensure we always return at least one model as fallback
|
641
|
+
models.empty? ? [] : models
|
612
642
|
end
|
613
643
|
end
|
614
644
|
end
|
@@ -575,7 +575,20 @@ module PropelApi
|
|
575
575
|
end
|
576
576
|
|
577
577
|
def migration_timestamp
|
578
|
-
|
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 -%>
|
@@ -101,13 +97,13 @@ one:
|
|
101
97
|
<%= attribute.name %>: "2024-06-15 10:30:00"
|
102
98
|
<% elsif attribute.type == :time -%>
|
103
99
|
<%= attribute.name %>: "10:30:00"
|
104
|
-
<% elsif attribute.type == :json || attribute.
|
100
|
+
<% elsif attribute.type == :json || attribute.type == :jsonb -%>
|
105
101
|
<% if attribute.name == 'metadata' -%>
|
106
102
|
<%= attribute.name %>: { resource_type: "<%= singular_table_name %>", category: "test", tags: ["fixture", "one"], attributes: { priority: "high", status_info: { verified: true, active: true } } }
|
107
103
|
<% elsif attribute.name == 'settings' -%>
|
108
104
|
<%= attribute.name %>: { ui_preferences: { theme: "light", language: "en", notifications: { email: true, sms: false, push: true } }, feature_flags: { beta_features: false, analytics: true } }
|
109
105
|
<% else -%>
|
110
|
-
<%= attribute.name %>: { test_data: "
|
106
|
+
<%= attribute.name %>: { field_type: "jsonb_field", test_data: { string_value: "sample_text_one", numeric_value: 42, boolean_value: true, array_value: ["item1", "item2", "item3"], nested_object: { property: "value", settings: ["option1", "option2"] } }, metadata: { generated_by: "test_fixture", field_name: "<%= attribute.name %>", fixture_id: "one" } }
|
111
107
|
<% end -%>
|
112
108
|
<% else -%>
|
113
109
|
<%= attribute.name %>: "test_value_one"
|
@@ -205,13 +201,13 @@ two:
|
|
205
201
|
<%= attribute.name %>: "2023-12-25 15:45:00"
|
206
202
|
<% elsif attribute.type == :time -%>
|
207
203
|
<%= attribute.name %>: "15:45:00"
|
208
|
-
<% elsif attribute.type == :json || attribute.
|
204
|
+
<% elsif attribute.type == :json || attribute.type == :jsonb -%>
|
209
205
|
<% if attribute.name == 'metadata' -%>
|
210
206
|
<%= attribute.name %>: { resource_type: "<%= singular_table_name %>", category: "premium", tags: ["fixture", "two"], attributes: { priority: "medium", status_info: { verified: false, active: true } } }
|
211
207
|
<% elsif attribute.name == 'settings' -%>
|
212
208
|
<%= attribute.name %>: { ui_preferences: { theme: "dark", language: "fr", notifications: { email: true, sms: true, push: false } }, feature_flags: { beta_features: true, analytics: false } }
|
213
209
|
<% else -%>
|
214
|
-
<%= attribute.name %>: { test_data: "
|
210
|
+
<%= attribute.name %>: { field_type: "jsonb_field", test_data: { string_value: "sample_text_two", numeric_value: 84, boolean_value: false, array_value: ["item4", "item5", "item6"], nested_object: { property: "different_value", settings: ["option3", "option4"] } }, metadata: { generated_by: "test_fixture", field_name: "<%= attribute.name %>", fixture_id: "two" } }
|
215
211
|
<% end -%>
|
216
212
|
<% else -%>
|
217
213
|
<%= attribute.name %>: "test_value_two"
|
@@ -309,13 +305,13 @@ three:
|
|
309
305
|
<%= attribute.name %>: "2025-03-10 08:15:00"
|
310
306
|
<% elsif attribute.type == :time -%>
|
311
307
|
<%= attribute.name %>: "08:15:00"
|
312
|
-
<% elsif attribute.type == :json || attribute.
|
308
|
+
<% elsif attribute.type == :json || attribute.type == :jsonb -%>
|
313
309
|
<% if attribute.name == 'metadata' -%>
|
314
310
|
<%= attribute.name %>: { resource_type: "<%= singular_table_name %>", category: "basic", tags: ["fixture", "three"], attributes: { priority: "low", status_info: { verified: true, active: false } } }
|
315
311
|
<% elsif attribute.name == 'settings' -%>
|
316
312
|
<%= attribute.name %>: { ui_preferences: { theme: "auto", language: "es", notifications: { email: false, sms: true, push: true } }, feature_flags: { beta_features: false, analytics: true } }
|
317
313
|
<% else -%>
|
318
|
-
<%= attribute.name %>: { test_data: "
|
314
|
+
<%= attribute.name %>: { field_type: "jsonb_field", test_data: { string_value: "sample_text_three", numeric_value: 126, boolean_value: true, array_value: ["item7", "item8", "item9"], nested_object: { property: "final_value", settings: ["option5", "option6"] } }, metadata: { generated_by: "test_fixture", field_name: "<%= attribute.name %>", fixture_id: "three" } }
|
319
315
|
<% end -%>
|
320
316
|
<% else -%>
|
321
317
|
<%= attribute.name %>: "test_value_three"
|
@@ -89,7 +89,7 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
89
89
|
<%= attribute.name %>: "password123"<%= ',' if index < attributes.length - 1 %>
|
90
90
|
<% elsif attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
|
91
91
|
<%= attribute.name %>: "https://workflow.example.com"<%= ',' if index < attributes.length - 1 %>
|
92
|
-
<% elsif attribute.name.to_s.end_with?('_type') -%>
|
92
|
+
<% elsif attribute.name.to_s.end_with?('_type') && attribute.name.to_s.match?(/_parent_type$/) -%>
|
93
93
|
<%= attribute.name %>: @<%= attribute.name.gsub('_type', '') %>.class.name<%= ',' if index < attributes.length - 1 %>
|
94
94
|
<% else -%>
|
95
95
|
<%= attribute.name %>: "Workflow Test <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
|
@@ -104,7 +104,7 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
104
104
|
<%= attribute.name %>: 100.50<%= ',' if index < attributes.length - 1 %>
|
105
105
|
<% elsif attribute.type == :datetime -%>
|
106
106
|
<%= attribute.name %>: Time.current<%= ',' if index < attributes.length - 1 %>
|
107
|
-
<% elsif attribute.type == :json || attribute.
|
107
|
+
<% elsif attribute.type == :json || attribute.type == :jsonb -%>
|
108
108
|
<% if attribute.name == 'metadata' -%>
|
109
109
|
<%= attribute.name %>: { resource_type: "<%= singular_table_name %>", category: "test", tags: ["integration", "auto_generated"], attributes: { priority: "medium", status_info: { verified: true, active: true } } }<%= ',' if index < attributes.length - 1 %>
|
110
110
|
<% elsif attribute.name == 'settings' -%>
|
@@ -117,7 +117,24 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
117
117
|
feature_flags: { beta_features: false, analytics: true }
|
118
118
|
}<%= ',' if index < attributes.length - 1 %>
|
119
119
|
<% else -%>
|
120
|
-
<%= attribute.name %>: {
|
120
|
+
<%= attribute.name %>: {
|
121
|
+
field_type: "jsonb_field",
|
122
|
+
test_data: {
|
123
|
+
string_value: "api_test_data",
|
124
|
+
numeric_value: 123,
|
125
|
+
boolean_value: true,
|
126
|
+
array_value: ["test1", "test2", "test3"],
|
127
|
+
nested_object: {
|
128
|
+
property: "api_value",
|
129
|
+
settings: ["api_option1", "api_option2"]
|
130
|
+
}
|
131
|
+
},
|
132
|
+
metadata: {
|
133
|
+
generated_by: "integration_test",
|
134
|
+
field_name: "<%= attribute.name %>",
|
135
|
+
test_id: "workflow_test"
|
136
|
+
}
|
137
|
+
}<%= ',' if index < attributes.length - 1 %>
|
121
138
|
<% end -%>
|
122
139
|
|
123
140
|
<% elsif !reference_names.include?(attribute.name) -%>
|
@@ -161,6 +178,8 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
161
178
|
<% elsif attribute.name.to_s.match?(/password/) -%>
|
162
179
|
# Password fields should NOT be returned in API responses for security
|
163
180
|
assert_not_includes created_<%= singular_table_name %>.keys, '<%= attribute.name %>', "Password fields should be filtered from API responses"
|
181
|
+
<% elsif attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
|
182
|
+
assert_equal "https://workflow.example.com", created_<%= singular_table_name %>['<%= attribute.name %>']
|
164
183
|
<% else -%>
|
165
184
|
assert_equal "Workflow Test <%= attribute.name.humanize %>", created_<%= singular_table_name %>['<%= attribute.name %>']
|
166
185
|
<% end -%>
|
@@ -173,12 +192,12 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
173
192
|
<% elsif attribute.type == :decimal || attribute.type == :float -%>
|
174
193
|
# Rails conventionally serializes decimal/float values as strings in JSON
|
175
194
|
assert_equal "100.5", created_<%= singular_table_name %>['<%= attribute.name %>']
|
176
|
-
<% elsif attribute.type == :datetime || attribute.type == :timestamp || attribute.name.to_s.match?(/_at$/) -%>
|
195
|
+
<% elsif attribute.type == :datetime || attribute.type == :timestamp || (attribute.name.to_s.match?(/_at$/) && attribute.type != :json && attribute.type != :jsonb) -%>
|
177
196
|
# Datetime fields should be properly formatted ISO timestamps, not exact values
|
178
197
|
if created_<%= singular_table_name %>['<%= attribute.name %>'].present?
|
179
198
|
assert_match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/, created_<%= singular_table_name %>['<%= attribute.name %>'], "<%= attribute.name %> should be ISO timestamp format")
|
180
199
|
end
|
181
|
-
<% elsif attribute.type == :json || attribute.
|
200
|
+
<% elsif attribute.type == :json || attribute.type == :jsonb -%>
|
182
201
|
<% if attribute.name == 'metadata' -%>
|
183
202
|
# Metadata field should be a hash with generic structure
|
184
203
|
assert_kind_of Hash, created_<%= singular_table_name %>['<%= attribute.name %>'], "Metadata should be a JSON object"
|
@@ -201,7 +220,35 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
201
220
|
assert_includes created_<%= singular_table_name %>['<%= attribute.name %>']['ui_preferences'].keys, "notifications", "UI preferences should contain notifications"
|
202
221
|
assert_kind_of Hash, created_<%= singular_table_name %>['<%= attribute.name %>']['ui_preferences']['notifications'], "Notifications should be a hash"
|
203
222
|
<% else -%>
|
204
|
-
|
223
|
+
# Generic JSON field should have standard test structure
|
224
|
+
assert_kind_of Hash, created_<%= singular_table_name %>['<%= attribute.name %>'], "<%= attribute.name.humanize %> should be a JSON object"
|
225
|
+
|
226
|
+
# Verify main structure
|
227
|
+
assert_includes created_<%= singular_table_name %>['<%= attribute.name %>'].keys, "field_type", "<%= attribute.name.humanize %> should contain field_type"
|
228
|
+
assert_includes created_<%= singular_table_name %>['<%= attribute.name %>'].keys, "test_data", "<%= attribute.name.humanize %> should contain test_data"
|
229
|
+
assert_includes created_<%= singular_table_name %>['<%= attribute.name %>'].keys, "metadata", "<%= attribute.name.humanize %> should contain metadata"
|
230
|
+
|
231
|
+
# Verify test_data structure (tests all JSON data types)
|
232
|
+
test_data = created_<%= singular_table_name %>['<%= attribute.name %>']['test_data']
|
233
|
+
assert_kind_of Hash, test_data, "test_data should be a hash"
|
234
|
+
assert_includes test_data.keys, "string_value", "test_data should contain string_value"
|
235
|
+
assert_includes test_data.keys, "numeric_value", "test_data should contain numeric_value"
|
236
|
+
assert_includes test_data.keys, "boolean_value", "test_data should contain boolean_value"
|
237
|
+
assert_includes test_data.keys, "array_value", "test_data should contain array_value"
|
238
|
+
assert_includes test_data.keys, "nested_object", "test_data should contain nested_object"
|
239
|
+
|
240
|
+
# Verify data types
|
241
|
+
assert_kind_of String, test_data['string_value'], "string_value should be a string"
|
242
|
+
assert_kind_of Integer, test_data['numeric_value'], "numeric_value should be a number"
|
243
|
+
assert_kind_of Array, test_data['array_value'], "array_value should be an array"
|
244
|
+
assert_kind_of Hash, test_data['nested_object'], "nested_object should be a hash"
|
245
|
+
|
246
|
+
# Verify metadata structure
|
247
|
+
metadata = created_<%= singular_table_name %>['<%= attribute.name %>']['metadata']
|
248
|
+
assert_kind_of Hash, metadata, "metadata should be a hash"
|
249
|
+
assert_includes metadata.keys, "generated_by", "metadata should contain generated_by"
|
250
|
+
assert_includes metadata.keys, "field_name", "metadata should contain field_name"
|
251
|
+
assert_equal "<%= attribute.name %>", metadata['field_name'], "metadata field_name should match attribute name"
|
205
252
|
<% end -%>
|
206
253
|
<% else -%>
|
207
254
|
assert_equal "workflow_test", created_<%= singular_table_name %>['<%= attribute.name %>']
|
@@ -599,7 +646,7 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
599
646
|
<%= attribute.name %>: "org1_secure_password"<%= ',' if index < attributes.length - 1 %>
|
600
647
|
<% elsif attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
|
601
648
|
<%= attribute.name %>: "https://org1.example.com"<%= ',' if index < attributes.length - 1 %>
|
602
|
-
<% elsif attribute.name.to_s.end_with?('_type') -%>
|
649
|
+
<% elsif attribute.name.to_s.end_with?('_type') && attribute.name.to_s.match?(/_parent_type$/) -%>
|
603
650
|
<%= attribute.name %>: @<%= attribute.name.gsub('_type', '') %>.class.name<%= ',' if index < attributes.length - 1 %>
|
604
651
|
<% else -%>
|
605
652
|
<%= attribute.name %>: "Org 1 <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
|
@@ -612,7 +659,7 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
612
659
|
<%= attribute.name %>: true<%= ',' if index < attributes.length - 1 %>
|
613
660
|
<% elsif attribute.type == :decimal || attribute.type == :float -%>
|
614
661
|
<%= attribute.name %>: 11.1<%= ',' if index < attributes.length - 1 %>
|
615
|
-
<% elsif attribute.type == :json || attribute.
|
662
|
+
<% elsif attribute.type == :json || attribute.type == :jsonb -%>
|
616
663
|
<% if attribute.name == 'metadata' -%>
|
617
664
|
<%= attribute.name %>: {
|
618
665
|
resource_type: "<%= singular_table_name %>",
|
@@ -626,7 +673,24 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
626
673
|
<% elsif attribute.name == 'settings' -%>
|
627
674
|
<%= attribute.name %>: { dark_mode: false, notifications: { email: true, sms: true } }<%= ',' if index < attributes.length - 1 %>
|
628
675
|
<% else -%>
|
629
|
-
<%= attribute.name %>: {
|
676
|
+
<%= attribute.name %>: {
|
677
|
+
field_type: "jsonb_field",
|
678
|
+
test_data: {
|
679
|
+
string_value: "api_test_data",
|
680
|
+
numeric_value: 123,
|
681
|
+
boolean_value: true,
|
682
|
+
array_value: ["test1", "test2", "test3"],
|
683
|
+
nested_object: {
|
684
|
+
property: "api_value",
|
685
|
+
settings: ["api_option1", "api_option2"]
|
686
|
+
}
|
687
|
+
},
|
688
|
+
metadata: {
|
689
|
+
generated_by: "integration_test",
|
690
|
+
field_name: "<%= attribute.name %>",
|
691
|
+
test_id: "workflow_test"
|
692
|
+
}
|
693
|
+
}<%= ',' if index < attributes.length - 1 %>
|
630
694
|
<% end -%>
|
631
695
|
<% else -%>
|
632
696
|
<%= attribute.name %>: "org1_value"<%= ',' if index < attributes.length - 1 %>
|
@@ -649,7 +713,7 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
649
713
|
<%= attribute.name %>: "org2_secure_password"<%= ',' if index < attributes.length - 1 %>
|
650
714
|
<% elsif attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
|
651
715
|
<%= attribute.name %>: "https://org2.example.com"<%= ',' if index < attributes.length - 1 %>
|
652
|
-
<% elsif attribute.name.to_s.end_with?('_type') -%>
|
716
|
+
<% elsif attribute.name.to_s.end_with?('_type') && attribute.name.to_s.match?(/_parent_type$/) -%>
|
653
717
|
<%= attribute.name %>: @<%= attribute.name.gsub('_type', '') %>.class.name<%= ',' if index < attributes.length - 1 %>
|
654
718
|
<% else -%>
|
655
719
|
<%= attribute.name %>: "Org 2 <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
|
@@ -662,7 +726,7 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
662
726
|
<%= attribute.name %>: false<%= ',' if index < attributes.length - 1 %>
|
663
727
|
<% elsif attribute.type == :decimal || attribute.type == :float -%>
|
664
728
|
<%= attribute.name %>: 22.2<%= ',' if index < attributes.length - 1 %>
|
665
|
-
<% elsif attribute.type == :json || attribute.
|
729
|
+
<% elsif attribute.type == :json || attribute.type == :jsonb -%>
|
666
730
|
<% if attribute.name == 'metadata' -%>
|
667
731
|
<%= attribute.name %>: {
|
668
732
|
resource_type: "<%= singular_table_name %>",
|
@@ -676,7 +740,24 @@ class <%= class_name %>ApiTest < ActionDispatch::IntegrationTest
|
|
676
740
|
<% elsif attribute.name == 'settings' -%>
|
677
741
|
<%= attribute.name %>: { dark_mode: true, notifications: { email: false, sms: true } }<%= ',' if index < attributes.length - 1 %>
|
678
742
|
<% else -%>
|
679
|
-
<%= attribute.name %>: {
|
743
|
+
<%= attribute.name %>: {
|
744
|
+
field_type: "jsonb_field",
|
745
|
+
test_data: {
|
746
|
+
string_value: "api_test_data",
|
747
|
+
numeric_value: 123,
|
748
|
+
boolean_value: true,
|
749
|
+
array_value: ["test1", "test2", "test3"],
|
750
|
+
nested_object: {
|
751
|
+
property: "api_value",
|
752
|
+
settings: ["api_option1", "api_option2"]
|
753
|
+
}
|
754
|
+
},
|
755
|
+
metadata: {
|
756
|
+
generated_by: "integration_test",
|
757
|
+
field_name: "<%= attribute.name %>",
|
758
|
+
test_id: "workflow_test"
|
759
|
+
}
|
760
|
+
}<%= ',' if index < attributes.length - 1 %>
|
680
761
|
<% end -%>
|
681
762
|
<% else -%>
|
682
763
|
<%= attribute.name %>: "org2_value"<%= ',' if index < attributes.length - 1 %>
|
@@ -809,7 +890,7 @@ if attributes.any? { |attr| attr.type == :references && attr.name == 'user' } &&
|
|
809
890
|
<%= attribute.name %>: "concurrent@example.com"<%= ',' if index < attributes.length - 1 %>
|
810
891
|
<% elsif attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
|
811
892
|
<%= attribute.name %>: "https://concurrent.example.com"<%= ',' if index < attributes.length - 1 %>
|
812
|
-
<% elsif attribute.name.to_s.end_with?('_type') -%>
|
893
|
+
<% elsif attribute.name.to_s.end_with?('_type') && attribute.name.to_s.match?(/_parent_type$/) -%>
|
813
894
|
<%= attribute.name %>: @<%= attribute.name.gsub('_type', '') %>.class.name<%= ',' if index < attributes.length - 1 %>
|
814
895
|
<% else -%>
|
815
896
|
<%= attribute.name %>: "Concurrent Test <%= attribute.name.humanize %>"<%= ',' if index < attributes.length - 1 %>
|
@@ -822,7 +903,7 @@ if attributes.any? { |attr| attr.type == :references && attr.name == 'user' } &&
|
|
822
903
|
<%= attribute.name %>: true<%= ',' if index < attributes.length - 1 %>
|
823
904
|
<% elsif attribute.type == :decimal || attribute.type == :float -%>
|
824
905
|
<%= attribute.name %>: 50.5<%= ',' if index < attributes.length - 1 %>
|
825
|
-
<% elsif attribute.type == :json || attribute.
|
906
|
+
<% elsif attribute.type == :json || attribute.type == :jsonb -%>
|
826
907
|
<% if attribute.name == 'metadata' -%>
|
827
908
|
<%= attribute.name %>: {
|
828
909
|
resource_type: "<%= singular_table_name %>",
|
@@ -843,7 +924,24 @@ if attributes.any? { |attr| attr.type == :references && attr.name == 'user' } &&
|
|
843
924
|
feature_flags: { beta_features: false, analytics: true }
|
844
925
|
}<%= ',' if index < attributes.length - 1 %>
|
845
926
|
<% else -%>
|
846
|
-
<%= attribute.name %>: {
|
927
|
+
<%= attribute.name %>: {
|
928
|
+
field_type: "jsonb_field",
|
929
|
+
test_data: {
|
930
|
+
string_value: "api_test_data",
|
931
|
+
numeric_value: 123,
|
932
|
+
boolean_value: true,
|
933
|
+
array_value: ["test1", "test2", "test3"],
|
934
|
+
nested_object: {
|
935
|
+
property: "api_value",
|
936
|
+
settings: ["api_option1", "api_option2"]
|
937
|
+
}
|
938
|
+
},
|
939
|
+
metadata: {
|
940
|
+
generated_by: "integration_test",
|
941
|
+
field_name: "<%= attribute.name %>",
|
942
|
+
test_id: "workflow_test"
|
943
|
+
}
|
944
|
+
}<%= ',' if index < attributes.length - 1 %>
|
847
945
|
<% end -%>
|
848
946
|
<% else -%>
|
849
947
|
<%= attribute.name %>: "concurrent_test"<%= ',' if index < attributes.length - 1 %>
|
@@ -928,7 +1026,7 @@ if attributes.any? { |attr| attr.type == :references && attr.name == 'user' } &&
|
|
928
1026
|
<%= attribute.name %>: "bulk#{i}@example.com"<%= ',' if index < attributes.length - 1 %>
|
929
1027
|
<% elsif attribute.name.to_s.match?(/\A(url|website|web_address|domain|domain_name)\z/i) -%>
|
930
1028
|
<%= attribute.name %>: "https://bulk#{i}.example.com"<%= ',' if index < attributes.length - 1 %>
|
931
|
-
<% elsif attribute.name.to_s.end_with?('_type') -%>
|
1029
|
+
<% elsif attribute.name.to_s.end_with?('_type') && attribute.name.to_s.match?(/_parent_type$/) -%>
|
932
1030
|
<%= attribute.name %>: @<%= attribute.name.gsub('_type', '') %>.class.name<%= ',' if index < attributes.length - 1 %>
|
933
1031
|
<% else -%>
|
934
1032
|
<%= attribute.name %>: "Bulk Test <%= attribute.name.humanize %> #{i}"<%= ',' if index < attributes.length - 1 %>
|
@@ -941,7 +1039,7 @@ if attributes.any? { |attr| attr.type == :references && attr.name == 'user' } &&
|
|
941
1039
|
<%= attribute.name %>: i.even?<%= ',' if index < attributes.length - 1 %>
|
942
1040
|
<% elsif attribute.type == :decimal || attribute.type == :float -%>
|
943
1041
|
<%= attribute.name %>: i * 10.5<%= ',' if index < attributes.length - 1 %>
|
944
|
-
<% elsif attribute.type == :json || attribute.
|
1042
|
+
<% elsif attribute.type == :json || attribute.type == :jsonb -%>
|
945
1043
|
<% if attribute.name == 'metadata' -%>
|
946
1044
|
<%= attribute.name %>: {
|
947
1045
|
resource_type: "<%= singular_table_name %>",
|
@@ -955,7 +1053,24 @@ if attributes.any? { |attr| attr.type == :references && attr.name == 'user' } &&
|
|
955
1053
|
<% elsif attribute.name == 'settings' -%>
|
956
1054
|
<%= attribute.name %>: { dark_mode: i.even?, notifications: { email: true, sms: i.even? } }<%= ',' if index < attributes.length - 1 %>
|
957
1055
|
<% else -%>
|
958
|
-
<%= attribute.name %>: {
|
1056
|
+
<%= attribute.name %>: {
|
1057
|
+
field_type: "jsonb_field",
|
1058
|
+
test_data: {
|
1059
|
+
string_value: "api_test_data",
|
1060
|
+
numeric_value: 123,
|
1061
|
+
boolean_value: true,
|
1062
|
+
array_value: ["test1", "test2", "test3"],
|
1063
|
+
nested_object: {
|
1064
|
+
property: "api_value",
|
1065
|
+
settings: ["api_option1", "api_option2"]
|
1066
|
+
}
|
1067
|
+
},
|
1068
|
+
metadata: {
|
1069
|
+
generated_by: "integration_test",
|
1070
|
+
field_name: "<%= attribute.name %>",
|
1071
|
+
test_id: "workflow_test"
|
1072
|
+
}
|
1073
|
+
}<%= ',' if index < attributes.length - 1 %>
|
959
1074
|
<% end -%>
|
960
1075
|
<% else -%>
|
961
1076
|
<%= attribute.name %>: "bulk_#{i}"<%= ',' if index < attributes.length - 1 %>
|
@@ -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 %>: "
|
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 %>: "
|
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
|
-
|
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 %>: "
|
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(
|
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
|
-
|
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 "
|
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
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.
|
4
|
+
version: 0.3.1.3
|
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
|
+
date: 2025-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|