about summary refs log tree commit diff
path: root/spec/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-05-12 19:09:21 +0200
committerGitHub <noreply@github.com>2017-05-12 19:09:21 +0200
commit5abdc77c8060a62ecf2259a1e9d63e862b9f7be7 (patch)
tree95b0a69d8943d6171ad19257af1655cd733fc245 /spec/models
parentb5a9c6b3d292abc7e47d8a6f830f6b5589c04862 (diff)
Add conversation model, <ostatus:conversation /> (#3016)
* Add <ostatus:conversation /> tag to Atom input/output

Only uses ref attribute (not href) because href would be
the alternate link that's always included also.

Creates new conversation for every non-reply status. Carries
over conversation for every reply. Keeps remote URIs verbatim,
generates local URIs on the fly like the rest of them.

* Fix conversation migration

* More spec coverage for status before_create

* Prevent n+1 query when generating Atom with the new conversations

* Improve code style

* Remove redundant local variable
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/conversation_spec.rb13
-rw-r--r--spec/models/status_spec.rb19
2 files changed, 32 insertions, 0 deletions
diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb
new file mode 100644
index 000000000..8b5e4fdaf
--- /dev/null
+++ b/spec/models/conversation_spec.rb
@@ -0,0 +1,13 @@
+require 'rails_helper'
+
+RSpec.describe Conversation, type: :model do
+  describe '#local?' do
+    it 'returns true when URI is nil' do
+      expect(Fabricate(:conversation).local?).to be true
+    end
+
+    it 'returns false when URI is not nil' do
+      expect(Fabricate(:conversation, uri: 'abc').local?).to be false
+    end
+  end
+end
diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb
index f5c65f5c9..b21fcd190 100644
--- a/spec/models/status_spec.rb
+++ b/spec/models/status_spec.rb
@@ -377,4 +377,23 @@ RSpec.describe Status, type: :model do
       expect(results).to include(status)
     end
   end
+
+  describe 'before_create' do
+    it 'sets account being replied to correctly over intermediary nodes' do
+      first_status = Fabricate(:status, account: bob)
+      intermediary = Fabricate(:status, thread: first_status, account: alice)
+      final        = Fabricate(:status, thread: intermediary, account: alice)
+
+      expect(final.in_reply_to_account_id).to eq bob.id
+    end
+
+    it 'creates new conversation for stand-alone status' do
+      expect(Status.create(account: alice, text: 'First').conversation_id).to_not be_nil
+    end
+
+    it 'keeps conversation of parent node' do
+      parent = Fabricate(:status, text: 'First')
+      expect(Status.create(account: alice, thread: parent, text: 'Response').conversation_id).to eq parent.conversation_id
+    end
+  end
 end