1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

55 commits

Author SHA1 Message Date
Jean Boussier
617f9908e3 Add Active Record Marshal forward compatibility tests
This is following a recent discussion on Basecamp.

So far Rails haven't tried to preserve Marshal compatibilty of Active Record instances,
and it probably shouldn't as it isn't as controllable as other serialization formats.

However it's common to store ActiveRecord instances in Rails.cache, and when the
Marshal format changes, it causes problems during Rails upgrade. Process using the new Rails
version might not be able to deserialize the existing cache, and also older process that
weren't restarted yet my fail to load the cache entries written by newer processes.

The goal of this PR is not to freeze the Marshal format, but to have a better visibility
when it changes, so that's it's done on purpose with good reasons rather than accidentally.

Note that this only test forward compatibility (AR vN reading entries written by AR vN-1),
ideally we'd also test backward compatibility (AR vN-1 reading entries written by AR vN),
but it means installing and loading and older Active Record as part of the test suite.
2020-07-02 14:11:51 +02:00
Ryuta Kamizono
4fe1452534
Merge pull request from kamipo/marshal_load_legacy_ar_object
Backward compatibility to work `Marshal.load(legacy_record.dump)` for MySQL
2020-07-01 22:43:12 +09:00
Ryuta Kamizono
748b472f46 Fix yaml_compatibility_fixtures/rails_v1_mysql.yml's structure
`attr_name` in `YAMLColumn` is not part of v1 YAML.

Ref .
2020-06-30 23:32:05 +09:00
Ryuta Kamizono
6a9301dcc5 Backward compatibility to work Marshal.load(legacy_record.dump) for MySQL
Context https://github.com/rails/rails/pull/39599#discussion_r445429365.

Similar with .

Actually we never said we would keep Mashal compatibility between two
versions of Rails, so we sometimes directly removed the dedicated types
in the past (e.g. f1a0fa9, ), but that direct removing makes cache
rotation harder.

Keeping the unused constant in new version at least during one version
will help cache rotation easier.
2020-06-30 23:22:44 +09:00
Ryuta Kamizono
5b47e26732 Restore legacy YAML compatibility for MySQL with active_record_yaml_version: 1
We had removed the dedicated `MysqlDateTime`, `MysqlJson`, and
`OID::Json` classes in the past (f1a0fa9, ), so legacy YAML
loading has no longer always perfectly compatiblity.

Fortunately, v2 (Rails 5.1 style) YAML doesn't contain type information
in almost all cases (unless serializing object using custom select), so
usually removing dedicated type affects to legacy YAML older than v1
(Rails 5.0 style) YAML only.

This restores legacy YAML compatibility for MySQL with v1 format by
adding the class alias in YAML for `MysqlString` which is most recently
reported about compatibility concern. It also affects to legacy Rails
4.2 style YAML, but 4.2 style YAML had already broken by removing
`MysqlDateTime` over 4 years ago.
2020-06-25 21:04:51 +09:00
Ryuta Kamizono
4148590ed9 Restore referencing BaseHandler in legacy_relation.dump
It accidentally lost at 550ce69f8a.
2020-06-21 06:51:16 +09:00
Ryuta Kamizono
550ce69f8a Remove less interested where_clause_factory
I'd not prefer to allocate its less interested object, it doesn't
improve readability, and make code slower.
2020-06-21 06:31:20 +09:00
Ryuta Kamizono
34d0836f6f Backward compatibility to work Marshal.load(legacy_relation.dump)
A relation has a predicate builder, so if a predicate handler which is
referenced by a legacy predicate builder is removed in the new code,
`Marshal.load(legacy_relation.dump)` will fail due to referencing
undefined constant.

I've restored no-op `BaseHandler` constant alias to make cache rotation
easier during Rails 6.1.

Fixes .
2020-06-13 09:39:02 +09:00
Rafael França
df186bd16f
Merge pull request from vinistock/stop_stringifying_during_attribute_assignment
Do not stringify attributes in assign_attributes
2020-02-13 16:54:35 -05:00
Kurtis Rainbolt-Greene
ef7599fe91
Extract internal ActiveSupport::ConfigurationFile object
Rails has a number of places where a YAML configuration file is read,
then ERB is evaluated and finally the YAML is parsed.

