about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-09-09 20:04:34 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-09 20:04:34 +0200
commit3cc47beb6e1f646baca64fdf56168e2f2e2bc726 (patch)
tree295d9442bec8fa7434b6a2c37a6cb835a3725dfd /spec
parent735b4cc62e3fb9ef7a10b657c8e437ac0cb3d1fe (diff)
Refactored generation of unique tags, URIs and object URLs into own classes,
as well as formatting of content
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/oauth/applications_controller_spec.rb9
-rw-r--r--spec/helpers/application_helper_spec.rb54
-rw-r--r--spec/helpers/atom_builder_helper_spec.rb12
-rw-r--r--spec/lib/feed_manager_spec.rb23
-rw-r--r--spec/lib/formatter_spec.rb39
-rw-r--r--spec/lib/tag_manager_spec.rb107
-rw-r--r--spec/models/account_spec.rb4
-rw-r--r--spec/models/media_attachment_spec.rb2
8 files changed, 184 insertions, 66 deletions
diff --git a/spec/controllers/oauth/applications_controller_spec.rb b/spec/controllers/oauth/applications_controller_spec.rb
index 350d5d521..ecd8b16c6 100644
--- a/spec/controllers/oauth/applications_controller_spec.rb
+++ b/spec/controllers/oauth/applications_controller_spec.rb
@@ -1,8 +1,15 @@
 require 'rails_helper'
 
 RSpec.describe Oauth::ApplicationsController, type: :controller do
+  before do
+    sign_in Fabricate(:user), scope: :user
+  end
+
   describe 'GET #index' do
-    it 'returns http success'
+    it 'returns http success' do
+      get :index
+      expect(response).to have_http_status(:success)
+    end
   end
 
   describe 'POST #create' do
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 9f68a504a..c2063c995 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -1,59 +1,5 @@
 require 'rails_helper'
 
 RSpec.describe ApplicationHelper, type: :helper do
-  let(:local_domain) { Rails.configuration.x.local_domain }
 
-  describe '#unique_tag' do
-    it 'returns a string' do
-      expect(helper.unique_tag(Time.now, 12, 'Status')).to be_a String
-    end
-  end
-
-  describe '#unique_tag_to_local_id' do
-    it 'returns the ID part' do
-      expect(helper.unique_tag_to_local_id("tag:#{local_domain};objectId=12:objectType=Status", 'Status')).to eql '12'
-    end
-  end
-
-  describe '#local_id?' do
-    it 'returns true for a local ID' do
-      expect(helper.local_id?("tag:#{local_domain};objectId=12:objectType=Status")).to be true
-    end
-
-    it 'returns false for a foreign ID' do
-      expect(helper.local_id?('tag:foreign.tld;objectId=12:objectType=Status')).to be false
-    end
-  end
-
-  describe '#linkify' do
-    let(:alice) { Fabricate(:account, username: 'alice') }
-    let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', url: 'http://example.com/bob') }
-
-    it 'turns mention of remote user into link' do
-      status = Fabricate(:status, text: 'Hello @bob@example.com', account: bob)
-      status.mentions.create(account: bob)
-      expect(helper.linkify(status)).to match('<a href="http://example.com/bob" class="mention">@<span>bob@example.com</span></a>')
-    end
-
-    it 'turns mention of local user into link' do
-      status = Fabricate(:status, text: 'Hello @alice', account: bob)
-      status.mentions.create(account: alice)
-      expect(helper.linkify(status)).to match('<a href="http://test.host/users/alice" class="mention">@<span>alice</span></a>')
-    end
-
-    it 'leaves mention of unresolvable user alone' do
-      status = Fabricate(:status, text: 'Hello @foo', account: bob)
-      expect(helper.linkify(status)).to match('Hello @foo')
-    end
-  end
-
-  describe '#account_from_mentions' do
-    let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
-    let(:status) { Fabricate(:status, text: 'Hello @bob@example.com', account: bob) }
-    let(:mentions) { [Mention.create(status: status, account: bob)] }
-
-    it 'returns account' do
-      expect(helper.account_from_mentions('bob@example.com', mentions)).to eq bob
-    end
-  end
 end
