run Rubocop on changed files
This commit is contained in:
parent
1c6d22355a
commit
989f4a5132
|
@ -4,10 +4,8 @@ class TypoedEmailValidator < ActiveModel::EachValidator
|
||||||
# this array contains "forbidden" email address endings
|
# this array contains "forbidden" email address endings
|
||||||
INVALID_ENDINGS = [
|
INVALID_ENDINGS = [
|
||||||
# without @:
|
# without @:
|
||||||
*%w[
|
".con",
|
||||||
.con
|
".coom",
|
||||||
.coom
|
|
||||||
],
|
|
||||||
|
|
||||||
# with @:
|
# with @:
|
||||||
*%w[
|
*%w[
|
||||||
|
@ -31,10 +29,10 @@ class TypoedEmailValidator < ActiveModel::EachValidator
|
||||||
|
|
||||||
def valid?(value)
|
def valid?(value)
|
||||||
# needs an @
|
# needs an @
|
||||||
return false unless value.include?('@')
|
return false unless value.include?("@")
|
||||||
|
|
||||||
# part after the @ needs to have at least one period
|
# part after the @ needs to have at least one period
|
||||||
return false if value.split('@', 2).last.count('.') == 0
|
return false if value.split("@", 2).last.count(".").zero?
|
||||||
|
|
||||||
# finally, common typos
|
# finally, common typos
|
||||||
return false if INVALID_ENDINGS.any? { value.end_with?(_1) }
|
return false if INVALID_ENDINGS.any? { value.end_with?(_1) }
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require "rails_helper"
|
||||||
|
|
||||||
RSpec.describe User, type: :model do
|
RSpec.describe User, type: :model do
|
||||||
let!(:me) { FactoryBot.create :user }
|
let!(:me) { FactoryBot.create :user }
|
||||||
|
|
||||||
describe 'basic assigns' do
|
describe "basic assigns" do
|
||||||
before :each do
|
before :each do
|
||||||
@user = User.new(
|
@user = User.new(
|
||||||
screen_name: 'FunnyMeme2004',
|
screen_name: "FunnyMeme2004",
|
||||||
password: 'y_u_no_secure_password?',
|
password: "y_u_no_secure_password?",
|
||||||
email: 'nice.meme@nsa.gov'
|
email: "nice.meme@nsa.gov"
|
||||||
)
|
)
|
||||||
Profile.new(user: @user)
|
Profile.new(user: @user)
|
||||||
end
|
end
|
||||||
|
@ -19,26 +19,26 @@ RSpec.describe User, type: :model do
|
||||||
|
|
||||||
it { should respond_to(:email) }
|
it { should respond_to(:email) }
|
||||||
|
|
||||||
it '#email returns a string' do
|
it "#email returns a string" do
|
||||||
expect(@user.email).to match 'nice.meme@nsa.gov'
|
expect(@user.email).to match "nice.meme@nsa.gov"
|
||||||
end
|
end
|
||||||
|
|
||||||
it '#motivation_header has a default value' do
|
it "#motivation_header has a default value" do
|
||||||
expect(@user.profile.motivation_header).to match ''
|
expect(@user.profile.motivation_header).to match ""
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not save an invalid screen name' do
|
it "does not save an invalid screen name" do
|
||||||
@user.screen_name = '$Funny-Meme-%&2004'
|
@user.screen_name = "$Funny-Meme-%&2004"
|
||||||
expect { @user.save! }.to raise_error(ActiveRecord::RecordInvalid)
|
expect { @user.save! }.to raise_error(ActiveRecord::RecordInvalid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'email validation' do
|
describe "email validation" do
|
||||||
subject do
|
subject do
|
||||||
FactoryBot.build(:user, email: email).tap(&:validate).errors[:email]
|
FactoryBot.build(:user, email: email).tap(&:validate).errors[:email]
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for 'valid email' do |example_email|
|
shared_examples_for "valid email" do |example_email|
|
||||||
context "when email is #{example_email}" do
|
context "when email is #{example_email}" do
|
||||||
let(:email) { example_email }
|
let(:email) { example_email }
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ RSpec.describe User, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for 'invalid email' do |example_email|
|
shared_examples_for "invalid email" do |example_email|
|
||||||
context "when email is #{example_email}" do
|
context "when email is #{example_email}" do
|
||||||
let(:email) { example_email }
|
let(:email) { example_email }
|
||||||
|
|
||||||
|
@ -58,62 +58,62 @@ RSpec.describe User, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples 'valid email', 'ifyouusethismailyouarebanned@nilsding.org'
|
include_examples "valid email", "ifyouusethismailyouarebanned@nilsding.org"
|
||||||
include_examples 'valid email', 'fritz.fantom@gmail.com'
|
include_examples "valid email", "fritz.fantom@gmail.com"
|
||||||
include_examples 'valid email', 'fritz.fantom@columbiamail.co'
|
include_examples "valid email", "fritz.fantom@columbiamail.co"
|
||||||
include_examples 'valid email', 'fritz.fantom@protonmail.com'
|
include_examples "valid email", "fritz.fantom@protonmail.com"
|
||||||
include_examples 'valid email', 'fritz.fantom@enterprise.k8s.420stripes.k8s.needs.more.k8s.jira.atlassian.k8s.eu-central-1.s3.amazonaws.com'
|
include_examples "valid email", "fritz.fantom@enterprise.k8s.420stripes.k8s.needs.more.k8s.jira.atlassian.k8s.eu-central-1.s3.amazonaws.com"
|
||||||
include_examples 'invalid email', '@jack'
|
include_examples "invalid email", "@jack"
|
||||||
|
|
||||||
# examples from the real world:
|
# examples from the real world:
|
||||||
|
|
||||||
# .con is not a valid TLD
|
# .con is not a valid TLD
|
||||||
include_examples 'invalid email', 'fritz.fantom@gmail.con'
|
include_examples "invalid email", "fritz.fantom@gmail.con"
|
||||||
include_examples 'invalid email', 'fritz.fantom@protonmail.con'
|
include_examples "invalid email", "fritz.fantom@protonmail.con"
|
||||||
# neither is .coom
|
# neither is .coom
|
||||||
include_examples 'invalid email', 'fritz.fantom@gmail.coom'
|
include_examples "invalid email", "fritz.fantom@gmail.coom"
|
||||||
# common typos:
|
# common typos:
|
||||||
include_examples 'invalid email', 'fritz.fantom@fmail.com'
|
include_examples "invalid email", "fritz.fantom@fmail.com"
|
||||||
include_examples 'invalid email', 'fritz.fantom@gemail.com'
|
include_examples "invalid email", "fritz.fantom@gemail.com"
|
||||||
include_examples 'invalid email', 'fritz.fantom@gmail.co'
|
include_examples "invalid email", "fritz.fantom@gmail.co"
|
||||||
include_examples 'invalid email', 'fritz.fantom@gmailcom'
|
include_examples "invalid email", "fritz.fantom@gmailcom"
|
||||||
include_examples 'invalid email', 'fritz.fantom@gmaile.com'
|
include_examples "invalid email", "fritz.fantom@gmaile.com"
|
||||||
include_examples 'invalid email', 'fritz.fantom@gmaill.com'
|
include_examples "invalid email", "fritz.fantom@gmaill.com"
|
||||||
include_examples 'invalid email', 'fritz.fantom@hotmailcom'
|
include_examples "invalid email", "fritz.fantom@hotmailcom"
|
||||||
include_examples 'invalid email', 'fritz.fantom@icluod.com'
|
include_examples "invalid email", "fritz.fantom@icluod.com"
|
||||||
# no TLD
|
# no TLD
|
||||||
include_examples 'invalid email', 'fritz.fantom@gmail'
|
include_examples "invalid email", "fritz.fantom@gmail"
|
||||||
include_examples 'invalid email', 'fritz.fantom@protonmail'
|
include_examples "invalid email", "fritz.fantom@protonmail"
|
||||||
# not registered as of 2022-01-11
|
# not registered as of 2022-01-11
|
||||||
include_examples 'invalid email', 'fritz.fantom@proton.mail'
|
include_examples "invalid email", "fritz.fantom@proton.mail"
|
||||||
end
|
end
|
||||||
|
|
||||||
# -- User::TimelineMethods --
|
# -- User::TimelineMethods --
|
||||||
|
|
||||||
shared_examples_for 'result is blank' do
|
shared_examples_for "result is blank" do
|
||||||
it 'result is blank' do
|
it "result is blank" do
|
||||||
expect(subject).to be_blank
|
expect(subject).to be_blank
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#timeline' do
|
describe "#timeline" do
|
||||||
subject { me.timeline }
|
subject { me.timeline }
|
||||||
|
|
||||||
context 'user answered nothing and is not following anyone' do
|
context "user answered nothing and is not following anyone" do
|
||||||
include_examples 'result is blank'
|
include_examples "result is blank"
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'user answered something and is not following anyone' do
|
context "user answered something and is not following anyone" do
|
||||||
let(:answer) { FactoryBot.create(:answer, user: me) }
|
let(:answer) { FactoryBot.create(:answer, user: me) }
|
||||||
|
|
||||||
let(:expected) { [answer] }
|
let(:expected) { [answer] }
|
||||||
|
|
||||||
it 'includes the answer' do
|
it "includes the answer" do
|
||||||
expect(subject).to eq(expected)
|
expect(subject).to eq(expected)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'user answered something and follows users with answers' do
|
context "user answered something and follows users with answers" do
|
||||||
let(:user1) { FactoryBot.create(:user) }
|
let(:user1) { FactoryBot.create(:user) }
|
||||||
let(:user2) { FactoryBot.create(:user) }
|
let(:user2) { FactoryBot.create(:user) }
|
||||||
let(:answer1) { FactoryBot.create(:answer, user: user1, created_at: 12.hours.ago) }
|
let(:answer1) { FactoryBot.create(:answer, user: user1, created_at: 12.hours.ago) }
|
||||||
|
@ -130,39 +130,39 @@ RSpec.describe User, type: :model do
|
||||||
me.follow(user2)
|
me.follow(user2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'includes all answers' do
|
it "includes all answers" do
|
||||||
expect(subject).to include(answer1)
|
expect(subject).to include(answer1)
|
||||||
expect(subject).to include(answer2)
|
expect(subject).to include(answer2)
|
||||||
expect(subject).to include(answer3)
|
expect(subject).to include(answer3)
|
||||||
expect(subject).to include(answer4)
|
expect(subject).to include(answer4)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'result is ordered by created_at in reverse order' do
|
it "result is ordered by created_at in reverse order" do
|
||||||
expect(subject).to eq(expected)
|
expect(subject).to eq(expected)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#cursored_timeline' do
|
describe "#cursored_timeline" do
|
||||||
let(:last_id) { nil }
|
let(:last_id) { nil }
|
||||||
|
|
||||||
subject { me.cursored_timeline(last_id: last_id, size: 3) }
|
subject { me.cursored_timeline(last_id: last_id, size: 3) }
|
||||||
|
|
||||||
context 'user answered nothing and is not following anyone' do
|
context "user answered nothing and is not following anyone" do
|
||||||
include_examples 'result is blank'
|
include_examples "result is blank"
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'user answered something and is not following anyone' do
|
context "user answered something and is not following anyone" do
|
||||||
let(:answer) { FactoryBot.create(:answer, user: me) }
|
let(:answer) { FactoryBot.create(:answer, user: me) }
|
||||||
|
|
||||||
let(:expected) { [answer] }
|
let(:expected) { [answer] }
|
||||||
|
|
||||||
it 'includes the answer' do
|
it "includes the answer" do
|
||||||
expect(subject).to eq(expected)
|
expect(subject).to eq(expected)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'user answered something and follows users with answers' do
|
context "user answered something and follows users with answers" do
|
||||||
let(:user1) { FactoryBot.create(:user) }
|
let(:user1) { FactoryBot.create(:user) }
|
||||||
let(:user2) { FactoryBot.create(:user) }
|
let(:user2) { FactoryBot.create(:user) }
|
||||||
let!(:answer1) { FactoryBot.create(:answer, user: me, created_at: 1.day.ago) }
|
let!(:answer1) { FactoryBot.create(:answer, user: me, created_at: 1.day.ago) }
|
||||||
|
@ -175,28 +175,28 @@ RSpec.describe User, type: :model do
|
||||||
me.follow(user2)
|
me.follow(user2)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'last_id is nil' do
|
context "last_id is nil" do
|
||||||
let(:last_id) { nil }
|
let(:last_id) { nil }
|
||||||
let(:expected) do
|
let(:expected) do
|
||||||
[answer4, answer3, answer2]
|
[answer4, answer3, answer2]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'includes three answers' do
|
it "includes three answers" do
|
||||||
expect(subject).not_to include(answer1)
|
expect(subject).not_to include(answer1)
|
||||||
expect(subject).to include(answer2)
|
expect(subject).to include(answer2)
|
||||||
expect(subject).to include(answer3)
|
expect(subject).to include(answer3)
|
||||||
expect(subject).to include(answer4)
|
expect(subject).to include(answer4)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'result is ordered by created_at in reverse order' do
|
it "result is ordered by created_at in reverse order" do
|
||||||
expect(subject).to eq(expected)
|
expect(subject).to eq(expected)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'last_id is answer2.id' do
|
context "last_id is answer2.id" do
|
||||||
let(:last_id) { answer2.id }
|
let(:last_id) { answer2.id }
|
||||||
|
|
||||||
it 'includes answer1' do
|
it "includes answer1" do
|
||||||
expect(subject).to include(answer1)
|
expect(subject).to include(answer1)
|
||||||
expect(subject).not_to include(answer2)
|
expect(subject).not_to include(answer2)
|
||||||
expect(subject).not_to include(answer3)
|
expect(subject).not_to include(answer3)
|
||||||
|
@ -204,10 +204,10 @@ RSpec.describe User, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'last_id is answer1.id' do
|
context "last_id is answer1.id" do
|
||||||
let(:last_id) { answer1.id }
|
let(:last_id) { answer1.id }
|
||||||
|
|
||||||
include_examples 'result is blank'
|
include_examples "result is blank"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue