Created
August 24, 2016 13:49
-
-
Save rubyandcoffee/0465387f1472bd5f12510f45405cfa75 to your computer and use it in GitHub Desktop.
Spec for contacts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Contact do | |
it "has a valid factory" do | |
expect(build(:contact)).to be_valid | |
end | |
it { should validate_presence_of :first_name } | |
it { should validate_presence_of :last_name } | |
it { should validate_presence_of :email } | |
it { should validate_uniqueness_of(:email) } | |
it "returns a contact's full name as a string" do | |
contact = build_stubbed(:contact, | |
first_name: "Jane", last_name: "Doe") | |
expect(contact.name).to eq "Jane Doe" | |
end | |
describe "filter last name by letter" do | |
let(:smith) { create(:contact, | |
last_name: 'Smith', email: '[email protected]') } | |
let(:jones) { create(:contact, | |
last_name: 'Jones', email: '[email protected]') } | |
let(:johnson) { create(:contact, | |
last_name: 'Johnson', email: '[email protected]') } | |
context "matching letters" do | |
it "returns a sorted array of results that match" do | |
expect(Contact.by_letter("J")).to eq [johnson, jones] | |
end | |
end | |
context "non-matching letters" do | |
it "returns a sorted array of results that match" do | |
expect(Contact.by_letter("J")).to_not include smith | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment