2016-01-09 14:30:34 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::AkismetHelper, type: :helper do
|
2016-07-18 19:17:43 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
2016-01-09 14:30:34 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url))
|
2016-05-27 22:05:52 -04:00
|
|
|
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')
|
2016-01-09 14:30:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#check_for_spam?' do
|
2016-07-18 19:17:43 -04:00
|
|
|
it 'returns true for public project' do
|
|
|
|
expect(helper.check_for_spam?(project)).to eq(true)
|
2016-01-09 14:30:34 -05:00
|
|
|
end
|
|
|
|
|
2016-07-18 19:17:43 -04:00
|
|
|
it 'returns false for private project' do
|
|
|
|
project.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
expect(helper.check_for_spam?(project)).to eq(false)
|
2016-01-09 14:30:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#is_spam?' do
|
|
|
|
it 'returns true for spam' do
|
|
|
|
environment = {
|
2016-04-28 01:04:40 -04:00
|
|
|
'action_dispatch.remote_ip' => '127.0.0.1',
|
2016-01-09 14:30:34 -05:00
|
|
|
'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
|