diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 4b5d2039c..a436667a9 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -9,7 +9,7 @@ class LikesController < ApplicationController respond_to :html, :mobile, :json def create - target = current_user.find_visible_post_by_id params[:status_message_id] + target = current_user.find_visible_post_by_id params[:post_id] positive = (params[:positive] == 'true') ? true : false if target @like = current_user.build_like(:positive => positive, :post => target) @@ -32,7 +32,7 @@ class LikesController < ApplicationController end def destroy - if @like = Like.where(:id => params[:id], :author_id => current_user.person.id, :post_id => params[:status_message_id]).first + if @like = Like.where(:id => params[:id], :author_id => current_user.person.id, :post_id => params[:post_id]).first current_user.retract(@like) else respond_to do |format| @@ -43,7 +43,7 @@ class LikesController < ApplicationController end def index - if target = current_user.find_visible_post_by_id(params[:status_message_id]) + if target = current_user.find_visible_post_by_id(params[:post_id]) @likes = target.likes.includes(:author => :profile) render :layout => false else diff --git a/app/helpers/likes_helper.rb b/app/helpers/likes_helper.rb index 0648bed4e..1de4f44b9 100644 --- a/app/helpers/likes_helper.rb +++ b/app/helpers/likes_helper.rb @@ -10,9 +10,9 @@ module LikesHelper def like_action(post, current_user=current_user) if current_user.liked?(post) - link_to t('shared.stream_element.unlike'), status_message_like_path(post, current_user.like_for(post)), :method => :delete, :class => 'unlike', :remote => true + link_to t('shared.stream_element.unlike'), post_like_path(post, current_user.like_for(post)), :method => :delete, :class => 'unlike', :remote => true else - link_to t('shared.stream_element.like'), status_message_likes_path(post, :positive => 'true'), :method => :post, :class => 'like', :remote => true + link_to t('shared.stream_element.like'), post_likes_path(post, :positive => 'true'), :method => :post, :class => 'like', :remote => true end end end diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index b07f69c56..5f2203a6b 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -5,7 +5,7 @@ %li.comment.posted{:data=>{:guid => comment.id}, :class => ("hidden" if(defined? hidden))} - if current_user && (current_user.owns?(comment) || current_user.owns?(post)) .right.controls - = link_to image_tag('deletelabel.png'), comment_path(comment), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete comment_delete", :title => t('delete') + = link_to image_tag('deletelabel.png'), post_comment_path(comment.post_id, comment), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete comment_delete", :title => t('delete') = person_image_link(comment.author) .content %span.from diff --git a/app/views/comments/_new_comment.html.haml b/app/views/comments/_new_comment.html.haml index 2e38cf322..522313aec 100644 --- a/app/views/comments/_new_comment.html.haml +++ b/app/views/comments/_new_comment.html.haml @@ -2,12 +2,11 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -= form_tag( comments_path, :id => "new_comment_on_#{post_id}", :class => 'new_comment', :remote => true) do += form_tag( post_comments_path(post_id), :id => "new_comment_on_#{post_id}", :class => 'new_comment', :remote => true) do = person_image_tag(current_user) %p = label_tag "comment_text_on_#{post_id}", t('.comment') = text_area_tag :text, nil, :rows => 2, :class => "comment_box",:id => "comment_text_on_#{post_id}" - = hidden_field_tag :post_id, post_id, :id => "post_id_on_#{post_id}" .submit_button = submit_tag t('.comment'), :id => "comment_submit_#{post_id}", :class => "comment_submit button creation", :disable_with => t('.commenting') diff --git a/app/views/comments/_new_comment.mobile.haml b/app/views/comments/_new_comment.mobile.haml index 08ae44a00..6bc495c2d 100644 --- a/app/views/comments/_new_comment.mobile.haml +++ b/app/views/comments/_new_comment.mobile.haml @@ -2,7 +2,7 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -= form_tag( comments_path, :id => "new_comment_on_#{post_id}", :class => 'new_comment') do += form_tag( post_comments_path(post_id), :id => "new_comment_on_#{post_id}", :class => 'new_comment') do = hidden_field_tag :post_id, post_id, :id => "post_id_on_#{post_id}" = text_area_tag :text, nil, :rows => 2, :class => "comment_box",:id => "comment_text_on_#{post_id}" diff --git a/app/views/likes/_likes_container.haml b/app/views/likes/_likes_container.haml index eb39d2136..1e1b03fe0 100644 --- a/app/views/likes/_likes_container.haml +++ b/app/views/likes/_likes_container.haml @@ -6,7 +6,7 @@ .likes_container .likes = image_tag('icons/heart.svg') - = link_to t('likes.likes.people_like_this', :count => likes_count), status_message_likes_path(post_id), :class => "expand_likes" + = link_to t('likes.likes.people_like_this', :count => likes_count), post_likes_path(post_id), :class => "expand_likes" %span.hidden.likes_list /= render 'likes/likes', :likes => likes diff --git a/config/routes.rb b/config/routes.rb index 8032d9cca..b65608746 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,11 +12,12 @@ Diaspora::Application.routes.draw do end resources :status_messages, :only => [:new, :create] do - resources :likes, :only => [:create, :destroy, :index] end - resources :comments, :only => [:create, :destroy] - resources :posts, :only => [:show, :destroy] + resources :posts, :only => [:show, :destroy] do + resources :likes, :only => [:create, :destroy, :index] + resources :comments, :only => [:create, :destroy] + end get 'bookmarklet' => 'status_messages#bookmarklet' get 'p/:id' => 'publics#post', :as => 'public_post' diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 8b1f3dd18..31a0e3ad8 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -80,13 +80,13 @@ describe CommentsController do it 'lets the user delete his comment' do alice.should_receive(:retract).with(@comment) - delete :destroy, :format => "js", :id => @comment.id + delete :destroy, :format => "js", :post_id => 1, :id => @comment.id response.status.should == 204 end it "lets the user destroy other people's comments" do alice.should_receive(:retract).with(@comment2) - delete :destroy, :format => "js", :id => @comment2.id + delete :destroy, :format => "js", :post_id => 1, :id => @comment2.id response.status.should == 204 end end @@ -101,18 +101,18 @@ describe CommentsController do it 'let the user delete his comment' do alice.should_receive(:retract).with(@comment) - delete :destroy, :format => "js", :id => @comment.id + delete :destroy, :format => "js", :post_id => 1, :id => @comment.id response.status.should == 204 end it 'does not let the user destroy comments he does not own' do alice.should_not_receive(:retract).with(@comment2) - delete :destroy, :format => "js", :id => @comment3.id + delete :destroy, :format => "js", :post_id => 1, :id => @comment3.id response.status.should == 403 end end it 'renders nothing and 404 on a nonexistent comment' do - delete :destroy, :id => 343415 + delete :destroy, :post_id => 1, :id => 343415 response.status.should == 404 response.body.strip.should be_empty end diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index b5e37fb42..e30f2954d 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -18,11 +18,11 @@ describe LikesController do describe '#create' do let(:like_hash) { {:positive => 1, - :status_message_id => "#{@post.id}"} + :post_id => "#{@post.id}"} } let(:dislike_hash) { {:positive => 0, - :status_message_id => "#{@post.id}"} + :post_id => "#{@post.id}"} } context "on my own post" do @@ -77,19 +77,19 @@ describe LikesController do end it 'returns a 404 for a post not visible to the user' do sign_in eve - get :index, :status_message_id => @message.id + get :index, :post_id => @message.id end it 'returns an array of likes for a post' do like = bob.build_like(:positive => true, :post => @message) like.save! - get :index, :status_message_id => @message.id + get :index, :post_id => @message.id assigns[:likes].map(&:id).should == @message.likes.map(&:id) end it 'returns an empty array for a post with no likes' do - get :index, :status_message_id => @message.id + get :index, :post_id => @message.id assigns[:likes].should == [] end end @@ -103,7 +103,7 @@ describe LikesController do it 'lets a user destroy their like' do expect { - delete :destroy, :format => "js", :status_message_id => @like.post_id, :id => @like.id + delete :destroy, :format => "js", :post_id => @like.post_id, :id => @like.id }.should change(Like, :count).by(-1) response.status.should == 200 end @@ -113,7 +113,7 @@ describe LikesController do like2.save expect { - delete :destroy, :format => "js", :status_message_id => like2.post_id, :id => like2.id + delete :destroy, :format => "js", :post_id => like2.post_id, :id => like2.id }.should_not change(Like, :count) response.status.should == 403