diff --git a/app/models/bike.rb b/app/models/bike.rb index ec676e0..70f2277 100644 --- a/app/models/bike.rb +++ b/app/models/bike.rb @@ -16,13 +16,13 @@ class Bike < ActiveRecord::Base validates :shop_id, :presence => true, :uniqueness => true, :numericality => { :only_integer => true } validates :serial_number, :length => { :minimum => 3 } validates :model, :length => { :maximum => 50 } - validates :bike_brand_id, :presence => true + validates :bike_brand_id, :presence => true, :numericality => { greater_than: 0, message: "is not a valid brand" } #validates :color, :presence => true - validates :bike_style_id, :presence => true - validates :seat_tube_height, :presence => true - validates :bike_wheel_size_id, :presence => true - validates :bike_condition_id, :presence => true - validates :bike_purpose_id, :presence => true + validates :bike_style_id, :presence => true, :numericality => { greater_than: 0, message: "is not a valid style" } + validates :seat_tube_height, :presence => true, :numericality => true + validates :bike_wheel_size_id, :presence => true, :numericality => { greater_than: 0, message: "is not a valid wheel size" } + validates :bike_condition_id, :presence => true, :numericality => { greater_than: 0, message: "is not a valid condition" } + validates :bike_purpose_id, :presence => true, :numericality => { greater_than: 0, message: "is not a valid purpose" } self.per_page = 15 diff --git a/app/views/bikes/new.html.haml b/app/views/bikes/new.html.haml index 972ad6a..76d7e65 100644 --- a/app/views/bikes/new.html.haml +++ b/app/views/bikes/new.html.haml @@ -17,32 +17,36 @@ .controls %input{id: "serial_number", placeholder: "Serial Number", type: "text", class: "input-lg" } .help-block - %p - .btn-group{ "data-toggle" => "buttons-radio"} - %label{ class: "btn btn-default"} - %input{ type: "radio", name: "bike_style", value: 3} RD - %label{ class: "btn btn-default"} - %input{ type: "radio", name: "bike_style", value: 1} MTN - %label{ class: "btn btn-default"} - %input{ type: "radio", name: "bike_style", value: 2} HYB - %label{ class: "btn btn-default"} - %input{ type: "radio", name: "bike_style", value: 4} OTHER - .help-block .control-group .controls - = select_tag(:bike_wheel_size, options_for_select(@wheel_sizes), id: :bike_wheel_size_id) - .help-block - %p - .btn-group{ "data-toggle" => "buttons-radio"} - %label{ class: "btn btn-default"} - %input{ type: "radio", name: "bike_condition", value: 2} Poor - %label{ class: "btn btn-default"} - %input{ type: "radio", name: "bike_condition", value: 3} Fair - %label{ class: "btn btn-default"} - %input{ type: "radio", name: "bike_condition", value: 4} Good - %label{ class: "btn btn-default"} - %input{ type: "radio", name: "bike_condition", value: 5} Excellent + .btn-group{ "data-toggle" => "buttons-radio"} + %label{ class: "btn btn-default"} + %input{ type: "radio", name: "bike_style", value: 3} RD + %label{ class: "btn btn-default"} + %input{ type: "radio", name: "bike_style", value: 1} MTN + %label{ class: "btn btn-default"} + %input{ type: "radio", name: "bike_style", value: 2} HYB + %label{ class: "btn btn-default"} + %input{ type: "radio", name: "bike_style", value: 4} OTHER + %input{ id: "bike_style_id", type: "hidden"} + .help-block + .control-group + .controls + = select_tag(:bike_wheel_size_id, options_for_select(@wheel_sizes), id: :bike_wheel_size_id) .help-block + .control-group + .controls + .btn-group{ "data-toggle" => "buttons-radio"} + %label{ class: "btn btn-default"} + %input{ type: "radio", name: "bike_condition", value: 2} Poor + %label{ class: "btn btn-default"} + %input{ type: "radio", name: "bike_condition", value: 3} Fair + %label{ class: "btn btn-default"} + %input{ type: "radio", name: "bike_condition", value: 4} Good + %label{ class: "btn btn-default"} + %input{ type: "radio", name: "bike_condition", value: 5} Excellent + %input{ id: "bike_condition_id", type: "hidden"} + .help-block .control-group .controls %input{id: "seat_tube_height", placeholder: "Seat Tube (cm)", type: "number", min: 0, max: 100, class: "input-lg" } diff --git a/spec/features/bikes/new_spec.rb b/spec/features/bikes/new_spec.rb index 87f6a09..555ca8b 100644 --- a/spec/features/bikes/new_spec.rb +++ b/spec/features/bikes/new_spec.rb @@ -23,6 +23,10 @@ feature "Bikes" do visit new_bike_path click_button "Add Bike" expect(page).to have_text(:all, "is not a number") + expect(page).to have_text(:all, "is not a valid brand") expect(page).to have_text(:all, "is too short") + expect(page).to have_text(:all, "is not a valid style") + expect(page).to have_text(:all, "is not a valid wheel size") + expect(page).to have_text(:all, "is not a valid condition") end end