1
0
mirror of https://github.com/fspc/bike-database.git synced 2025-02-23 09:33:23 -05:00

lk | bikes with voided applications show up in the available for freecyclery list

This commit is contained in:
Louis Knapp 2016-07-30 21:46:04 -05:00
parent cc00aec5ad
commit 6119733ad7
3 changed files with 11 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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