-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Module#alias_attribute [Jamis/DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4653 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
- Loading branch information
Showing
5 changed files
with
80 additions
and
4 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
31 changes: 31 additions & 0 deletions
31
activesupport/test/core_ext/module/attribute_aliasing_test.rb
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,31 @@ | |||
require File.dirname(__FILE__) + '/../../abstract_unit' | |||
|
|||
module AttributeAliasing | |||
class Content | |||
attr_accessor :title | |||
|
|||
def title? | |||
!title.nil? | |||
end | |||
end | |||
|
|||
class Email < Content | |||
alias_attribute :subject, :title | |||
end | |||
end | |||
|
|||
class AttributeAliasingTest < Test::Unit::TestCase | |||
def test_attribute_alias | |||
e = AttributeAliasing::Email.new | |||
|
|||
assert !e.subject? | |||
|
|||
e.title = "Upgrade computer" | |||
assert_equal "Upgrade computer", e.subject | |||
assert e.subject? | |||
|
|||
e.subject = "We got a long way to go" | |||
assert_equal "We got a long way to go", e.title | |||
assert e.title? | |||
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