diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb index dbd8bd9..d25bb8c 100644 --- a/app/controllers/bikes_controller.rb +++ b/app/controllers/bikes_controller.rb @@ -15,6 +15,7 @@ class BikesController < ApplicationController def new @bike = Bike.new + @log_number = Bike.order(:log_number).last.log_number + 1 end def edit diff --git a/app/views/bikes/_fields.html.haml b/app/views/bikes/_fields.html.haml index 09d43c3..8966ffb 100644 --- a/app/views/bikes/_fields.html.haml +++ b/app/views/bikes/_fields.html.haml @@ -61,22 +61,22 @@ = 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 "Tag Info", class: "col-sm-4 control-label" .col-sm-6 = f.text_area :tag_info, class: "form-control", placeholder: "+ New Component ", disabled: disabled - + .form-group = f.label "Notes", class: "col-sm-4 control-label" .col-sm-6 = f.text_area :notes, class: "form-control", disabled: disabled - + .form-group = f.label "Date Sold:", class: "col-sm-4 control-label" .col-sm-6 = f.text_field :date_sold, class: "form-control datepicker", disabled: disabled - + .form-group = f.label "Price", class: "col-sm-4 control-label" .col-sm-6 diff --git a/spec/controllers/bikes_controller_spec.rb b/spec/controllers/bikes_controller_spec.rb index 538fad5..72bf851 100644 --- a/spec/controllers/bikes_controller_spec.rb +++ b/spec/controllers/bikes_controller_spec.rb @@ -15,4 +15,12 @@ describe BikesController do end end + describe "GET #new" do + it "assigns a log number" do + FactoryGirl.create(:bike, log_number: 3) + get :new + expect(assigns(:log_number)).to eq(4) + end + end + end diff --git a/spec/factories/bikes.rb b/spec/factories/bikes.rb index ecbeb7e..2bf1ab2 100644 --- a/spec/factories/bikes.rb +++ b/spec/factories/bikes.rb @@ -1,10 +1,10 @@ FactoryGirl.define do factory :bike do - log_number "1234" - brand "Windsor" - model "Clockwork" - bike_type "Fixed Gear" - color "Black" - serial_number "12345678" + sequence(:log_number) + brand "Windsor" + model "Clockwork" + bike_type "Fixed Gear" + color "Black" + sequence(:serial_number) end end