about summary refs log tree commit diff
path: root/spec/controllers
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-30 16:28:58 -0400
committerGitHub <noreply@github.com>2017-05-30 16:28:58 -0400
commit1dcfb902024a7d4049306d9bc48c499856e2e429 (patch)
tree138cb9b489139095333ad26a74d92b4b8ab22ea6 /spec/controllers
parent22cf18e16f2ff07e5cd6e90b53d1b038e1956c99 (diff)
Clean up api/salmon controller (#3449)
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/api/salmon_controller_spec.rb53
1 files changed, 33 insertions, 20 deletions
diff --git a/spec/controllers/api/salmon_controller_spec.rb b/spec/controllers/api/salmon_controller_spec.rb
index 6897caeeb..3e4686200 100644
--- a/spec/controllers/api/salmon_controller_spec.rb
+++ b/spec/controllers/api/salmon_controller_spec.rb
@@ -13,29 +13,42 @@ RSpec.describe Api::SalmonController, type: :controller do
   end
 
   describe 'POST #update' do
-    before do
-      request.env['RAW_POST_DATA'] = File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
-      post :update, params: { id: account.id }
+    context 'with valid post data' do
+      before do
+        request.env['RAW_POST_DATA'] = File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
+        post :update, params: { id: account.id }
+      end
+
+      it 'contains XML in the request body' do
+        expect(request.body.read).to be_a String
+      end
+
+      it 'returns http success' do
+        expect(response).to have_http_status(:success)
+      end
+
+      it 'creates remote account' do
+        expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
+      end
+
+      it 'creates status' do
+        expect(Status.find_by(uri: 'tag:quitter.no,2016-03-20:noticeId=1276923:objectType=note')).to_not be_nil
+      end
+
+      it 'creates mention for target account' do
+        expect(account.mentions.count).to eq 1
+      end
     end
 
-    it 'contains XML in the request body' do
-      expect(request.body.read).to be_a String
-    end
-
-    it 'returns http success' do
-      expect(response).to have_http_status(:success)
-    end
-
-    it 'creates remote account' do
-      expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
-    end
-
-    it 'creates status' do
-      expect(Status.find_by(uri: 'tag:quitter.no,2016-03-20:noticeId=1276923:objectType=note')).to_not be_nil
-    end
+    context 'with invalid post data' do
+      before do
+        request.env['RAW_POST_DATA'] = ''
+        post :update, params: { id: account.id }
+      end
 
-    it 'creates mention for target account' do
-      expect(account.mentions.count).to eq 1
+      it 'returns http success' do
+        expect(response).to have_http_status(202)
+      end
     end
   end
 end