From 83c979fb84fbc4750f7a70411bc872668f58f53d Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Tue, 27 Mar 2018 18:58:00 -0400 Subject: [PATCH] Rename `createTemporary` to `dangerouslyCreateAndAdd` Class: `ConversationController`. This function should not be used in application code as it creates potentially invalid `Conversation` instances in our global conversation collection. We keep making it available for testing purposes. --- js/conversation_controller.js | 2 +- js/views/conversation_search_view.js | 2 +- test/keychange_listener_test.js | 15 +++++++++++---- test/views/message_view_test.js | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/js/conversation_controller.js b/js/conversation_controller.js index 54719049b..a8bae8511 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -95,7 +95,7 @@ getUnsafe: function(id) { return conversations.get(id); }, - createTemporary: function(attributes) { + dangerouslyCreateAndAdd: function(attributes) { return conversations.add(attributes); }, getOrCreate: function(id, type) { diff --git a/js/views/conversation_search_view.js b/js/views/conversation_search_view.js index cb34e94a6..15649e933 100644 --- a/js/views/conversation_search_view.js +++ b/js/views/conversation_search_view.js @@ -92,7 +92,7 @@ // Creates a view to display a new contact this.new_contact_view = new Whisper.NewContactView({ el: this.$new_contact, - model: ConversationController.createTemporary({ + model: ConversationController.dangerouslyCreateAndAdd({ type: 'private', }), }).render(); diff --git a/test/keychange_listener_test.js b/test/keychange_listener_test.js index 3e8182fd0..055a8bb7f 100644 --- a/test/keychange_listener_test.js +++ b/test/keychange_listener_test.js @@ -16,9 +16,12 @@ describe('KeyChangeListener', function() { }); describe('When we have a conversation with this contact', function() { - var convo = new Whisper.Conversation({ id: phoneNumberWithKeyChange, type: 'private'}); + let convo; before(function() { - ConversationController.createTemporary(convo); + convo = ConversationController.dangerouslyCreateAndAdd({ + id: phoneNumberWithKeyChange, + type: 'private', + }); return convo.save(); }); @@ -41,9 +44,13 @@ describe('KeyChangeListener', function() { describe('When we have a group with this contact', function() { - var convo = new Whisper.Conversation({ id: 'groupId', type: 'group', members: [phoneNumberWithKeyChange] }); + let convo; before(function() { - ConversationController.createTemporary(convo); + convo = ConversationController.dangerouslyCreateAndAdd({ + id: 'groupId', + type: 'group', + members: [phoneNumberWithKeyChange], + }); return convo.save(); }); after(function() { diff --git a/test/views/message_view_test.js b/test/views/message_view_test.js index 8c40ba33f..1383c73e5 100644 --- a/test/views/message_view_test.js +++ b/test/views/message_view_test.js @@ -2,7 +2,7 @@ describe('MessageView', function() { var convo, message; before(function() { - convo = ConversationController.createTemporary({id: 'foo'}); + convo = ConversationController.dangerouslyCreateAndAdd({id: 'foo'}); message = convo.messageCollection.add({ conversationId: convo.id, body: 'hello world',