5096: if only collection name or description is being updated, do not include manifes...
authorRadhika Chippada <radhika@curoverse.com>
Sat, 14 Feb 2015 23:46:14 +0000 (18:46 -0500)
committerRadhika Chippada <radhika@curoverse.com>
Sat, 14 Feb 2015 23:46:14 +0000 (18:46 -0500)
apps/workbench/app/controllers/collections_controller.rb
apps/workbench/test/controllers/collections_controller_test.rb

index 3ef46887d82c24a2edc2e5e6778b1a1fd20769e9..d9bf3a96ccde9645c955d05491aab13e0482306e 100644 (file)
@@ -266,6 +266,21 @@ class CollectionsController < ApplicationController
     sharing_popup
   end
 
+  def update
+    @updates ||= params[@object.resource_param_name.to_sym]
+    if @updates && (@updates.keys - ["name", "description"]).empty?
+      # exclude manifest_text since only name or description is being updated
+      @object.manifest_text = nil
+      if @object.update_attributes @updates
+        show
+      else
+        self.render_error status: 422
+      end
+    else
+      super
+    end
+  end
+
   protected
 
   def find_usable_token(token_list)
index 45124f7a9e3ff8cdf3fbff29ef0c488caa1dcf5d..85183780973c5bf0e3c332d315269591c53155b4 100644 (file)
@@ -355,4 +355,19 @@ class CollectionsControllerTest < ActionController::TestCase
     assert /#{stage3_id}&#45;&gt;#{stage3_out}/.match(used_by_svg)
 
   end
+
+  test "update description and check manifest_text is not lost" do
+    collection = api_fixture("collections")["multilevel_collection_1"]
+    post :update, {
+      id: collection["uuid"],
+      collection: {
+        description: 'test description update'
+      },
+      format: :json
+    }, session_for(:active)
+    assert_response :success
+    assert_not_nil assigns(:object)
+    assert_equal 'test description update', assigns(:object).description
+    assert_equal collection['manifest_text'], assigns(:object).manifest_text
+  end
 end