Browse Source

lk | adds explanatory text to waiting list & disables mark_as_sold button for sold bikes, and removes unused columns

master
Louis Knapp 8 years ago
parent
commit
9c53f81672
  1. 2
      app/controllers/bikes_controller.rb
  2. 4
      app/models/bike.rb
  3. 2
      app/views/bikes/edit.html.haml
  4. 7
      app/views/bikes/show.html.haml
  5. 1
      app/views/clients/index.html.haml
  6. 5
      db/migrate/20160731014517_remove_entry_date_column_from_bikes.rb
  7. 3
      db/schema.rb
  8. 102
      lib/tasks/dummydata.rake
  9. 7
      notes.md
  10. 12
      spec/models/bike_spec.rb

2
app/controllers/bikes_controller.rb

@ -1,5 +1,5 @@
class BikesController < ApplicationController
before_action :set_bike, only: [:show, :edit, :update, :destroy]
before_action :set_bike, only: [:edit, :update, :destroy]
before_action :authenticate_user!
def index

4
app/models/bike.rb

@ -25,6 +25,10 @@ class Bike < ActiveRecord::Base
]
end
def sold?
date_sold.present?
end
def name
self.color + " " + self.brand + ' ' + self.model + " (" + self.log_number.to_s + ")"
end

2
app/views/bikes/edit.html.haml

@ -3,7 +3,7 @@
.col-sm-6
%h1 Edit bike
.col-sm-3.col-sm-offset-3
=button_to "Mark as sold", {action: "mark_as_sold", id: @bike.id}, method: :patch, class: "btn btn-default"
=button_to "Mark as sold", {action: "mark_as_sold", id: @bike.id}, method: :patch, class: "btn btn-default", disabled: @bike.sold?
= render 'edit_form'
.bottom-nav-links
- if @previous_bike

7
app/views/bikes/show.html.haml

@ -1,7 +0,0 @@
.container
%p#notice= notice
= form_for(@bike) do |f|
= render 'fields', f: f, disabled: true
= link_to 'Edit', edit_bike_path(@bike)
|
= link_to 'Back', bikes_path

1
app/views/clients/index.html.haml

@ -3,6 +3,7 @@
= link_to ' + New Client', new_client_path, class: "btn btn-default"
.row
%h1 Client Waiting List
%p The waiting list shows clients who have not been voided or picked up their bike. Only clients with an application date are shown.
%table.table.table-striped.table-bordered.table-hover
%thead

5
db/migrate/20160731014517_remove_entry_date_column_from_bikes.rb

@ -0,0 +1,5 @@
class RemoveEntryDateColumnFromBikes < ActiveRecord::Migration
def change
remove_column :bikes, :entry_date
end
end

3
db/schema.rb

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160724130507) do
ActiveRecord::Schema.define(version: 20160731014517) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -28,7 +28,6 @@ ActiveRecord::Schema.define(version: 20160724130507) do
end
create_table "bikes", force: :cascade do |t|
t.string "entry_date"
t.string "brand"
t.string "model"
t.string "bike_type"

102
lib/tasks/dummydata.rake

@ -1,102 +0,0 @@
namespace :db do
desc "Add some random sample data"
task dummy_data: :environment do
puts "clearing users"
User.destroy_all
puts "clearing bikes"
Bike.destroy_all
puts "clearing clients"
Client.destroy_all
puts "clearing agencies"
Agency.destroy_all
def random_agency
return {
name: Faker::Company.name,
contact_name: Faker::Name.name,
street_address: Faker::Address.street_address,
city: Faker::Address.city,
state: "IL",
postal_code: Faker::Number.number(5),
phone: Faker::Number.number(7),
email: Faker::Internet.email
}
end
def random_client
return {
first_name: Faker::Name.first_name,
last_name: Faker::Name.last_name,
application_date: rand(5.years).ago,
gender: ["male", "female"].sample,
age: rand(45) + 15,
weight: rand(100) + 100,
helmet: [true, false].sample,
lock: [true, false].sample,
bike_type_requested: ["Cruiser", "Road", "Mountain"].sample,
will_pay: [true, false].sample,
notes: "A great client!",
bike_fixed: [true, false].sample,
number_of_calls: [0, 1, 2].sample,
application_voided: [false, false, false, false, true].sample,
pickup_date: rand(10.days).ago,
volunteer_at_pickup: Faker::Name.first_name
}
end
def random_bike
return {
entry_date: rand(3.years).ago,
brand: ["Windsor", "Schwinn", "Magna", "Fuji", "Cannondale", "Bianchi", "Jamis", "Felt"].sample,
model: Faker::Hacker.verb,
bike_type: ["Cruiser", "BMX", "Fixie", "Utility", "Road", "Hybrid", "Kids"].sample,
color: Faker::Commerce.color,
serial_number: Faker::Number.number(10),
notes: Faker::Lorem.sentence,
tag_info: Faker::Lorem.sentence,
price: rand(400) + 50,
seat_tube_size: rand(45),
top_tube_size: rand(45),
log_number: Faker::Number.number(8),
purpose: ["Sale", "Freecyclery"].sample,
mechanic: Faker::Name.first_name,
new_parts: Array.new(4) {Faker::Commerce.product_name}.join("\n"),
work_done: Faker::Hacker.say_something_smart
## , date_sold: rand(2.months).ago,
}
end
puts "creating a new user"
user = User.new(email: "user@example.com", password: "password").save
puts "creating some clients"
10.times do
Client.new(random_client).save
end
clients = Client.all
puts "creating some bikes"
30.times do
Bike.new(random_bike).save
end
bikes = Bike.all
puts "creating some agencies"
5.times do
Agency.new(random_agency).save
end
agencies = Agency.all
puts "assigning agencies to clients"
Client.all.each do |client|
client.update_attribute("agency_id", agencies.sample.id)
end
puts "assigning bikes to clients"
Client.all.each_with_index do |client, index|
client.update_attribute("bike_id", Bike.all[index].id)
end
end
end

7
notes.md

@ -8,9 +8,6 @@
- restyle agencies page to not have show or destroy links
# Tech
- bike date_sold column should be datetime
- remove bike#entry_date column because it is now fixed_at
- add tests to ensure that pages render
- use log number in bike url instead of id
- paginate 'all clients' page
- convert to bootstrap-less
@ -19,10 +16,10 @@
- remove clients#number_of_calls
- remove clients#application_date_bkp
- remove clients#pickup_Date_bkp
- bike date_sold column should be datetime
- add tests to ensure that pages render
# Bugs
- when client is created without date, app breaks
- mark as sold should be disabled after bike is sold
- when application voided, bike should go back to pool of bikes
# Other

12
spec/models/bike_spec.rb

@ -1,6 +1,18 @@
require 'spec_helper'
describe Bike do
describe "#sold?" do
it "returns true if the date_sold is present" do
bike = build :bike, date_sold: Time.zone.now
expect(bike.sold?).to be true
end
it "returns false if date_sold is not present" do
bike = build :bike
expect(bike.sold?).to be false
end
end
describe "#post_to_bike_index" do
it "does not calls BikeIndexLogger if no bike_index_id is present" do
expect(BikeIndexLogger).not_to receive(:perform_async)

Loading…
Cancel
Save