mirror of
https://github.com/fspc/bike-database.git
synced 2025-02-23 09:33:23 -05:00
lk | add time_spent field to bikes
This commit is contained in:
parent
fa2c2ede08
commit
d49f6030ed
@ -76,6 +76,7 @@ class BikesController < ApplicationController
|
||||
params[:bike][:fixed_at] = DateTime.strptime(params[:bike][:fixed_at], "%m/%d/%Y") if params[:bike][:fixed_at].present?
|
||||
params[:bike][:date_sold] = DateTime.strptime(params[:bike][:date_sold], "%m/%d/%Y") if params[:bike][:date_sold].present?
|
||||
params.require(:bike).permit(
|
||||
:time_spent,
|
||||
:fixed_at,
|
||||
:brand,
|
||||
:model,
|
||||
|
@ -5,6 +5,7 @@ class Bike < ActiveRecord::Base
|
||||
validates :bike_type, presence: true
|
||||
validates :color, presence: true
|
||||
validates :serial_number, presence: true
|
||||
validates_numericality_of :time_spent, greater_than_or_equal_to: 0, allow_nil: true
|
||||
has_one :client
|
||||
|
||||
FREECYCLERY = "Freecyclery"
|
||||
|
@ -30,6 +30,11 @@
|
||||
.col-sm-6
|
||||
= f.text_field :color, class: "form-control", disabled: disabled
|
||||
|
||||
.form-group
|
||||
= f.label "Purpose:", class: "col-sm-4 control-label"
|
||||
.col-sm-6
|
||||
= f.select :purpose, [["Freecyclery", "Freecyclery"], ["Sale", "Sale"]], {}, class: "selectpicker", disabled: disabled
|
||||
|
||||
.col-sm-6
|
||||
.form-group
|
||||
= f.label "Mechanic:", class: "col-sm-4 control-label"
|
||||
@ -56,14 +61,13 @@
|
||||
.col-sm-6
|
||||
= f.text_field :fixed_at, class: "form-control datepicker", :value => @bike.fixed_at ? @bike.fixed_at.strftime("%m/%d/%Y") : "", disabled: disabled
|
||||
|
||||
.form-group
|
||||
= f.label "Time Spent (Hours):", class: "col-sm-4 control-label"
|
||||
.col-sm-6
|
||||
= f.text_field :time_spent, class: "form-control", type: "number", disabled: disabled
|
||||
|
||||
.row
|
||||
.col-sm-6
|
||||
%br
|
||||
%br
|
||||
.form-group
|
||||
= f.label "Purpose:", class: "col-sm-4 control-label"
|
||||
.col-sm-6
|
||||
= f.select :purpose, [["Freecyclery", "Freecyclery"], ["Sale", "Sale"]], {}, class: "selectpicker", disabled: disabled
|
||||
|
||||
.form-group
|
||||
= f.label "New Parts", class: "col-sm-4 control-label"
|
||||
|
5
db/migrate/20170713233459_add_time_spent_to_bikes.rb
Normal file
5
db/migrate/20170713233459_add_time_spent_to_bikes.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddTimeSpentToBikes < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :bikes, :time_spent, :int
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160731020658) do
|
||||
ActiveRecord::Schema.define(version: 20170713233459) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -46,6 +46,7 @@ ActiveRecord::Schema.define(version: 20160731020658) do
|
||||
t.datetime "date_sold"
|
||||
t.integer "bike_index_id"
|
||||
t.datetime "fixed_at"
|
||||
t.integer "time_spent"
|
||||
end
|
||||
|
||||
create_table "clients", force: :cascade do |t|
|
||||
|
@ -1,6 +1,12 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Bike do
|
||||
describe "validations" do
|
||||
it "is invalid if time_spent is negative" do
|
||||
bike = build :bike, time_spent: -3
|
||||
expect(bike.valid?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#sold?" do
|
||||
it "returns true if the date_sold is present" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user