diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-03-31 01:09:39 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-03-31 01:09:39 +0000 |
commit | 2cf72ad250f7c393e6aa97384768ed803686eb97 (patch) | |
tree | 404c8edecdc0528ea83fe0c0f61949fe85743c56 /activesupport | |
parent | 181378d1e9b7874148a63d55bd7d01f39c36eac4 (diff) | |
download | rails-2cf72ad250f7c393e6aa97384768ed803686eb97.tar.gz rails-2cf72ad250f7c393e6aa97384768ed803686eb97.tar.bz2 rails-2cf72ad250f7c393e6aa97384768ed803686eb97.zip |
Add query methods for superclass_delegating_reader
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9156 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/class/delegating_attributes.rb | 8 | ||||
-rw-r--r-- | activesupport/test/core_ext/class/delegating_attributes_test.rb | 18 |
2 files changed, 21 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb b/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb index f5f0ef8779..368317df9b 100644 --- a/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb +++ b/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb @@ -19,6 +19,12 @@ class Class def #{name} self.class.#{name} end + def self.#{name}? + !!#{name} + end + def #{name}? + !!#{name} + end EOS end end @@ -37,4 +43,4 @@ class Class superclass_delegating_reader(*names) superclass_delegating_writer(*names) end -end
\ No newline at end of file +end diff --git a/activesupport/test/core_ext/class/delegating_attributes_test.rb b/activesupport/test/core_ext/class/delegating_attributes_test.rb index fa605e6d19..8fc08a0250 100644 --- a/activesupport/test/core_ext/class/delegating_attributes_test.rb +++ b/activesupport/test/core_ext/class/delegating_attributes_test.rb @@ -25,7 +25,9 @@ class DelegatingAttributesTest < Test::Unit::TestCase # The class and instance should have an accessor, but there # should be no mutator assert single_class.respond_to?(:only_reader) + assert single_class.respond_to?(:only_reader?) assert single_class.public_instance_methods.map(&:to_s).include?("only_reader") + assert single_class.public_instance_methods.map(&:to_s).include?("only_reader?") assert !single_class.respond_to?(:only_reader=) end @@ -51,9 +53,17 @@ class DelegatingAttributesTest < Test::Unit::TestCase def test_working_with_simple_attributes single_class.superclass_delegating_accessor :both - single_class.both= "HMMM" + + single_class.both = "HMMM" + assert_equal "HMMM", single_class.both + assert_equal true, single_class.both? + assert_equal "HMMM", single_class.new.both + assert_equal true, single_class.new.both? + + single_class.both = false + assert_equal false, single_class.both? end def test_working_with_accessors @@ -73,14 +83,14 @@ class DelegatingAttributesTest < Test::Unit::TestCase parent = Class.new parent.superclass_delegating_accessor :both child = Class.new(parent) - parent.both= "1" + parent.both = "1" assert_equal "1", child.both - child.both="2" + child.both = "2" assert_equal "1", parent.both assert_equal "2", child.both - parent.both="3" + parent.both = "3" assert_equal "3", parent.both assert_equal "2", child.both end |