about summary refs log tree commit diff
path: root/spec/controllers/api/v1
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/api/v1')
-rw-r--r--spec/controllers/api/v1/accounts/notes_controller_spec.rb2
-rw-r--r--spec/controllers/api/v1/admin/accounts_controller_spec.rb2
-rw-r--r--spec/controllers/api/v1/reports_controller_spec.rb54
-rw-r--r--spec/controllers/api/v1/statuses/favourited_by_accounts_controller_spec.rb2
-rw-r--r--spec/controllers/api/v1/statuses/reblogged_by_accounts_controller_spec.rb2
-rw-r--r--spec/controllers/api/v1/statuses_controller_spec.rb4
-rw-r--r--spec/controllers/api/v1/trends/tags_controller_spec.rb7
7 files changed, 57 insertions, 16 deletions
diff --git a/spec/controllers/api/v1/accounts/notes_controller_spec.rb b/spec/controllers/api/v1/accounts/notes_controller_spec.rb
index 47d595c70..42c2d8a86 100644
--- a/spec/controllers/api/v1/accounts/notes_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts/notes_controller_spec.rb
@@ -31,7 +31,7 @@ describe Api::V1::Accounts::NotesController do
       end
     end
 
-    context 'when account note exceends allowed length' do
+    context 'when account note exceeds allowed length' do
       let(:comment) { 'a' * 2_001 }
 
       it 'returns 422' do
diff --git a/spec/controllers/api/v1/admin/accounts_controller_spec.rb b/spec/controllers/api/v1/admin/accounts_controller_spec.rb
index bf79ee520..3f61bbc0b 100644
--- a/spec/controllers/api/v1/admin/accounts_controller_spec.rb
+++ b/spec/controllers/api/v1/admin/accounts_controller_spec.rb
@@ -140,7 +140,7 @@ RSpec.describe Api::V1::Admin::AccountsController, type: :controller do
       expect(response).to have_http_status(200)
     end
 
-    it 'unsensitives account' do
+    it 'unsensitizes account' do
       expect(account.reload.sensitized?).to be false
     end
   end
diff --git a/spec/controllers/api/v1/reports_controller_spec.rb b/spec/controllers/api/v1/reports_controller_spec.rb
index a13de1370..b5baf60e1 100644
--- a/spec/controllers/api/v1/reports_controller_spec.rb
+++ b/spec/controllers/api/v1/reports_controller_spec.rb
@@ -13,22 +13,64 @@ RSpec.describe Api::V1::ReportsController, type: :controller do
   end
 
   describe 'POST #create' do
-    let(:scopes)  { 'write:reports' }
-    let!(:status) { Fabricate(:status) }
-    let!(:admin)  { Fabricate(:user, admin: true) }
+    let!(:admin) { Fabricate(:user, admin: true) }
+
+    let(:scopes) { 'write:reports' }
+    let(:status) { Fabricate(:status) }
+    let(:target_account) { status.account }
+    let(:category) { nil }
+    let(:forward) { nil }
+    let(:rule_ids){ nil }
 
     before do
       allow(AdminMailer).to receive(:new_report).and_return(double('email', deliver_later: nil))
-      post :create, params: { status_ids: [status.id], account_id: status.account.id, comment: 'reasons' }
+      post :create, params: { status_ids: [status.id], account_id: target_account.id, comment: 'reasons', category: category, rule_ids: rule_ids, forward: forward }
     end
 
-    it 'creates a report' do
-      expect(status.reload.account.targeted_reports).not_to be_empty
+    it 'returns http success' do
       expect(response).to have_http_status(200)
     end
 
+    it 'creates a report' do
+      expect(target_account.targeted_reports).to_not be_empty
+    end
+
+    it 'saves comment' do
+      expect(target_account.targeted_reports.first.comment).to eq 'reasons'
+    end
+
     it 'sends e-mails to admins' do
       expect(AdminMailer).to have_received(:new_report).with(admin.account, Report)
     end
