Skip to content

Commit

Permalink
Ensure blank initial columns for models without a primary key; Implem…
Browse files Browse the repository at this point in the history
…ent Scrooge::Callsite#inspect
  • Loading branch information
methodmissing committed Mar 19, 2009
1 parent 7aad6b9 commit 0469adc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/callsite.rb
Expand Up @@ -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 )
Expand All @@ -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

Expand Down
7 changes: 7 additions & 0 deletions test/callsite_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 0469adc

Please sign in to comment.