From e7c6c3bb30751c759f18b5be047d71a1c824df23 Mon Sep 17 00:00:00 2001 From: Spatterjaaay Date: Tue, 9 May 2017 15:14:10 -0700 Subject: [PATCH 1/2] added tests for customer validations --- app/models/customer.rb | 4 ++ test/models/customer_test.rb | 98 ++++++++++++++++++++++-------------- 2 files changed, 65 insertions(+), 37 deletions(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index a62356cd9..5e3aa1363 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -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 diff --git a/test/models/customer_test.rb b/test/models/customer_test.rb index 6e3c91944..fca3f5f42 100644 --- a/test/models/customer_test.rb +++ b/test/models/customer_test.rb @@ -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 = Customer.new + 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 From 72b597ee1fc88eb9bd6c905927ff1e26d0bf15bf Mon Sep 17 00:00:00 2001 From: Spatterjaaay Date: Tue, 9 May 2017 15:16:50 -0700 Subject: [PATCH 2/2] fixed one failing test --- test/models/customer_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/customer_test.rb b/test/models/customer_test.rb index fca3f5f42..00baceb4a 100644 --- a/test/models/customer_test.rb +++ b/test/models/customer_test.rb @@ -5,7 +5,7 @@ # let(:customer) { Customer.new } it "you can create a customer" do - customer = Customer.new + customer = customers(:bare_minimum) customer.valid?.must_equal true end