From fc956425d405e75bcf310f3e6f08cf201cc8131a Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 6 Jan 2012 10:48:47 -0200 Subject: [PATCH] Revert "Revert "More 1.9 way"" Fixed failing tests This reverts commit 8350ce97f2065eed9638c595d3938a573d6fa343. --- actionpack/test/template/form_helper_test.rb | 2 ++ activemodel/lib/active_model/conversion.rb | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 9a13d4e399..a36b1f713f 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -867,6 +867,7 @@ class FormHelperTest < ActionView::TestCase def test_form_for_with_remote_without_html @post.persisted = false + def @post.id; nil; end form_for(@post, :remote => true) do |f| concat f.text_field(:title) concat f.text_area(:body) @@ -1016,6 +1017,7 @@ class FormHelperTest < ActionView::TestCase old_locale, I18n.locale = I18n.locale, :submit @post.persisted = false + def @post.id; nil; end form_for(@post) do |f| concat f.submit end diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb index 80a3ba51c3..c7c805f1a2 100644 --- a/activemodel/lib/active_model/conversion.rb +++ b/activemodel/lib/active_model/conversion.rb @@ -39,11 +39,9 @@ module ActiveModel # Returns an Enumerable of all key attributes if any is set, regardless # if the object is persisted or not. - # - # Note the default implementation uses persisted? just because all objects - # in Ruby 1.8.x responds to :id. def to_key - persisted? ? [id] : nil + key = respond_to?(:id) && id + key ? [key] : nil end # Returns a string representing the object's key suitable for use in URLs,