mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
models with rspec3 syntax
This commit is contained in:
@@ -7,18 +7,18 @@ describe ScreenedEmail do
|
||||
|
||||
describe "new record" do
|
||||
it "sets a default action_type" do
|
||||
ScreenedEmail.create(email: email).action_type.should == ScreenedEmail.actions[:block]
|
||||
expect(ScreenedEmail.create(email: email).action_type).to eq(ScreenedEmail.actions[:block])
|
||||
end
|
||||
|
||||
it "last_match_at is null" do
|
||||
# If we manually load the table with some emails, we can see whether those emails
|
||||
# have ever been blocked by looking at last_match_at.
|
||||
ScreenedEmail.create(email: email).last_match_at.should == nil
|
||||
expect(ScreenedEmail.create(email: email).last_match_at).to eq(nil)
|
||||
end
|
||||
|
||||
it "downcases the email" do
|
||||
s = ScreenedEmail.create(email: 'SPAMZ@EXAMPLE.COM')
|
||||
s.email.should == 'spamz@example.com'
|
||||
expect(s.email).to eq('spamz@example.com')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,16 +26,16 @@ describe ScreenedEmail do
|
||||
context 'email is not being blocked' do
|
||||
it 'creates a new record with default action of :block' do
|
||||
record = ScreenedEmail.block(email)
|
||||
record.should_not be_new_record
|
||||
record.email.should == email
|
||||
record.action_type.should == ScreenedEmail.actions[:block]
|
||||
expect(record).not_to be_new_record
|
||||
expect(record.email).to eq(email)
|
||||
expect(record.action_type).to eq(ScreenedEmail.actions[:block])
|
||||
end
|
||||
|
||||
it 'lets action_type be overriden' do
|
||||
record = ScreenedEmail.block(email, action_type: ScreenedEmail.actions[:do_nothing])
|
||||
record.should_not be_new_record
|
||||
record.email.should == email
|
||||
record.action_type.should == ScreenedEmail.actions[:do_nothing]
|
||||
expect(record).not_to be_new_record
|
||||
expect(record.email).to eq(email)
|
||||
expect(record.action_type).to eq(ScreenedEmail.actions[:do_nothing])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@ describe ScreenedEmail do
|
||||
end
|
||||
|
||||
it "returns the existing record" do
|
||||
ScreenedEmail.block(email).should == existing
|
||||
expect(ScreenedEmail.block(email)).to eq(existing)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -56,44 +56,44 @@ describe ScreenedEmail do
|
||||
subject { ScreenedEmail.should_block?(email) }
|
||||
|
||||
it "returns false if a record with the email doesn't exist" do
|
||||
subject.should == false
|
||||
expect(subject).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true when there is a record with the email" do
|
||||
ScreenedEmail.should_block?(email).should == false
|
||||
expect(ScreenedEmail.should_block?(email)).to eq(false)
|
||||
ScreenedEmail.create(email: email).save
|
||||
ScreenedEmail.should_block?(email).should == true
|
||||
expect(ScreenedEmail.should_block?(email)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when there is a record with a similar email" do
|
||||
ScreenedEmail.should_block?(email).should == false
|
||||
expect(ScreenedEmail.should_block?(email)).to eq(false)
|
||||
ScreenedEmail.create(email: similar_email).save
|
||||
ScreenedEmail.should_block?(email).should == true
|
||||
expect(ScreenedEmail.should_block?(email)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when it's same email, but all caps" do
|
||||
ScreenedEmail.create(email: email).save
|
||||
ScreenedEmail.should_block?(email.upcase).should == true
|
||||
expect(ScreenedEmail.should_block?(email.upcase)).to eq(true)
|
||||
end
|
||||
|
||||
shared_examples "when a ScreenedEmail record matches" do
|
||||
it "updates statistics" do
|
||||
Timecop.freeze(Time.zone.now) do
|
||||
expect { subject }.to change { screened_email.reload.match_count }.by(1)
|
||||
screened_email.last_match_at.should be_within_one_second_of(Time.zone.now)
|
||||
expect(screened_email.last_match_at).to be_within_one_second_of(Time.zone.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "action_type is :block" do
|
||||
let!(:screened_email) { Fabricate(:screened_email, email: email, action_type: ScreenedEmail.actions[:block]) }
|
||||
it { should == true }
|
||||
it { is_expected.to eq(true) }
|
||||
include_examples "when a ScreenedEmail record matches"
|
||||
end
|
||||
|
||||
context "action_type is :do_nothing" do
|
||||
let!(:screened_email) { Fabricate(:screened_email, email: email, action_type: ScreenedEmail.actions[:do_nothing]) }
|
||||
it { should == false }
|
||||
it { is_expected.to eq(false) }
|
||||
include_examples "when a ScreenedEmail record matches"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user