diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index a5c018af237fd78d07186e2b72594d59607a06e8..92bda1a361a001dac4eead46304448478ac364bd 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -13,9 +13,7 @@ class StatusMessagesController < ApplicationController public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false params[:status_message][:public] = public_flag - data = clean_hash params[:status_message] - message = params[:status_message][:message] - status_message = current_user.post(:status_message, data) + status_message = current_user.post(:status_message, params[:status_message]) render :nothing => true end @@ -29,13 +27,4 @@ class StatusMessagesController < ApplicationController @status_message = current_user.find_visible_post_by_id params[:id] respond_with @status_message end - - private - def clean_hash(params) - return { - :message => params[:message], - :to => params[:to], - :public => params[:public] - } - end end diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index c1fff84cad9383e739033396c7b689f63af41ca5..100d60ebe62b7baac693a891c8680068d504f95c 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -16,7 +16,12 @@ describe StatusMessagesController do end describe '#create' do - let(:status_message_hash) {{"status_message"=>{"public"=>"true", "message"=>"facebook, is that you?", "to" =>"#{aspect.id}"}}} + let(:status_message_hash) { + {:status_message =>{ + :public =>"true", + :message =>"facebook, is that you?", + :to =>"#{aspect.id}"}} + } context "posting out to facebook" do let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s } @@ -27,10 +32,22 @@ describe StatusMessagesController do end it 'should not post to facebook when public is not set' do - status_message_hash['status_message']['public'] = 'false' + status_message_hash[:status_message][:public] = 'false' user.should_not_receive(:post_to_facebook) post :create, status_message_hash end + it "doesn't overwrite person_id" do + new_user = make_user + status_message_hash[:status_message][:person_id] = new_user.person.id + post :create, status_message_hash + StatusMessage.find_by_message(status_message_hash[:status_message][:message]).person_id.should == user.person.id + end + it "doesn't overwrite id" do + old_status_message = user.post(:status_message, :message => "hello", :to => aspect.id) + status_message_hash[:status_message][:id] = old_status_message.id + post :create, status_message_hash + old_status_message.reload.message.should == 'hello' + end end context "posting to twitter" do @@ -42,7 +59,7 @@ describe StatusMessagesController do end it 'should not post to twitter when public in not set' do - status_message_hash['status_message']['public'] = 'false' + status_message_hash[:status_message][:public] = 'false' user.should_not_receive(:post_to_twitter) post :create, status_message_hash end