Always use symbol keys for object attribute names and string keys
authorTom Clegg <tom@curoverse.com>
Sat, 25 Jan 2014 06:24:37 +0000 (22:24 -0800)
committerTom Clegg <tom@curoverse.com>
Sat, 25 Jan 2014 06:24:37 +0000 (22:24 -0800)
inside serialized hashes, rather than HashWithIndifferentAccess.

This ensures serialized attributes go into the database as plain
hashes with string keys, even when Rails was responsible for
unserializing the data coming from the client.

refs #1944
refs #1987

services/api/app/controllers/application_controller.rb
services/api/test/functional/arvados/v1/links_controller_test.rb

index fff52f5d621967704bfc8c5dc4c32b9393d91a06..dcb9c0c0d8deedcdb73a9f566d4756e6ee079b2e 100644 (file)
@@ -220,6 +220,7 @@ class ApplicationController < ActionController::Base
     %w(created_at modified_by_client_uuid modified_by_user_uuid modified_at).each do |x|
       @attrs.delete x.to_sym
     end
+    @attrs = @attrs.symbolize_keys if @attrs.is_a? HashWithIndifferentAccess
     @attrs
   end
 
index b3bc58667943efdb5323fb9c63a8eb8dc37c3a6e..afecc18bb01d778f536cc9dbdf6ee5bb6799d3f9 100644 (file)
@@ -1,4 +1,25 @@
 require 'test_helper'
 
 class Arvados::V1::LinksControllerTest < ActionController::TestCase
+
+  test "no symbol keys in serialized hash" do
+    link = {
+      properties: {username: 'testusername'},
+      link_class: 'test',
+      name: 'encoding',
+      tail_kind: 'arvados#user',
+      tail_uuid: users(:admin).uuid,
+      head_kind: 'arvados#virtualMachine',
+      head_uuid: virtual_machines(:testvm).uuid
+    }
+    authorize_with :admin
+    [link, link.to_json].each do |formatted_link|
+      post :create, link: formatted_link
+      assert_response :success
+      assert_not_nil assigns(:object)
+      assert_equal 'testusername', assigns(:object).properties['username']
+      assert_equal false, assigns(:object).properties.has_key?(:username)
+    end
+  end
+  
 end