about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2018-06-12 16:39:30 -0500
committerDavid Yip <yipdw@member.fsf.org>2018-06-12 16:39:30 -0500
commite931cf656d1de6d89b5b048d8f1de15be7b52690 (patch)
treeb1c0c66b6a88b56c422ea8be1dbef77e42afae72 /spec
parent97d2df77aae687c983c1294ebcd3962e4f9d985c (diff)
parent34f1fd2a621ca869c17009487e2f10063812fbd0 (diff)
Merge remote-tracking branch 'glitchsoc/master' into 454-allow-keyword-mutes-to-skip-mentions
  Conflicts:
 	app/models/glitch/keyword_mute.rb
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/web/embeds_controller_spec.rb52
-rw-r--r--spec/controllers/settings/sessions_controller_spec.rb30
-rw-r--r--spec/lib/status_finder_spec.rb7
-rw-r--r--spec/models/glitch/keyword_mute_spec.rb8
4 files changed, 91 insertions, 6 deletions
diff --git a/spec/controllers/api/web/embeds_controller_spec.rb b/spec/controllers/api/web/embeds_controller_spec.rb
new file mode 100644
index 000000000..6b7297189
--- /dev/null
+++ b/spec/controllers/api/web/embeds_controller_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Api::Web::EmbedsController do
+  render_views
+
+  let(:user) { Fabricate(:user) }
+  before { sign_in user }
+
+  describe 'POST #create' do
+    subject(:response) { post :create, params: { url: url } }
+    subject(:body) { JSON.parse(response.body, symbolize_names: true) }
+
+    context 'when successfully finds status' do
+      let(:status) { Fabricate(:status) }
+      let(:url) { "http://#{ Rails.configuration.x.web_domain }/@#{status.account.username}/#{status.id}" }
+
+      it 'returns a right response' do
+        expect(response).to have_http_status :ok
+        expect(body[:author_name]).to eq status.account.username
+      end
+    end
+
+    context 'when fails to find status' do
+      let(:url) { 'https://host.test/oembed.html' }
+      let(:service_instance) { double('fetch_oembed_service') }
+
+      before do
+        allow(FetchOEmbedService).to receive(:new) { service_instance }
+        allow(service_instance).to receive(:call) { call_result }
+      end
+
+      context 'when successfully fetching oembed' do
+        let(:call_result) { { result: :ok } }
+
+        it 'returns a right response' do
+          expect(response).to have_http_status :ok
+          expect(body[:result]).to eq 'ok'
+        end
+      end
+
+      context 'when fails to fetch oembed' do
+        let(:call_result) { nil }
+
+        it 'returns a right response' do
+          expect(response).to have_http_status :not_found
+        end
+      end
+    end
+  end
+end
diff --git a/spec/controllers/settings/sessions_controller_spec.rb b/spec/controllers/settings/sessions_controller_spec.rb
new file mode 100644
index 000000000..52b204a6a
--- /dev/null
+++ b/spec/controllers/settings/sessions_controller_spec.rb
@@ -0,0 +1,30 @@
+require 'rails_helper'
+
+describe Settings::SessionsController do
+  render_views
+
+  let(:user) { Fabricate(:user) }
+  let(:session_activation) { Fabricate(:session_activation, user: user) }
+  before { sign_in user, scope: :user }
+
+  describe 'DELETE #destroy' do
+    subject { delete :destroy, params: { id: id } }
+
+    context 'when session activation exists' do
+      let(:id) { session_activation.id }
+
+      it 'destroys session activation' do
+        is_expected.to redirect_to edit_user_registration_path
+        expect(SessionActivation.find_by(id: id)).to be_nil
+      end
+    end
+
+    context 'when session activation does not exist' do
+      let(:id) { session_activation.id + 1000 }
+
+      it 'destroys session activation' do
+        is_expected.to have_http_status :not_found
+      end
+    end
+  end
+end
diff --git a/spec/lib/status_finder_spec.rb b/spec/lib/status_finder_spec.rb
index 3ef086736..6b4ee434f 100644
--- a/spec/lib/status_finder_spec.rb
+++ b/spec/lib/status_finder_spec.rb
@@ -6,10 +6,11 @@ describe StatusFinder do
   include RoutingHelper
 
   describe '#status' do
+    subject { described_class.new(url) }
+
     context 'with a status url' do
       let(:status) { Fabricate(:status) }
       let(:url) { short_account_status_url(account_username: status.account.username, id: status.id) }
-      subject { described_class.new(url) }
 
       it 'finds the stream entry' do
         expect(subject.status).to eq(status)
@@ -27,7 +28,6 @@ describe StatusFinder do
     context 'with a stream entry url' do
       let(:stream_entry) { Fabricate(:stream_entry) }
       let(:url) { account_stream_entry_url(stream_entry.account, stream_entry) }
-      subject { described_class.new(url) }
 
       it 'finds the stream entry' do
         expect(subject.status).to eq(stream_entry.status)
@@ -37,7 +37,6 @@ describe StatusFinder do
     context 'with a remote url even if id exists on local' do
       let(:status) { Fabricate(:status) }
       let(:url) { "https://example.com/users/test/statuses/#{status.id}" }
-      subject { described_class.new(url) }
 
       it 'raises an error' do
         expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
@@ -46,7 +45,6 @@ describe StatusFinder do
 
     context 'with a plausible url' do
       let(:url) { 'https://example.com/users/test/updates/123/embed' }
-      subject { described_class.new(url) }
 
       it 'raises an error' do
         expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
@@ -55,7 +53,6 @@ describe StatusFinder do
 
     context 'with an unrecognized url' do
       let(:url) { 'https://example.com/about' }
-      subject { described_class.new(url) }
 
       it 'raises an error' do
         expect { subject.status }.to raise_error(ActiveRecord::RecordNotFound)
diff --git a/spec/models/glitch/keyword_mute_spec.rb b/spec/models/glitch/keyword_mute_spec.rb
index de1376e4c..58c9d89df 100644
--- a/spec/models/glitch/keyword_mute_spec.rb
+++ b/spec/models/glitch/keyword_mute_spec.rb
@@ -81,12 +81,18 @@ RSpec.describe Glitch::KeywordMute, type: :model do
         expect(matcher.matches?('(hot take)', Unscoped)).to be_truthy
       end
 
-      it 'escapes metacharacters in keywords' do
+      it 'escapes metacharacters in whole-word keywords' do
         Glitch::KeywordMute.create!(account: alice, keyword: '(hot take)')
 
         expect(matcher.matches?('(hot take)', Unscoped)).to be_truthy
       end
 
+      it 'escapes metacharacters in non-whole-word keywords' do
+        Glitch::KeywordMute.create!(account: alice, keyword: '(-', whole_word: false)
+
+        expect(matcher.matches?('bad (-)')).to be_truthy
+      end
+
       it 'uses case-folding rules appropriate for more than just English' do
         Glitch::KeywordMute.create!(account: alice, keyword: 'großeltern')