summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2016-08-02 16:21:57 -0500
committerPatricio Cano <suprnova32@gmail.com>2016-08-15 13:18:15 -0500
commit96399a81cbb2e8a0f666241eeaff7cc784c26983 (patch)
tree7123e352717a846300c031cb884028fbd0a7f1d3 /spec
parentabf2dcd25c4a176801314872733ede91297d1ab0 (diff)
downloadgitlab-ce-96399a81cbb2e8a0f666241eeaff7cc784c26983.tar.gz
Allow `Issue` to be submitted as spam
- Added controller actions as reusable concerns - Added controller tests
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin/spam_logs_controller_spec.rb12
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb29
-rw-r--r--spec/models/concerns/spammable_spec.rb9
3 files changed, 46 insertions, 4 deletions
diff --git a/spec/controllers/admin/spam_logs_controller_spec.rb b/spec/controllers/admin/spam_logs_controller_spec.rb
index 520a4f6f9c5..f94afd1139d 100644
--- a/spec/controllers/admin/spam_logs_controller_spec.rb
+++ b/spec/controllers/admin/spam_logs_controller_spec.rb
@@ -34,4 +34,16 @@ describe Admin::SpamLogsController do
expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
end
end
+
+ describe '#mark_as_ham' do
+ before do
+ allow_any_instance_of(Gitlab::AkismetHelper).to receive(:ham!).and_return(true)
+ end
+ it 'submits the log as ham' do
+ post :mark_as_ham, id: first_spam.id
+
+ expect(response).to have_http_status(302)
+ expect(SpamLog.find(first_spam.id).submitted_as_ham).to be_truthy
+ end
+ end
end
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index efca838613f..8fcde9a38bc 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -322,6 +322,35 @@ describe Projects::IssuesController do
end
end
+ describe 'POST #mark_as_spam' do
+ context 'properly submits to Akismet' do
+ before do
+ allow_any_instance_of(Spammable).to receive_messages(can_be_submitted?: true, submit_spam: true)
+ end
+
+ def post_spam
+ admin = create(:admin)
+ create(:user_agent_detail, subject: issue)
+ project.team << [admin, :master]
+ sign_in(admin)
+ post :mark_as_spam, {
+ namespace_id: project.namespace.path,
+ project_id: project.path,
+ id: issue.iid
+ }
+ end
+
+ it 'creates a system note' do
+ expect{ post_spam }.to change(Note, :count)
+ end
+
+ it 'updates issue' do
+ post_spam
+ expect(issue.submitted?).to be_truthy
+ end
+ end
+ end
+
describe "DELETE #destroy" do
context "when the user is a developer" do
before { sign_in(user) }
diff --git a/spec/models/concerns/spammable_spec.rb b/spec/models/concerns/spammable_spec.rb
index 7492c42f71e..4e52d05918f 100644
--- a/spec/models/concerns/spammable_spec.rb
+++ b/spec/models/concerns/spammable_spec.rb
@@ -14,6 +14,10 @@ describe Issue, 'Spammable' do
end
describe 'InstanceMethods' do
+ before do
+ allow_any_instance_of(Gitlab::AkismetHelper).to receive(:akismet_enabled?).and_return(true)
+ end
+
it 'should return the correct creator' do
expect(issue.send(:owner).id).to eq(issue.author_id)
end
@@ -24,14 +28,11 @@ describe Issue, 'Spammable' do
end
it 'should be submittable' do
- create(:user_agent_detail, subject_id: issue.id, subject_type: issue.class.to_s)
+ create(:user_agent_detail, subject: issue)
expect(issue.can_be_submitted?).to be_truthy
end
describe '#check_for_spam?' do
- before do
- allow_any_instance_of(Gitlab::AkismetHelper).to receive(:akismet_enabled?).and_return(true)
- end
it 'returns true for public project' do
issue.project.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PUBLIC)
expect(issue.check_for_spam?).to eq(true)