From c3845de76a2989beee38e7944baef0c439370ea4 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Wed, 9 Jul 2014 12:00:14 -0400 Subject: [PATCH] Fix bug in inline discussion post creation Commit 994ccd1 contained a bug that caused new posts created via the courseware interface to not get posted to the correct topic. They would appear to work but would actually be posted to the "undefined" topic. This has now been fixed. JIRA: FOR-154 --- .../discussion/view/new_post_view_spec.coffee | 37 ++++++++++++++++++- .../discussion/discussion_module_view.coffee | 3 +- .../src/discussion/views/new_post_view.coffee | 1 + 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee b/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee index 1f8b9ad627..7cea95b0e3 100644 --- a/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee +++ b/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee @@ -23,6 +23,17 @@ describe "NewPostView", -> + + @@ -92,6 +103,9 @@ describe "NewPostView", -> window.$$course_id = "edX/999/test" spyOn(DiscussionUtil, "makeWmdEditor") @discussion = new Discussion([], {pages: 1}) + + describe "Drop down works correct", -> + beforeEach -> @view = new NewPostView( el: $(".new-post-article"), collection: @discussion, @@ -122,8 +136,6 @@ describe "NewPostView", -> @parent_category_text = "Basic Question Types" @selected_option_text = "Selection From Options" - describe "Drop down works correct", -> - it "completely show parent category and sub-category", -> complete_text = @parent_category_text + " / " + @selected_option_text selected_text_width = @view.getNameWidth(complete_text) @@ -158,3 +170,24 @@ describe "NewPostView", -> @view.$el.find( "ul.topic_menu li[role='menuitem'] > a" )[1].click() dropdown_text = @view.$el.find(".form-topic-drop > a").text() expect(dropdown_text.indexOf("/ span>")).toEqual(-1) + + it "posts to the correct URL", -> + topicId = "test_topic" + spyOn($, "ajax").andCallFake( + (params) -> + expect(params.url.path()).toEqual(DiscussionUtil.urlFor("create_thread", topicId)) + {always: ->} + ) + view = new NewPostView( + el: $(".new-post-article"), + collection: @discussion, + course_settings: new DiscussionCourseSettings({ + allow_anonymous: false, + allow_anonymous_to_peers: false + }), + mode: "inline", + topicId: topicId + ) + view.render() + view.$(".new-post-form").submit() + expect($.ajax).toHaveBeenCalled() diff --git a/common/static/coffee/src/discussion/discussion_module_view.coffee b/common/static/coffee/src/discussion/discussion_module_view.coffee index 11c353677b..811305037b 100644 --- a/common/static/coffee/src/discussion/discussion_module_view.coffee +++ b/common/static/coffee/src/discussion/discussion_module_view.coffee @@ -107,7 +107,8 @@ if Backbone? @newPostView = new NewPostView( el: @newPostForm, collection: @discussion, - course_settings: @course_settings + course_settings: @course_settings, + topicId: discussionId ) @newPostView.render() @discussion.on "add", @addThread diff --git a/common/static/coffee/src/discussion/views/new_post_view.coffee b/common/static/coffee/src/discussion/views/new_post_view.coffee index 24696323bd..cd4d959f3a 100644 --- a/common/static/coffee/src/discussion/views/new_post_view.coffee +++ b/common/static/coffee/src/discussion/views/new_post_view.coffee @@ -7,6 +7,7 @@ if Backbone? throw new Error("invalid mode: " + @mode) @course_settings = options.course_settings @maxNameWidth = 100 + @topicId = options.topicId render: () -> if @mode is "tab"