mirror of
				https://github.com/fspc/BikeShed-1.git
				synced 2025-10-31 00: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 :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 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -17,7 +17,8 @@ | |||||||
|     .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 | ||||||
|  |     .controls | ||||||
|       .btn-group{ "data-toggle" => "buttons-radio"} |       .btn-group{ "data-toggle" => "buttons-radio"} | ||||||
|         %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: 3} RD | ||||||
| @ -27,12 +28,14 @@ | |||||||
|           %input{ type: "radio", name: "bike_style", value: 2} HYB |           %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: 4} OTHER |           %input{ type: "radio", name: "bike_style", value: 4} OTHER | ||||||
|  |     %input{ id: "bike_style_id", type: "hidden"} | ||||||
|     .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) |       = select_tag(:bike_wheel_size_id, options_for_select(@wheel_sizes), id: :bike_wheel_size_id) | ||||||
|       .help-block |       .help-block | ||||||
|   %p |   .control-group | ||||||
|  |     .controls | ||||||
|       .btn-group{ "data-toggle" => "buttons-radio"} |       .btn-group{ "data-toggle" => "buttons-radio"} | ||||||
|         %label{ class: "btn btn-default"} |         %label{ class: "btn btn-default"} | ||||||
|           %input{ type: "radio", name: "bike_condition", value: 2} Poor |           %input{ type: "radio", name: "bike_condition", value: 2} Poor | ||||||
| @ -42,6 +45,7 @@ | |||||||
|           %input{ type: "radio", name: "bike_condition", value: 4} Good |           %input{ type: "radio", name: "bike_condition", value: 4} Good | ||||||
|         %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: 5} Excellent | ||||||
|  |     %input{ id: "bike_condition_id", type: "hidden"} | ||||||
|     .help-block |     .help-block | ||||||
|   .control-group |   .control-group | ||||||
|     .controls |     .controls | ||||||
|  | |||||||
| @ -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 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user