Permalink
Browse files

Merge master into reload_all_records branch

  • Loading branch information...
2 parents 8930328 + a7df1dc commit 68296e6359e18c22fa60cd377b63b4c4a22b6dbd @sdsykes sdsykes committed Mar 22, 2009
View
@@ -15,34 +15,50 @@ class Callsite
def initialize( klass, signature )
@klass = klass
@signature = signature
- @columns = setup_columns
- @associations = setup_associations
end
# Flag a column as seen
#
def column!( column )
Mtx.synchronize do
- @columns << column
+ columns << column
end
end
# Flag an association as seen
#
def association!( association )
Mtx.synchronize do
- @associations << association if preloadable_association?( association )
+ associations << association if preloadable_association?( association )
end
end
def inspect
- "<##{@klass.name} :select => '#{@klass.scrooge_select_sql( @columns )}', :include => [#{associations_for_inspect}]>"
+ "<##{@klass.name} :select => '#{@klass.scrooge_select_sql( columns )}', :include => [#{associations_for_inspect}]>"
+ end
+
+ # Lazy init default columns
+ #
+ def default_columns
+ @default_columns ||= setup_columns()
+ end
+
+ # Lazy init columns
+ #
+ def columns
+ @columns ||= default_columns.dup
+ end
+
+ # Lazy init associations
+ #
+ def associations
+ @associations ||= setup_associations()
end
private
def associations_for_inspect
- @associations.map{|a| ":#{a.to_s}" }.join(', ')
+ associations.map{|a| ":#{a.to_s}" }.join(', ')
end
# Only register associations that isn't polymorphic or a collection
@@ -50,9 +50,10 @@ def scrooge_preloading_exclude
# Let's not preload polymorphic associations or collections
#
def preloadable_associations
- @@preloadable_associations[self.name] ||= reflect_on_all_associations.reject{|a| a.options[:polymorphic] || a.macro == :has_many }.map{|a| a.name }
- end
-
+ @@preloadable_associations[self.name] ||=
+ reflect_on_all_associations.reject{|a| a.options[:xxxpolymorphic] || a.macro == :xxxhas_many}.map(&:name)
+ end
+
end
module InstanceMethods
View
@@ -16,6 +16,18 @@ def setup
assert_equal Scrooge::Callsite.new( MysqlUser, 123456 ).columns, Set["User","inheritance"]
end
+ test "should be able to return all augmented columns" do
+ assert_equal @callsite.augmented_columns, Set.new
+ @callsite.column! :Db
+ assert_equal @callsite.augmented_columns, Set[:Db]
+ end
+
+ test "should be able to determine if any columns has been augmented" do
+ assert !@callsite.augmented_columns?
+ @callsite.column! :Db
+ assert @callsite.augmented_columns?
+ end
+
test "should be inspectable" do
@callsite.association! :mysql_user
@callsite.column! :db
View
@@ -2,6 +2,7 @@
require 'rubygems'
require 'mocha'
require 'active_support/test_case'
+ENV["BACKTRACE"] = "1"
module Scrooge
class Test
@@ -7,6 +7,10 @@ class OptimizationsAssociationsMacroTest < ActiveSupport::TestCase
test "should flag a record as being scrooged when found through a supported SQL query" do
assert MysqlUser.find(:first).scrooged?
end
+
+ test "should always flag records via Model.find with a custom :select requirement as scrooged" do
+ assert MysqlUser.find(:first, :select => 'user.Password' ).scrooged?
+ end
test "should be able to flag any associations instantiated from a record" do
@user = MysqlUser.find(:first)

0 comments on commit 68296e6

Please sign in to comment.