mirror of
				https://github.com/fspc/BikeShed-1.git
				synced 2025-10-28 15:45:35 -04:00 
			
		
		
		
	Fix validations for creating a bike, view respond to errors
This commit is contained in:
		
							parent
							
								
									55974feb4c
								
							
						
					
					
						commit
						d0c05a0244
					
				| @ -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 | ||||
| 
 | ||||
|  | ||||
| @ -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 | ||||
|   .control-group | ||||
|     .controls | ||||
|       .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 | ||||
|       = 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 | ||||
|       .help-block | ||||
|       .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" } | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user