From ba23905e20b12e1cffd98d0d47afb2e8a97f2ed3 Mon Sep 17 00:00:00 2001 From: Louis Knapp Date: Sat, 30 Jul 2016 20:35:22 -0500 Subject: [PATCH] lk | doesn't display clients without agencies on the print select page --- app/controllers/clients_controller.rb | 5 ++++- app/views/clients/print_select.html.haml | 1 + spec/controllers/clients_controller_spec.rb | 10 ++++++++++ spec/factories/agencies.rb | 5 +++++ spec/factories/clients.rb | 1 - 5 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 spec/factories/agencies.rb diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 1e816c5..32a0aa6 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -32,7 +32,10 @@ class ClientsController < ApplicationController end def print_select - @clients = Client.includes(:bike).where.not(bike_id: nil).order(application_date: :desc).paginate(:page => params[:page], :per_page => 30) + @clients = Client.includes(:bike, :agency) + .where.not(bike_id: nil, agency_id: nil) + .order(application_date: :desc) + .paginate(:page => params[:page], :per_page => 30) end def print_receipts diff --git a/app/views/clients/print_select.html.haml b/app/views/clients/print_select.html.haml index 0aa6409..3b8110a 100644 --- a/app/views/clients/print_select.html.haml +++ b/app/views/clients/print_select.html.haml @@ -1,5 +1,6 @@ .container %h1 Select the clients whose receipts you would like to print + %p Only clients with a bike and an agency assigned are shown on this page. =form_tag("/clients/print_receipts", method: "get") do %table.table.table-striped.table-bordered.table-hover diff --git a/spec/controllers/clients_controller_spec.rb b/spec/controllers/clients_controller_spec.rb index 5ba4bc4..9eb95de 100644 --- a/spec/controllers/clients_controller_spec.rb +++ b/spec/controllers/clients_controller_spec.rb @@ -8,6 +8,16 @@ describe ClientsController do sign_in user end + describe "#print_select" do + it "only assigns clients with a bike and an agency" do + client_with_bike_and_agency = create :client, bike: create(:bike), agency: create(:agency) + create :client, bike: create(:bike) + create :client, agency: create(:agency) + get :print_select + expect(assigns(:clients)).to eq [client_with_bike_and_agency] + end + 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"} diff --git a/spec/factories/agencies.rb b/spec/factories/agencies.rb new file mode 100644 index 0000000..ee421a8 --- /dev/null +++ b/spec/factories/agencies.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :agency do + sequence(:name) { |n| "Agency #{n}" } + end +end diff --git a/spec/factories/clients.rb b/spec/factories/clients.rb index 7c80689..95838b4 100644 --- a/spec/factories/clients.rb +++ b/spec/factories/clients.rb @@ -4,6 +4,5 @@ FactoryGirl.define do last_name "Doe" application_date Date.new(2010, 03, 02) gender "Male" - end end