Merge branch 'master' of github.com:rails/rails

This commit is contained in:
David Heinemeier Hansson 2013-04-19 10:27:35 -07:00
commit eaec0ec71f
9 changed files with 66 additions and 15 deletions

View File

@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
* Run `rake migrate:down` & `rake migrate:up` in transaction if database supports.
*Alexander Bondarev*
* `0x` prefix must be added when assigning hexadecimal string into `bit` column in PostgreSQL.
*kennyj*

View File

@ -32,7 +32,7 @@ module ActiveRecord
when 'point' then super(PostgreSQLColumn.point_to_string(value))
else
if column.array
"'#{PostgreSQLColumn.array_to_string(value, column, self)}'"
"'#{PostgreSQLColumn.array_to_string(value, column, self).gsub(/'/, "''")}'"
else
super
end

View File

@ -307,9 +307,11 @@ module ActiveRecord
id.hash
end
# Freeze the attributes hash such that associations are still accessible, even on destroyed records.
# Clone and freeze the attributes hash such that associations are still
# accessible, even on destroyed records, but cloned models will not be
# frozen.
def freeze
@attributes.freeze
@attributes = @attributes.clone.freeze
self
end

View File

@ -867,11 +867,18 @@ module ActiveRecord
alias :current :current_migration
def run
target = migrations.detect { |m| m.version == @target_version }
raise UnknownMigrationVersionError.new(@target_version) if target.nil?
unless (up? && migrated.include?(target.version.to_i)) || (down? && !migrated.include?(target.version.to_i))
target.migrate(@direction)
record_version_state_after_migrating(target.version)
migration = migrations.detect { |m| m.version == @target_version }
raise UnknownMigrationVersionError.new(@target_version) if migration.nil?
unless (up? && migrated.include?(migration.version.to_i)) || (down? && !migrated.include?(migration.version.to_i))
begin
ddl_transaction(migration) do
migration.migrate(@direction)
record_version_state_after_migrating(migration.version)
end
rescue => e
canceled_msg = use_transaction?(migration) ? ", this migration was canceled" : ""
raise StandardError, "An error has occurred#{canceled_msg}:\n\n#{e}", e.backtrace
end
end
end

View File

@ -81,6 +81,12 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
assert_cycle(['1',nil,nil])
end
def test_insert_fixture
tag_values = ["val1", "val2", "val3_with_'_multiple_quote_'_chars"]
@connection.insert_fixture({"tags" => tag_values}, "pg_arrays" )
assert_equal(PgArray.last.tags, tag_values)
end
private
def assert_cycle array
# test creation

View File

@ -29,5 +29,12 @@ module ActiveRecord
topic.author_name = 'Aaron'
assert_equal 'Aaron', cloned.author_name
end
def test_freezing_a_cloned_model_does_not_freeze_clone
cloned = Topic.new
clone = cloned.clone
cloned.freeze
assert_not clone.frozen?
end
end
end

View File

@ -258,6 +258,32 @@ class MigrationTest < ActiveRecord::TestCase
"On error, the Migrator should revert schema changes but it did not."
end
def test_migrator_one_up_with_exception_and_rollback_using_run
unless ActiveRecord::Base.connection.supports_ddl_transactions?
skip "not supported on #{ActiveRecord::Base.connection.class}"
end
assert_not Person.column_methods_hash.include?(:last_name)
migration = Class.new(ActiveRecord::Migration) {
def version; 100 end
def migrate(x)
add_column "people", "last_name", :string
raise 'Something broke'
end
}.new
migrator = ActiveRecord::Migrator.new(:up, [migration], 100)
e = assert_raise(StandardError) { migrator.run }
assert_equal "An error has occurred, this migration was canceled:\n\nSomething broke", e.message
Person.reset_column_information
assert_not Person.column_methods_hash.include?(:last_name),
"On error, the Migrator should revert schema changes but it did not."
end
def test_migration_without_transaction
unless ActiveRecord::Base.connection.supports_ddl_transactions?
skip "not supported on #{ActiveRecord::Base.connection.class}"

View File

@ -28,7 +28,7 @@ module ActiveSupport
end
class InvalidMessage < StandardError; end
OpenSSLCipherError = OpenSSL::Cipher.const_defined?(:CipherError) ? OpenSSL::Cipher::CipherError : OpenSSL::CipherError
OpenSSLCipherError = OpenSSL::Cipher::CipherError
# Initialize a new MessageEncryptor. +secret+ must be at least as long as
# the cipher key size. For the default 'aes-256-cbc' cipher, this is 256
@ -66,12 +66,11 @@ module ActiveSupport
def _encrypt(value)
cipher = new_cipher
# Rely on OpenSSL for the initialization vector
iv = cipher.random_iv
cipher.encrypt
cipher.key = @secret
cipher.iv = iv
# Rely on OpenSSL for the initialization vector
iv = cipher.random_iv
encrypted_data = cipher.update(@serializer.dump(value))
encrypted_data << cipher.final

View File

@ -15,9 +15,9 @@
<tbody>
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
<tr>
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<% attributes.reject(&:password_digest?).each do |attribute| -%>
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
<% end -%>
<% end -%>
<td><%%= link_to 'Show', <%= singular_table_name %> %></td>
<td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
<td><%%= link_to 'Destroy', <%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' } %></td>