diff --git a/app/models/bike.rb b/app/models/bike.rb index 5106b9d..4a16c24 100644 --- a/app/models/bike.rb +++ b/app/models/bike.rb @@ -42,8 +42,12 @@ class Bike < ActiveRecord::Base end def self.available_for_freecyclery - assigned_bikes = Client.all.includes(:bike).select{|c| !c.bike_id.nil?}.map(&:bike) - all_freecyclery_bikes = Bike.where(purpose: FREECYCLERY).order(log_number: :desc) + assigned_bikes = Client + .where("application_voided != ? or application_voided is null", true) + .includes(:bike) + .select{|c| !c.bike_id.nil?}.map(&:bike) + all_freecyclery_bikes = Bike.where(purpose: FREECYCLERY) + .order(log_number: :desc) all_freecyclery_bikes - assigned_bikes end diff --git a/notes.md b/notes.md index cfcd6c6..a1857be 100644 --- a/notes.md +++ b/notes.md @@ -15,9 +15,6 @@ - enable posting to bike index when a bike is created - add tests to ensure that pages render -# Bugs -- when application voided, bike should go back to pool of bikes - # Other Reports General Reports diff --git a/spec/models/bike_spec.rb b/spec/models/bike_spec.rb index 6b37ddf..2dc8acd 100644 --- a/spec/models/bike_spec.rb +++ b/spec/models/bike_spec.rb @@ -31,6 +31,11 @@ describe Bike do create :client, bike_id: bike.id expect(Bike.available_for_freecyclery).to be_empty end + it "returns bikes that were assigned to clients whose application has been voided" do + bike = create :bike, :freecyclery + create :client, bike_id: bike.id, application_voided: true + expect(Bike.available_for_freecyclery).to eq [bike] + end it "does not return sales bikes" do bike = create :bike, :sale create :client, bike_id: bike.id