1
0
mirror of https://github.com/fspc/BikeShed-1.git synced 2025-02-28 16:53:23 -05:00

Fix validations for creating a bike, view respond to errors

This commit is contained in:
Jason Denney 2014-02-09 18:23:35 -05:00
parent 55974feb4c
commit d0c05a0244
3 changed files with 37 additions and 29 deletions

View File

@ -16,13 +16,13 @@ class Bike < ActiveRecord::Base
validates :shop_id, :presence => true, :uniqueness => true, :numericality => { :only_integer => true } validates :shop_id, :presence => true, :uniqueness => true, :numericality => { :only_integer => true }
validates :serial_number, :length => { :minimum => 3 } validates :serial_number, :length => { :minimum => 3 }
validates :model, :length => { :maximum => 50 } 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 :color, :presence => true
validates :bike_style_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 validates :seat_tube_height, :presence => true, :numericality => true
validates :bike_wheel_size_id, :presence => 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 validates :bike_condition_id, :presence => true, :numericality => { greater_than: 0, message: "is not a valid condition" }
validates :bike_purpose_id, :presence => true validates :bike_purpose_id, :presence => true, :numericality => { greater_than: 0, message: "is not a valid purpose" }
self.per_page = 15 self.per_page = 15

View File

@ -17,32 +17,36 @@
.controls .controls
%input{id: "serial_number", placeholder: "Serial Number", type: "text", class: "input-lg" } %input{id: "serial_number", placeholder: "Serial Number", type: "text", class: "input-lg" }
.help-block .help-block
%p .control-group
.btn-group{ "data-toggle" => "buttons-radio"} .controls
%label{ class: "btn btn-default"} .btn-group{ "data-toggle" => "buttons-radio"}
%input{ type: "radio", name: "bike_style", value: 3} RD %label{ class: "btn btn-default"}
%label{ class: "btn btn-default"} %input{ type: "radio", name: "bike_style", value: 3} RD
%input{ type: "radio", name: "bike_style", value: 1} MTN %label{ class: "btn btn-default"}
%label{ class: "btn btn-default"} %input{ type: "radio", name: "bike_style", value: 1} MTN
%input{ type: "radio", name: "bike_style", value: 2} HYB %label{ class: "btn btn-default"}
%label{ class: "btn btn-default"} %input{ type: "radio", name: "bike_style", value: 2} HYB
%input{ type: "radio", name: "bike_style", value: 4} OTHER %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 .help-block
.control-group .control-group
.controls .controls
= select_tag(:bike_wheel_size, options_for_select(@wheel_sizes), id: :bike_wheel_size_id) .btn-group{ "data-toggle" => "buttons-radio"}
.help-block %label{ class: "btn btn-default"}
%p %input{ type: "radio", name: "bike_condition", value: 2} Poor
.btn-group{ "data-toggle" => "buttons-radio"} %label{ class: "btn btn-default"}
%label{ class: "btn btn-default"} %input{ type: "radio", name: "bike_condition", value: 3} Fair
%input{ type: "radio", name: "bike_condition", value: 2} Poor %label{ class: "btn btn-default"}
%label{ class: "btn btn-default"} %input{ type: "radio", name: "bike_condition", value: 4} Good
%input{ type: "radio", name: "bike_condition", value: 3} Fair %label{ class: "btn btn-default"}
%label{ class: "btn btn-default"} %input{ type: "radio", name: "bike_condition", value: 5} Excellent
%input{ type: "radio", name: "bike_condition", value: 4} Good %input{ id: "bike_condition_id", type: "hidden"}
%label{ class: "btn btn-default"} .help-block
%input{ type: "radio", name: "bike_condition", value: 5} Excellent
.help-block
.control-group .control-group
.controls .controls
%input{id: "seat_tube_height", placeholder: "Seat Tube (cm)", type: "number", min: 0, max: 100, class: "input-lg" } %input{id: "seat_tube_height", placeholder: "Seat Tube (cm)", type: "number", min: 0, max: 100, class: "input-lg" }

View File

@ -23,6 +23,10 @@ feature "Bikes" do
visit new_bike_path visit new_bike_path
click_button "Add Bike" click_button "Add Bike"
expect(page).to have_text(:all, "is not a number") 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 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
end end