about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-10-03 18:17:06 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-10-03 18:17:06 +0200
commit7b9a4af3112dc4edcd378dc94190e2eb8e041f56 (patch)
tree8a817939f09f0b5fca6b46feb44b8ef6f9113e86 /spec
parent2c9e672ee2437677d6e39383e5f8e8e0837024b9 (diff)
API for blocking and unblocking
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/accounts_controller_spec.rb38
-rw-r--r--spec/services/block_service_spec.rb5
-rw-r--r--spec/services/unblock_service_spec.rb5
3 files changed, 48 insertions, 0 deletions
diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb
index 7a67f1c56..e4532305b 100644
--- a/spec/controllers/api/v1/accounts_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts_controller_spec.rb
@@ -79,6 +79,44 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
     end
   end
 
+  describe 'POST #block' do
+    let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+    before do
+      user.account.follow!(other_account)
+      post :block, params: { id: other_account.id }
+    end
+
+    it 'returns http success' do
+      expect(response).to have_http_status(:success)
+    end
+
+    it 'removes the following relation between user and target user' do
+      expect(user.account.following?(other_account)).to be false
+    end
+
+    it 'creates a blocking relation' do
+      expect(user.account.blocking?(other_account)).to be true
+    end
+  end
+
+  describe 'POST #unblock' do
+    let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+    before do
+      user.account.block!(other_account)
+      post :unblock, params: { id: other_account.id }
+    end
+
+    it 'returns http success' do
+      expect(response).to have_http_status(:success)
+    end
+
+    it 'removes the blocking relation between user and target user' do
+      expect(user.account.blocking?(other_account)).to be false
+    end
+  end
+
   describe 'GET #relationships' do
     let(:simon) { Fabricate(:user, email: 'simon@example.com', account: Fabricate(:account, username: 'simon')).account }
     let(:lewis) { Fabricate(:user, email: 'lewis@example.com', account: Fabricate(:account, username: 'lewis')).account }
diff --git a/spec/services/block_service_spec.rb b/spec/services/block_service_spec.rb
new file mode 100644
index 000000000..f6f07fa20
--- /dev/null
+++ b/spec/services/block_service_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe BlockService do
+  subject { BlockService.new }
+end
diff --git a/spec/services/unblock_service_spec.rb b/spec/services/unblock_service_spec.rb
new file mode 100644
index 000000000..126f70ff1
--- /dev/null
+++ b/spec/services/unblock_service_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe UnblockService do
+  subject { UnblockService.new }
+end