Commit Graph

26 Commits

Author SHA1 Message Date
Sergey Tokarenko ca4f532623 Skip excess cloning of JSONized `object_changes` (#1189)
* Skip excess cloning of JSONized `object_changes`

* Suggestions for PR 1189, to be squashed
2019-03-13 13:47:23 -04:00
Anton Rieder 8f8f5587e9
Change URLs to paper-trail-gem 2018-05-09 13:25:56 +02:00
Jared Beck cfbf7a647c Lint: Style/FrozenStringLiteralComment 2017-12-10 23:05:39 -05:00
Jared Beck 325e368c4c Raise error re: where_object_changes, YAML
Using where_object_changes to read YAML from a text column will now raise
error, was deprecated in 8.1.0.
2017-12-10 22:42:16 -05:00
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
Jared Beck 6d7b93ff49 Remove unreachable code re: syck
In ruby >= 2.1, the removed code was no longer reachable, because
`YAML::ENGINE.yamler` is always psych, never syck.
2017-03-31 22:26:41 -04:00
Jared Beck 1125b96594 Docs: re: where_object_changes
[ci skip]
2016-05-10 17:16:35 -04:00
Jared Beck a0e3f43ad1 Docs: Describe all modules 2016-04-09 01:08:34 -04:00
Jared Beck 3eac0c245e Extract private method yaml_engine_id 2016-03-05 17:50:36 -05:00
Jared Beck 94fc96804c Reduce duplication in where_object_changes_condition 2016-03-05 17:39:00 -05:00
Jared Beck 6e2fd6130e Fix indentation in conditionals 2016-03-05 17:30:53 -05:00
Jared Beck 8980f08d0e Fix Style/StringLiterals: Use double quotes 2016-03-05 17:07:32 -05:00
Ben Atkins cff34a7b11 Close #518; Merge branch 'json_attribute_search'
Add support for querying of PostgreSQL's JSON and JSONB column types via VersionConcern#where_object
and VersionConcern#where_object_changes
2015-05-07 15:42:33 -04:00
Yang Bo 89595b8071 fix ::YAML:ENGINE is no found
in 2.0, doesn't has ::YAML::ENGINE, ::YAML is Psych as default
2015-05-05 22:29:02 +08:00
Michael Raimondi 237f7f7f09 Update YAML engine check for new Ruby versions
On Ruby 2.2.1, '::YAML' returns the class Psych, which has no ::ENGINE
constant defined.
2015-04-14 23:28:03 -04:00
Ben Atkins 642774e69e One additional tweak to PaperTrail::Serializers::YAML#where_object_changes to handle spacing inconsistencies 2015-01-14 15:52:07 -05:00
Ben Atkins bd3946c87b Adjust PaperTrail::Serializers::YAML#where_object_changes
to handle inconsistencies with spacing between values in YAML dumps of Arrays
2015-01-14 14:53:45 -05:00
Ben Atkins d904af21e3 Fix failing tests by accounting for differences in dumping of Array to YAML in Psych vs Syck 2015-01-14 14:19:37 -05:00
Ben Atkins 4a92ed7ea5 close #420; Add VersionConcern#where_object_changes 2015-01-07 16:57:45 -05:00
Jacob Evelyn 703ec9ae88 Add where_object query to PaperTrail::Version. 2014-06-07 14:11:50 -04:00
Ben Atkins b32ced84c5 Upcasing the provided YAML and JSON serializers 2013-10-17 22:05:24 -04:00
Ben Atkins f54ada67e2 Making the built-in serializers declare 'extend self' so that their :load and :dump methods are available as module methods and instance methods. This enables classes/modules that mix in one of these serializers to invoke or override the methods. Close #196 2013-01-31 15:10:31 -05:00
Ben Atkins 64758ca163 Fixing some comments in the serializer tests to be accurate. Also tweaking the syntax of the 'dump' methods in the serializers to clarify that the serializers can acceptobjects other than just Hashes (even though PaperTrail will only pass attribute hashes to the serializers). 2013-01-31 11:22:03 -05:00
Ben Atkins 05301e586e Refactoring the serializers to be modules instead of classes, since they never get instantiated. 2013-01-23 15:56:10 -05:00
Ben Atkins 38e05bc53e Merge remote-tracking branch 'bradleypriest/master'
Conflicts:
	lib/paper_trail/has_paper_trail.rb
	lib/paper_trail/version.rb
2012-12-28 01:12:42 -05:00
Bradley Priest 41e255bf51 Add the ability to use a custom serializer for storing the object in the database 2012-10-13 16:08:39 +08:00