Permalink
Browse files

Ensure blank initial columns for models without a primary key; Implem…

…ent Scrooge::Callsite#inspect
  • Loading branch information...
1 parent 7aad6b9 commit 0469adc2bd331bd0374e8d93e4e2a30aba532f65 @methodmissing committed Mar 19, 2009
Showing with 16 additions and 1 deletion.
  1. +9 −1 lib/callsite.rb
  2. +7 −0 test/callsite_test.rb
View
@@ -47,8 +47,16 @@ def association!( association )
end
end
+ def inspect
+ "<##{@klass.name} :select => '#{@klass.scrooge_select_sql( @columns )}', :include => [#{associations_for_inspect}]>"
+ end
+
private
+ def associations_for_inspect
+ @associations.map{|a| ":#{a.to_s}" }.join(', ')
+ end
+
# Only register associations that isn't polymorphic or a collection
#
def preloadable_association?( association )
@@ -68,7 +76,7 @@ def setup_columns
if inheritable?
Set.new([primary_key, inheritance_column])
else
- Set.new([primary_key])
+ primary_key.blank? ? Set.new : Set.new([primary_key])
end
end
View
@@ -9,12 +9,19 @@ def setup
end
test "should initialize with a default set of columns" do
+ assert @callsite.columns.empty?
assert_equal Scrooge::Callsite.new( MysqlUser, 123456 ).columns, Set["User"]
Scrooge::Callsite.any_instance.stubs(:inheritable?).returns(true)
Scrooge::Callsite.any_instance.stubs(:inheritance_column).returns("inheritance")
assert_equal Scrooge::Callsite.new( MysqlUser, 123456 ).columns, Set["User","inheritance"]
end
+ test "should be inspectable" do
+ @callsite.association! :mysql_user
+ @callsite.column! :db
+ assert_equal @callsite.inspect, "<#MysqlTablePrivilege :select => '`tables_priv`.db', :include => [:mysql_user]>"
+ end
+
test "should flag a column as seen" do
assert_difference '@callsite.columns.size' do
@callsite.column! :Db

0 comments on commit 0469adc

Please sign in to comment.