-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32d04d2
commit 9cafcfe
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters