diff --git a/app/coffeescripts/discussions/Reply.coffee b/app/coffeescripts/discussions/Reply.coffee index f4f8ea4c44e..0bc00c0256e 100644 --- a/app/coffeescripts/discussions/Reply.coffee +++ b/app/coffeescripts/discussions/Reply.coffee @@ -40,7 +40,7 @@ define [ attachKeyboardShortcuts: => - $('.toggle-wrapper').first().before((new KeyboardShortcuts()).render().$el) + @view.$('.toggle-wrapper').first().before((new KeyboardShortcuts()).render().$el) ## # Shows or hides the TinyMCE editor for a reply diff --git a/app/coffeescripts/models/Entry.coffee b/app/coffeescripts/models/Entry.coffee index c7e22254f47..d1e38190a66 100644 --- a/app/coffeescripts/models/Entry.coffee +++ b/app/coffeescripts/models/Entry.coffee @@ -15,8 +15,7 @@ define [ # Model representing an entry in discussion topic class Entry extends Backbone.Model - defaults: - + defaults: -> ## # Attributes persisted with the server id: null diff --git a/spec/coffeescripts/helpers/fakeENV.coffee b/spec/coffeescripts/helpers/fakeENV.coffee index 7f7dbbd2f77..d0965c242ed 100644 --- a/spec/coffeescripts/helpers/fakeENV.coffee +++ b/spec/coffeescripts/helpers/fakeENV.coffee @@ -11,6 +11,6 @@ define ['underscore'], (_) -> context_cache_key: "users/1-20111116001415" PERMISSIONS: {} - window.ENV = _.extend(defaults,options) + window.ENV = _.extend(defaults, options) - teardown: -> window.ENV = {} \ No newline at end of file + teardown: -> window.ENV = {} diff --git a/spec/coffeescripts/views/DiscussionTopic/EntryViewSpec.coffee b/spec/coffeescripts/views/DiscussionTopic/EntryViewSpec.coffee new file mode 100644 index 00000000000..f0f9e976b2b --- /dev/null +++ b/spec/coffeescripts/views/DiscussionTopic/EntryViewSpec.coffee @@ -0,0 +1,54 @@ +define [ + 'jquery' + 'compiled/models/Entry' + 'compiled/views/DiscussionTopic/EntryView' + 'compiled/discussions/Reply' + 'helpers/fakeENV' +], ($, Entry, EntryView, Reply, fakeENV) -> + + module 'EntryView', + setup: -> + fakeENV.setup + DISCUSSION: + PERMISSIONS: { CAN_REPLY: true } + CURRENT_USER: {} + THREADED: true + + teardown: -> + fakeENV.teardown() + $('#fixtures').empty() + + test 'renders', -> + entry = new Entry(id: 1, message: 'hi') + $('#fixtures').append($('
').attr('id', 'e1')) + view = new EntryView + model: entry + el: '#e1' + view.render() + ok view + + test 'two entries do not render keyboard shortcuts to the same place', -> + clock = sinon.useFakeTimers() + sinon.stub(Reply.prototype, 'edit') + $('#fixtures').append($('').attr('id', 'e1')) + $('#fixtures').append($('').attr('id', 'e2')) + + entry1 = new Entry(id: 1, message: 'hi') + entry2 = new Entry(id: 2, message: 'reply') + view1 = new EntryView + model: entry1 + el: '#e1' + view1.render() + view1.addReply() + view2 = new EntryView + model: entry2 + el: '#e2' + view2.render() + view2.addReply() + + clock.tick 1 + + equal view1.$('.tinymce-keyboard-shortcuts-toggle').length, 1 + equal view2.$('.tinymce-keyboard-shortcuts-toggle').length, 1 + + clock.restore()