diff --git a/spec/helpers/atom_builder_helper_spec.rb b/spec/helpers/atom_builder_helper_spec.rb
index 7366b5b79..7e11a8a77 100644
--- a/spec/helpers/atom_builder_helper_spec.rb
+++ b/spec/helpers/atom_builder_helper_spec.rb
@@ -20,7 +20,7 @@ RSpec.describe AtomBuilderHelper, type: :helper do
   describe '#unique_id' do
     it 'creates an id' do
       time = Time.now
-      expect(used_in_builder { |xml| helper.unique_id(xml, time, 1, 'Status') }).to match "<id>#{helper.unique_tag(time, 1, 'Status')}</id>"
+      expect(used_in_builder { |xml| helper.unique_id(xml, time, 1, 'Status') }).to match "<id>#{TagManager.instance.unique_tag(time, 1, 'Status')}</id>"
     end
   end
 
@@ -146,18 +146,10 @@ RSpec.describe AtomBuilderHelper, type: :helper do
     let(:account) { Fabricate(:account, username: 'alice') }
 
     it 'creates a link' do
-      expect(used_in_builder { |xml| helper.link_mention(xml, account) }).to match '<link rel="mentioned" href="http://test.host/users/alice"/>'
+      expect(used_in_builder { |xml| helper.link_mention(xml, account) }).to match '<link rel="mentioned" href="https://cb6e6126.ngrok.io/users/alice"/>'
     end
   end
 
-  describe '#disambiguate_uri' do
-    pending
-  end
-
-  describe '#disambiguate_url' do
-    pending
-  end
-
   describe '#include_author' do
     pending
   end
diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb
new file mode 100644
index 000000000..4501e27b7
--- /dev/null
+++ b/spec/lib/feed_manager_spec.rb
@@ -0,0 +1,23 @@
+require 'rails_helper'
+
+RSpec.describe FeedManager do
+  describe '#key' do
+    subject { FeedManager.instance.key(:home, 1) }
+
+    it 'returns a string' do
+      expect(subject).to be_a String
+    end
+  end
+
+  describe '#filter_status?' do
+    let(:followee) { Fabricate(:account, username: 'alice') }
+    let(:status)   { Fabricate(:status, text: 'Hello world', account: followee) }
+    let(:follower) { Fabricate(:account, username: 'bob') }
+
+    subject { FeedManager.instance.filter_status?(status, follower) }
+
+    it 'returns a boolean value' do
+      expect(subject).to be false
+    end
+  end
+end
diff --git a/spec/lib/formatter_spec.rb b/spec/lib/formatter_spec.rb
new file mode 100644
index 000000000..36c4af748
--- /dev/null
+++ b/spec/lib/formatter_spec.rb
@@ -0,0 +1,39 @@
+require 'rails_helper'
+
+RSpec.describe Formatter do
+  let(:account)       { Fabricate(:account, username: 'alice') }
+  let(:local_status)  { Fabricate(:status, text: 'Hello world http://google.com', account: account) }
+  let(:remote_status) { Fabricate(:status, text: '<script>alert("Hello")</script> Beep boop', uri: 'beepboop', account: account) }
+
+  describe '#format' do
+    subject { Formatter.instance.format(local_status) }
+
+    it 'returns a string' do
+      expect(subject).to be_a String
+    end
+
+    it 'contains plain text' do
+      expect(subject).to match('Hello world')
+    end
+
+    it 'contains a link' do
+      expect(subject).to match('<a rel="nofollow noopener" href="http://google.com">http://google.com</a>')
+    end
+  end
+
+  describe '#reformat' do
+    subject { Formatter.instance.format(remote_status) }
+
+    it 'returns a string' do
+      expect(subject).to be_a String
+    end
+
+    it 'contains plain text' do
+      expect(subject).to match('Beep boop')
+    end
+
+    it 'does not contain scripts' do
+      expect(subject).to_not match('<script>alert("Hello")</script>')
+    end
+  end
+end
diff --git a/spec/lib/tag_manager_spec.rb b/spec/lib/tag_manager_spec.rb
new file mode 100644
index 000000000..b60584253
--- /dev/null
+++ b/spec/lib/tag_manager_spec.rb
@@ -0,0 +1,107 @@
+require 'rails_helper'
+
+RSpec.describe TagManager do
+  let(:local_domain) { Rails.configuration.x.local_domain }
+
+  describe '#unique_tag' do
+    it 'returns a string' do
+      expect(TagManager.instance.unique_tag(Time.now, 12, 'Status')).to be_a String
+    end
+  end
+
+  describe '#unique_tag_to_local_id' do
+    it 'returns the ID part' do
+      expect(TagManager.instance.unique_tag_to_local_id("tag:#{local_domain};objectId=12:objectType=Status", 'Status')).to eql '12'
+    end
+  end
+
+  describe '#local_id?' do
+    it 'returns true for a local ID' do
+      expect(TagManager.instance.local_id?("tag:#{local_domain};objectId=12:objectType=Status")).to be true
+    end
+
+    it 'returns false for a foreign ID' do
+      expect(TagManager.instance.local_id?('tag:foreign.tld;objectId=12:objectType=Status')).to be false
+    end
+  end
+
+  describe '#uri_for' do
+    let(:alice)  { Fabricate(:account, username: 'alice') }
+    let(:bob)    { Fabricate(:account, username: 'bob') }
+    let(:status) { Fabricate(:status, text: 'Hello world', account: alice) }
+
+    subject { TagManager.instance.uri_for(target) }
+
+    context 'Account' do
+      let(:target) { alice }
+
+      it 'returns a string' do
+        expect(subject).to be_a String
+      end
+    end
+
+    context 'Status' do
+      let(:target) { status }
+
+      it 'returns a string' do
+        expect(subject).to be_a String
+      end
+    end
+
+    context 'Follow' do
+      let(:target) { Fabricate(:follow, account: alice, target_account: bob) }
+
+      it 'returns a string' do
+        expect(subject).to be_a String
+      end
+    end
+
+    context 'Favourite' do
+      let(:target) { Fabricate(:favourite, account: bob, status: status) }
+
+      it 'returns a string' do
+        expect(subject).to be_a String
+      end
+    end
+  end
+
+  describe '#url_for' do
+    let(:alice)  { Fabricate(:account, username: 'alice') }
+    let(:bob)    { Fabricate(:account, username: 'bob') }
+    let(:status) { Fabricate(:status, text: 'Hello world', account: alice) }
+
+    subject { TagManager.instance.url_for(target) }
+
+    context 'Account' do
+      let(:target) { alice }
+
+      it 'returns a URL' do
+        expect(subject).to be_a String
+      end
+    end
+
+    context 'Status' do
+      let(:target) { status }
+
+      it 'returns a URL' do
+        expect(subject).to be_a String
+      end
+    end
+
+    context 'Follow' do
+      let(:target) { Fabricate(:follow, account: alice, target_account: bob) }
+
+      it 'returns a URL' do
+        expect(subject).to be_a String
+      end
+    end
+
+    context 'Favourite' do
+      let(:target) { Fabricate(:favourite, account: bob, status: status) }
+
+      it 'returns a URL' do
+        expect(subject).to be_a String
+      end
+    end
+  end
+end
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index 9d19fd3b4..93731d1e4 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -112,6 +112,10 @@ RSpec.describe Account, type: :model do
     pending
   end
 
+  describe '.find_remote' do
+    pending
+  end
+
   describe 'MENTION_RE' do
     subject { Account::MENTION_RE }
 
diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb
index 0a1627684..5995aa4f4 100644
--- a/spec/models/media_attachment_spec.rb
+++ b/spec/models/media_attachment_spec.rb
@@ -1,5 +1,5 @@
 require 'rails_helper'
 
 RSpec.describe MediaAttachment, type: :model do
-  pending "add some examples to (or delete) #{__FILE__}"
+
 end