aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Merge pull request #21233 from ↵Rafael Mendonça França2017-01-031-1/+1
| | | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges" This reverts commit eeac6151a55cb7d5f799e1ae33aa64a839cbc3aa, reversing changes made to 5c40239d3104543e70508360d27584a3e4dc5baf. Reason: Broke the isolated tests. https://travis-ci.org/rails/rails/builds/188721346
* Merge pull request #27563 from kamipo/fix_typoRafael França2017-01-031-1/+1
|\ | | | | Fix typo s/permited/permitted/
| * Fix typo s/permited/permitted/Ryuta Kamizono2017-01-041-1/+1
| | | | | | | | | | | | | | | | | | ``` % git grep -n permited actionview/test/template/url_helper_test.rb:238: def test_button_to_with_permited_strong_params actionview/test/template/url_helper_test.rb:245: def test_button_to_with_unpermited_strong_params activerecord/test/cases/relations_test.rb:1620: def test_update_on_relation_passing_active_record_object_is_not_permited ```
* | Merge pull request #21233 from ↵Rafael França2017-01-031-1/+1
|\ \ | |/ |/| | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser privileges
| * Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2016-12-031-1/+1
| | | | | | | | | | | | | | | | | | privileges ref: 72c1557254 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
* | Remove deprecation of using ActiveRecord::Base instance in .updateRafael Mendonça França2017-01-031-2/+2
| |
* | Remove deprecated `#uniq`, `#uniq!`, and `#uniq_value`Ryuta Kamizono2016-12-301-6/+0
| |
* | Remove deprecated conditions parameter from #delete_allRafael Mendonça França2016-12-291-6/+0
| |
* | Remove deprecated conditions parameter from `#destroy_all`Rafael Mendonça França2016-12-291-6/+0
| |
* | Remove deprecated support to passing a class as a value in a queryRafael Mendonça França2016-12-291-9/+0
| |
* | "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-251-8/+8
|/
* Respect new records for `CollectionProxy#uniq`Ryuta Kamizono2016-11-131-1/+0
| | | | | | | | | | | | | Currently if `CollectionProxy` has more than one new record, `CollectionProxy#uniq` result is incorrect. And `CollectionProxy#uniq` was aliased to `distinct` in a1bb6c8b06db. But the `uniq` method and the `SELECT DISTINCT` method are different methods. The doc in `CollectionProxy` is for the `SELECT DISTINCT` method, not for the `uniq` method. Therefore, reverting the alias in `CollectionProxy` to fix the inconsistency and to have the both methods.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-21/+21
|
* Tweak a test so the queries matchMatthew Draper2016-10-081-1/+1
|
* improve error message when include assertions failMichael Grosser2016-09-161-4/+4
| | | | | | assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
* Merge pull request #25987 from aquajach/masterRafael Mendonça França2016-08-171-0/+9
|\ | | | | | | Fix does_not_support_reverse? to find sql functions with commas in nested brackets
| * have does_not_support_reverse? support sql functions with commas in nested ↵Jack2016-07-291-0/+9
| | | | | | | | brackets
* | Add three new rubocop rulesRafael Mendonça França2016-08-161-17/+17
| | | | | | | | | | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* | Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
| |
* | applies remaining conventions across the projectXavier Noria2016-08-061-1/+1
| |
* | remove redundant curlies from hash argumentsXavier Noria2016-08-061-2/+2
| |
* | modernizes hash syntax in activerecordXavier Noria2016-08-061-89/+89
| |
* | applies new string literal convention in activerecord/testXavier Noria2016-08-061-251/+251
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Merge pull request #24203 from sferik/count_with_blockKasper Timm Hansen2016-05-161-0/+5
|\ | | | | Forward ActiveRecord::Relation#count to Enumerable#count if block given
| * Forward ActiveRecord::Relation#count to Enumerable#count if block givenErik Michaels-Ober2016-03-191-0/+5
| |
* | 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
* Merge pull request #23751 from chezou/add-test-case-order-by-fieldAndrew White2016-02-221-0/+6
|\ | | | | Add test cases about MySQL ORDER BY FIELD()
| * Add assertions order by field with empty dataMichiaki Ariga2016-02-181-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Add assertions to MySQL `ORDER BY FIELD()` with empty data. These tests examine to sanitize `ORDER BY FIELD()` with empty data appropriately. ```ruby Tag.order(['field(id, ?)', []]).to_sql # => SELECT "tags".* FROM "tags" ORDER BY field(id, NULL) Tag.order(['field(id, ?)', nil]).to_sql # => SELECT "tags".* FROM "tags" ORDER BY field(id, NULL) ```
* | Mutating the result of Relation#to_a should not affect the relationMatthew Draper2016-02-211-0/+10
|/ | | | | | Clarifying this separation and enforcing relation immutability is the culmination of the previous efforts to remove the mutator method delegations.
* Introduce ActiveRecord::IrreversibleOrderErrorBogdan Gusiev2016-01-271-0/+34
| | | | | Raises when #reverse_order can not process SQL order instead of making invalid SQL before this patch
* Merge pull request #22053 from Empact/first-loadedYves Senn2015-12-281-3/+26
|\ | | | | | | Fix #first(limit) to take advantage of #loaded? records if available
| * Fix `first(limit)` to take advantage of `loaded?` records if availableBen Woosley2015-12-241-3/+14
|/ | | | | | | | | | | | | | | | | I realized that `first(2)`, etc. was unnecessarily querying for the records when they were already preloaded. This was because `find_nth_with_limit` can not know which `@records` to return because it conflates the `offset` and `index` into a single variable, while the `@records` only needs the `index` itself to select the proper record. Because `find_nth` and `find_nth_with_limit` are public methods, I instead introduced a private method `find_nth_with_limit_and_offset` which is called internally and handles the `loaded?` checking. Once the `offset` argument is removed from `find_nth`, `find_nth_with_limit_and_offset` can be collapsed into `find_nth_with_limit`, with `offset` always equal to `offset_index`.
* Revert "Perform a more efficient query in `Relation#any?`"Sean Griffin2015-12-141-0/+7
| | | | | | | | | This reverts commit 6d5b1fdf55611de2a1071c37544933bb588ae88e. `eager_load` and `references` can include hashes, which won't match up with `references` A test case has been added to demonstrate the problem
* Merge pull request #13008 from ktheory/sanitize_orderSean Griffin2015-10-291-0/+5
|\ | | | | | | Support SQL sanitization in AR::QueryMethods#order
| * Support SQL sanitization in AR::QueryMethods#orderAaron Suggs2013-11-221-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for sanitizing arrays in SQL ORDER clauses. This is useful when using MySQL `ORDER BY FIELD()` to return records in a predetermined way. ```ruby Tag.order(['field(id, ?', [1,3,2]].to_sql # => SELECT "tags".* FROM "tags" ORDER BY field(id, 1,3,2) ``` Prior to this, developers must be careful to sanitize `#order` arguments themselves.
* | Add deprecation warning to `ActiveRecord::Relation#update`Ted Johansson2015-10-151-0/+7
| | | | | | | | | | | | | | | | When passing an instance of `ActiveRecord::Base` to `#update`, it would internally call `#find`, resulting in a misleading deprecation warning. This change gives this deprecated use of `#update` its own, meaningful warning.
* | Skip the test added in 9cc324a on buggy versions of SQliteSean Griffin2015-09-211-10/+0
| | | | | | | | See 7dcfc25e7c52682a4343c2ba7188a69e7c06c936 for more details
* | Ensure aliased attributes passed to `select` are quoted if using `from`Sean Griffin2015-09-211-0/+10
| | | | | | | | | | | | Fixes #21488 [Sean Griffin & johanlunds]
* | Deprecate passing conditions to AR::Relation destroy_all and delete_all methodsWojciech Wnętrzak2015-09-061-0/+12
| |
* | Fix regression caused by a01d164bRafael Mendonça França2015-07-071-0/+19
| | | | | | | | | | | | | | | | | | When preload is used in a default scope the preload_values were returning nested arrays and causing the preloader to fail because it doesn't know how to deal with nested arrays. So before calling preload! we need to splat the arguments. This is not needed to includes because it flatten its arguments.
* | Merge pull request #20196 from huoxito/preload-association-and-mergesRafael Mendonça França2015-05-281-1/+27
|\ \ | | | | | | Properly append preload / includes args on Merger
| * | Properly append preload / includes args on MergerWashington Luiz2015-05-281-1/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Couldn't find other way to get the association name from a given class other than looping through `reflect_on_all_associations` reflections .. Noticed this one while looking at this example: ```ruby class Product < ActiveRecord::Base has_many :variants has_many :translations end class Translation < ActiveRecord::Base belongs_to :product end class Variant < ActiveRecord::Base belongs_to :product end class BugTest < Minitest::Test def test_merge_stuff product = Product.create! name: 'huhu' variant = Variant.create! product_id: product.id Translation.create! locale: 'en', product_id: product.id product_relation = Product.all .preload(:translations) .joins(:translations) .merge(Translation.where(locale: 'en')) .where(name: 'huhu') assert_equal variant, Variant.joins(:product).merge(product_relation).first end end ```
* | | deprecate `Relation#uniq` use `Relation#distinct` instead.Yves Senn2015-05-261-4/+7
|/ / | | | | | | | | | | | | | | | | See #9683 for the reasons we switched to `distinct`. Here is the discussion that triggered the actual deprecation #20198. `uniq`, `uniq!` and `uniq_value` are still around. They will be removed in the next minor release after Rails 5.
* | Raise ArgumentError when find_by receives no argumentsKohei Suzuki2015-04-111-0/+8
| | | | | | | | | | | | | | | | | | It fixes the strange error saying undefined method `take'. ``` RelationTest#test_find_by_without_arg_behaves_same_with_find_by({}): NoMethodError: undefined method `take' for #<ActiveRecord::QueryMethods::WhereChain:0x007f9c55db1d68> ```
* | Merge pull request #18744 from mfazekas/no-table-name-with-fromRafael Mendonça França2015-02-241-0/+11
| | | | | | | | Fix appending table_name to select and group when used with subquery (fr...
* | Optimize none? and one? relation query methods to use LIMIT and COUNT.Eugene Gilburg2015-02-121-0/+34
| | | | | | | | | | | | | | | | Use SQL COUNT and LIMIT 1 queries for none? and one? methods if no block or limit is given, instead of loading the entire collection to memory. The any? and many? methods already follow this behavior. [Eugene Gilburg & Rafael Mendonça França]
* | Fixed AR::Relation#group method when argument is a SQL reserved keywordBogdan Gusiev2015-01-291-0/+5
| |
* | Remove Relation#bind_paramsSean Griffin2015-01-271-1/+1
| | | | | | | | | | | | | | | | `bound_attributes` is now used universally across the board, removing the need for the conversion layer. These changes are mostly mechanical, with the exception of the log subscriber. Additional, we had to implement `hash` on the attribute objects, so they could be used as a key for query caching.
* | Use an `Attribute` object to represent a bind valueSean Griffin2015-01-271-3/+2
| | | | | | | | | | | | | | | | | | | | | | The column is primarily used for type casting, which we're trying to separate from the idea of a column. Since what we really need is the combination of a name, type, and value, let's use the object that we already have to represent that concept, rather than this tuple. No consumers of the bind values have been changed, only the producers (outside of tests which care too much about internals). This is *finally* possible since the bind values are now produced from a reasonable number of lcoations.
* | Remove unused `bind` and `bind!` methods from `Relation`Sean Griffin2015-01-261-9/+0
| |