aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
Commit message (Collapse)AuthorAgeFilesLines
...
* | | | Ensure hashes can be passed to attributes using `composed_of`Sean Griffin2016-05-312-1/+11
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This behavior was broken by 36e9be85. When the value is assigned directly, either through mass assignment or directly assigning a hash, the hash gets passed through to this writer method directly. While this is intended to handle certain cases, when an explicit converter has been provided, we should continue to use that instead. The positioning of the added guard caused the new behavior to override that case. Fixes #25210
* | | Exists shouldn't error when used with `includes`Sean Griffin2016-05-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently `exists?` does some hackery where it assumes that we can join onto anything that we passed to `eager_load` or `includes`, which doesn't work if we are joining onto a polymorphic association. Actually figuring out if we want to include something would require knowledge deep within the join dependency module, which is hard to pull up. The simplest solution is just to pass a flag down that says we're not actually going to try to eager load any of the data. It's not the solution I'd like, but that code really needs to be untangled before we can do much with it. This is another attempt at 6d5b1fd which should address the concerns that led to reverting it in 4ecabed.
* | | Merge pull request #25175 from kamipo/fix_migration_class_names_in_testsKasper Timm Hansen2016-05-306-6/+6
|\ \ \ | | | | | | | | Fix migration class names in tests
| * | | Fix migration class names in testsRyuta Kamizono2016-05-286-6/+6
| | | |
* | | | Merge pull request #24965 from arthurnn/arthurnn/conn_apiArthur Nogueira Neves2016-05-293-12/+15
|\ \ \ \ | |/ / / |/| | | Change some establish_connection logic
| * | | Add to_hash to specificationArthur Neves2016-05-251-1/+1
| | | |
| * | | Remove `name` from `establish_connection`Arthur Neves2016-05-243-12/+15
| | | | | | | | | | | | | | | | | | | | Instead of passing a separete name variable, we can make the resolver merge a name on the config, and use that before creating the Specification.
* | | | Fix `has_one` `enum` `where` queriesJon Moss2016-05-261-0/+18
|/ / / | | | | | | | | | Fixes #25128
* | | Merge pull request #25093 from Erol/activerecord-transaction-serialization-errorRafael França2016-05-212-0/+134
|\ \ \ | | | | | | | | Introduce AR::TransactionSerializationError for transaction serialization failures or deadlocks
| * | | Add AR::TransactionSerializationError for transaction serialization failures ↵Erol Fornoles2016-05-212-0/+134
| | | | | | | | | | | | | | | | or deadlocks
* | | | Merge pull request #24732 from y-yagi/update_record_specified_in_the_keyRafael França2016-05-211-0/+17
|\ \ \ \ | |/ / / |/| | | update record specified in key
| * | | update record specified in keyyuuji.yaginuma2016-04-271-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | `#first_or_initialize` does not use attributes to data acquisition. Therefore, there is a possibility of updating the different record than the one specified in the key, I think this is not expected behavior.
* | | | Merge pull request #24958 from maclover7/fix-24955Rafael França2016-05-201-0/+6
|\ \ \ \ | | | | | | | | | | Fix ActiveRecord::LogSubscriber edge case
| * | | | Fix ActiveRecord::LogSubscriber edge caseJon Moss2016-05-101-0/+6
| | |/ / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 ```
* | | | Merge pull request #24984 from kamipo/remove_magic_comment_in_schema.rbRafael França2016-05-201-4/+0
|\ \ \ \ | | | | | | | | | | Remove magic comment in generated `schema.rb`
| * | | | Remove magic comment in generated `schema.rb`Ryuta Kamizono2016-05-121-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | Rails 5.0 has been dropped Ruby 1.9 support. I think no need magic comment anymore.
* | | | | Support for unified Integer class in Ruby 2.4+Jeremy Daer2016-05-189-16/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | Merge pull request #24203 from sferik/count_with_blockKasper Timm Hansen2016-05-162-0/+9
|\ \ \ \ \ | | | | | | | | | | | | Forward ActiveRecord::Relation#count to Enumerable#count if block given
| * | | | | Forward ActiveRecord::Relation#count to Enumerable#count if block givenErik Michaels-Ober2016-03-192-0/+9
| | | | | |
* | | | | | Merge pull request #25009 from jahfer/suppressor-keep-stateSean Griffin2016-05-161-0/+12
|\ \ \ \ \ \ | | | | | | | | | | | | | | Keep previous state around for nested calls to #suppress
| * | | | | | Keep state around for nested calls to #suppressJahfer Husain2016-05-161-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | | | Merge pull request #23810 from xijo/fix_json_coder_when_mysql_strict_is_disabledSean Griffin2016-05-161-0/+15
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | Fix bug in JSON deserialization when column default is an empty string
| * | | | | | | Fix bug in JSON deserialization when column default is an empty stringJohannes Opper2016-02-221-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When `ActiveRecord::Coders::JSON` serialization is used and the default of the column returns `''` it raises the following error: ``` JSON::ParserError: A JSON text must at least contain two octets! ``` If MySQL is running in non-strict mode, it returns an empty string as column default for a text column: ```ruby def extract_default if blob_or_text_column? @default = null || strict ? nil : '' end end ``` Since `''` is invalid JSON, there shouldn't be an attempt to parse it, it should be treated like nil. ActiveRecord::Coders::JSON should behave consistently for all possible non-user-set column default values.
* | | | | | | | Rails 5.1 point type should not raise exception if empty string is provided ↵bUg2016-05-151-0/+7
| |/ / / / / / |/| | | | | | | | | | | | | | | | | | | | as value
* | | | | | | Give more context from `AssociationMismatchError`Sean Griffin2016-05-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | | | Rename test methodMolchanov Andrey2016-05-121-1/+1
| | | | | | |
* | | | | | | Fix false positive mutation detection when JSON is used with serializeSean Griffin2016-05-121-0/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | | | Merge pull request #24980 from merhard/virtual-attribute-defaultSean Griffin2016-05-111-0/+9
|\ \ \ \ \ \ \ | |_|_|/ / / / |/| | | | | | Define ActiveRecord::Attribute::Null#type_cast
| * | | | | | Define ActiveRecord::Attribute::Null#type_castMatthew Erhard2016-05-111-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 https://github.com/rails/rails/blob/59d252196b36f6afaafd231756d69ea21537cf5d/activerecord/lib/active_record/attribute.rb#L84. This is called from https://github.com/rails/rails/blob/59d252196b36f6afaafd231756d69ea21537cf5d/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 (https://github.com/rails/rails/blob/59d252196b36f6afaafd231756d69ea21537cf5d/activerecord/lib/active_record/attribute.rb#L173..L175) can be replaced with its super method (https://github.com/rails/rails/blob/59d252196b36f6afaafd231756d69ea21537cf5d/activerecord/lib/active_record/attribute.rb#L36..L40). fixes #24979
* | | | | | | remove_connection should not remove parent connectionArthur Neves2016-05-111-0/+7
|/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When calling remove_connection in a subclass, that should not fallback to the parent, otherwise it will remove the parent connection from the handler.
* | | | | | Dont cache the conn_spec_name when emptyArthur Neves2016-05-111-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | | Make sure we reset the connection_specification_name onArthur Neves2016-05-101-0/+14
| |_|/ / / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | Should quote `lock_name` to pass to `get_advisory_lock`Ryuta Kamizono2016-05-101-3/+3
| | | | |
* | | | | Merge pull request #24844 from arthurnn/arthurnn/connArthur Nogueira Neves2016-05-066-30/+43
|\ \ \ \ \ | | | | | | | | | | | | Refactor connection handler
| * | | | | s/specification_name/connection_specification_nameArthur Neves2016-05-061-2/+2
| | | | | |
| * | | | | s/specification_id/specification_nameArthur Neves2016-05-053-13/+13
| | | | | |
| * | | | | Test to swap connection at runtimeArthur Neves2016-05-051-0/+7
| | | | | |
| * | | | | fix testArthur Neves2016-05-051-8/+7
| | | | | |
| * | | | | Add spec_id testsArthur Neves2016-05-051-0/+9
| | | | | |
| * | | | | Use spec key, when given as spec_idArthur Neves2016-05-051-19/+15
| | | | | |
| * | | | | Refactor connection handlerArthur Neves2016-05-055-33/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ConnectionHandler will not have any knowlodge of AR models now, it will only know about the specs. Like that we can decouple the two, and allow the same model to use more than one connection. Historically, folks used to create abstract AR classes on the fly in order to have multiple connections for the same model, and override the connection methods. With this, now we can override the `specificiation_id` method in the model, to return a key, that will be used to find the connection_pool from the handler.
* | | | | | Merge pull request #24871 from vipulnsward/disable-transaction-failureArthur Nogueira Neves2016-05-061-0/+2
|\ \ \ \ \ \ | | | | | | | | | | | | | | Fix failures due to transactions
| * | | | | | We are erroring due to nested transaction failures from mysql on ↵Vipul A M2016-05-061-0/+2
| |/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | test_migrate_clears_schema_cache_afterward test. Disable transactions for this test. Fixes #24391
* / / / / / Allow the connection adapters to determine the order of bind paramsSean Griffin2016-05-061-0/+18
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | | | | Fix some typos in comments.Joe Rafaniello2016-05-042-2/+2
| | | | | | | | | | | | | | | | | | | | [ci skip]
* | | | | Followup of #24835Vipul A M2016-05-033-5/+5
| | | | | | | | | | | | | | | | | | | | Fix failing tests
* | | | | Do not delegate `AR::Base#empty?` to `all`Sean Griffin2016-05-021-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unlike `one?` and `none?`, `empty?` has interactions with methods outside of enumerable. It also doesn't fit in the same vein. `Topic.any?` makes sense. `Topic.empty?` does not, as `Topic` is not a container. Fixes #24808 Close #24812
* | | | | Merge pull request #24713 from tomkadwill/fix_counter_cache_incrementSean Griffin2016-04-301-0/+11
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | Fix counter_cache double increment bug Close #24183
| * | | | | Fix counter_cache double increment bugTom Kadwill2016-04-281-0/+11
| | | | | |
* | | | | | Replace `Rails.version.to_f` with Active RecordJon Moss2016-04-301-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rails should not be explicity mentioned within Active Record, since railties and the Rails ecosystem is not required for use.