2020-05-19 21:08:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-01-27 09:09:01 +00:00
|
|
|
RSpec.shared_examples 'checking spam' do
|
2020-05-19 21:08:05 +00:00
|
|
|
before do
|
2021-01-27 09:09:01 +00:00
|
|
|
allow_next_instance_of(UserAgentDetailService) do |instance|
|
|
|
|
allow(instance).to receive(:create)
|
2020-05-19 21:08:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-27 09:09:01 +00:00
|
|
|
it 'executes SpamActionService' do
|
|
|
|
expect_next_instance_of(
|
|
|
|
Spam::SpamActionService,
|
|
|
|
{
|
|
|
|
spammable: kind_of(Snippet),
|
2021-06-21 12:07:45 +00:00
|
|
|
spam_params: spam_params,
|
2021-01-27 09:09:01 +00:00
|
|
|
user: an_instance_of(User),
|
2022-08-22 09:11:23 +00:00
|
|
|
action: action,
|
|
|
|
extra_features: { files: an_instance_of(Array) }
|
2021-01-27 09:09:01 +00:00
|
|
|
}
|
|
|
|
) do |instance|
|
2021-06-21 12:07:45 +00:00
|
|
|
expect(instance).to receive(:execute)
|
2021-01-27 09:09:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
subject
|
2020-05-19 21:08:05 +00:00
|
|
|
end
|
|
|
|
end
|
2020-09-04 21:08:41 +00:00
|
|
|
|
2022-08-18 15:12:17 +00:00
|
|
|
RSpec.shared_examples 'invalid params error response' do
|
2020-09-04 21:08:41 +00:00
|
|
|
before do
|
|
|
|
allow_next_instance_of(described_class) do |service|
|
|
|
|
allow(service).to receive(:valid_params?).and_return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds to errors appropriately' do
|
|
|
|
response = subject
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(response).to be_error
|
|
|
|
expect(response.http_status).to eq 422
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|