1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00
paper-trail-gem--paper_trail/spec/models
Sergey Alekseev 626d0a6772 Deprecate where_object_changes reading YAML from text column
* clarify the issue with `where_object_changes` for numeric values

History
---
[The first problem mention](1ad78383aa).
[The major issue](https://github.com/airblade/paper_trail/issues/803) with relevant discussions.

Details
---
I see the problem only with one specific case – when the method is `where_object_changes` and the serializer is YAML. Which is a default configuration.

I see there are 6 types of queries with a numeric value for `where_object_changes` and `where_object` (grabbed from `version_spec.rb`):
```
.where_object_changes
N1
SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (object_changes @> '{"an_integer":[1]}')  ORDER BY "versions"."created_at" ASC, "versions"."id" ASC

N1
SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND ("versions"."object_changes" ILIKE '%
an_integer:
- 1
%' OR "versions"."object_changes" ILIKE '%
an_integer:
-%
- 1
%')  ORDER BY "versions"."created_at" ASC, "versions"."id" ASC

N3
SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (((object_changes->>'an_integer' ILIKE '[1,%') OR (object_changes->>'an_integer' ILIKE '[%,1]%')))  ORDER BY "versions"."created_at" ASC, "versions"."id" ASC

.where_object
N4
SELECT "versions".* FROM "versions" WHERE (object @> '{"an_integer":1}')

N5
SELECT "versions".* FROM "versions" WHERE (object->>'an_integer' = '1')

N6
SELECT "versions".* FROM "versions" WHERE ("versions"."object" ILIKE '%
an_integer: 1
%')
```

The only problematic one is N2. It incorrectly matches `object_changes` like
```
---
name:
-
- Kimberli
an_integer:
-
- 0
created_at:
-
- 2017-09-28 18:30:13.369889000 Z
updated_at:
-
- 2017-09-28 18:30:13.369889000 Z
id:
-
- 1
---
name:
- foobar
- Hayes
an_integer:
- 77
- 1
updated_at:
- 2017-09-28 18:30:13.383966000 Z
- 2017-09-28 18:30:13.395539000 Z
```
2017-10-23 13:07:27 -04:00
..
family Move tests from associations_spec to family_spec 2017-10-04 23:01:48 -04:00
kitchen Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
on Organizing model tests 2017-07-05 00:15:15 -04:00
animal_spec.rb Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
article_spec.rb Organizing model tests 2017-07-05 00:15:15 -04:00
boolit_spec.rb Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
callback_modifier_spec.rb Support belongs_to_required_by_default 2017-08-30 14:02:56 -07:00
car_spec.rb Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
custom_primary_key_record_spec.rb Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
document_spec.rb Organizing model tests 2017-07-05 00:15:15 -04:00
gadget_spec.rb Lint: Fix various offenses, mostly rspec 2017-09-19 01:25:53 -04:00
joined_version_spec.rb Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
json_version_spec.rb Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
legacy_widget_spec.rb Organizing model tests 2017-07-05 00:15:15 -04:00
not_on_update_spec.rb Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
post_with_status_spec.rb Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
skipper_spec.rb Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
thing_spec.rb Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
translation_spec.rb Organizing model tests 2017-07-05 00:15:15 -04:00
vehicle_spec.rb Merge rails_helper into spec_helper 2017-05-30 00:59:55 -04:00
version_spec.rb Deprecate where_object_changes reading YAML from text column 2017-10-23 13:07:27 -04:00
widget_spec.rb Lint: Fix various offenses, mostly rspec 2017-09-19 01:25:53 -04:00