aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relation
Commit message (Collapse)AuthorAgeFilesLines
* Fix failing testsSean Griffin2017-07-251-1/+1
| | | | `bind_values` was removed from Arel
* Refactor Active Record to let Arel manage bind paramsSean Griffin2017-07-244-60/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common source of bugs and code bloat within Active Record has been the need for us to maintain the list of bind values separately from the AST they're associated with. This makes any sort of AST manipulation incredibly difficult, as any time we want to potentially insert or remove an AST node, we need to traverse the entire tree to find where the associated bind parameters are. With this change, the bind parameters now live on the AST directly. Active Record does not need to know or care about them until the final AST traversal for SQL construction. Rather than returning just the SQL, the Arel collector will now return both the SQL and the bind parameters. At this point the connection adapter will have all the values that it had before. A bit of this code is janky and something I'd like to refactor later. In particular, I don't like how we're handling associations in the predicate builder, the special casing of `StatementCache::Substitute` in `QueryAttribute`, or generally how we're handling bind value replacement in the statement cache when prepared statements are disabled. This also mostly reverts #26378, as it moved all the code into a location that I wanted to delete. /cc @metaskills @yahonda, this change will affect the adapters Fixes #29766. Fixes #29804. Fixes #26541. Close #28539. Close #24769. Close #26468. Close #26202. There are probably other issues/PRs that can be closed because of this commit, but that's all I could find on the first few pages.
* Merge pull request #29732 from kirs/frozen-activerecordRafael França2017-07-219-0/+18
|\ | | | | Use frozen-string-literal in ActiveRecord
| * Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-199-0/+18
| |
* | Revert "Extract `bind_param` and `bind_attribute` into `ActiveRecord::TestCase`"Sean Griffin2017-07-212-11/+19
|/ | | | | | | | This reverts commit b6ad4052d18e4b29b8a092526c2beef013e2bf4f. This is not something that the majority of Active Record should be testing or care about. We should look at having fewer places rely on these details, not make it easier to rely on them.
* Bugfix: unscope(where: [columns]) would not remove the correct binds sometimesMaxime Lapointe2017-07-131-1/+17
| | | | | Post.where(id: 1).or(Post.where(id: 2)).where(foo: 3).unscope(where: :foo).where_clause.binds.map(&:value) Would return [2, 3] instead of the expected [1,2]
* Extract `FakeKlass` in `relation_test.rb` and `relation/mutation_test.rb`Ryuta Kamizono2017-07-111-33/+5
| | | | | `FakeKlass` in `relation_test.rb` and `relation/mutation_test.rb` are almost the same.
* Skip query cache for in_batches and friendsEugene Kenny2017-07-061-1/+6
| | | | | | | | | | | The `find_each`, `find_in_batches` and `in_batches` APIs usually operate on large numbers of records, where it's preferable not to load them all into memory at once. If the query cache is enabled, it will hold onto the query results until the end of the execution context (request/job), which means the memory used is still proportional to the total number of records. These queries are typically not repeated, so the query cache isn't desirable here.
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-029-9/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-019-0/+9
|
* Deprecate delegating to `arel` in `Relation`Ryuta Kamizono2017-06-291-0/+15
| | | | | | | | | | | | | Active Record doesn't rely delegating to `arel` in the internal since 425f2ca. The delegation is a lower priority than delegating to `klass`, so it is pretty unclear which method is delegated to `arel`. For example, `bind_values` method was removed at b06f64c (a series of changes https://github.com/rails/rails/compare/79f71d3...b06f64c). But a relation still could respond to the method because `arel` also have the same named method (#28976). Removing the delegation will achieve predictable behavior.
* Merge pull request #29415 from kamipo/remove_unused_defined_associationGuillermo Iguaran2017-06-161-1/+1
|\ | | | | Remove unused defined association
| * Remove unused defined associationRyuta Kamizono2017-06-111-1/+1
| | | | | | | | | | `belongs_to :developer` on `Comment` model was added in 431f8e0 but it is unused.
* | Don't require 'unscope' to be the same for both sides of a 'or' relation.Dan Sherson2017-06-151-0/+25
|/
* Prevent making bind param if casted value is nilRyuta Kamizono2017-05-311-1/+5
| | | | | | | | If casted value is nil, generated SQL should be `IS NULL`. But currently it is generated as `= NULL`. To prevent this behavior, avoid making bind param if casted value is nil. Fixes #28945.
* Merge pull request #29003 from kamipo/delegate_ast_and_locked_to_arel_explicitlyMatthew Draper2017-05-281-1/+1
|\ | | | | Delegate `ast` and `locked` to `arel` explicitly
| * Delegate `ast` and `locked` to `arel` explicitlyRyuta Kamizono2017-05-061-1/+1
| | | | | | | | | | | | | | | | Currently `ast` and `locked` are used in the internal but delegating to `arel` is depend on `method_missing`. If a model class is defined these methods, `select_all` will be broken. It should be delegated to `arel` explicitly.
* | Remove unused `left_joins_values` generationRyuta Kamizono2017-05-231-1/+1
|/ | | | This was added at #22125 but `left_joins_values` is never used.
* Remove unused `DelegationTest#call_method`Ryuta Kamizono2017-05-061-27/+7
| | | | `DelegationTest#call_method` is no longer used since 9d79334a.
* Extract `bind_param` and `bind_attribute` into `ActiveRecord::TestCase`Ryuta Kamizono2017-05-042-18/+10
| | | | These are used in tests from anywhere.
* Restore `fixtures :author_addresses`Ryuta Kamizono2017-04-272-3/+3
| | | | | This change reverted in eac6f369 but it is needed for data integrity. See #25328.
* Revert "Merge pull request #27636 from ↵Rafael Mendonça França2017-04-262-3/+3
| | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privilege-take-2" This reverts commit c1faca6333abe4b938b98fedc8d1f47b88209ecf, reversing changes made to 8c658a0ecc7f2b5fc015d424baf9edf6f3eb2b0b. See https://github.com/rails/rails/pull/27636#issuecomment-297534129
* Replace \Z to \zRyuta Kamizono2017-04-241-1/+1
| | | | \Z was a mistake of \z. Replace \Z to \z to prevent newly \Z added.
* Add a test case for #20802Ryuta Kamizono2017-04-131-0/+5
| | | | | | The issue #20802 has been fixed in cc0b566. Closes #20802.
* Remove duplicated "test" prefixRyuta Kamizono2017-04-071-1/+1
|
* Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2017-03-262-3/+3
| | | | | | | | | | | | | | | privileges (take 2) Re-create https://github.com/rails/rails/pull/21233 eeac6151a5 was reverted (127509c071b4) because it breaks tests. ---------------- 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.
* Simply delegate `as_json` to `records`Ryuta Kamizono2017-03-101-1/+1
|
* Delegate `to_sentence` and `to_fomatted_s` to `records`kenta-s2017-02-041-1/+2
|
* class Foo < Struct.new(:x) creates an extra unneeded anonymous classAkira Matsuda2017-01-131-1/+1
| | | | because Struct.new returns a Class, we just can give it a name and use it directly without inheriting from it
* `self.` is not needed when calling its own instance methodAkira Matsuda2017-01-051-1/+1
| | | | Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
* Revert "Merge pull request #21233 from ↵Rafael Mendonça França2017-01-032-3/+3
| | | | | | | | | | 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 #21233 from ↵Rafael França2017-01-032-3/+3
|\ | | | | | | | | 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-032-3/+3
| | | | | | | | | | | | | | | | | | 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 deprecated `#uniq`, `#uniq!`, and `#uniq_value`Ryuta Kamizono2016-12-301-17/+1
| |
* | assert_equal takes expectation firstAkira Matsuda2016-12-261-1/+1
|/
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-6/+6
|
* improve error message when include assertions failMichael Grosser2016-09-162-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
* Change require order to come `require "models/post"` before `require ↵Yasuo Honda2016-09-021-1/+1
| | | | | | | | | | | | "models/comment"` to address BasicsTest#test_readonly_attributes failure #26368 It reproduces only when both of these conditions are satisfied: - Other test files `autosave_association_test.rb` or `where_test.rb` which executes `require "models/comment"` then `require "models/post"` - When `autosave_association_test.rb` or `where_test.rb` executed before `base_test.rb`
* Do not handle as an associated predicate if a table has the columnRyuta Kamizono2016-08-161-1/+1
| | | | | | If handled as an associated predicate even though a table has the column, will generate invalid SQL by valid column name treated as a table name.
* Add three new rubocop rulesRafael Mendonça França2016-08-163-4/+4
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* Use `ActiveRecord::TestCase` rather than `ActiveSupport::TestCase` in AR ↵Ryuta Kamizono2016-08-111-1/+1
| | | | test cases
* Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-062-10/+10
|
* modernizes hash syntax in activerecordXavier Noria2016-08-063-17/+17
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-069-121/+121
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* No need `public_send`Ryuta Kamizono2016-07-171-2/+2
|
* Add missing test case for record_fetched_greater_than configPrathamesh Sonpatki2016-04-111-11/+23
| | | | - The negative scenario test case was missing earlier.
* Merge pull request #22365 from ↵Sean Griffin2016-02-171-1/+13
|\ | | | | | | | | phuibonhoa/phuibonhoa/polymorphic_where_multiple_types Fixed `where` for polymorphic associations when passed an array containing different types.
| * Fixed `where` for polymorphic associations when passed an array containing ↵Philippe Huibonhoa2016-02-161-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | different types. When passing in an array of different types of objects to `where`, it would only take into account the class of the first object in the array. PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)]) # => SELECT "price_estimates".* FROM "price_estimates" WHERE ("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" IN (1, 2)) This is fixed to properly look for any records matching both type and id: PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)]) # => SELECT "price_estimates".* FROM "price_estimates" WHERE (("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" = 1) OR ("price_estimates"."estimate_of_type" = 'Car' AND "price_estimates"."estimate_of_id" = 2))
* | Show proper error message when a non-relation object is passed to ↵Prathamesh Sonpatki2016-02-171-0/+6
|/ | | | | | | | | | | | | | AR::Relation#or - Previously it used to show error message <"undefined method `limit_value' for {:title=>\"Rails\"}:Hash"> - Now it shows following error message. >> Post.where.not(name: 'DHH').or(name: 'Tenderlove') ArgumentError: You have passed Hash object to #or. Pass an ActiveRecord::Relation object instead. - Fixes #23714.