From cc3f684e01d70361d79e9a6c04532037b46208d5 Mon Sep 17 00:00:00 2001 From: Louis Knapp Date: Sat, 30 Jul 2016 20:42:08 -0500 Subject: [PATCH] lk | fixes client date saves and improves test readability --- app/controllers/clients_controller.rb | 4 ++-- spec/controllers/clients_controller_spec.rb | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 32a0aa6..93fbeb4 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -49,8 +49,8 @@ class ClientsController < ApplicationController end def client_params - params["client"]["application_date"] = Date.strptime(params["client"]["application_date"], '%m/%d/%Y') unless params["client"]["application_date"].empty? - params["client"]["pickup_date"] = Date.strptime(params["client"]["pickup_date"], '%m/%d/%Y') unless params["client"]["pickup_date"].empty? + params["client"]["application_date"] = Date.strptime(params["client"]["application_date"], '%m/%d/%Y') if params["client"]["application_date"].present? + params["client"]["pickup_date"] = Date.strptime(params["client"]["pickup_date"], '%m/%d/%Y') if params["client"]["pickup_date"].present? params.require(:client).permit( :first_name, :last_name, diff --git a/spec/controllers/clients_controller_spec.rb b/spec/controllers/clients_controller_spec.rb index 9eb95de..79e9659 100644 --- a/spec/controllers/clients_controller_spec.rb +++ b/spec/controllers/clients_controller_spec.rb @@ -19,13 +19,16 @@ describe ClientsController do end describe "PUT #update" do - xit "updates a client with an application date" do - put :update, id: client.id, client: {application_date: "12/21/2015"} - expect(client.reload.application_date.strftime('%m/%d/%Y')).to eq("12/21/2015") + it "updates a client with an application date" do + date = Time.zone.now.beginning_of_day + put :update, id: client.id, client: {application_date: date.strftime('%m/%d/%Y')} + expect(client.reload.application_date).to eq(date) end - xit "updates a client with a pickup date" do - put :update, id: client.id, client: {pickup_date: "12/21/2015"} - expect(client.reload.pickup_date.strftime('%m/%d/%Y')).to eq("12/21/2015") + + it "updates a client with a pickup date" do + date = Time.zone.now.beginning_of_day + put :update, id: client.id, client: {pickup_date: date.strftime('%m/%d/%Y')} + expect(client.reload.pickup_date).to eq(date) end end end