Files
nairobi/spec/models/verification/management/email_spec.rb
Javi Martín db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00

53 lines
2.0 KiB
Ruby

require "rails_helper"
describe Verification::Management::Email do
describe "#user" do
subject { Verification::Management::Email.new(document_type: "1", document_number: "1234", email: "inexisting@gmail.com") }
it "returns nil/false when the user does not exist" do
expect(subject.user).to be_nil
expect(subject.user?).not_to be
end
end
describe "validations" do
it "is not valid if the user does not exist" do
expect(Verification::Management::Email.new(document_type: "1", document_number: "1234", email: "inexisting@gmail.com")).not_to be_valid
end
it "is not valid if the user is already level 3" do
user = create(:user, :level_three)
expect(Verification::Management::Email.new(document_type: "1", document_number: "1234", email: user.email)).not_to be_valid
end
it "is not valid if the user already has a different document number" do
user = create(:user, document_number: "1234", document_type: "1")
expect(Verification::Management::Email.new(document_type: "1", document_number: "5678", email: user.email)).not_to be_valid
end
end
describe "#save" do
it "does nothing if not valid" do
expect(Verification::Management::Email.new(document_type: "1", document_number: "1234", email: "inexisting@gmail.com").save).to eq(false)
end
it "updates the user and sends an email" do
user = create(:user)
validation = Verification::Management::Email.new(document_type: "1", document_number: "1234", email: user.email)
mail = double(:mail)
allow(validation).to receive(:user).and_return user
allow(mail).to receive(:deliver_later)
allow(Devise.token_generator).to receive(:generate).with(User, :email_verification_token).and_return(["1", "2"])
allow(Mailer).to receive(:email_verification).with(user, user.email, "2", "1", "1234").and_return(mail)
validation.save!
expect(user.reload).to be_level_two_verified
expect(user.document_type).to eq("1")
expect(user.document_number).to eq("1234")
end
end
end