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
This commit is contained in:
Jonne Haß 2012-01-24 18:54:36 +01:00
parent 4797e8f2f8
commit 19785d909b
2 changed files with 11 additions and 0 deletions

View file

@ -44,6 +44,9 @@ class StatusMessagesController < ApplicationController
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])
photos = Photo.where(:id => [*params[:photos]], :diaspora_handle => current_user.person.diaspora_handle)

View file

@ -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