summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2016-08-05 17:10:08 -0500
committerPatricio Cano <suprnova32@gmail.com>2016-08-15 13:18:15 -0500
commit43e756d4eafd79f4d2f366b646ebb94af78b5a4c (patch)
tree07949d3368affcda301fd266e1e5bf0649474b23 /spec
parent7179165af7553720089a0b7e7024374c371e2f90 (diff)
downloadgitlab-ce-43e756d4eafd79f4d2f366b646ebb94af78b5a4c.tar.gz
Refactored AkismetHelper into AkismetService and cleaned up `Spammable`
- Refactored SpamCheckService into SpamService
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin/spam_logs_controller_spec.rb2
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb6
-rw-r--r--spec/lib/gitlab/akismet_helper_spec.rb24
-rw-r--r--spec/models/concerns/spammable_spec.rb27
-rw-r--r--spec/requests/api/issues_spec.rb2
5 files changed, 14 insertions, 47 deletions
diff --git a/spec/controllers/admin/spam_logs_controller_spec.rb b/spec/controllers/admin/spam_logs_controller_spec.rb
index f94afd1139d..ac0441d0a4e 100644
--- a/spec/controllers/admin/spam_logs_controller_spec.rb
+++ b/spec/controllers/admin/spam_logs_controller_spec.rb
@@ -37,7 +37,7 @@ describe Admin::SpamLogsController do
describe '#mark_as_ham' do
before do
- allow_any_instance_of(Gitlab::AkismetHelper).to receive(:ham!).and_return(true)
+ allow_any_instance_of(AkismetService).to receive(:ham!).and_return(true)
end
it 'submits the log as ham' do
post :mark_as_ham, id: first_spam.id
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index 8fcde9a38bc..0e8d4b80b0e 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -275,7 +275,7 @@ describe Projects::IssuesController do
context 'Akismet is enabled' do
before do
allow_any_instance_of(Spammable).to receive(:check_for_spam?).and_return(true)
- allow_any_instance_of(Gitlab::AkismetHelper).to receive(:is_spam?).and_return(true)
+ allow_any_instance_of(AkismetService).to receive(:is_spam?).and_return(true)
end
def post_spam_issue
@@ -325,7 +325,9 @@ describe Projects::IssuesController do
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)
+ allow_any_instance_of(AkismetService).to receive_messages(spam!: true)
+ allow_any_instance_of(ApplicationSetting).to receive_messages(akismet_enabled: true)
+ allow_any_instance_of(SpamService).to receive_messages(can_be_submitted?: true)
end
def post_spam
diff --git a/spec/lib/gitlab/akismet_helper_spec.rb b/spec/lib/gitlab/akismet_helper_spec.rb
deleted file mode 100644
index 80b4f912d41..00000000000
--- a/spec/lib/gitlab/akismet_helper_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require 'spec_helper'
-
-describe Gitlab::AkismetHelper, type: :helper do
- let(:project) { create(:project, :public) }
- let(:user) { create(:user) }
-
- before do
- allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url))
- allow_any_instance_of(ApplicationSetting).to receive(:akismet_enabled).and_return(true)
- allow_any_instance_of(ApplicationSetting).to receive(:akismet_api_key).and_return('12345')
- end
-
- describe '#is_spam?' do
- it 'returns true for spam' do
- environment = {
- 'action_dispatch.remote_ip' => '127.0.0.1',
- 'HTTP_USER_AGENT' => 'Test User Agent'
- }
-
- allow_any_instance_of(::Akismet::Client).to receive(:check).and_return([true, true])
- expect(helper.is_spam?(environment, user, 'Is this spam?')).to eq(true)
- end
- end
-end
diff --git a/spec/models/concerns/spammable_spec.rb b/spec/models/concerns/spammable_spec.rb
index 4e52d05918f..7944305e7b3 100644
--- a/spec/models/concerns/spammable_spec.rb
+++ b/spec/models/concerns/spammable_spec.rb
@@ -14,25 +14,24 @@ 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)
+ expect(issue.owner_id).to eq(issue.author_id)
end
it 'should be invalid if spam' do
- issue.spam = true
- expect(issue.valid?).to be_truthy
+ issue = build(:issue, spam: true)
+ expect(issue.valid?).to be_falsey
end
- it 'should be submittable' do
+ it 'should not be submitted' do
create(:user_agent_detail, subject: issue)
- expect(issue.can_be_submitted?).to be_truthy
+ expect(issue.submitted?).to be_falsey
end
describe '#check_for_spam?' do
+ before do
+ allow_any_instance_of(ApplicationSetting).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)
@@ -43,14 +42,4 @@ describe Issue, 'Spammable' do
end
end
end
-
- describe 'AkismetMethods' do
- before do
- allow_any_instance_of(Gitlab::AkismetHelper).to receive_messages(is_spam?: true, spam!: true, akismet_enabled?: true)
- allow_any_instance_of(Spammable).to receive(:can_be_submitted?).and_return(true)
- end
-
- it { expect(issue.spam_detected?(:mock_env)).to be_truthy }
- it { expect(issue.submit_spam).to be_truthy }
- end
end
diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb
index 353b01d4a09..30b939c797c 100644
--- a/spec/requests/api/issues_spec.rb
+++ b/spec/requests/api/issues_spec.rb
@@ -532,7 +532,7 @@ describe API::API, api: true do
describe 'POST /projects/:id/issues with spam filtering' do
before do
allow_any_instance_of(Spammable).to receive(:check_for_spam?).and_return(true)
- allow_any_instance_of(Gitlab::AkismetHelper).to receive(:is_spam?).and_return(true)
+ allow_any_instance_of(AkismetService).to receive_messages(is_spam?: true)
end
let(:params) do