From 9c53f8167249ed72af19d8a6735e5518422cdca9 Mon Sep 17 00:00:00 2001 From: Louis Knapp Date: Sat, 30 Jul 2016 20:58:56 -0500 Subject: [PATCH] lk | adds explanatory text to waiting list & disables mark_as_sold button for sold bikes, and removes unused columns --- app/controllers/bikes_controller.rb | 2 +- app/models/bike.rb | 4 + app/views/bikes/edit.html.haml | 2 +- app/views/bikes/show.html.haml | 7 -- app/views/clients/index.html.haml | 1 + ...517_remove_entry_date_column_from_bikes.rb | 5 + db/schema.rb | 3 +- lib/tasks/dummydata.rake | 102 ------------------ notes.md | 7 +- spec/models/bike_spec.rb | 12 +++ 10 files changed, 27 insertions(+), 118 deletions(-) delete mode 100644 app/views/bikes/show.html.haml create mode 100644 db/migrate/20160731014517_remove_entry_date_column_from_bikes.rb delete mode 100644 lib/tasks/dummydata.rake diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb index 27d01b1..2f371cb 100644 --- a/app/controllers/bikes_controller.rb +++ b/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 diff --git a/app/models/bike.rb b/app/models/bike.rb index a241237..5106b9d 100644 --- a/app/models/bike.rb +++ b/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 diff --git a/app/views/bikes/edit.html.haml b/app/views/bikes/edit.html.haml index c1240fa..e748045 100644 --- a/app/views/bikes/edit.html.haml +++ b/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 diff --git a/app/views/bikes/show.html.haml b/app/views/bikes/show.html.haml deleted file mode 100644 index e292bfa..0000000 --- a/app/views/bikes/show.html.haml +++ /dev/null @@ -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 diff --git a/app/views/clients/index.html.haml b/app/views/clients/index.html.haml index 8a031e1..c708056 100644 --- a/app/views/clients/index.html.haml +++ b/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 diff --git a/db/migrate/20160731014517_remove_entry_date_column_from_bikes.rb b/db/migrate/20160731014517_remove_entry_date_column_from_bikes.rb new file mode 100644 index 0000000..cb618f5 --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index e6e9b5c..ba35ca1 100644 --- a/db/schema.rb +++ b/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" diff --git a/lib/tasks/dummydata.rake b/lib/tasks/dummydata.rake deleted file mode 100644 index 5046278..0000000 --- a/lib/tasks/dummydata.rake +++ /dev/null @@ -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 diff --git a/notes.md b/notes.md index 4811f5c..16f576e 100644 --- a/notes.md +++ b/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 diff --git a/spec/models/bike_spec.rb b/spec/models/bike_spec.rb index dcf1d2f..6b37ddf 100644 --- a/spec/models/bike_spec.rb +++ b/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)