+
+    context 'when a status does not belong to the reported account' do
+      let(:target_account) { Fabricate(:account) }
+
+      it 'returns http not found' do
+        expect(response).to have_http_status(404)
+      end
+    end
+
+    context 'when a category is chosen' do
+      let(:category) { 'spam' }
+
+      it 'saves category' do
+        expect(target_account.targeted_reports.first.spam?).to be true
+      end
+    end
+
+    context 'when violated rules are chosen' do
+      let(:rule) { Fabricate(:rule) }
+      let(:category) { 'violation' }
+      let(:rule_ids) { [rule.id] }
+
+      it 'saves category' do
+        expect(target_account.targeted_reports.first.violation?).to be true
+      end
+
+      it 'saves rule_ids' do
+        expect(target_account.targeted_reports.first.rule_ids).to match_array([rule.id])
+      end
+    end
   end
 end
diff --git a/spec/controllers/api/v1/statuses/favourited_by_accounts_controller_spec.rb b/spec/controllers/api/v1/statuses/favourited_by_accounts_controller_spec.rb
index 439a4738d..7cc77f430 100644
--- a/spec/controllers/api/v1/statuses/favourited_by_accounts_controller_spec.rb
+++ b/spec/controllers/api/v1/statuses/favourited_by_accounts_controller_spec.rb
@@ -56,7 +56,7 @@ RSpec.describe Api::V1::Statuses::FavouritedByAccountsController, type: :control
           Fabricate(:favourite, status: status)
         end
 
-        it 'returns http unautharized' do
+        it 'returns http unauthorized' do
           get :index, params: { status_id: status.id }
           expect(response).to have_http_status(404)
         end
diff --git a/spec/controllers/api/v1/statuses/reblogged_by_accounts_controller_spec.rb b/spec/controllers/api/v1/statuses/reblogged_by_accounts_controller_spec.rb
index 31320349d..8d4a6f91c 100644
--- a/spec/controllers/api/v1/statuses/reblogged_by_accounts_controller_spec.rb
+++ b/spec/controllers/api/v1/statuses/reblogged_by_accounts_controller_spec.rb
@@ -56,7 +56,7 @@ RSpec.describe Api::V1::Statuses::RebloggedByAccountsController, type: :controll
           Fabricate(:status, reblog_of_id: status.id)
         end
 
-        it 'returns http unautharized' do
+        it 'returns http unauthorized' do
           get :index, params: { status_id: status.id }
           expect(response).to have_http_status(404)
         end
diff --git a/spec/controllers/api/v1/statuses_controller_spec.rb b/spec/controllers/api/v1/statuses_controller_spec.rb
index 190dfad11..2eb30af74 100644
--- a/spec/controllers/api/v1/statuses_controller_spec.rb
+++ b/spec/controllers/api/v1/statuses_controller_spec.rb
@@ -130,7 +130,7 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
       let(:status) { Fabricate(:status, account: user.account, visibility: :private) }
 
       describe 'GET #show' do
-        it 'returns http unautharized' do
+        it 'returns http unauthorized' do
           get :show, params: { id: status.id }
           expect(response).to have_http_status(404)
         end
@@ -141,7 +141,7 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
           Fabricate(:status, account: user.account, thread: status)
         end
 
-        it 'returns http unautharized' do
+        it 'returns http unauthorized' do
           get :context, params: { id: status.id }
           expect(response).to have_http_status(404)
         end
diff --git a/spec/controllers/api/v1/trends/tags_controller_spec.rb b/spec/controllers/api/v1/trends/tags_controller_spec.rb
index e2e26dcab..d29551c56 100644
--- a/spec/controllers/api/v1/trends/tags_controller_spec.rb
+++ b/spec/controllers/api/v1/trends/tags_controller_spec.rb
@@ -7,10 +7,9 @@ RSpec.describe Api::V1::Trends::TagsController, type: :controller do
 
   describe 'GET #index' do
     before do
-      trending_tags = double()
-
-      allow(trending_tags).to receive(:get).and_return(Fabricate.times(10, :tag))
-      allow(Trends).to receive(:tags).and_return(trending_tags)
+      Fabricate.times(10, :tag).each do |tag|
+        10.times { |i| Trends.tags.add(tag, i) }
+      end
 
       get :index
     end