Browse Source

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

master
Louis Knapp 8 years ago
parent
commit
6119733ad7
  1. 8
      app/models/bike.rb
  2. 3
      notes.md
  3. 5
      spec/models/bike_spec.rb

8
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

3
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

5
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

Loading…
Cancel
Save