Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[EPIC B] add wheels scaffold.

  • Loading branch information...
commit 584beb00e38a3ea6774fc73e64457e7a82aa4c5d 1 parent c6c28f4
@btelles authored
View
20 app/controllers/wheels_controller.rb
@@ -0,0 +1,20 @@
+class WheelsController < ApplicationController
+ expose :bicycle
+ expose :wheel
+ expose(:wheels) { bicycle.wheels }
+
+ def create
+ if wheel.save
+ redirect_to [bicycle, wheel], notice: 'Wheel was successfully saved.'
+ else
+ render action: "new"
+ end
+ end
+
+ alias update create
+
+ def destroy
+ wheel.destroy
+ redirect_to bicycles_wheels_url(bicycle)
+ end
+end
View
13 app/views/wheels/_form.html.haml
@@ -0,0 +1,13 @@
+= form_for [bicycle, wheel] do |f|
+ -if wheel.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(wheel.errors.count, "error")} prohibited this wheel from being saved:"
+ %ul
+ - wheel.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :name
+ = f.text_field :name
+ .actions
+ = f.submit 'Save'
View
7 app/views/wheels/edit.html.haml
@@ -0,0 +1,7 @@
+%h1 Editing wheel
+
+= render 'form'
+
+= link_to 'Show', [bicycle, wheel]
+\|
+= link_to 'Back', [bicycle, :wheels]
View
19 app/views/wheels/index.html.haml
@@ -0,0 +1,19 @@
+%h1 Listing wheels
+
+%table
+ %tr
+ %th Name
+ %th
+ %th
+ %th
+
+ - wheels.each do |wheel|
+ %tr
+ %td= wheel.name
+ %td= link_to 'Show', [bicycle, wheel]
+ %td= link_to 'Edit', [:edit, bicycle, wheel]
+ %td= link_to 'Destroy', [bicycle, wheel], :confirm => 'Are you sure?', :method => :delete
+
+%br
+
+= link_to 'New Wheel', [:new, bicycle, :wheel]
View
5 app/views/wheels/new.html.haml
@@ -0,0 +1,5 @@
+%h1 New wheel
+
+= render 'form'
+
+= link_to 'Back', [bicycle, :wheels]
View
9 app/views/wheels/show.html.haml
@@ -0,0 +1,9 @@
+%p#notice= notice
+
+%p
+ %b Name:
+ = wheel.name
+
+= link_to 'Edit', [:edit, bicycle, wheel]
+\|
+= link_to 'Back', [bicycle, :wheels]
View
4 config/routes.rb
@@ -1,5 +1,7 @@
WildfirePc::Application.routes.draw do
- resources :bicycles
+ resources :bicycles do
+ resources :wheels
+ end
root :to => "welcome#index"
View
50 spec/requests/wheels_spec.rb
@@ -0,0 +1,50 @@
+require 'spec_helper'
+
+describe "Wheels" do
+ let(:bicycle) { FactoryGirl.create(:bicycle) }
+ let(:wheel) { FactoryGirl.create(:wheel, :name => 'First wheel', :bicycle => bicycle) }
+
+ describe "GET /wheels" do
+ it "lists all wheels" do
+ wheel
+ visit bicycle_wheels_path(bicycle)
+ page.should have_css 'td', text: 'First wheel'
+ end
+ end
+
+ describe "#show" do
+ it "shows a wheel" do
+ visit bicycle_wheel_path(bicycle, wheel)
+ page.should have_css 'p', text: 'First wheel'
+ end
+ end
+
+ describe "#new" do
+ it "lets you create new wheels" do
+ visit new_bicycle_wheel_path(bicycle)
+ fill_in('Name', with: 'my first wheel')
+ click_button 'Save'
+ page.should have_css('#notice', text: 'Wheel was successfully saved')
+ end
+ end
+
+ describe "#edit" do
+ it "lets you change existing wheels" do
+ visit edit_bicycle_wheel_path(bicycle, wheel)
+ fill_in('Name', with: 'my second wheel')
+ click_button 'Save'
+ page.should have_css('#notice', text: 'Wheel was successfully saved')
+ page.should have_css('p', text: 'my second wheel')
+ end
+ end
+
+ describe "#destroy", js: true do
+ it "lets you destroy/remove an existing wheel" do
+ wheel
+ visit bicycle_wheels_path(bicycle)
+ page.evaluate_script('window.confirm = function() { return true; }')
+ click_link 'Destroy'
+ page.should_not have_css('td', text: 'my first wheel')
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.