Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

am/model testing #1

Merged
merged 2 commits into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
class Customer < ApplicationRecord
validates :name, presence: true
validates :registered_at, presence: true
validates :postal_code, presence: true
validates :phone, presence: true
validates :movies_checked_out_count, presence: true
end
98 changes: 61 additions & 37 deletions test/models/customer_test.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,70 @@
require "test_helper"

describe Customer do
describe "validations" do
# let(:customer) { Customer.new }

it "you can create a customer" do
customer = Customer.new
customer.valid?.must_equal true
end
it "you can create a customer" do
customer = customers(:bare_minimum)
customer.valid?.must_equal true
end

it "won't create customer without name" do
customer = customers(:bare_minimum)
customer.name = ""
it "won't create customer without name" do
customer = customers(:bare_minimum)
customer.name = ""

customer.valid?.must_equal false
customer.errors.messages.must_include :name
end
customer.valid?.must_equal false
customer.errors.messages.must_include :name
end

it "won't create customer without registered_at" do
customer = customers(:bare_minimum)
customer.registered_at = ""

customer.valid?.must_equal false
customer.errors.messages.must_include :registered_at
end

it "won't create customer without postal_code" do
customer = customers(:bare_minimum)
customer.postal_code = ""

customer.valid?.must_equal false
customer.errors.messages.must_include :postal_code
end

it "won't create customer without phone" do
customer = customers(:bare_minimum)
customer.phone = ""

# it "won't create customer without registered_at" do
#
# end
#
# it "won't create customer without postal_code" do
#
# end
#
# it "won't create customer without phone" do
#
# end
#
# it "won't create customer without movies_checked_out_count" do
#
# end
#
# it "creates customer without address" do
#
# end
#
# it "creates customer without city" do
#
# end
#
# it "creates customer without state" do
#
# end
customer.valid?.must_equal false
customer.errors.messages.must_include :phone
end

it "won't create customer without movies_checked_out_count" do
customer = customers(:bare_minimum)
customer.movies_checked_out_count = nil

customer.valid?.must_equal false
customer.errors.messages.must_include :movies_checked_out_count
end

it "creates customer without address" do
customer = customers("has_all")
customer.address = ""
customer.valid?.must_equal true
end

it "creates customer without city" do
customer = customers("has_all")
customer.city = ""
customer.valid?.must_equal true
end

it "creates customer without state" do
customer = customers("has_all")
customer.state = ""
customer.valid?.must_equal true
end
end
end