Skip to content

Instantly share code, notes, and snippets.

@nmanzi
Created April 25, 2017 02:39
Show Gist options
  • Save nmanzi/21aa316549dd2c0ac258aaf974fe8ffc to your computer and use it in GitHub Desktop.
Save nmanzi/21aa316549dd2c0ac258aaf974fe8ffc to your computer and use it in GitHub Desktop.
require 'rails_helper'
RSpec.describe WorkerUser, type: :model do
it "has a valid factory" do
expect(build(:worker_user)).to be_valid
end
context "validation" do
let(:user) { build(:worker_user) }
subject { user }
it { is_expected.to validate_presence_of :phone_number }
it { is_expected.to validate_uniqueness_of(:phone_number).case_insensitive }
it { is_expected.to validate_uniqueness_of(:email).case_insensitive }
it "should fail validation with a bad phone number" do
user = build :worker_user, phone_number: "1234567890"
expect(user).to_not be_valid
end
it "should pass validation with a good phone number" do
user = build :worker_user, phone_number: "0437221171"
expect(user).to be_valid
end
context "password" do
let(:user) { WorkerUser.new }
subject { user }
it { is_expected.to validate_presence_of :password }
it { is_expected.to validate_confirmation_of :password }
end
end
context "defaults" do
let(:user) { create(:worker_user) }
it "should be enabled by default" do
expect(user).to have_attributes(enabled: true)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment