about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorJenkins <jenkins@jenkins.ninjawedding.org>2018-03-25 15:17:21 +0000
committerJenkins <jenkins@jenkins.ninjawedding.org>2018-03-25 15:17:21 +0000
commit837b3804bfed9db1cf92923c4f6202aa7117d408 (patch)
treec8b5a921754a6b40227364225002332b54d0d0dd /spec
parent995b59526b06e1f949cba59d76e5e2718a1674f6 (diff)
parent85a395fab6d7077a252bfe6f96673931ea3aa5ee (diff)
Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master
Diffstat (limited to 'spec')
-rw-r--r--spec/fabricators/notification_fabricator.rb4
-rw-r--r--spec/lib/request_spec.rb14
-rw-r--r--spec/models/notification_spec.rb10
3 files changed, 16 insertions, 12 deletions
diff --git a/spec/fabricators/notification_fabricator.rb b/spec/fabricators/notification_fabricator.rb
index b92af0683..638844e0f 100644
--- a/spec/fabricators/notification_fabricator.rb
+++ b/spec/fabricators/notification_fabricator.rb
@@ -1,4 +1,4 @@
 Fabricator(:notification) do
-  activity_id   1
-  activity_type 'Favourite'
+  activity fabricator: [:mention, :status, :follow, :follow_request, :favourite].sample
+  account
 end
diff --git a/spec/lib/request_spec.rb b/spec/lib/request_spec.rb
index 5da357c55..4d6b20dd5 100644
--- a/spec/lib/request_spec.rb
+++ b/spec/lib/request_spec.rb
@@ -39,12 +39,10 @@ describe Request do
 
   describe '#perform' do
     context 'with valid host' do
-      before do
-        stub_request(:get, 'http://example.com')
-        subject.perform
-      end
+      before { stub_request(:get, 'http://example.com') }
 
       it 'executes a HTTP request' do
+        expect { |block| subject.perform &block }.to yield_control
         expect(a_request(:get, 'http://example.com')).to have_been_made.once
       end
 
@@ -52,12 +50,20 @@ describe Request do
         allow(Addrinfo).to receive(:foreach).with('example.com', nil, nil, :SOCK_STREAM)
                                             .and_yield(Addrinfo.new(["AF_INET", 0, "example.com", "0.0.0.0"], :PF_INET, :SOCK_STREAM))
                                             .and_yield(Addrinfo.new(["AF_INET6", 0, "example.com", "2001:4860:4860::8844"], :PF_INET6, :SOCK_STREAM))
+
+        expect { |block| subject.perform &block }.to yield_control
         expect(a_request(:get, 'http://example.com')).to have_been_made.once
       end
 
       it 'sets headers' do
+        expect { |block| subject.perform &block }.to yield_control
         expect(a_request(:get, 'http://example.com').with(headers: subject.headers)).to have_been_made
       end
+
+      it 'closes underlaying connection' do
+        expect_any_instance_of(HTTP::Client).to receive(:close)
+        expect { |block| subject.perform &block }.to yield_control
+      end
     end
 
     context 'with private host' do
diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb
index 8444c8f63..c781f2a29 100644
--- a/spec/models/notification_spec.rb
+++ b/spec/models/notification_spec.rb
@@ -6,14 +6,13 @@ RSpec.describe Notification, type: :model do
   end
 
   describe '#target_status' do
-    let(:notification) { Fabricate(:notification, activity_type: type, activity: activity) }
+    let(:notification) { Fabricate(:notification, activity: activity) }
     let(:status)       { Fabricate(:status) }
     let(:reblog)       { Fabricate(:status, reblog: status) }
     let(:favourite)    { Fabricate(:favourite, status: status) }
     let(:mention)      { Fabricate(:mention, status: status) }
 
-    context 'type is :reblog' do
-      let(:type)     { :reblog }
+    context 'activity is reblog' do
       let(:activity) { reblog }
 
       it 'returns status' do
@@ -21,7 +20,7 @@ RSpec.describe Notification, type: :model do
       end
     end
 
-    context 'type is :favourite' do
+    context 'activity is favourite' do
       let(:type)     { :favourite }
       let(:activity) { favourite }
 
@@ -30,8 +29,7 @@ RSpec.describe Notification, type: :model do
       end
     end
 
-    context 'type is :mention' do
-      let(:type)     { :mention }
+    context 'activity is mention' do
       let(:activity) { mention }
 
       it 'returns status' do