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
      spec/controllers/bikes_controller_spec.rb
  3. 4
      spec/factories/bikes.rb

1
app/controllers/bikes_controller.rb

@ -15,6 +15,7 @@ class BikesController < ApplicationController
def new def new
@bike = Bike.new @bike = Bike.new
@log_number = Bike.order(:log_number).last.log_number + 1
end end
def edit def edit

8
spec/controllers/bikes_controller_spec.rb

@ -15,4 +15,12 @@ describe BikesController do
end end
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 end

4
spec/factories/bikes.rb

@ -1,10 +1,10 @@
FactoryGirl.define do FactoryGirl.define do
factory :bike do factory :bike do
log_number "1234" sequence(:log_number)
brand "Windsor" brand "Windsor"
model "Clockwork" model "Clockwork"
bike_type "Fixed Gear" bike_type "Fixed Gear"
color "Black" color "Black"
serial_number "12345678" sequence(:serial_number)
end end
end end

Loading…
Cancel
Save