diff options
author | Bryan Helmkamp <bryan@brynary.com> | 2009-11-09 19:49:51 -0500 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2009-11-09 19:49:51 -0500 |
commit | 4dcfe6786e5fe72c27cadc5c0ee18aa6a67ba2bd (patch) | |
tree | f92d4cd13d30243e6951d22085d98a26d78cf6d7 /lib/arel/engines | |
parent | 34e35c7cbc9f378564bf1dd0d6d29553dc59534e (diff) | |
download | rails-4dcfe6786e5fe72c27cadc5c0ee18aa6a67ba2bd.tar.gz rails-4dcfe6786e5fe72c27cadc5c0ee18aa6a67ba2bd.tar.bz2 rails-4dcfe6786e5fe72c27cadc5c0ee18aa6a67ba2bd.zip |
Ruby 1.9: Sort attributes deterministically so specs always pass
Diffstat (limited to 'lib/arel/engines')
-rw-r--r-- | lib/arel/engines/sql/relations/writes.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index 42496ef735..50fcb8e07e 100644 --- a/lib/arel/engines/sql/relations/writes.rb +++ b/lib/arel/engines/sql/relations/writes.rb @@ -14,8 +14,19 @@ module Arel insertion_attributes_values_sql = if record.is_a?(Value) record.value else - build_query "(#{record.keys.collect { |key| engine.quote_column_name(key.name) }.join(', ')})", - "VALUES (#{record.collect { |key, value| key.format(value) }.join(', ')})" + attributes = record.keys.sort_by do |attribute| + attribute.name.to_s + end + + first = attributes.collect do |key| + engine.quote_column_name(key.name) + end.join(', ') + + second = attributes.collect do |key| + key.format(record[key]) + end.join(', ') + + build_query "(#{first})", "VALUES (#{second})" end build_query \ @@ -37,7 +48,12 @@ module Arel def assignment_sql if assignments.respond_to?(:collect) - assignments.collect do |attribute, value| + attributes = assignments.keys.sort_by do |attribute| + attribute.name.to_s + end + + attributes.map do |attribute| + value = assignments[attribute] "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}" end.join(",\n") else |