diff --git a/Gemfile b/Gemfile index 4ae55c93d..a6e0bdd54 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,7 @@ gem 'puma', '~> 3.7' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + gem 'pry-rails' end group :development do diff --git a/app/models/customer.rb b/app/models/customer.rb index d2533dbf9..68e735ecb 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,3 +1,5 @@ class Customer < ApplicationRecord has_many :rentals + + validates :name, presence: true end diff --git a/config/routes.rb b/config/routes.rb index 787824f88..b53201270 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,4 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + end diff --git a/test/models/customer_test.rb b/test/models/customer_test.rb index 5ebc5c850..c55490b8d 100644 --- a/test/models/customer_test.rb +++ b/test/models/customer_test.rb @@ -3,7 +3,27 @@ describe Customer do let(:customer) { Customer.new } - it "must be valid" do - value(customer).must_be :valid? - end + describe "validations" do + it "can be created if all fields are provided" do + start_count = Customer.count + c = Customer.new(name: "Tamira", registered_at: "Date registered", address: "An address", city: "Seattle", state: "WA", postal_code: "zip", phone: "111111111", account_credit: 15.50) + + c.must_be :valid? + + c.save + Customer.count.must_equal start_count + 1 + end # can be created + + it "can't be created without a title" do + start_count = Customer.count + c = Customer.new(registered_at: "Date registered", address: "An address", city: "Seattle", state: "WA", postal_code: "zip", phone: "111111111", account_credit: 15.50) + + c.wont_be :valid? + + # can't be saved because it isn't valid + c.save + Customer.count.must_equal start_count + + end + end # validations end diff --git a/test/models/rental_test.rb b/test/models/rental_test.rb index 6ea53d94f..0bea59f1c 100644 --- a/test/models/rental_test.rb +++ b/test/models/rental_test.rb @@ -1,9 +1,5 @@ require "test_helper" describe Rental do - let(:rental) { Rental.new } - it "must be valid" do - value(rental).must_be :valid? - end end