forked from methodmissing/scrooge
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
9cafcfe
commit 10cc592
Showing
7 changed files
with
57 additions
and
11 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
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
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
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
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,5 @@ | ||
class MysqlHost < ActiveRecord::Base | ||
set_table_name 'host' | ||
set_primary_key 'Host' | ||
|
||
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
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,31 @@ | ||
require "#{File.dirname(__FILE__)}/../../helper" | ||
|
||
Scrooge::Test.prepare! | ||
|
||
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 be able to flag any associations instantiated from a record" do | ||
@user = MysqlUser.find(:first) | ||
@user.host | ||
assert_equal MysqlUser.scrooge_callsite( @user.callsite_signature ).associations, Set[:host] | ||
end | ||
|
||
test "should only flag preloadable associations" do | ||
Scrooge::Callsite.any_instance.expects(:association!).once | ||
@user = MysqlUser.find(:first) | ||
@user.table_privileges | ||
assert_equal MysqlUser.scrooge_callsite( @user.callsite_signature ).associations, Set.new | ||
end | ||
|
||
test "should be able to identify all preloadable associations for a given Model" do | ||
assert_equal MysqlUser.preloadable_associations, [:host] | ||
assert_equal MysqlHost.preloadable_associations, [] | ||
assert_equal MysqlColumnPrivilege.preloadable_associations, [:mysql_user] | ||
assert_equal MysqlTablePrivilege.preloadable_associations, [:mysql_user, :column_privilege] | ||
end | ||
|
||
end |