diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2010-01-31 18:32:28 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-02-01 02:02:42 -0800 |
commit | e5ab4b0d07ade8d89d633ca744c0eafbc53ee921 (patch) | |
tree | aa2480b38f79e623b98da0274695f99db73bff20 /actionmailer | |
parent | 8ae25a8e41168801590fdb95891cc5990b4db21c (diff) | |
download | rails-e5ab4b0d07ade8d89d633ca744c0eafbc53ee921.tar.gz rails-e5ab4b0d07ade8d89d633ca744c0eafbc53ee921.tar.bz2 rails-e5ab4b0d07ade8d89d633ca744c0eafbc53ee921.zip |
Convert to class_attribute
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 10 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/delivery_methods.rb | 14 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/deprecated_api.rb | 2 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 24 | ||||
-rw-r--r-- | actionmailer/test/delivery_methods_test.rb | 6 |
5 files changed, 25 insertions, 31 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index aa9822c6ab..ec85a20f70 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -268,13 +268,13 @@ module ActionMailer #:nodoc: private_class_method :new #:nodoc: - extlib_inheritable_accessor :default_params + class_attribute :default_params self.default_params = { :mime_version => "1.0", :charset => "utf-8", :content_type => "text/plain", :parts_order => [ "text/plain", "text/enriched", "text/html" ] - } + }.freeze class << self @@ -284,9 +284,9 @@ module ActionMailer #:nodoc: attr_writer :mailer_name alias :controller_path :mailer_name - def default(value=nil) - self.default_params.merge!(value) if value - self.default_params + def default(value = nil) + self.default_params = default_params.merge(value).freeze if value + default_params end # Receives a raw email, parses it into an email object, decodes it, diff --git a/actionmailer/lib/action_mailer/delivery_methods.rb b/actionmailer/lib/action_mailer/delivery_methods.rb index 7e92aea8fd..043794bb12 100644 --- a/actionmailer/lib/action_mailer/delivery_methods.rb +++ b/actionmailer/lib/action_mailer/delivery_methods.rb @@ -7,8 +7,7 @@ module ActionMailer extend ActiveSupport::Concern included do - extlib_inheritable_accessor :delivery_methods, :delivery_method, - :instance_writer => false + class_attribute :delivery_methods, :delivery_method # Do not make this inheritable, because we always want it to propagate cattr_accessor :raise_delivery_errors @@ -17,7 +16,7 @@ module ActionMailer cattr_accessor :perform_deliveries self.perform_deliveries = true - self.delivery_methods = {} + self.delivery_methods = {}.freeze self.delivery_method = :smtp add_delivery_method :smtp, Mail::SMTP, @@ -53,12 +52,9 @@ module ActionMailer # :arguments => '-i -t' # def add_delivery_method(symbol, klass, default_options={}) - unless respond_to?(:"#{symbol}_settings") - extlib_inheritable_accessor(:"#{symbol}_settings", :instance_writer => false) - end - + class_attribute(:"#{symbol}_settings") unless respond_to?(:"#{symbol}_settings") send(:"#{symbol}_settings=", default_options) - self.delivery_methods[symbol.to_sym] = klass + self.delivery_methods = delivery_methods.merge(symbol.to_sym => klass).freeze end def wrap_delivery_behavior(mail, method=nil) #:nodoc: @@ -87,4 +83,4 @@ module ActionMailer self.class.wrap_delivery_behavior(message, *args) end end -end
\ No newline at end of file +end diff --git a/actionmailer/lib/action_mailer/deprecated_api.rb b/actionmailer/lib/action_mailer/deprecated_api.rb index 54ad18f796..c08ab4164e 100644 --- a/actionmailer/lib/action_mailer/deprecated_api.rb +++ b/actionmailer/lib/action_mailer/deprecated_api.rb @@ -47,7 +47,7 @@ module ActionMailer end def template_root=(root) - ActiveSupport::Deprecation.warn "template_root= is deprecated, use view_paths.unshift instead", caller[0,2] + ActiveSupport::Deprecation.warn "template_root= is deprecated, use prepend_view_path instead", caller[0,2] self.view_paths = ActionView::Base.process_view_paths(root) end diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 57bfe2375e..20ecfdcbdb 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -254,7 +254,7 @@ class BaseTest < ActiveSupport::TestCase end test "subject gets default from I18n" do - BaseMailer.default[:subject] = nil + BaseMailer.default :subject => nil email = BaseMailer.welcome(:subject => nil) assert_equal "Welcome", email.subject @@ -331,22 +331,24 @@ class BaseTest < ActiveSupport::TestCase end test "implicit multipart with several view paths uses the first one with template" do + old = BaseMailer.view_paths begin - BaseMailer.view_paths.unshift(File.join(FIXTURE_LOAD_PATH, "another.path")) + BaseMailer.view_paths = [File.join(FIXTURE_LOAD_PATH, "another.path")] + old.dup email = BaseMailer.welcome assert_equal("Welcome from another path", email.body.encoded) ensure - BaseMailer.view_paths.shift + BaseMailer.view_paths = old end end test "implicit multipart with inexistent templates uses the next view path" do + old = BaseMailer.view_paths begin - BaseMailer.view_paths.unshift(File.join(FIXTURE_LOAD_PATH, "unknown")) + BaseMailer.view_paths = [File.join(FIXTURE_LOAD_PATH, "unknown")] + old.dup email = BaseMailer.welcome assert_equal("Welcome", email.body.encoded) ensure - BaseMailer.view_paths.shift + BaseMailer.view_paths = old end end @@ -503,16 +505,10 @@ class BaseTest < ActiveSupport::TestCase end def with_default(klass, new_values) - hash = klass.default - old_values = {} - new_values.each do |key, value| - old_values[key] = hash[key] - hash[key] = value - end + old = klass.default_params + klass.default(new_values) yield ensure - old_values.each do |key, value| - hash[key] = value - end + klass.default_params = old end end diff --git a/actionmailer/test/delivery_methods_test.rb b/actionmailer/test/delivery_methods_test.rb index 4907ca0903..22a7d19bc2 100644 --- a/actionmailer/test/delivery_methods_test.rb +++ b/actionmailer/test/delivery_methods_test.rb @@ -45,7 +45,9 @@ class CustomDeliveryMethodsTest < ActiveSupport::TestCase def teardown ActionMailer::Base.delivery_method = @old_delivery_method - ActionMailer::Base.delivery_methods.delete(:custom) + new = ActionMailer::Base.delivery_methods.dup + new.delete(:custom) + ActionMailer::Base.delivery_methods = new end test "allow to add custom delivery method" do @@ -167,4 +169,4 @@ class MailDeliveryTest < ActiveSupport::TestCase assert_equal(0, DeliveryMailer.deliveries.length) end -end
\ No newline at end of file +end |