Commit Graph

15211 Commits

Author SHA1 Message Date
Benjamin Quorning
e4701e613c [] and read_attribute are not aliases [ci skip]
The `#[]` method *used to be* an alias of `#read_attribute`, but since Rails 4
(10f6f90d9d1bbc9598bffea90752fc6bd76904cd), it will raise an exception for
missing attributes. Saying that it is an alias is confusing.
2016-05-24 13:20:28 +02:00
Rafael França
cf403266e5 Merge pull request #24862 from maclover7/jm-ar-fixes
Add missing `the`
2016-05-21 12:47:39 -03:00
Rafael França
c0d4aa2293 Merge pull request #25093 from Erol/activerecord-transaction-serialization-error
Introduce AR::TransactionSerializationError for transaction serialization failures or deadlocks
2016-05-21 12:36:20 -03:00
Jon Moss
355f68bcbf
Add missing the
[ci skip]
2016-05-21 10:43:18 -04:00
Erol Fornoles
4d525a6f75 Add AR::TransactionSerializationError for transaction serialization failures or deadlocks 2016-05-21 21:51:52 +08:00
Rafael Mendonça França
85ee483fe1
Whitespaces [ci skip] 2016-05-21 09:55:06 -03:00
Jon Moss
d95947a87e Add CHANGELOG.md reference for #24958 (#25094)
Sorry for forgetting to include it in my original PR 😬

r? @rafaelfranca

[ci skip]
2016-05-21 09:51:36 -03:00
Rafael França
91421984b7 Merge pull request #24732 from y-yagi/update_record_specified_in_the_key
update record specified in key
2016-05-21 09:01:36 -03:00
Rafael França
3e54c1c40e Merge pull request #24958 from maclover7/fix-24955
Fix ActiveRecord::LogSubscriber edge case
2016-05-20 23:34:48 -03:00
Rafael França
d0c257f5da Merge pull request #24984 from kamipo/remove_magic_comment_in_schema.rb
Remove magic comment in generated `schema.rb`
2016-05-20 23:26:04 -03:00
Benjamin Quorning
70d504f626 [ci skip] Update retrieve_connection_pool comment
After PR https://github.com/rails/rails/pull/24844 the documentation for
`#retrieve_connection_pool` was out of date. This commit changes:

- the reference from `@class_to_pool` to `@owner_to_pool`.
- with newer Rubies, `#fetch` isn't significantly slower than `#[]`. Since Rails 5
requires Ruby >= 2.2.2, we can just use `#fetch` here.
2016-05-20 14:30:08 +02:00
Jeremy Daer
89e2f7e722
Support for unified Integer class in Ruby 2.4+
Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005

* Forward compat with new unified Integer class in Ruby 2.4+.
* Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3.
* Drops needless Fixnum distinction in docs, preferring Integer.
2016-05-18 21:58:51 -07:00
Kasper Timm Hansen
8fffee4b1c Merge pull request #24203 from sferik/count_with_block
Forward ActiveRecord::Relation#count to Enumerable#count if block given
2016-05-16 20:39:28 +02:00
Sean Griffin
a7ecc63679 Merge pull request #25009 from jahfer/suppressor-keep-state
Keep previous state around for nested calls to #suppress
2016-05-16 14:11:32 -04:00
Jahfer Husain
25801cfe78 Keep state around for nested calls to #suppress
If a call to #suppress from the same class occurred inside another #suppress
block, the suppression state would be set to false before the outer block
completes.

This change keeps the previous state around in memory and unwinds it
as the blocks exit.
2016-05-16 14:07:32 -04:00
Sean Griffin
aa7ded6a36 Merge pull request #23810 from xijo/fix_json_coder_when_mysql_strict_is_disabled
Fix bug in JSON deserialization when column default is an empty string
2016-05-16 10:44:58 -04:00
bUg
e3cd321d4b Rails 5.1 point type should not raise exception if empty string is provided as value 2016-05-15 16:14:57 +03:00
Vijay Dev
83ecf3fe56 Merge branch 'master' of github.com:rails/docrails
Conflicts:
	guides/source/configuring.md
