Browse Source

lk | generates log number when new bike is logged

master
Loos 10 years ago
parent
commit
9e1f397fd7
  1. 1
      app/controllers/bikes_controller.rb
  2. 8
      app/views/bikes/_fields.html.haml
  3. 8
      spec/controllers/bikes_controller_spec.rb
  4. 12
      spec/factories/bikes.rb

1
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

8
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

8
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

12
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

Loading…
Cancel
Save