diff --git a/app/assets/javascripts/admin/controllers/admin_flags_controller.js b/app/assets/javascripts/admin/controllers/admin_flags_controller.js index 46485ffc3e6..77ca65d793f 100644 --- a/app/assets/javascripts/admin/controllers/admin_flags_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_flags_controller.js @@ -46,12 +46,12 @@ Discourse.AdminFlagsController = Ember.ArrayController.extend({ Deletes a post @method deletePost - @param {Discourse.FlaggedPost} item The post to delete + @param {Discourse.FlaggedPost} post The post to delete **/ - deletePost: function(item) { + deletePost: function(post) { var adminFlagsController = this; - item.deletePost().then((function() { - adminFlagsController.removeObject(item); + post.deletePost().then((function() { + adminFlagsController.removeObject(post); }), function() { bootbox.alert(I18n.t("admin.flags.error")); }); diff --git a/app/assets/javascripts/admin/models/flagged_post.js b/app/assets/javascripts/admin/models/flagged_post.js index 34a4c095310..a6802e65989 100644 --- a/app/assets/javascripts/admin/models/flagged_post.js +++ b/app/assets/javascripts/admin/models/flagged_post.js @@ -66,7 +66,7 @@ Discourse.FlaggedPost = Discourse.Post.extend({ }.property('flaggedForSpam'), deletePost: function() { - if (this.get('post_number') === '1') { + if (this.get('post_number') === 1) { return Discourse.ajax('/t/' + this.topic_id, { type: 'DELETE', cache: false }); } else { return Discourse.ajax('/posts/' + this.id, { type: 'DELETE', cache: false }); diff --git a/app/assets/javascripts/discourse/views/post_menu_view.js b/app/assets/javascripts/discourse/views/post_menu_view.js index 06c461363a3..e49e13c04d8 100644 --- a/app/assets/javascripts/discourse/views/post_menu_view.js +++ b/app/assets/javascripts/discourse/views/post_menu_view.js @@ -75,7 +75,7 @@ Discourse.PostMenuView = Discourse.View.extend({ if (post.get('post_number') === 1) { - // If if it's the first post, the delete/undo actions are related to the topic + // If it's the first post, the delete/undo actions are related to the topic var topic = post.get('topic'); if (topic.get('deleted_at')) { if (!topic.get('details.can_recover')) { return; } diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index eabf5d9017d..990d233ad2c 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -154,7 +154,6 @@ class PostsController < ApplicationController raise Discourse::InvalidParameters.new(:post_ids) if posts.blank? # Make sure we can delete the posts - posts.each {|p| guardian.ensure_can_delete!(p) } Post.transaction do diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index b97f6f08697..1280ebe8589 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -231,7 +231,7 @@ describe PostsController do update_params.delete(:post) lambda { xhr :put, :update, update_params - }.should raise_error(ActionController::ParameterMissing) + }.should raise_error(ActionController::ParameterMissing) end it "raises an error when the user doesn't have permission to see the post" do diff --git a/test/javascripts/controllers/admin_email_index_controller_test.js b/test/javascripts/admin/controllers/admin_email_index_controller_test.js similarity index 100% rename from test/javascripts/controllers/admin_email_index_controller_test.js rename to test/javascripts/admin/controllers/admin_email_index_controller_test.js diff --git a/test/javascripts/controllers/admin_email_preview_digest_controller_test.js b/test/javascripts/admin/controllers/admin_email_preview_digest_controller_test.js similarity index 100% rename from test/javascripts/controllers/admin_email_preview_digest_controller_test.js rename to test/javascripts/admin/controllers/admin_email_preview_digest_controller_test.js diff --git a/test/javascripts/admin/models/flagged_post_test.js b/test/javascripts/admin/models/flagged_post_test.js new file mode 100644 index 00000000000..e59441ff79c --- /dev/null +++ b/test/javascripts/admin/models/flagged_post_test.js @@ -0,0 +1,19 @@ +module("Discourse.FlaggedPost"); + +test('delete first post', function() { + this.stub(Discourse, 'ajax'); + + Discourse.FlaggedPost.create({ id: 1, topic_id: 2, post_number: 1 }) + .deletePost(); + + ok(Discourse.ajax.calledWith("/t/2", { type: 'DELETE', cache: false }), "it deleted the topic"); +}); + +test('delete second post', function() { + this.stub(Discourse, 'ajax'); + + Discourse.FlaggedPost.create({ id: 1, topic_id: 2, post_number: 2 }) + .deletePost(); + + ok(Discourse.ajax.calledWith("/posts/1", { type: 'DELETE', cache: false }), "it deleted the post"); +});