Skip to content

Commit

Permalink
Callsite test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
methodmissing committed Mar 19, 2009
1 parent 32d04d2 commit 9cafcfe
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/callsite_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "#{File.dirname(__FILE__)}/helper"

Scrooge::Test.prepare!

class CallsiteTest < ActiveSupport::TestCase

def setup
@callsite = Scrooge::Callsite.new( MysqlTablePrivilege, 123456 )
end

test "should initialize with a default set of columns" do
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 flag a column as seen" do
assert_difference '@callsite.columns.size' do
@callsite.column! :Db
end
end

test "should flag only preloadable associations as seen" do
assert_no_difference '@callsite.associations.size' do
@callsite.association! :undefined
end
assert_difference '@callsite.associations.size', 2 do
@callsite.association! :column_privilege
@callsite.association! :mysql_user
end
end

test "should be able to overload given association preload options" do
assert_equal @callsite.preload( { :nested => :include } ), { :nested => :include }
assert_equal @callsite.preload( [:column_privilege] ), [:column_privilege]
@callsite.association! :column_privilege
@callsite.association! :mysql_user
assert_equal @callsite.preload( nil ), [:column_privilege, :mysql_user]
end


end
7 changes: 7 additions & 0 deletions test/models/mysql_column_privilege.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class MysqlColumnPrivilege < ActiveRecord::Base
set_table_name 'columns_priv'
set_primary_key nil

belongs_to :mysql_user, :class_name => 'MysqlUser', :foreign_key => 'User'

end
8 changes: 8 additions & 0 deletions test/models/mysql_table_privilege.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class MysqlTablePrivilege < ActiveRecord::Base
set_table_name 'tables_priv'
set_primary_key nil

belongs_to :mysql_user, :class_name => 'MysqlUser', :foreign_key => 'User'
belongs_to :column_privilege, :class_name => 'MysqlColumnPrivilege', :foreign_key => 'Column_priv'

end
3 changes: 3 additions & 0 deletions test/models/mysql_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ class MysqlUser < ActiveRecord::Base
set_table_name 'user'
set_primary_key 'User'

has_many :table_privileges, :class_name => 'MysqlTablePrivilege', :foreign_key => 'User'

def after_initialize
max_connections if @attributes.has_key?("max_user_connections")
end

end

0 comments on commit 9cafcfe

Please sign in to comment.