This consolidates that into one common class.

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2020-02-10 02:50:12 +01:00
Vinicius Stock
2e9e940e22
Change safe guard to check for each_pair instead of stringify_keys 2020-02-07 11:36:35 -05:00
eileencodes
7315c91d45
Deprecate #remove_connection in favor of #remove_connection_pool
Calling `#remove_connection` on the handler is deprecated in favor of
`#remove_connection_pool`. This change was made to support changing the
return value from a hash to a `DatabaseConfig` object.
`#remove_connection` will be removed in 6.2.

NOTE: `#remove_connection` on `ActiveRecord::Base` will also now return
a `DatabaseConfig` object. We didn't use a deprecation here since
it's not documented that this method used to return a `Hash`.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2020-01-21 16:49:20 -05:00
John Crepezzi
3f743b01ff Rename a test method to not conflict with a deprecated method
This method in test has a confusing name that also is the same as a
method with a different behavior on `ActiveRecord::Base` so we're just
renaming it to avoid confusion between the two!

Co-authored-by: eileencodes <eileencodes@gmail.com>
2019-12-17 12:35:15 -05:00
Ryuta Kamizono
c81af6ae72 Enable Layout/EmptyLinesAroundAccessModifier cop
We sometimes say "✂️ newline after `private`" in a code review (e.g.
https://github.com/rails/rails/pull/18546#discussion_r23188776,
https://github.com/rails/rails/pull/34832#discussion_r244847195).

Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style
`EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059).

That cop and enforced style will reduce the our code review cost.
2019-06-13 12:00:45 +09:00
Ryuta Kamizono
a99e00452b Remove duplicated protected params definitions
Use "support/stubs/strong_parameters" instead.
2019-02-24 19:50:53 +09:00
Eileen Uchitelle
8d32346cde Add ability to change the names of the default handlers
When I wrote the `connected_to` and `connects_to` API's I wrote them
with the idea in mind that it didn't really matter what the
handlers/roles were called as long as those connecting to the roles knew
which one wrote and which one read.

With the introduction of the middleware Rails begins to assume it's
`writing` and `reading` and there's no room for other roles. At GitHub
we've been using this method for a long time so we have a ton of legacy
code that uses different handler names `default` and `readonly`. We
could rename all our code but I think this is better for a few reasons:

- Legacy apps that have been using multiple databases for a long time
  can have an eaiser time switching.
- If we later find this to cause more issues than it's worth we can
  easily deprecate.
- We won't force old apps to rewrite the resolver middleware just to use
  a different handler.

Adding the writing_role/reading_role required that I move the code that
creates the first handler for writing to the railtie. If I didn't move
this the core class would assign the handler before I was able to assign
a new one in my configuration and I'd end up with 3 handlers instead of
2.
2019-02-01 14:11:35 -05:00
bogdanvlviv
6410c70f7c
Ensure that AR::Relation#exists? allows only permitted params
Clarify changelog entry
Related to 
2019-01-17 20:10:01 +00:00
Gannon McGibbon
1e923b4984 Allow strong params in ActiveRecord::Base#exists?
Allow `ActionController::Params` as argument of
`ActiveRecord::Base#exists?`
2019-01-07 14:59:02 -05:00
Vinicius Stock
3b7a4d3d75
Upgrade Rubocop to 0.61.1 and fix offenses 2018-12-10 19:22:56 -02:00
Kir Shatrov
831be98f9a Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Kir Shatrov
4846eeee0f Handle non-existing $ARCONN 2017-02-27 08:23:02 -06:00
Julia Lopez
5e46f4ccb4 fix #create_fixtures when equal table names in different databases 2016-12-21 11:09:29 +01:00
Ryuta Kamizono
8e1b28ad7f Fix typo s/with/without/
Follow up to .
2016-11-20 05:47:30 +09:00
Prathamesh Sonpatki
7b6b52d6bc
Fix tests for prepared_statements: false and queries hitting #select_all
- The query needs to be executed for hitting `select_all` so made sure
  that query gets executed.
- Also instead of changing instance variable, just add new
  configuration for prepared_statements: false and use it for this
  test.
- This way we don't have to touch the internals of AR code and still
  disable prepared statements config for this test.
2016-11-19 21:52:52 +05:30
Akira Matsuda
81e16dad6c Erubis is not actually used in AR 2016-11-06 03:42:16 +09:00
Xavier Noria
9617db2078 applies new string literal convention in activerecord/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:26:53 +02:00
yui-knk
7429633b82 Deprecate #table_exists?, #tables and passing arguments to #talbes
Reported on , how views is treated by `#tables` are differ
by each adapters. To fix this different behavior, after Rails 5.0
is released, deprecate `#tables`.

And `#table_exists?` would check both tables and views.
To make their behavior consistent with `#tables`, after Rails 5.0
is released, deprecate `#table_exists?`.
2015-11-09 23:13:23 +09:00
Matt Hanlon
5ec9e9349e use correct DB connection for generated HABTM table 2015-08-07 12:33:09 -07:00
Sean Griffin
4e7217027f Add YAML compatibility for objects from Rails 4.2
As of Ruby 2.2, Psych can handle any object which is marshallable. This
was not true on previous versions of Ruby, so our delegator types had to
provide their own implementation of `init_with` and `encode_with`.
Unfortunately, this doesn't match up with what Psych will do today.

Since by the time we hit this layer, the objects will have already been
created, I think it makes the most sense to just grab the current type
from the class.
2015-03-10 11:56:45 -06:00
Akira Matsuda
3cce7628e4 Reset ActiveRecord::SchemaDumper.ignore_tables value after changed in tests 2014-09-03 11:30:36 +09:00
Yves Senn
a48b675d54 fk: :primary_key option for non-standard pk's. 2014-06-26 22:03:48 +02:00
Yves Senn
ed1b747b85 pg test, examples for default values and schema dumping of point types.
/cc @sgrif
2014-06-03 13:46:32 +02:00
Guo Xiang Tan
f1169d9d25 Add ConnectionHelper to refactor tests. 2014-04-03 01:06:43 -07:00
Guo Xiang Tan
9896c5fba9 Allow postgresql enum_test to be run in random order.
Creating and dropping similar tables within the same connection causes postgresql to look up old values in the cache of tables which have already been dropped.
2014-04-01 21:34:11 -07:00
Guo Xiang Tan
79405a07a4 Extract with_example_table into helper method.
This setups the helper method which other tests can benefit from.
2014-03-20 11:48:17 -07:00
José Valim
ec11807368 Deprecate use of string in establish_connection as connection lookup 2013-12-24 10:18:54 +01:00
Andrey Deryabin
da67d192d2 Revert "Fix annoy warning, when executing testcase."
This reverts commit a3024f8122.

REASON: Since warning doesn't exist
2012-11-30 12:07:55 +04:00
Jon Leighton
9e4c41c903 Remove ActiveRecord::Model
In the end I think the pain of implementing this seamlessly was not
worth the gain provided.

The intention was that it would allow plain ruby objects that might not
live in your main application to be subclassed and have persistence
mixed in. But I've decided that the benefit of doing that is not worth
the amount of complexity that the implementation introduced.
2012-10-26 15:51:02 +01:00
Rafael Mendonça França
64391cd520 Rotate the debug.log on each 100MB 2012-10-20 17:09:27 -03:00
Yasuo Honda
048866aa14 Revert "truncate debug.log on each test run"
This reverts commit 98043c689f.

Because if every time `debug.log` is truncated,
developers have no way to see the previous ActiveRecord unit test results.
`debug.log` file can be easily reduced
by executing `$ touch /dev/null > debug.log` periodically.
2012-10-20 04:30:07 +09:00
Francesco Rodriguez
98043c689f truncate debug.log on each test run 2012-10-19 12:11:38 -05:00
kennyj
a3024f8122 Fix annoy warning, when executing testcase. 2012-09-11 00:17:08 +09:00
Jon Leighton
6e57d5c584 Use method compilation for association methods
Method compilation provides better performance and I think the code
comes out cleaner as well.

A knock on effect is that methods that get redefined produce warnings. I
think this is a good thing. I had to deal with a bunch of warnings
coming from our tests, though.
2012-08-10 23:28:08 +01:00
Carlos Antonio da Silva
a8dd21d8b4 Remove IdentityMap 2012-03-13 20:08:54 -03:00
Rick Martinez
30b6d4f7f1 added test for 2012-02-10 17:35:22 -05:00
Jon Leighton
dae7b65453 Support establishing connection on ActiveRecord::Model.
This is the 'top level' connection, inherited by any models that include
ActiveRecord::Model or inherit from ActiveRecord::Base.
2011-12-28 18:27:41 +00:00
Karunakar (Ruby)
730209a679 Changed the old logger to new active support logger 2011-12-21 23:00:06 +05:30
Jon Leighton
e510c2c642 Add require 'pathname' as it has not already been required in some circumstances 2011-06-17 14:55:34 +01:00