From 19785d909b2cf7f4539bea500010a9d12d4b18c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Tue, 24 Jan 2012 18:54:36 +0100 Subject: [PATCH] ensure services is an array in StatusMessagesController#create This fixes posting to a single service for Ruby 1.9 For some reason Rails doesn't convert a single foo[]=bar not to the expected :foo => ["bar"] but to :foo => "bar" On Ruby 1.8 String#map exists and just yields self, on Ruby 1.9 String#map got removed --- app/controllers/status_messages_controller.rb | 3 +++ spec/controllers/status_messages_controller_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 726835961..21c72711b 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -43,6 +43,9 @@ class StatusMessagesController < ApplicationController def create params[:status_message][:aspect_ids] = [*params[:aspect_ids]] normalize_public_flag! + + # ensure services is an array since .map doesn't work on a string for ruby 1.9 + params[:services] = [params[:services]] if params[:services].is_a?(String) @status_message = current_user.build_post(:status_message, params[:status_message]) diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index c851d9acd..e7e9ef7de 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -72,6 +72,14 @@ describe StatusMessagesController do post :create, status_message_hash end + it "works if services is a string" do + s1 = Services::Facebook.new + alice.services << s1 + status_message_hash[:services] = "facebook" + alice.should_receive(:dispatch_post).with(anything(), hash_including(:services => [s1])) + post :create, status_message_hash + end + it "doesn't overwrite author_id" do status_message_hash[:status_message][:author_id] = bob.person.id post :create, status_message_hash