diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index dd284481f7e6cd1d31e60fe0a0dd9630060a1888..0f5b0b782b473955c44ee1409f76cafa78f51f5b 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -9,9 +9,8 @@ class StatusMessagesController < ApplicationController respond_to :json, :only => :show def create - if params[:status_message][:aspect_ids] == "all" - params[:status_message][:aspect_ids] = current_user.aspects.collect{|x| x.id} + params[:status_message][:aspect_ids] = current_user.aspects.collect { |x| x.id } end photos = Photo.where(:id => [*params[:photos]], :diaspora_handle => current_user.person.diaspora_handle) @@ -19,29 +18,25 @@ class StatusMessagesController < ApplicationController public_flag = params[:status_message][:public] public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false params[:status_message][:public] = public_flag - @status_message = current_user.build_post(:status_message, params[:status_message]) + @status_message = current_user.build_post(:status_message, params[:status_message]) - if !photos.empty? || @status_message.save - pp photos - pp @status_message - raise 'MongoMapper failed to catch a failed save' unless @status_message.id - - @status_message.photos += photos unless photos.nil? + if @status_message.save current_user.add_to_streams(@status_message, params[:status_message][:aspect_ids]) current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids], :url => post_url(@status_message)) - - for photo in photos - photo.public = public_flag - photo.save - current_user.add_to_streams(photo, params[:status_message][:aspect_ids]) - current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids]) + if !photos.empty? + @status_message.photos += photos + for photo in photos + photo.public = public_flag + photo.save + current_user.add_to_streams(photo, params[:status_message][:aspect_ids]) + current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids]) + end end - respond_to do |format| - format.js{ render :json => { :post_id => @status_message.id, + format.js { render :json => {:post_id => @status_message.id, :html => render_to_string( :partial => 'shared/stream_element', :locals => { @@ -51,21 +46,21 @@ class StatusMessagesController < ApplicationController :comments => [], :aspects => current_user.aspects, :current_user => current_user - } + } ) - }, - :status => 201 } - format.html{ respond_with @status_message } + }, + :status => 201 } + format.html { respond_with @status_message } end else respond_to do |format| - format.js{ render :status => 406 } + format.js { render :status => 406 } end end end def destroy - @status_message = current_user.posts.where(:id => params[:id]).first + @status_message = current_user.posts.where(:id => params[:id]).first if @status_message @status_message.destroy render :nothing => true, :status => 200 @@ -81,9 +76,10 @@ class StatusMessagesController < ApplicationController person_hash = Person.from_post_comment_hash comments_hash @comment_hashes = comments_hash[@status_message.id].map do |comment| {:comment => comment, - :person => person_hash[comment.person_id] + :person => person_hash[comment.person_id] } end respond_with @status_message end + end diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index 9224417737ab1daaf7545cde29f05ba057e9162d..89d349fa95983171c91b1aed650d998de4e1c910 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -21,31 +21,17 @@ describe StatusMessagesController do end describe '#show' do - before do - @video_id = "ABYnqp-bxvg" - @url="http://www.youtube.com/watch?v=#{@video_id}&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1" - end - it 'renders posts with youtube urls' do - message = user1.build_post :status_message, :message => @url, :to => aspect1.id - message[:youtube_titles]= {@video_id => "title"} + it 'succeeds' do + message = user1.build_post :status_message, :message => "ohai", :to => aspect1.id message.save! user1.add_to_streams(message, aspect1.id) user1.dispatch_post message, :to => aspect1.id - get :show, :id => message.id - response.body.should match /Youtube: title/ - end - it 'renders posts with comments with youtube urls' do - message = user1.post :status_message, :message => "Respond to this with a video!", :to => aspect1.id - @comment = user1.comment "none", :on => message - @comment.text = @url - @comment[:youtube_titles][@video_id] = "title" - @comment.save! - - get :show, :id => message.id - response.body.should match /Youtube: title/ + get :show, "id" => message.id.to_s + response.should be_success end end + describe '#create' do let(:status_message_hash) { { :status_message => { @@ -90,6 +76,7 @@ describe StatusMessagesController do post :create, hash end end + describe '#destroy' do let!(:message) {user1.post(:status_message, :message => "hey", :to => aspect1.id)} let!(:message2) {user2.post(:status_message, :message => "hey", :to => aspect2.id)} diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 4ffcfd96a0aff9debcb20d867dd0d7c19b0fe106..0f1eb22c599664c4bcbbeea6be993f595974cee1 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -93,6 +93,7 @@ describe ApplicationHelper do video_id = "0x__dDWdf23" url = "http://www.youtube.com/watch?v=" + video_id + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1" res = markdownify(url) + res.should =~ /Youtube:/ res.should =~ /data-host="youtube.com"/ res.should =~ /data-video-id="#{video_id}"/ end @@ -101,6 +102,7 @@ describe ApplicationHelper do video_id = "ABYnqp-bxvg" url = "http://www.youtube.com/watch?v=" + video_id + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1" res = markdownify(url) + res.should =~ /Youtube:/ res.should =~ /data-host="youtube.com"/ res.should =~ /data-video-id="#{video_id}"/ end