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
Neeraj Singh
committed
Jul 1, 2011
1 parent
58b778f
commit 5b1a025
Showing
6 changed files
with
49 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Brake < ActiveRecord::Base | ||
belongs_to :car | ||
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class Car < ActiveRecord::Base | ||
belongs_to :user | ||
has_many :brakes, :foreign_key => 'vehicle_id' | ||
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,17 @@ | ||
require "test_helper" | ||
require "minitest/autorun" | ||
|
||
class ActiveRecordUtilTest < MiniTest::Unit::TestCase | ||
|
||
def test_foreign_key_for_has_many_for_standard_case | ||
result = AdminData::ActiveRecordUtil.foreign_key_for_has_many(User, :phone_numbers) | ||
assert_equal 'user_id', result | ||
end | ||
|
||
def test_foreign_key_for_has_many_for_non_standard_case | ||
result = AdminData::ActiveRecordUtil.foreign_key_for_has_many(Car, :brakes) | ||
assert_equal 'vehicle_id', result | ||
end | ||
|
||
end | ||
|