Skip to content

Commit 3715085

Browse files
committed
Update test class names and assertions in upsert and product tests
Renames test classes and references in upsert_methods_integration_test.rb to use UpsertTestUser and UpsertTestProduct for clarity and isolation. Updates a test assertion in mongodb_operators_integration_test.rb to expect 3 products ending with 'Pro' instead of 2. Also renames the test class in product_test.rb to ProductModelTest. Updates CHANGELOG.md to fix a version section ordering issue and clarify improvements.
1 parent f4bd663 commit 3715085

7 files changed

Lines changed: 47 additions & 50 deletions

CHANGELOG.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@
1010

1111
- **IMPROVED**: CI now tests against Ruby 3.1, 3.2, 3.3, and 3.4.
1212

13-
### 3.2.3
13+
### 3.2.2
1414

1515
#### Improvements
1616

17+
- **IMPROVED**: `latest` and `last_updated` methods now support a `limit:` option when passing constraints. This allows fetching multiple recent records while also filtering by query conditions.
18+
19+
```ruby
20+
# Class methods
21+
Song.latest(:user.eq => user, limit: 5) # 5 most recent for user
22+
Song.last_updated(status: "active", limit: 10) # 10 most recently updated active
23+
24+
# Query instance methods
25+
query.latest(:user.eq => x, limit: 5)
26+
query.where(genre: "rock").last_updated(limit: 3)
27+
```
28+
1729
- **IMPROVED**: `PointerCollectionProxy#as_json` now supports the `pointers_only` option. By default it returns pointers (preserving backward compatibility), but you can set `pointers_only: false` to serialize objects with their fetched fields. This is useful when returning `has_many :through => :array` relationships in webhook responses.
1830

1931
When `pointers_only: false`:
@@ -59,22 +71,6 @@ song.as_json(exclude_keys: [:acl, :created_at])
5971
song.as_json(exclude: [:acl, :created_at])
6072
```
6173

62-
### 3.2.2
63-
64-
#### Improvements
65-
66-
- **IMPROVED**: `latest` and `last_updated` methods now support a `limit:` option when passing constraints. This allows fetching multiple recent records while also filtering by query conditions.
67-
68-
```ruby
69-
# Class methods
70-
Song.latest(:user.eq => user, limit: 5) # 5 most recent for user
71-
Song.last_updated(status: "active", limit: 10) # 10 most recently updated active
72-
73-
# Query instance methods
74-
query.latest(:user.eq => x, limit: 5)
75-
query.where(genre: "rock").last_updated(limit: 3)
76-
```
77-
7874
### 3.2.1
7975

8076
#### New Features

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ GEM
8080
pry-stack_explorer (0.6.1)
8181
binding_of_caller (~> 1.0)
8282
pry (~> 0.13)
83-
rack (3.2.2)
83+
rack (3.2.4)
8484
rake (13.3.0)
8585
redcarpet (3.6.1)
8686
redis (5.4.1)

test/lib/parse/hooks_and_validation_integration_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# Test model with hooks, validations, and change tracking
66
class TestProduct < Parse::Object
7+
parse_class "HooksTestProduct"
78
property :name, :string
89
property :price, :float
910
property :sku, :string

test/lib/parse/models/product_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require_relative "../../../test_helper"
22

3-
class TestProduct < Minitest::Test
3+
class ProductModelTest < Minitest::Test
44
CORE_FIELDS = Parse::Object.fields.merge({
55
:id => :string,
66
:created_at => :date,

test/lib/parse/mongodb_operators_integration_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_regex_and_string_operators_with_mongodb_direct
102102
puts "MongoDB Direct (:name.ends_with => 'Pro'): #{direct_names.inspect}"
103103

104104
assert_equal parse_names, direct_names, "ends_with results should match"
105-
assert_equal 2, direct_names.length, "Should find 2 products ending with Pro"
105+
assert_equal 3, direct_names.length, "Should find 3 products ending with Pro"
106106

107107
# --- Test 2c: ends_with with special characters ---
108108
puts "\n--- Test: ends_with with special characters ---"

test/lib/parse/query_pointers_contains_integration_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class QueryTestBook < Parse::Object
1818
property :isbn, :string
1919
property :price, :float
2020
property :publication_year, :integer
21-
property :author, :object # pointer to QueryTestAuthor
21+
belongs_to :author, as: :query_test_author
2222
property :genres, :array
2323
property :awards, :array
2424
property :related_books, :array # array of pointers to other QueryTestBook

test/lib/parse/upsert_methods_integration_test.rb

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require_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
1212
end
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

Comments
 (0)