Permalink
Browse files

stop caching the class on the statement cache object

  • Loading branch information...
tenderlove committed Apr 11, 2014
1 parent 8de3c43 commit 2d3969c82fd8aa57186c263afd4b2d93eb6ba5d3
@@ -139,7 +139,7 @@ def find(*ids)
where(key => params[key]).limit(1)
}
}
- record = s.execute(key => id).first
+ record = s.execute({key => id}, self, connection).first
unless record
raise RecordNotFound, "Couldn't find #{name} with '#{primary_key}'=#{id}"
end
@@ -167,7 +167,7 @@ def find_by(*args)
}
}
begin
- s.execute(hash).first
+ s.execute(hash, self, connection).first
rescue TypeError => e
raise ActiveRecord::StatementInvalid.new(e.message, e)
end
@@ -74,19 +74,19 @@ def bind(values)
end
end
- attr_reader :bind_map, :query_builder, :klass
+ attr_reader :bind_map, :query_builder
def initialize(block = Proc.new)
relation = block.call Params.new
@bind_map = BindMap.new relation.bind_values
- @klass = relation.klass
- @query_builder = make_query_builder @klass.connection, relation.arel
+ klass = relation.klass
+ @query_builder = make_query_builder klass.connection, relation.arel
end
- def execute(params)
+ def execute(params, klass, connection)
bind_values = bind_map.bind params
- sql = query_builder.sql_for bind_values, klass.connection
+ sql = query_builder.sql_for bind_values, connection
klass.find_by_sql sql, bind_values
end
@@ -19,9 +19,9 @@ def test_statement_cache
Book.where(:name => params[:name])
end
- b = cache.execute name: "my book"
+ b = cache.execute({ name: "my book" }, Book, Book.connection)
assert_equal "my book", b[0].name
- b = cache.execute name: "my other book"
+ b = cache.execute({ name: "my other book" }, Book, Book.connection)
assert_equal "my other book", b[0].name
end
@@ -34,9 +34,9 @@ def test_statement_cache_id
Book.where(id: params[:id])
end
- b = cache.execute id: b1.id
+ b = cache.execute({ id: b1.id }, Book, Book.connection)
assert_equal b1.name, b[0].name
- b = cache.execute id: b2.id
+ b = cache.execute({ id: b2.id }, Book, Book.connection)
assert_equal b2.name, b[0].name
end
@@ -59,7 +59,7 @@ def test_statement_cache_with_simple_statement
Book.create(name: "my book", author_id: 4)
- books = cache.execute({})
+ books = cache.execute({}, Book, Book.connection)
assert_equal "my book", books[0].name
end
@@ -72,7 +72,7 @@ def test_statement_cache_with_complex_statement
molecule = salty.molecules.create(name: 'dioxane')
molecule.electrons.create(name: 'lepton')
- liquids = cache.execute({})
+ liquids = cache.execute({}, Book, Book.connection)
assert_equal "salty", liquids[0].name
end
@@ -85,13 +85,13 @@ def test_statement_cache_values_differ
Book.create(name: "my book")
end
- first_books = cache.execute({})
+ first_books = cache.execute({}, Book, Book.connection)
3.times do
Book.create(name: "my book")
end
- additional_books = cache.execute({})
+ additional_books = cache.execute({}, Book, Book.connection)
assert first_books != additional_books
end
end

0 comments on commit 2d3969c

Please sign in to comment.