From 1efe30ebcef2e6d3967742f9bcf4f6675a946d14 Mon Sep 17 00:00:00 2001 From: Larry Lv Date: Sat, 15 Sep 2012 03:25:21 +0800 Subject: set up config_accessor with a default value by block * ActiveSupport::Configurable should allow config_accessor to take default value by block, just like cattr_accessor. class User include ActiveSupport::Configurable config_accessor :hair_colors do [:brown, :black, :blonde, :red] end end User.hair_colors # => [:brown, :black, :blonde, :red] * remove trailing whitespaces in configurable.rb and its test file. * Update ActiveSupport CHANGELOG. --- activesupport/test/configurable_test.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/configurable_test.rb b/activesupport/test/configurable_test.rb index da7729d066..215a6e06b0 100644 --- a/activesupport/test/configurable_test.rb +++ b/activesupport/test/configurable_test.rb @@ -48,6 +48,18 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase assert !instance.respond_to?(:baz=) end + test "configuration accessors can take a default value" do + parent = Class.new do + include ActiveSupport::Configurable + config_accessor :hair_colors, :tshirt_colors do + [:black, :blue, :white] + end + end + + assert_equal [:black, :blue, :white], parent.hair_colors + assert_equal [:black, :blue, :white], parent.tshirt_colors + end + test "configuration hash is available on instance" do instance = Parent.new assert_equal :bar, instance.config.foo @@ -78,7 +90,7 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase test "should raise name error if attribute name is invalid" do assert_raises NameError do - Class.new do + Class.new do include ActiveSupport::Configurable config_accessor "invalid attribute name" end @@ -94,4 +106,4 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase methods = object.public_methods.map(&:to_s) assert !methods.include?(method.to_s), "Expected #{methods.inspect} to not include #{method.to_s.inspect}" end -end \ No newline at end of file +end -- cgit v1.2.3