11require_relative "../../test_helper_integration"
22
33# Test models for upsert method integration testing
4- class TestUser < Parse ::Object
5- parse_class "TestUser "
4+ class UpsertTestUser < Parse ::Object
5+ parse_class "UpsertTestUser "
66
77 property :email , :string
88 property :name , :string
@@ -11,8 +11,8 @@ class TestUser < Parse::Object
1111 property :last_login , :date
1212end
1313
14- class TestProduct < Parse ::Object
15- parse_class "TestProduct "
14+ class UpsertTestProduct < Parse ::Object
15+ parse_class "UpsertTestProduct "
1616
1717 property :sku , :string
1818 property :name , :string
@@ -40,12 +40,12 @@ def test_first_or_create_finds_existing_object_unchanged
4040 puts "\n === Testing first_or_create Finds Existing Object Unchanged ==="
4141
4242 # Create initial user
43- original_user = TestUser . new ( email : "existing@example.com" , name : "Original Name" , age : 25 )
43+ original_user = UpsertTestUser . new ( email : "existing@example.com" , name : "Original Name" , age : 25 )
4444 assert original_user . save , "Original user should save"
4545 original_id = original_user . id
4646
4747 # Use first_or_create with different resource_attrs
48- found_user = TestUser . first_or_create (
48+ found_user = UpsertTestUser . first_or_create (
4949 { email : "existing@example.com" } ,
5050 { name : "Different Name" , age : 30 , status : "inactive" }
5151 )
@@ -70,7 +70,7 @@ def test_first_or_create_creates_new_object_unsaved
7070 puts "\n === Testing first_or_create Creates New Object (Unsaved) ==="
7171
7272 # Use first_or_create for non-existing user
73- new_user = TestUser . first_or_create (
73+ new_user = UpsertTestUser . first_or_create (
7474 { email : "new@example.com" } ,
7575 { name : "New User" , age : 35 , status : "pending" }
7676 )
@@ -84,7 +84,7 @@ def test_first_or_create_creates_new_object_unsaved
8484 assert_nil new_user . id , "Unsaved object should not have ID"
8585
8686 # Verify object is not yet in database
87- found_in_db = TestUser . first ( email : "new@example.com" )
87+ found_in_db = UpsertTestUser . first ( email : "new@example.com" )
8888 assert_nil found_in_db , "Object should not be in database yet"
8989
9090 puts "✅ first_or_create creates new unsaved object with combined attributes"
@@ -100,12 +100,12 @@ def test_first_or_create_bang_finds_existing_unchanged
100100 puts "\n === Testing first_or_create! Finds Existing Object Unchanged ==="
101101
102102 # Create initial product
103- original_product = TestProduct . new ( sku : "PROD-001" , name : "Original Product" , price : 19.99 )
103+ original_product = UpsertTestProduct . new ( sku : "PROD-001" , name : "Original Product" , price : 19.99 )
104104 assert original_product . save , "Original product should save"
105105 original_id = original_product . id
106106
107107 # Use first_or_create! with different resource_attrs
108- found_product = TestProduct . first_or_create! (
108+ found_product = UpsertTestProduct . first_or_create! (
109109 { sku : "PROD-001" } ,
110110 { name : "Different Product" , price : 29.99 , category : "electronics" }
111111 )
@@ -130,7 +130,7 @@ def test_first_or_create_bang_creates_and_saves_new_object
130130 puts "\n === Testing first_or_create! Creates and Saves New Object ==="
131131
132132 # Use first_or_create! for non-existing product
133- new_product = TestProduct . first_or_create! (
133+ new_product = UpsertTestProduct . first_or_create! (
134134 { sku : "PROD-NEW" } ,
135135 { name : "New Product" , price : 49.99 , category : "gadgets" }
136136 )
@@ -144,7 +144,7 @@ def test_first_or_create_bang_creates_and_saves_new_object
144144 assert_equal "gadgets" , new_product . category , "Category should be set from resource_attrs"
145145
146146 # Verify object is in database
147- found_in_db = TestProduct . first ( sku : "PROD-NEW" )
147+ found_in_db = UpsertTestProduct . first ( sku : "PROD-NEW" )
148148 assert found_in_db , "Object should be in database"
149149 assert_equal new_product . id , found_in_db . id , "Should find the same object"
150150 assert_equal "New Product" , found_in_db . name , "Database object should have correct name"
@@ -162,12 +162,12 @@ def test_create_or_update_bang_finds_and_updates_existing
162162 puts "\n === Testing create_or_update! Finds and Updates Existing Object ==="
163163
164164 # Create initial user
165- original_user = TestUser . new ( email : "update@example.com" , name : "Old Name" , age : 25 , status : "active" )
165+ original_user = UpsertTestUser . new ( email : "update@example.com" , name : "Old Name" , age : 25 , status : "active" )
166166 assert original_user . save , "Original user should save"
167167 original_id = original_user . id
168168
169169 # Use create_or_update! to update existing user
170- updated_user = TestUser . create_or_update! (
170+ updated_user = UpsertTestUser . create_or_update! (
171171 { email : "update@example.com" } ,
172172 { name : "Updated Name" , age : 30 , last_login : Time . now }
173173 )
@@ -181,7 +181,7 @@ def test_create_or_update_bang_finds_and_updates_existing
181181 refute updated_user . new? , "Object should still be persisted"
182182
183183 # Verify changes are persisted in database
184- found_in_db = TestUser . first ( email : "update@example.com" )
184+ found_in_db = UpsertTestUser . first ( email : "update@example.com" )
185185 assert_equal "Updated Name" , found_in_db . name , "Database should reflect name change"
186186 assert_equal 30 , found_in_db . age , "Database should reflect age change"
187187
@@ -198,7 +198,7 @@ def test_create_or_update_bang_creates_new_object
198198 puts "\n === Testing create_or_update! Creates New Object ==="
199199
200200 # Use create_or_update! for non-existing user
201- new_user = TestUser . create_or_update! (
201+ new_user = UpsertTestUser . create_or_update! (
202202 { email : "create@example.com" } ,
203203 { name : "Created User" , age : 28 , status : "pending" }
204204 )
@@ -212,7 +212,7 @@ def test_create_or_update_bang_creates_new_object
212212 assert_equal "pending" , new_user . status , "Status should be set from resource_attrs"
213213
214214 # Verify object is in database
215- found_in_db = TestUser . first ( email : "create@example.com" )
215+ found_in_db = UpsertTestUser . first ( email : "create@example.com" )
216216 assert found_in_db , "Object should be in database"
217217 assert_equal new_user . id , found_in_db . id , "Should find the same object"
218218
@@ -229,15 +229,15 @@ def test_create_or_update_bang_no_save_when_no_changes
229229 puts "\n === Testing create_or_update! No Save When No Changes ==="
230230
231231 # Create initial product
232- original_product = TestProduct . new ( sku : "NO-CHANGE" , name : "Same Product" , price : 15.50 )
232+ original_product = UpsertTestProduct . new ( sku : "NO-CHANGE" , name : "Same Product" , price : 15.50 )
233233 assert original_product . save , "Original product should save"
234234 original_updated_at = original_product . updated_at
235235
236236 # Small delay to ensure updated_at would change if saved
237237 sleep ( 0.1 )
238238
239239 # Use create_or_update! with identical values
240- result_product = TestProduct . create_or_update! (
240+ result_product = UpsertTestProduct . create_or_update! (
241241 { sku : "NO-CHANGE" } ,
242242 { name : "Same Product" , price : 15.50 } # Identical values
243243 )
@@ -261,15 +261,15 @@ def test_create_or_update_bang_empty_resource_attrs
261261 puts "\n === Testing create_or_update! with Empty resource_attrs ==="
262262
263263 # Create initial user
264- original_user = TestUser . new ( email : "empty@example.com" , name : "Original" , age : 40 )
264+ original_user = UpsertTestUser . new ( email : "empty@example.com" , name : "Original" , age : 40 )
265265 assert original_user . save , "Original user should save"
266266 original_updated_at = original_user . updated_at
267267
268268 # Small delay to ensure updated_at would change if saved
269269 sleep ( 0.1 )
270270
271271 # Use create_or_update! with empty resource_attrs
272- result_user = TestUser . create_or_update! (
272+ result_user = UpsertTestUser . create_or_update! (
273273 { email : "empty@example.com" } ,
274274 { } # Empty resource_attrs
275275 )
@@ -293,37 +293,37 @@ def test_performance_comparison_across_methods
293293 puts "\n === Testing Performance Comparison Across Methods ==="
294294
295295 # Create initial test data
296- test_user = TestUser . new ( email : "perf@example.com" , name : "Performance Test" , age : 35 )
296+ test_user = UpsertTestUser . new ( email : "perf@example.com" , name : "Performance Test" , age : 35 )
297297 assert test_user . save , "Test user should save"
298298
299299 # Test first_or_create performance (existing object)
300300 start_time = Time . now
301301 5 . times do
302- result = TestUser . first_or_create ( { email : "perf@example.com" } , { name : "Different" } )
302+ result = UpsertTestUser . first_or_create ( { email : "perf@example.com" } , { name : "Different" } )
303303 assert_equal "Performance Test" , result . name , "Should find unchanged object"
304304 end
305305 first_or_create_time = Time . now - start_time
306306
307307 # Test first_or_create! performance (existing object)
308308 start_time = Time . now
309309 5 . times do
310- result = TestUser . first_or_create! ( { email : "perf@example.com" } , { name : "Different" } )
310+ result = UpsertTestUser . first_or_create! ( { email : "perf@example.com" } , { name : "Different" } )
311311 assert_equal "Performance Test" , result . name , "Should find unchanged object"
312312 end
313313 first_or_create_bang_time = Time . now - start_time
314314
315315 # Test create_or_update! performance (no changes)
316316 start_time = Time . now
317317 5 . times do
318- result = TestUser . create_or_update! ( { email : "perf@example.com" } , { name : "Performance Test" , age : 35 } )
318+ result = UpsertTestUser . create_or_update! ( { email : "perf@example.com" } , { name : "Performance Test" , age : 35 } )
319319 assert_equal "Performance Test" , result . name , "Should find unchanged object"
320320 end
321321 create_or_update_no_change_time = Time . now - start_time
322322
323323 # Test create_or_update! performance (with changes)
324324 start_time = Time . now
325325 5 . times do |i |
326- result = TestUser . create_or_update! ( { email : "perf@example.com" } , { age : 35 + i } )
326+ result = UpsertTestUser . create_or_update! ( { email : "perf@example.com" } , { age : 35 + i } )
327327 end
328328 create_or_update_with_change_time = Time . now - start_time
329329
@@ -355,7 +355,7 @@ def test_complex_upsert_workflow
355355 # Workflow: User registration and profile updates
356356
357357 # Step 1: Try to find existing user, create if not found (unsaved)
358- user = TestUser . first_or_create (
358+ user = UpsertTestUser . first_or_create (
359359 { email : "workflow@example.com" } ,
360360 { name : "Workflow User" , age : 25 , status : "pending" }
361361 )
@@ -368,7 +368,7 @@ def test_complex_upsert_workflow
368368 assert user . save , "Should save user after completing registration"
369369
370370 # Step 3: Update profile information
371- updated_user = TestUser . create_or_update! (
371+ updated_user = UpsertTestUser . create_or_update! (
372372 { email : "workflow@example.com" } ,
373373 { age : 26 , last_login : Time . now }
374374 )
@@ -379,7 +379,7 @@ def test_complex_upsert_workflow
379379 assert updated_user . last_login . present? , "Should have last_login set"
380380
381381 # Step 4: Subsequent login (no changes needed)
382- login_user = TestUser . create_or_update! (
382+ login_user = UpsertTestUser . create_or_update! (
383383 { email : "workflow@example.com" } ,
384384 { age : 26 } # Same age, should not save
385385 )
0 commit comments