diff options
17 files changed, 82 insertions, 12 deletions
@@ -52,7 +52,6 @@ platforms :mri do end platforms :ruby do - gem 'json' gem 'yajl-ruby' gem 'nokogiri', '>= 1.4.5' diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index d938ffbb4c..74aede2cb7 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,15 +1,26 @@ +## Rails 3.2.9 (unreleased) ## + +* Do not render views when mail() isn't called. + Fix #7761 + + *Yves Senn* + + ## Rails 3.2.8 (Aug 9, 2012) ## * No changes. + ## Rails 3.2.7 (Jul 26, 2012) ## * No changes. + ## Rails 3.2.6 (Jun 12, 2012) ## * No changes. + ## Rails 3.2.5 (Jun 1, 2012) ## * No changes. diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 2a11cb6ca7..a9fb49a303 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -454,7 +454,19 @@ module ActionMailer #:nodoc: def process(*args) #:nodoc: lookup_context.skip_default_locale! - super + + generated_mail = super + unless generated_mail + @_message = NullMail.new + end + end + + class NullMail #:nodoc: + def body; '' end + + def method_missing(*args) + nil + end end def mailer_name diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index d92fc01ef8..b69b26faf0 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -471,6 +471,12 @@ class BaseTest < ActiveSupport::TestCase assert_equal(%{<img alt="Dummy" src="http://local.com/images/dummy.png" />}, mail.body.to_s.strip) end + test 'the view is not rendered when mail was never called' do + mail = BaseMailer.without_mail_call + assert_equal('', mail.body.to_s.strip) + mail.deliver + end + # Before and After hooks class MyObserver diff --git a/actionmailer/test/fixtures/base_mailer/without_mail_call.erb b/actionmailer/test/fixtures/base_mailer/without_mail_call.erb new file mode 100644 index 0000000000..290379d5fb --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/without_mail_call.erb @@ -0,0 +1 @@ +<% raise 'the template should not be rendered' %>
\ No newline at end of file diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb index e55d72fdb4..8c4430b046 100644 --- a/actionmailer/test/mailers/base_mailer.rb +++ b/actionmailer/test/mailers/base_mailer.rb @@ -115,4 +115,7 @@ class BaseMailer < ActionMailer::Base def email_with_translations mail :body => render("email_with_translations", :formats => [:html]) end + + def without_mail_call + end end diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb index c845440120..4060425725 100644 --- a/activemodel/lib/active_model/serializers/json.rb +++ b/activemodel/lib/active_model/serializers/json.rb @@ -2,8 +2,8 @@ require 'active_support/json' require 'active_support/core_ext/class/attribute' module ActiveModel - # == Active Model JSON Serializer module Serializers + # == Active Model JSON Serializer module JSON extend ActiveSupport::Concern include ActiveModel::Serialization diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb index d61d9d7119..2dc7d00f52 100644 --- a/activemodel/lib/active_model/serializers/xml.rb +++ b/activemodel/lib/active_model/serializers/xml.rb @@ -5,12 +5,16 @@ require 'active_support/core_ext/hash/conversions' require 'active_support/core_ext/hash/slice' module ActiveModel - # == Active Model XML Serializer module Serializers + # == Active Model XML Serializer module Xml extend ActiveSupport::Concern include ActiveModel::Serialization + included do + extend ActiveModel::Naming + end + class Serializer #:nodoc: class Attribute #:nodoc: attr_reader :name, :value, :type diff --git a/activemodel/test/cases/serializers/json_serialization_test.rb b/activemodel/test/cases/serializers/json_serialization_test.rb index 4ac5fb1779..4eabe82153 100644 --- a/activemodel/test/cases/serializers/json_serialization_test.rb +++ b/activemodel/test/cases/serializers/json_serialization_test.rb @@ -4,7 +4,6 @@ require 'models/automobile' require 'active_support/core_ext/object/instance_variables' class Contact - extend ActiveModel::Naming include ActiveModel::Serializers::JSON include ActiveModel::Validations diff --git a/activemodel/test/cases/serializers/xml_serialization_test.rb b/activemodel/test/cases/serializers/xml_serialization_test.rb index 7f14b21cf4..83db8d21f4 100644 --- a/activemodel/test/cases/serializers/xml_serialization_test.rb +++ b/activemodel/test/cases/serializers/xml_serialization_test.rb @@ -4,7 +4,6 @@ require 'active_support/core_ext/object/instance_variables' require 'ostruct' class Contact - extend ActiveModel::Naming include ActiveModel::Serializers::Xml attr_accessor :address, :friends @@ -25,7 +24,6 @@ class Customer < Struct.new(:name) end class Address - extend ActiveModel::Naming include ActiveModel::Serializers::Xml attr_accessor :street, :city, :state, :zip diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index aafdbec25c..aa68934099 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,5 +1,13 @@ ## Rails 3.2.9 (unreleased) +* Fix bug where `update_columns` and `update_column` would not let you update the primary key column. + + *Henrik Nyh* + +* Decode URI encoded attributes on database connection URLs. + + *Shawn Veader* + * Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original and the dup'ed object shared the same errors. diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb index 6c8a102caf..f366392c50 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb @@ -68,6 +68,7 @@ module ActiveRecord :database => config.path.sub(%r{^/},""), :host => config.host } spec.reject!{ |_,value| !value } + spec.map { |key,value| spec[key] = URI.unescape(value) if value.is_a?(String) } if config.query options = Hash[config.query.split("&").map{ |pair| pair.split("=") }].symbolize_keys spec.merge!(options) diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 731f7e2049..e80b465bab 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -205,7 +205,7 @@ module ActiveRecord value = super if column.type == :string && value.encoding == Encoding::ASCII_8BIT logger.error "Binary data inserted for `string` type on column `#{column.name}`" if logger - value.encode! 'utf-8' + value = value.encode Encoding::UTF_8 end value end diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 8a3c3fed7d..d492ac7f16 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -193,8 +193,12 @@ module ActiveRecord name = name.to_s raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attributes.include?(name) raise ActiveRecordError, "can not update on a new record object" unless persisted? + + updated_count = self.class.update_all({ name => value }, self.class.primary_key => id) == 1 + raw_write_attribute(name, value) - self.class.update_all({ name => value }, self.class.primary_key => id) == 1 + + updated_count == 1 end # Updates the attributes of the model from the passed-in hash and saves the diff --git a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb index 97b56d38d7..ec69a36174 100644 --- a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb @@ -164,6 +164,14 @@ module ActiveRecord end end + def test_type_cast_should_not_mutate_encoding + return skip('only test encoding on 1.9') unless "<3".encoding_aware? + + name = 'hello'.force_encoding(Encoding::ASCII_8BIT) + owner = Owner.create(:name => name) + assert_equal Encoding::ASCII_8BIT, name.encoding + end + def test_execute @conn.execute "INSERT INTO items (number) VALUES (10)" records = @conn.execute "SELECT * FROM items" diff --git a/activerecord/test/cases/connection_specification/resolver_test.rb b/activerecord/test/cases/connection_specification/resolver_test.rb index 0e9ab8e3fc..46fc1a252f 100644 --- a/activerecord/test/cases/connection_specification/resolver_test.rb +++ b/activerecord/test/cases/connection_specification/resolver_test.rb @@ -9,7 +9,7 @@ module ActiveRecord end def test_url_host_no_db - skip "only if mysql is available" unless defined?(MysqlAdapter) + skip "only if mysql is available" unless current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter) spec = resolve 'mysql://foo?encoding=utf8' assert_equal({ :adapter => "mysql", @@ -19,7 +19,7 @@ module ActiveRecord end def test_url_host_db - skip "only if mysql is available" unless defined?(MysqlAdapter) + skip "only if mysql is available" unless current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter) spec = resolve 'mysql://foo/bar?encoding=utf8' assert_equal({ :adapter => "mysql", @@ -29,7 +29,7 @@ module ActiveRecord end def test_url_port - skip "only if mysql is available" unless defined?(MysqlAdapter) + skip "only if mysql is available" unless current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter) spec = resolve 'mysql://foo:123?encoding=utf8' assert_equal({ :adapter => "mysql", @@ -38,6 +38,14 @@ module ActiveRecord :host => "foo", :encoding => "utf8" }, spec) end + + def test_encoded_password + skip "only if mysql is available" unless current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter) + password = 'am@z1ng_p@ssw0rd#!' + encoded_password = URI.respond_to?(:encode_www_form_component) ? URI.encode_www_form_component(password) : "am%40z1ng_p%40ssw0rd%23%21" + spec = resolve "mysql://foo:#{encoded_password}@localhost/bar" + assert_equal password, spec[:password] + end end end end diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index e4b8caae52..66f884287d 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -505,6 +505,14 @@ class PersistencesTest < ActiveRecord::TestCase assert_equal 'super_title', t.title end + def test_update_column_changing_id + topic = Topic.find(1) + topic.update_column("id", 123) + assert_equal 123, topic.id + topic.reload + assert_equal 123, topic.id + end + def test_update_attributes topic = Topic.find(1) assert !topic.approved? |