From 9ba03c8aacc4e0d11c1f2cb680816c1e761f9458 Mon Sep 17 00:00:00 2001
From: Waqas Khalid <waqas.khalid@arbisoft.com>
Date: Fri, 17 Oct 2014 16:07:10 +0500
Subject: [PATCH] Post with the discussion id containing dots uneditable

When user try to edit the post under dicussion whose
id contains dots it doesn't allow user to edit taht
post.

TNL-607
---
 .../view/discussion_thread_edit_view_spec.js  | 54 ++++++++++++++++---
 .../views/discussion_topic_menu_view.js       |  2 +-
 2 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/common/static/coffee/spec/discussion/view/discussion_thread_edit_view_spec.js b/common/static/coffee/spec/discussion/view/discussion_thread_edit_view_spec.js
index a75303ca2e0..76487445bdd 100644
--- a/common/static/coffee/spec/discussion/view/discussion_thread_edit_view_spec.js
+++ b/common/static/coffee/spec/discussion/view/discussion_thread_edit_view_spec.js
@@ -26,16 +26,16 @@
             };
         });
 
-        testUpdate = function(view, thread) {
+        testUpdate = function(view, thread, newTopicId, newTopicName) {
             spyOn($, 'ajax').andCallFake(function(params) {
                 expect(params.url.path()).toEqual(DiscussionUtil.urlFor('update_thread', 'dummy_id'));
                 expect(params.data.thread_type).toBe('discussion');
-                expect(params.data.commentable_id).toBe('other_topic');
+                expect(params.data.commentable_id).toBe(newTopicId);
                 expect(params.data.title).toBe('changed thread title');
                 params.success();
                 return {always: function() {}};
             });
-            view.$el.find('a.topic-title')[1].click(); // set new topic
+            view.$el.find('a.topic-title[data-discussion-id="'+newTopicId+'"]').click(); // set new topic
             view.$('.edit-post-title').val('changed thread title'); // set new title
             view.$("label[for$='post-type-discussion']").click(); // set new thread type
             view.$('.post-update').click();
@@ -43,20 +43,20 @@
 
             expect(thread.get('title')).toBe('changed thread title');
             expect(thread.get('thread_type')).toBe('discussion');
-            expect(thread.get('commentable_id')).toBe('other_topic');
-            expect(thread.get('courseware_title')).toBe('Other Topic');
+            expect(thread.get('commentable_id')).toBe(newTopicId);
+            expect(thread.get('courseware_title')).toBe(newTopicName);
             expect(view.$('.edit-post-title')).toHaveValue('');
             expect(view.$('.wmd-preview p')).toHaveText('');
         };
 
         it('can save new data correctly in tab mode', function() {
             this.createEditView();
-            testUpdate(this.view, this.thread);
+            testUpdate(this.view, this.thread, 'other_topic', 'Other Topic');
         });
 
         it('can save new data correctly in inline mode', function() {
             this.createEditView({"mode": "inline"});
-            testUpdate(this.view, this.thread);
+            testUpdate(this.view, this.thread, 'other_topic', 'Other Topic');
         });
 
         testCancel = function(view) {
@@ -73,5 +73,45 @@
             this.createEditView({"mode": "inline"});
             testCancel(this.view);
         });
+        describe('renderComments', function() {
+            beforeEach(function() {
+                this.course_settings = new DiscussionCourseSettings({
+                    'category_map': {
+                        'children': ['Topic', 'General', 'Basic Question'],
+                        'entries': {
+                            'Topic': {
+                                'is_cohorted': true,
+                                'id': 'topic'
+                            },
+                            "General": {
+                                "sort_key": "General",
+                                "is_cohorted": false,
+                                "id": "6.00.1x_General"
+                            },
+                            "Basic Question": {
+                                "is_cohorted": false,
+                                "id": "6>00'1x\"Basic_Question"
+                            }
+                        }
+                    },
+                    'is_cohorted': true
+                });
+            });
+            it('can save new data correctly for current discussion id without dots', function () {
+                this.createEditView({topicId: "topic"});
+                testUpdate(this.view, this.thread, "6.00.1x_General", "General");
+            });
+
+            it('can save new data correctly for current discussion id with dots', function () {
+                this.createEditView({topicId: "6.00.1x_General"});
+                testUpdate(this.view, this.thread, "6>00'1x\"Basic_Question", "Basic Question");
+            });
+
+            it('can save new data correctly for current discussion id with special characters', function () {
+                this.createEditView({topicId: "6>00'1x\"Basic_Question"});
+                testUpdate(this.view, this.thread, "6.00.1x_General", "General");
+            });
+        });
+
     });
 }).call(this);
diff --git a/common/static/coffee/src/discussion/views/discussion_topic_menu_view.js b/common/static/coffee/src/discussion/views/discussion_topic_menu_view.js
index 57e44e626aa..c205a7535ed 100644
--- a/common/static/coffee/src/discussion/views/discussion_topic_menu_view.js
+++ b/common/static/coffee/src/discussion/views/discussion_topic_menu_view.js
@@ -40,7 +40,7 @@
                 this.selectedTopic = this.$('.js-selected-topic');
                 this.hideTopicDropdown();
                 if (this.getCurrentTopicId()) {
-                    this.setTopic(this.$('a.topic-title').filter('[data-discussion-id=' + this.getCurrentTopicId() + ']'));
+                    this.setTopic(this.$('a.topic-title').filter('[data-discussion-id="' + this.getCurrentTopicId() + '"]'));
                 } else {
                     this.setTopic(this.$('a.topic-title').first());
                 }
-- 
GitLab