From 5129de7bbdbd15e47ce5baf7945caf2e78d82882 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 21 Nov 2005 07:29:33 +0000 Subject: [PATCH] r3220@asus: jeremy | 2005-11-20 03:19:22 -0800 Enable Action Mailer warnings in unit tests. adv_attr_accessor hecks for presence of instance variable before getting it. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3132 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionmailer/Rakefile | 1 + actionmailer/lib/action_mailer/adv_attr_accessor.rb | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile index 51ec9ed6b9..f0dd7b66d7 100755 --- a/actionmailer/Rakefile +++ b/actionmailer/Rakefile @@ -25,6 +25,7 @@ Rake::TestTask.new { |t| t.libs << "test" t.pattern = 'test/*_test.rb' t.verbose = true + t.warning = true } diff --git a/actionmailer/lib/action_mailer/adv_attr_accessor.rb b/actionmailer/lib/action_mailer/adv_attr_accessor.rb index a8b83c5e64..50afe4d742 100644 --- a/actionmailer/lib/action_mailer/adv_attr_accessor.rb +++ b/actionmailer/lib/action_mailer/adv_attr_accessor.rb @@ -8,16 +8,20 @@ module ActionMailer module ClassMethods #:nodoc: def adv_attr_accessor(*names) names.each do |name| + ivar = "@#{name}" + define_method("#{name}=") do |value| - instance_variable_set("@#{name}", value) + instance_variable_set(ivar, value) end define_method(name) do |*parameters| raise ArgumentError, "expected 0 or 1 parameters" unless parameters.length <= 1 if parameters.empty? - instance_variable_get("@#{name}") + if instance_variables.include?(ivar) + instance_variable_get(ivar) + end else - instance_variable_set("@#{name}", parameters.first) + instance_variable_set(ivar, parameters.first) end end end