aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relation/mutation_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix `order` with custom attributesRyuta Kamizono2019-02-171-2/+2
| | | | This follows up 0ee96d13de29680e148ccb8e5b68025f29fd091c.
* don't check for immutability when setting skip_preloading as it doesn't ↵Lachlan Sylvester2018-04-121-1/+1
| | | | effect the arel and the arel may already be generated by fresh_when
* Only preload misses on multifetch cacheLachlan Sylvester2018-03-061-1/+6
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-2/+2
|
* Avoid passing unnecessary arguments to relationDaniel Colson2018-01-241-1/+1
| | | | | | | | | | | | Most of the time the table and predicate_builder passed to Relation.new are exactly the arel_table and predicate builder of the given klass. This uses klass.arel_table and klass.predicate_builder as the defaults, so we don't have to pass them in most cases. This does change the signaure of both Relation and AssocationRelation. Are we ok with that?
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+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-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Remove unused `left_joins_values` generationRyuta Kamizono2017-05-231-1/+1
| | | | This was added at #22125 but `left_joins_values` is never used.
* Remove duplicated "test" prefixRyuta Kamizono2017-04-071-1/+1
|
* 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
* Remove deprecated `#uniq`, `#uniq!`, and `#uniq_value`Ryuta Kamizono2016-12-301-17/+1
|
* improve error message when include assertions failMichael Grosser2016-09-161-1/+1
| | | | | | 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
* Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | 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
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-37/+37
| | | | | 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
|
* Defer Arel attribute lookup to the model classMatthew Draper2016-02-041-0/+4
| | | | | This still isn't as separated as I'd like, but it at least moves most of the burden of alias mapping in one place.
* Define `sanitize_sql_for_order` for AR and use it inside `preprocess_order_args`yui-knk2015-11-021-0/+4
| | | | This commit follows up of 6a6dbb4c51fb0c58ba1a810eaa552774167b758a.
* Alias left_joins to left_outer_joinsTakashi Kokubun2015-10-311-1/+1
|
* Removed mocha from Active Record Part 2Ronak Jangir2015-09-161-3/+4
|
* Remove unused variableArun Agrawal2015-05-261-1/+1
| | | | Was left in adfab2dcf4003ca564d78d4425566dd2d9cd8b4f
* deprecate `Relation#uniq` use `Relation#distinct` instead.Yves Senn2015-05-261-4/+13
| | | | | | | | | 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.
* Move the `from` bind logic to a `FromClause` classSean Griffin2015-01-261-3/+3
| | | | | | | Contrary to my previous commit message, it wasn't overkill, and led to much cleaner code. [Sean Griffin & anthonynavarre]
* Remove `Relation#bind_values=`Sean Griffin2015-01-261-1/+1
| | | | | | | | | | The last place that was assigning it was when `from` is called with a relation to use as a subquery. The implementation was actually completely broken, and would break if you called `from` more than once, or if you called it on a relation, which also had its own join clause, as the bind values would get completely scrambled. The simplest solution was to just move it into its own array, since creating a `FromClause` class for this would be overkill.
* Remove all references to `where_values` in testsSean Griffin2015-01-251-3/+3
|
* Fix new warning in ruby 2.2Sean Griffin2014-12-261-2/+2
|
* Inject the `PredicateBuilder` into the `Relation` instanceSean Griffin2014-12-261-1/+1
| | | | | | | Construction of relations can be a hotspot, we don't want to create one of these in the constructor. This also allows us to do more expensive things in the predicate builder's constructor, since it's created once per AR::Base subclass
* A `NullRelation` should represent nothing. Closes #15176.Yves Senn2014-09-111-0/+4
| | | | | | [Matthew Draper & Yves Senn] Closes #16860. (pull request to discuss the implementation)
* select! renamed to avoid name collision Array#select!Earl J St Sauver2014-04-211-1/+6
| | | | | | | | Fixes #14752 Select mimics the block interface of arrays, but does not mock the block interface for select!. This change moves the api to be a private method, _select!.
* Build the reverse_order on its proper method.Lauro Caetano2014-04-071-3/+11
| | | | | | | | | | | | | | | | | | The reverse_order method was using a flag to control if the order should be reversed or not. Instead of using this variable just build the reverse order inside its proper method. This implementation was leading to an unexpected behavior when using reverse_order and then applying reorder(nil). Example: Before Post.order(:name).reverse_order.reorder(nil) # => SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC After Post.order(:name).reverse_order.reorder(nil) # => SELECT "posts".* FROM "posts"
* Handle aliased attributes in AR::Relation#select, #order, etc.Tsutomu Kuroda2014-01-291-0/+4
| | | | | | | With this we can write `Model#select(:aliased)`, `Model#order(:aliased)`, `Model#reoder(aliased: :desc)`, etc. Supplementary work to 54122067acaad39b277a5363c6d11d6804c7bf6b.
* Fix ActiveRecord::Relation#unscopeJon Leighton2013-11-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm pretty confused about the addition of this method. The documentation says that it was intended to allow the removal of values from the default scope (in contrast to #except). However it behaves exactly the same as except: https://gist.github.com/jonleighton/7537008 (other than having a slightly enhanced syntax). The removal of the default scope is allowed by 94924dc32baf78f13e289172534c2e71c9c8cade, which was not a change we could make until 4.1 due to the need to deprecate things. However after that change #unscope still gives us nothing that #except doesn't already give us. However there *is* a desire to be able to unscope stuff in a way that persists across merges, which would allow associations to be defined which unscope stuff from the default scope of the associated model. E.g. has_many :comments, -> { unscope where: :trashed } So that's what this change implements. I've also corrected the documentation. I removed the guide references to #except as I think unscope really supercedes #except now. While we're here, there's also a potential desire to be able to write this: has_many :comments, -> { unscoped } However, it doesn't make sense and would not be straightforward to implement. While with #unscope we're specifying exactly what we want to be removed from the relation, with "unscoped" we're just saying that we want it to not have some things which were added earlier on by the default scope. However in the case of an association, we surely don't want *all* conditions to be removed, otherwise the above would just become "SELECT * FROM comments" with no foreign key constraint. To make the above work, we'd have to somehow tag the relation values which get added when evaluating the default scope in order to differentiate them from other relation values. Which is way too much complexity and therefore not worth it when most use cases can be satisfied with unscope. Closes #10643, #11061.
* use arel nodes to represent non-string `order_values`.Yves Senn2013-11-191-5/+1
| | | | | | | | | | | | | | | | | | | This fixes a bug when merging relations of different classes. ``` Given: Post.joins(:author).merge(Author.order(name: :desc)).to_sql Before: SELECT "posts".* FROM "posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" ORDER BY "posts"."name" DESC After: SELECT "posts".* FROM "posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" ORDER BY "authors"."name" DESC ```
* Merge pull request #12129 from Empact/deprecate-array-bang-delegationRafael Mendonça França2013-09-121-7/+16
| | | | | | | | Deprecate the delegation of Array bang methods in ActiveRecord::Delegation Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/relation_test.rb
* Pull the RelationMutationTests from cases/relation_test to ↵Ben Woosley2013-09-031-0/+139
cases/relation/mutation_test.