don't check for immutability when setting skip_preloading as it doesn't effect the arel and the arel may already be generated by fresh_when

This commit is contained in:
Lachlan Sylvester 2018-04-12 10:08:13 +10:00
parent 733f3cbea8
commit 115bbdac2b
3 changed files with 12 additions and 3 deletions

@ -8,8 +8,8 @@ class Relation
:extending, :unscope]
SINGLE_VALUE_METHODS = [:limit, :offset, :lock, :readonly, :reordering,
:reverse_order, :distinct, :create_with, :skip_query_cache,
:skip_preloading]
:reverse_order, :distinct, :create_with, :skip_query_cache]
CLAUSE_METHODS = [:where, :having, :from]
INVALID_METHODS_FOR_DELETE_ALL = [:distinct, :group, :having]
@ -19,6 +19,7 @@ class Relation
include FinderMethods, Calculations, SpawnMethods, QueryMethods, Batches, Explain, Delegation
attr_reader :table, :klass, :loaded, :predicate_builder
attr_accessor :skip_preloading_value
alias :model :klass
alias :loaded? :loaded
alias :locked? :lock_value

@ -59,7 +59,7 @@ class RelationMutationTest < ActiveRecord::TestCase
assert_equal [], relation.extending_values
end
(Relation::SINGLE_VALUE_METHODS - [:lock, :reordering, :reverse_order, :create_with, :skip_query_cache, :skip_preloading]).each do |method|
(Relation::SINGLE_VALUE_METHODS - [:lock, :reordering, :reverse_order, :create_with, :skip_query_cache]).each do |method|
test "##{method}!" do
assert relation.public_send("#{method}!", :foo).equal?(relation)
assert_equal :foo, relation.public_send("#{method}_value")

@ -315,6 +315,14 @@ def test_update_all_goes_through_normal_type_casting
assert_equal "type cast from database", UpdateAllTestModel.first.body
end
def test_skip_preloading_after_arel_has_been_generated
assert_nothing_raised do
relation = Comment.all
relation.arel
relation.skip_preloading!
end
end
private
def skip_if_sqlite3_version_includes_quoting_bug