Don't pass ActiveRecord objects to find and exists?
authorTom Hughes <tom@compton.nu>
Sat, 10 Jan 2015 12:35:52 +0000 (12:35 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 10 Jan 2015 12:41:16 +0000 (12:41 +0000)
app/controllers/changeset_controller.rb
app/views/browse/changeset.html.erb
test/models/changeset_comment_test.rb
test/models/node_test.rb

index adda8c20c0fe536a882ad7894ef0240973725368..224c2c48859ea9dec1044a0dbaf09a2a947973f1 100644 (file)
@@ -341,7 +341,7 @@ class ChangesetController < ApplicationController
     end
 
     # Add the commenter to the subscribers if necessary
-    changeset.subscribers << @user unless changeset.subscribers.exists?(@user)
+    changeset.subscribers << @user unless changeset.subscribers.exists?(@user.id)
 
     # Return a copy of the updated changeset
     render :text => changeset.to_xml.to_s, :content_type => "text/xml"
@@ -359,7 +359,7 @@ class ChangesetController < ApplicationController
     # Find the changeset and check it is valid
     changeset = Changeset.find(id)
     raise OSM::APIChangesetNotYetClosedError.new(changeset) if changeset.is_open?
-    raise OSM::APIChangesetAlreadySubscribedError.new(changeset) if changeset.subscribers.exists?(@user)
+    raise OSM::APIChangesetAlreadySubscribedError.new(changeset) if changeset.subscribers.exists?(@user.id)
 
     # Add the subscriber
     changeset.subscribers << @user
@@ -380,7 +380,7 @@ class ChangesetController < ApplicationController
     # Find the changeset and check it is valid
     changeset = Changeset.find(id)
     raise OSM::APIChangesetNotYetClosedError.new(changeset) if changeset.is_open?
-    raise OSM::APIChangesetNotSubscribedError.new(changeset) unless changeset.subscribers.exists?(@user)
+    raise OSM::APIChangesetNotSubscribedError.new(changeset) unless changeset.subscribers.exists?(@user.id)
 
     # Remove the subscriber
     changeset.subscribers.delete(@user)
index bbe22792101c283e39fd7084be5a0d930627aa85..efb7bb7f986945a79c47b9a1defb37bcfece763b 100644 (file)
@@ -15,7 +15,7 @@
   
   <div class="buttons clearfix subscribe-buttons">
     <form action="#" class="hide_unless_logged_in">
-      <% if @changeset.subscribers.exists?(@user) %>
+      <% if @user and @changeset.subscribers.exists?(@user.id) %>
         <input class="action-button" type="submit" name="unsubscribe" value="<%= t('javascripts.changesets.show.unsubscribe') %>" data-method="POST" data-url="<%= changeset_unsubscribe_url(@changeset) %>" />
       <% else %>
         <input class="action-button" type="submit" name="subscribe" value="<%= t('javascripts.changesets.show.subscribe') %>" data-method="POST" data-url="<%= changeset_subscribe_url(@changeset) %>" />
index 5f8efdbbdef8bf65262aafb8c8003d7f61e4d14f..c13fde8e28e31734c7ae755deba6388e46b88d4c 100644 (file)
@@ -36,6 +36,6 @@ class ChangesetCommentTest < ActiveSupport::TestCase
   end
 
   def test_comments_of_changeset_count
-    assert_equal 3, Changeset.find(changesets(:normal_user_closed_change)).comments.count
+    assert_equal 3, Changeset.find(changesets(:normal_user_closed_change).id).comments.count
   end
 end
index 7acc6168f73a518f499a147793a5d256aab3cfee..612bff7034d51eb01f678dc10ae2e5f1af8939c1 100644 (file)
@@ -137,7 +137,7 @@ class NodeTest < ActiveSupport::TestCase
   end
 
   def test_delete
-    node_template = Node.find(current_nodes(:visible_node))
+    node_template = Node.find(current_nodes(:visible_node).id)
     assert_not_nil node_template
 
     assert_equal OldNode.where(:node_id => node_template.id).count, 1