about summary refs log tree commit diff
path: root/spec/controllers
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2018-05-23 19:19:28 +0200
committerGitHub <noreply@github.com>2018-05-23 19:19:28 +0200
commit88ec5193cb377500c4500d31d7ba9fa441f1f5ee (patch)
treed517f10fdeffb6adaf7e349ea78593c02534c84a /spec/controllers
parent7719fe0df27a59cb7292989688efaa4efc6cbccc (diff)
parente0ef89c73f6b380a2841b9dcde07725d515340a4 (diff)
Merge pull request #510 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/admin/report_notes_controller_spec.rb91
-rw-r--r--spec/controllers/invites_controller_spec.rb13
2 files changed, 100 insertions, 4 deletions
diff --git a/spec/controllers/admin/report_notes_controller_spec.rb b/spec/controllers/admin/report_notes_controller_spec.rb
new file mode 100644
index 000000000..2c32303fb
--- /dev/null
+++ b/spec/controllers/admin/report_notes_controller_spec.rb
@@ -0,0 +1,91 @@
+require 'rails_helper'
+
+describe Admin::ReportNotesController do
+  render_views
+
+  let(:user) { Fabricate(:user, admin: true) }
+
+  before do
+    sign_in user, scope: :user
+  end
+
+  describe 'POST #create' do
+    subject { post :create, params: params }
+
+    let(:report) { Fabricate(:report, action_taken: action_taken, action_taken_by_account_id: account_id) }
+
+    context 'when parameter is valid' do
+
+      context 'when report is unsolved' do
+        let(:action_taken) { false }
+        let(:account_id) { nil }
+
+        context 'when create_and_resolve flag is on' do
+          let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_resolve: nil } }
+
+          it 'creates a report note and resolves report' do
+            expect{ subject }.to change{ ReportNote.count }.by(1)
+            expect(report.reload).to be_action_taken
+            expect(subject).to redirect_to admin_reports_path
+          end
+        end
+
+        context 'when create_and_resolve flag is false' do
+          let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
+
+          it 'creates a report note and does not resolve report' do
+            expect{ subject }.to change{ ReportNote.count }.by(1)
+            expect(report.reload).not_to be_action_taken
+            expect(subject).to redirect_to admin_report_path(report)
+          end
+        end
+      end
+
+      context 'when report is resolved' do
+        let(:action_taken) { true }
+        let(:account_id) { user.account.id }
+
+        context 'when create_and_unresolve flag is on' do
+          let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_unresolve: nil } }
+
+          it 'creates a report note and unresolves report' do
+            expect{ subject }.to change{ ReportNote.count }.by(1)
+            expect(report.reload).not_to be_action_taken
+            expect(subject).to redirect_to admin_report_path(report)
+          end
+        end
+
+        context 'when create_and_unresolve flag is false' do
+          let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
+
+          it 'creates a report note and does not unresolve report' do
+            expect{ subject }.to change{ ReportNote.count }.by(1)
+            expect(report.reload).to be_action_taken
+            expect(subject).to redirect_to admin_report_path(report)
+          end
+        end
+      end
+    end
+
+    context 'when parameter is invalid' do
+      let(:params) { { report_note: { content: '', report_id: report.id } } }
+      let(:action_taken) { false }
+      let(:account_id) { nil }
+
+      it 'renders admin/reports/show' do
+        expect(subject).to render_template 'admin/reports/show'
+      end
+    end
+  end
+
+  describe 'DELETE #destroy' do
+    subject { delete :destroy, params: { id: report_note.id } }
+
+    let!(:report_note) { Fabricate(:report_note) }
+
+    it 'deletes note' do
+      expect{ subject }.to change{ ReportNote.count }.by(-1)
+      expect(subject).to redirect_to admin_report_path(report_note.report)
+    end
+  end
+end
diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb
index c5c6cb651..9f5ab67c3 100644
--- a/spec/controllers/invites_controller_spec.rb
+++ b/spec/controllers/invites_controller_spec.rb
@@ -7,15 +7,21 @@ describe InvitesController do
     sign_in user
   end
 
+  around do |example|
+    min_invite_role = Setting.min_invite_role
+    example.run
+    Setting.min_invite_role = min_invite_role
+  end
+
   describe 'GET #index' do
     subject { get :index }
 
+    let(:user) { Fabricate(:user, moderator: false, admin: false) }
     let!(:invite) { Fabricate(:invite, user: user) }
 
     context 'when user is a staff' do
-      let(:user) { Fabricate(:user, moderator: true, admin: false) }
-
       it 'renders index page' do
+        Setting.min_invite_role = 'user'
         expect(subject).to render_template :index
         expect(assigns(:invites)).to include invite
         expect(assigns(:invites).count).to eq 1
@@ -23,9 +29,8 @@ describe InvitesController do
     end
 
     context 'when user is not a staff' do
-      let(:user) { Fabricate(:user, moderator: false, admin: false) }
-
       it 'returns 403' do
+        Setting.min_invite_role = 'modelator'
         expect(subject).to have_http_status 403
       end
     end