mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-18 11:32:24 -05:00
53 lines
1.7 KiB
Ruby
53 lines
1.7 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe ScreenedUrl do
|
|
|
|
let(:url) { 'http://shopppping.com/bad/drugz' }
|
|
let(:domain) { 'shopppping.com' }
|
|
|
|
let(:valid_params) { {url: url, domain: domain} }
|
|
|
|
describe "new record" do
|
|
it "sets a default action_type" do
|
|
described_class.create(valid_params).action_type.should == described_class.actions[:do_nothing]
|
|
end
|
|
|
|
it "last_match_at is null" do
|
|
described_class.create(valid_params).last_match_at.should be_nil
|
|
end
|
|
|
|
['http://', 'HTTP://', 'https://', 'HTTPS://'].each do |prefix|
|
|
it "strips #{prefix}" do
|
|
described_class.create(valid_params.merge(url: url.gsub('http://', prefix))).url.should == url.gsub('http://', '')
|
|
end
|
|
end
|
|
end
|
|
|
|
describe '#watch' do
|
|
context 'url is not being blocked' do
|
|
it 'creates a new record with default action of :do_nothing' do
|
|
record = described_class.watch(url, domain)
|
|
record.should_not be_new_record
|
|
record.action_type.should == described_class.actions[:do_nothing]
|
|
end
|
|
|
|
it 'lets action_type be overriden' do
|
|
record = described_class.watch(url, domain, action_type: described_class.actions[:block])
|
|
record.should_not be_new_record
|
|
record.action_type.should == described_class.actions[:block]
|
|
end
|
|
end
|
|
|
|
context 'url is already being blocked' do
|
|
let!(:existing) { Fabricate(:screened_url, url: url, domain: domain) }
|
|
|
|
it "doesn't create a new record" do
|
|
expect { described_class.watch(url, domain) }.to_not change { described_class.count }
|
|
end
|
|
|
|
it "returns the existing record" do
|
|
described_class.watch(url, domain).should == existing
|
|
end
|
|
end
|
|
end
|
|
end
|