2016-05-14 09:54:23 +00:00
Kang-Kyu Lee
238c77dedf Add missing space and newline for clarity 2016-05-12 20:59:38 -07:00
Sean Griffin
0991c4c6fc Give more context from AssociationMismatchError
The error message that we give today makes this error difficult to debug
if you receive it. I have no clue why we're printing the object ID of
the class (the commit doesn't give context), but I've left it as it was
deliberate.
2016-05-12 22:20:45 -04:00
Molchanov Andrey
37f2674d64 Rename test method 2016-05-12 22:45:18 +03:00
Sean Griffin
6007e584d8 Fix false positive mutation detection when JSON is used with serialize
When looking for mutation, we compare the serialized version of the
value to the before_type_cast form. `Type::Serialized` was breaking this
contract by passing the already serialized attribute to the subtype's
mutation detection. This never manifested previously, as all mutable
subtypes either didn't do anything in their `serialize` method, or had a
way to detect double serialization (e.g. `is_a?(String)`). However, now
that JSON types can handle string primitives, we need to avoid double
serialization.

Fixes #24993.
2016-05-12 09:09:47 -04:00
Sean Griffin
d1794cd88c Merge pull request #24980 from merhard/virtual-attribute-default
Define ActiveRecord::Attribute::Null#type_cast
2016-05-11 22:00:37 -04:00
Ryuta Kamizono
2a71885a3f Remove magic comment in generated schema.rb
Rails 5.0 has been dropped Ruby 1.9 support.
I think no need magic comment anymore.
2016-05-12 05:43:08 +09:00
Arthur Neves
537a342a83
remove_connection should not remove parent connection
When calling remove_connection in a subclass, that should not fallback
to the parent, otherwise it will remove the parent connection from the
handler.
2016-05-11 13:39:26 -04:00
Matthew Erhard
556e530da4 Define ActiveRecord::Attribute::Null#type_cast
Using ActiveRecord::Base.attribute to declare an attribute with a default value on a model where the attribute is not backed by the database would raise a NotImplementedError when model.save is called.

The error originates from 59d252196b/activerecord/lib/active_record/attribute.rb (L84).
This is called from 59d252196b/activerecord/lib/active_record/attribute.rb (L46) on an ActiveRecord::Attribute::Null object.

This commit corrects the behavior by implementing ActiveRecord::Attribute::Null#type_cast.

With ActiveRecord::Attribute::Null#type_cast defined, ActiveRecord::Attribute::Null#value (59d252196b/activerecord/lib/active_record/attribute.rb (L173..L175)) can be replaced with its super method (59d252196b/activerecord/lib/active_record/attribute.rb (L36..L40)).

fixes #24979
2016-05-11 13:21:01 -04:00
Arthur Nogueira Neves
733161d48b Merge pull request #24971 from arthurnn/arthurnn/dont_cache_specification_name
Dont cache the conn_spec_name when empty
2016-05-11 09:02:10 -04:00
Arthur Neves
897decaceb
Set conn_spec_name after remove
`remove_connection` can reset the `connection_specification_name`, so we
need to to set it after the remove_connection call on
`establish_connection` method.
2016-05-11 08:37:56 -04:00
Arthur Neves
f1030fd897
Dont cache the conn_spec_name when empty
We cannot cache the connection_specification_name when it doesnt
exist. Thats because the parent value could change, and we should keep
failling back to the parent. If we cache that in a children as an ivar,
we would not fallback anymore in the next call, so the children would
not get the new parent spec_name.
2016-05-11 08:04:26 -04:00
yui-knk
64634ce61a [ci skip] Update documents of ConnectionHandler
Follow up of #24844.
The key of `@owner_to_pool` was changed from `klass.name` to
`spec.name`. By this change "memory leaks in development mode"
will not happen, bacause the equality of string is not changed
by reloading of model files.
2016-05-11 13:40:57 +09:00
Arthur Neves
d6f3ad7ce7
Make sure we reset the connection_specification_name on
remove_connection

When calling `remove_connection` on a model, we delete the pool so we also
need to reset the `connection_specification_name` so it will fallback to
the parent.
This was the current behavior before rails 5, which will fallback to the
parent connection pool.

[fixes #24959]

Special thanks to @jrafanie for working with me on this fix.
2016-05-10 23:42:26 -04:00
Jon Moss
c650341573 Fix ActiveRecord::LogSubscriber edge case
If an attribute was of the binary type, and also was a Hash, it would
previously not be logged, and instead raise an error saying that
`bytesize` was not defined for the `attribute.value` (a `Hash`).

Now, as is done on 4-2-stable, the attribute's database value is
`bytesize`d, and then logged out to the terminal.

Reproduction script:

```ruby
require 'active_record'
require 'minitest/autorun'
require 'logger'

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do
  create_table :posts, force: true do |t|
    t.binary :preferences
  end
end

class Post < ActiveRecord::Base
  serialize :preferences
end

class BugTest < Minitest::Test
  def test_24955
    Post.create!(preferences: {a: 1})

    assert_equal 1, Post.count
  end
end
```
2016-05-10 15:42:07 -04:00
Rafael França
6dec764519 Merge pull request #24950 from kamipo/should_quote_lock_name
Should quote `lock_name` to pass to `get_advisory_lock`
2016-05-10 05:10:23 -03:00
Xavier Noria
6c471becf0 Merge pull request #24939 from Neodelf/again_with_loop
Replacement cycle for readability
2016-05-10 09:15:22 +02:00
Ryuta Kamizono
54772667ee Should quote lock_name to pass to get_advisory_lock 2016-05-10 16:14:45 +09:00
Molchanov Andrey
88f804d3a9 Replacement cycle for readability 2016-05-10 09:55:58 +03:00
Rafael Mendonça França
697ab08af9 Add migration compatibility class for Rails 5.1 2016-05-10 03:46:56 -03:00
Rafael Mendonça França
8ecc5ab1d8 Start Rails 5.1 development 🎉 2016-05-10 03:46:56 -03:00
Molchanov Andrey
ce8b0cbf34 Replacement cycle for readability 2016-05-09 00:45:22 +03:00
Jon Moss
a8258e2bed Followup to #24844
Some slight documentation edits and fixes. Also, run remove unnecessary
`RuntimeError`.

r? @arthurnn
2016-05-07 17:41:11 -04:00
Rafael Mendonça França
fbdcf5221a Preparing for 5.0.0.rc1 release 2016-05-06 16:54:40 -05:00
Arthur Nogueira Neves
fcb223dd53 Merge pull request #24844 from arthurnn/arthurnn/conn
Refactor connection handler
2016-05-06 15:50:50 -05:00
Arthur Neves
36ce6aba98
Update docs for connection handler
[skip ci]
2016-05-06 15:11:48 -05:00
Arthur Nogueira Neves
40d5c3370f Merge pull request #24871 from vipulnsward/disable-transaction-failure
Fix failures due to transactions
2016-05-06 14:00:49 -05:00
Vipul A M
8a42229fcf We are erroring due to nested transaction failures from mysql on test_migrate_clears_schema_cache_afterward test.
Disable transactions for this test.

Fixes #24391
2016-05-06 14:00:21 -05:00
Arthur Neves
22a127c57b
s/specification_name/connection_specification_name 2016-05-06 13:22:49 -05:00
Sean Griffin
96f3f3d826 Allow the connection adapters to determine the order of bind params
In 5.0 we use bind parameters for limit and offset, while in 4.2 we used
the values directly. The code as it was written assumed that limit and
offset worked as `LIMIT ? OFFSET ?`. Both Oracle and SQL Server have a
different syntax, where the offset is stated before the limit. We
delegate this behavior to the connection adapter so that these adapters
are able to determine how the bind parameters are flattened based on
what order their specification has the various clauses appear.

Fixes #24775
2016-05-06 11:58:01 -05:00
Arthur Neves
598e7c9e20
s/specification_id/specification_name 2016-05-05 15:39:27 -05:00
Rafael França
ed94ed3e1f Merge pull request #24869 from vipulnsward/change-example
Change to use a more realistic example [ci skip]
2016-05-05 15:32:52 -05:00
Rafael França
dd7bdd0e90 Merge pull request #24868 from vipulnsward/delegate_encode_with
delegate encode_with instead of to_yaml, which is deprecated
2016-05-05 15:32:07 -05:00