Adding scaffolding for "Person"
This commit is contained in:
parent
93951515f2
commit
21ce651984
3
rails/gerbil/app/assets/javascripts/people.js.coffee
Normal file
3
rails/gerbil/app/assets/javascripts/people.js.coffee
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
3
rails/gerbil/app/assets/stylesheets/people.css.scss
Normal file
3
rails/gerbil/app/assets/stylesheets/people.css.scss
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Place all the styles related to the People controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
56
rails/gerbil/app/assets/stylesheets/scaffolds.css.scss
Normal file
56
rails/gerbil/app/assets/stylesheets/scaffolds.css.scss
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
body {
|
||||||
|
background-color: #fff;
|
||||||
|
color: #333;
|
||||||
|
font-family: verdana, arial, helvetica, sans-serif;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 18px; }
|
||||||
|
|
||||||
|
p, ol, ul, td {
|
||||||
|
font-family: verdana, arial, helvetica, sans-serif;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 18px; }
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background-color: #eee;
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 11px; }
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #000;
|
||||||
|
&:visited {
|
||||||
|
color: #666; }
|
||||||
|
&:hover {
|
||||||
|
color: #fff;
|
||||||
|
background-color: #000; } }
|
||||||
|
|
||||||
|
div {
|
||||||
|
&.field, &.actions {
|
||||||
|
margin-bottom: 10px; } }
|
||||||
|
|
||||||
|
#notice {
|
||||||
|
color: green; }
|
||||||
|
|
||||||
|
.field_with_errors {
|
||||||
|
padding: 2px;
|
||||||
|
background-color: red;
|
||||||
|
display: table; }
|
||||||
|
|
||||||
|
#error_explanation {
|
||||||
|
width: 450px;
|
||||||
|
border: 2px solid red;
|
||||||
|
padding: 7px;
|
||||||
|
padding-bottom: 0;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
h2 {
|
||||||
|
text-align: left;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 5px 5px 5px 15px;
|
||||||
|
font-size: 12px;
|
||||||
|
margin: -7px;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
background-color: #c00;
|
||||||
|
color: #fff; }
|
||||||
|
ul li {
|
||||||
|
font-size: 12px;
|
||||||
|
list-style: square; } }
|
83
rails/gerbil/app/controllers/people_controller.rb
Normal file
83
rails/gerbil/app/controllers/people_controller.rb
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
class PeopleController < ApplicationController
|
||||||
|
# GET /people
|
||||||
|
# GET /people.json
|
||||||
|
def index
|
||||||
|
@people = Person.all
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # index.html.erb
|
||||||
|
format.json { render :json => @people }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /people/1
|
||||||
|
# GET /people/1.json
|
||||||
|
def show
|
||||||
|
@person = Person.find(params[:id])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # show.html.erb
|
||||||
|
format.json { render :json => @person }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /people/new
|
||||||
|
# GET /people/new.json
|
||||||
|
def new
|
||||||
|
@person = Person.new
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # new.html.erb
|
||||||
|
format.json { render :json => @person }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /people/1/edit
|
||||||
|
def edit
|
||||||
|
@person = Person.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /people
|
||||||
|
# POST /people.json
|
||||||
|
def create
|
||||||
|
@person = Person.new(params[:person])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @person.save
|
||||||
|
format.html { redirect_to @person, :notice => 'Person was successfully created.' }
|
||||||
|
format.json { render :json => @person, :status => :created, :location => @person }
|
||||||
|
else
|
||||||
|
format.html { render :action => "new" }
|
||||||
|
format.json { render :json => @person.errors, :status => :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PUT /people/1
|
||||||
|
# PUT /people/1.json
|
||||||
|
def update
|
||||||
|
@person = Person.find(params[:id])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @person.update_attributes(params[:person])
|
||||||
|
format.html { redirect_to @person, :notice => 'Person was successfully updated.' }
|
||||||
|
format.json { head :ok }
|
||||||
|
else
|
||||||
|
format.html { render :action => "edit" }
|
||||||
|
format.json { render :json => @person.errors, :status => :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /people/1
|
||||||
|
# DELETE /people/1.json
|
||||||
|
def destroy
|
||||||
|
@person = Person.find(params[:id])
|
||||||
|
@person.destroy
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to people_url }
|
||||||
|
format.json { head :ok }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
2
rails/gerbil/app/helpers/people_helper.rb
Normal file
2
rails/gerbil/app/helpers/people_helper.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
module PeopleHelper
|
||||||
|
end
|
2
rails/gerbil/app/models/person.rb
Normal file
2
rails/gerbil/app/models/person.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
class Person < ActiveRecord::Base
|
||||||
|
end
|
29
rails/gerbil/app/views/people/_form.html.erb
Normal file
29
rails/gerbil/app/views/people/_form.html.erb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<%= form_for(@person) do |f| %>
|
||||||
|
<% if @person.errors.any? %>
|
||||||
|
<div id="error_explanation">
|
||||||
|
<h2><%= pluralize(@person.errors.count, "error") %> prohibited this person from being saved:</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<% @person.errors.full_messages.each do |msg| %>
|
||||||
|
<li><%= msg %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :name %><br />
|
||||||
|
<%= f.text_field :name %>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :age %><br />
|
||||||
|
<%= f.number_field :age %>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :zipcode %><br />
|
||||||
|
<%= f.text_field :zipcode %>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<%= f.submit %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
6
rails/gerbil/app/views/people/edit.html.erb
Normal file
6
rails/gerbil/app/views/people/edit.html.erb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<h1>Editing person</h1>
|
||||||
|
|
||||||
|
<%= render 'form' %>
|
||||||
|
|
||||||
|
<%= link_to 'Show', @person %> |
|
||||||
|
<%= link_to 'Back', people_path %>
|
27
rails/gerbil/app/views/people/index.html.erb
Normal file
27
rails/gerbil/app/views/people/index.html.erb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<h1>Listing people</h1>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Age</th>
|
||||||
|
<th>Zipcode</th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% @people.each do |person| %>
|
||||||
|
<tr>
|
||||||
|
<td><%= person.name %></td>
|
||||||
|
<td><%= person.age %></td>
|
||||||
|
<td><%= person.zipcode %></td>
|
||||||
|
<td><%= link_to 'Show', person %></td>
|
||||||
|
<td><%= link_to 'Edit', edit_person_path(person) %></td>
|
||||||
|
<td><%= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<%= link_to 'New Person', new_person_path %>
|
5
rails/gerbil/app/views/people/new.html.erb
Normal file
5
rails/gerbil/app/views/people/new.html.erb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<h1>New person</h1>
|
||||||
|
|
||||||
|
<%= render 'form' %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', people_path %>
|
20
rails/gerbil/app/views/people/show.html.erb
Normal file
20
rails/gerbil/app/views/people/show.html.erb
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<p id="notice"><%= notice %></p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Name:</b>
|
||||||
|
<%= @person.name %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Age:</b>
|
||||||
|
<%= @person.age %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Zipcode:</b>
|
||||||
|
<%= @person.zipcode %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<%= link_to 'Edit', edit_person_path(@person) %> |
|
||||||
|
<%= link_to 'Back', people_path %>
|
@ -1,4 +1,6 @@
|
|||||||
Gerbil::Application.routes.draw do
|
Gerbil::Application.routes.draw do
|
||||||
|
resources :people
|
||||||
|
|
||||||
# The priority is based upon order of creation:
|
# The priority is based upon order of creation:
|
||||||
# first created -> highest priority.
|
# first created -> highest priority.
|
||||||
|
|
||||||
|
11
rails/gerbil/db/migrate/20111114120238_create_people.rb
Normal file
11
rails/gerbil/db/migrate/20111114120238_create_people.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
class CreatePeople < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :people do |t|
|
||||||
|
t.string :name
|
||||||
|
t.integer :age
|
||||||
|
t.string :zipcode
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
23
rails/gerbil/db/schema.rb
Normal file
23
rails/gerbil/db/schema.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# This file is auto-generated from the current state of the database. Instead
|
||||||
|
# of editing this file, please use the migrations feature of Active Record to
|
||||||
|
# incrementally modify your database, and then regenerate this schema definition.
|
||||||
|
#
|
||||||
|
# Note that this schema.rb definition is the authoritative source for your
|
||||||
|
# database schema. If you need to create the application database on another
|
||||||
|
# system, you should be using db:schema:load, not running all the migrations
|
||||||
|
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||||
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||||
|
#
|
||||||
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
|
ActiveRecord::Schema.define(:version => 20111114120238) do
|
||||||
|
|
||||||
|
create_table "people", :force => true do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.integer "age"
|
||||||
|
t.string "zipcode"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
157
rails/gerbil/spec/controllers/people_controller_spec.rb
Normal file
157
rails/gerbil/spec/controllers/people_controller_spec.rb
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
||||||
|
# It demonstrates how one might use RSpec to specify the controller code that
|
||||||
|
# was generated by Rails when you ran the scaffold generator.
|
||||||
|
#
|
||||||
|
# It assumes that the implementation code is generated by the rails scaffold
|
||||||
|
# generator. If you are using any extension libraries to generate different
|
||||||
|
# controller code, this generated spec may or may not pass.
|
||||||
|
#
|
||||||
|
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
||||||
|
# of tools you can use to make these specs even more expressive, but we're
|
||||||
|
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
||||||
|
#
|
||||||
|
# Compared to earlier versions of this generator, there is very limited use of
|
||||||
|
# stubs and message expectations in this spec. Stubs are only used when there
|
||||||
|
# is no simpler way to get a handle on the object needed for the example.
|
||||||
|
# Message expectations are only used when there is no simpler way to specify
|
||||||
|
# that an instance is receiving a specific message.
|
||||||
|
|
||||||
|
describe PeopleController do
|
||||||
|
|
||||||
|
# This should return the minimal set of attributes required to create a valid
|
||||||
|
# Person. As you add validations to Person, be sure to
|
||||||
|
# update the return value of this method accordingly.
|
||||||
|
def valid_attributes
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET index" do
|
||||||
|
it "assigns all people as @people" do
|
||||||
|
person = Person.create! valid_attributes
|
||||||
|
get :index
|
||||||
|
assigns(:people).should eq([person])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET show" do
|
||||||
|
it "assigns the requested person as @person" do
|
||||||
|
person = Person.create! valid_attributes
|
||||||
|
get :show, :id => person.id
|
||||||
|
assigns(:person).should eq(person)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET new" do
|
||||||
|
it "assigns a new person as @person" do
|
||||||
|
get :new
|
||||||
|
assigns(:person).should be_a_new(Person)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET edit" do
|
||||||
|
it "assigns the requested person as @person" do
|
||||||
|
person = Person.create! valid_attributes
|
||||||
|
get :edit, :id => person.id
|
||||||
|
assigns(:person).should eq(person)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "POST create" do
|
||||||
|
describe "with valid params" do
|
||||||
|
it "creates a new Person" do
|
||||||
|
expect {
|
||||||
|
post :create, :person => valid_attributes
|
||||||
|
}.to change(Person, :count).by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "assigns a newly created person as @person" do
|
||||||
|
post :create, :person => valid_attributes
|
||||||
|
assigns(:person).should be_a(Person)
|
||||||
|
assigns(:person).should be_persisted
|
||||||
|
end
|
||||||
|
|
||||||
|
it "redirects to the created person" do
|
||||||
|
post :create, :person => valid_attributes
|
||||||
|
response.should redirect_to(Person.last)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "with invalid params" do
|
||||||
|
it "assigns a newly created but unsaved person as @person" do
|
||||||
|
# Trigger the behavior that occurs when invalid params are submitted
|
||||||
|
Person.any_instance.stub(:save).and_return(false)
|
||||||
|
post :create, :person => {}
|
||||||
|
assigns(:person).should be_a_new(Person)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "re-renders the 'new' template" do
|
||||||
|
# Trigger the behavior that occurs when invalid params are submitted
|
||||||
|
Person.any_instance.stub(:save).and_return(false)
|
||||||
|
post :create, :person => {}
|
||||||
|
response.should render_template("new")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "PUT update" do
|
||||||
|
describe "with valid params" do
|
||||||
|
it "updates the requested person" do
|
||||||
|
person = Person.create! valid_attributes
|
||||||
|
# Assuming there are no other people in the database, this
|
||||||
|
# specifies that the Person created on the previous line
|
||||||
|
# receives the :update_attributes message with whatever params are
|
||||||
|
# submitted in the request.
|
||||||
|
Person.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
|
||||||
|
put :update, :id => person.id, :person => {'these' => 'params'}
|
||||||
|
end
|
||||||
|
|
||||||
|
it "assigns the requested person as @person" do
|
||||||
|
person = Person.create! valid_attributes
|
||||||
|
put :update, :id => person.id, :person => valid_attributes
|
||||||
|
assigns(:person).should eq(person)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "redirects to the person" do
|
||||||
|
person = Person.create! valid_attributes
|
||||||
|
put :update, :id => person.id, :person => valid_attributes
|
||||||
|
response.should redirect_to(person)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "with invalid params" do
|
||||||
|
it "assigns the person as @person" do
|
||||||
|
person = Person.create! valid_attributes
|
||||||
|
# Trigger the behavior that occurs when invalid params are submitted
|
||||||
|
Person.any_instance.stub(:save).and_return(false)
|
||||||
|
put :update, :id => person.id, :person => {}
|
||||||
|
assigns(:person).should eq(person)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "re-renders the 'edit' template" do
|
||||||
|
person = Person.create! valid_attributes
|
||||||
|
# Trigger the behavior that occurs when invalid params are submitted
|
||||||
|
Person.any_instance.stub(:save).and_return(false)
|
||||||
|
put :update, :id => person.id, :person => {}
|
||||||
|
response.should render_template("edit")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "DELETE destroy" do
|
||||||
|
it "destroys the requested person" do
|
||||||
|
person = Person.create! valid_attributes
|
||||||
|
expect {
|
||||||
|
delete :destroy, :id => person.id
|
||||||
|
}.to change(Person, :count).by(-1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "redirects to the people list" do
|
||||||
|
person = Person.create! valid_attributes
|
||||||
|
delete :destroy, :id => person.id
|
||||||
|
response.should redirect_to(people_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
15
rails/gerbil/spec/helpers/people_helper_spec.rb
Normal file
15
rails/gerbil/spec/helpers/people_helper_spec.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
# Specs in this file have access to a helper object that includes
|
||||||
|
# the PeopleHelper. For example:
|
||||||
|
#
|
||||||
|
# describe PeopleHelper do
|
||||||
|
# describe "string concat" do
|
||||||
|
# it "concats two strings with spaces" do
|
||||||
|
# helper.concat_strings("this","that").should == "this that"
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
describe PeopleHelper do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
5
rails/gerbil/spec/models/person_spec.rb
Normal file
5
rails/gerbil/spec/models/person_spec.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Person do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
11
rails/gerbil/spec/requests/people_spec.rb
Normal file
11
rails/gerbil/spec/requests/people_spec.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe "People" do
|
||||||
|
describe "GET /people" do
|
||||||
|
it "works! (now write some real specs)" do
|
||||||
|
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
|
||||||
|
get people_path
|
||||||
|
response.status.should be(200)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
35
rails/gerbil/spec/routing/people_routing_spec.rb
Normal file
35
rails/gerbil/spec/routing/people_routing_spec.rb
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe PeopleController do
|
||||||
|
describe "routing" do
|
||||||
|
|
||||||
|
it "routes to #index" do
|
||||||
|
get("/people").should route_to("people#index")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #new" do
|
||||||
|
get("/people/new").should route_to("people#new")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #show" do
|
||||||
|
get("/people/1").should route_to("people#show", :id => "1")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #edit" do
|
||||||
|
get("/people/1/edit").should route_to("people#edit", :id => "1")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #create" do
|
||||||
|
post("/people").should route_to("people#create")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #update" do
|
||||||
|
put("/people/1").should route_to("people#update", :id => "1")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "routes to #destroy" do
|
||||||
|
delete("/people/1").should route_to("people#destroy", :id => "1")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
22
rails/gerbil/spec/views/people/edit.html.erb_spec.rb
Normal file
22
rails/gerbil/spec/views/people/edit.html.erb_spec.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe "people/edit.html.erb" do
|
||||||
|
before(:each) do
|
||||||
|
@person = assign(:person, stub_model(Person,
|
||||||
|
:name => "MyString",
|
||||||
|
:age => 1,
|
||||||
|
:zipcode => "MyString"
|
||||||
|
))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders the edit person form" do
|
||||||
|
render
|
||||||
|
|
||||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||||
|
assert_select "form", :action => people_path(@person), :method => "post" do
|
||||||
|
assert_select "input#person_name", :name => "person[name]"
|
||||||
|
assert_select "input#person_age", :name => "person[age]"
|
||||||
|
assert_select "input#person_zipcode", :name => "person[zipcode]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
28
rails/gerbil/spec/views/people/index.html.erb_spec.rb
Normal file
28
rails/gerbil/spec/views/people/index.html.erb_spec.rb
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe "people/index.html.erb" do
|
||||||
|
before(:each) do
|
||||||
|
assign(:people, [
|
||||||
|
stub_model(Person,
|
||||||
|
:name => "Name",
|
||||||
|
:age => 1,
|
||||||
|
:zipcode => "Zipcode"
|
||||||
|
),
|
||||||
|
stub_model(Person,
|
||||||
|
:name => "Name",
|
||||||
|
:age => 1,
|
||||||
|
:zipcode => "Zipcode"
|
||||||
|
)
|
||||||
|
])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders a list of people" do
|
||||||
|
render
|
||||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||||
|
assert_select "tr>td", :text => "Name".to_s, :count => 2
|
||||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||||
|
assert_select "tr>td", :text => 1.to_s, :count => 2
|
||||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||||
|
assert_select "tr>td", :text => "Zipcode".to_s, :count => 2
|
||||||
|
end
|
||||||
|
end
|
22
rails/gerbil/spec/views/people/new.html.erb_spec.rb
Normal file
22
rails/gerbil/spec/views/people/new.html.erb_spec.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe "people/new.html.erb" do
|
||||||
|
before(:each) do
|
||||||
|
assign(:person, stub_model(Person,
|
||||||
|
:name => "MyString",
|
||||||
|
:age => 1,
|
||||||
|
:zipcode => "MyString"
|
||||||
|
).as_new_record)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders new person form" do
|
||||||
|
render
|
||||||
|
|
||||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||||
|
assert_select "form", :action => people_path, :method => "post" do
|
||||||
|
assert_select "input#person_name", :name => "person[name]"
|
||||||
|
assert_select "input#person_age", :name => "person[age]"
|
||||||
|
assert_select "input#person_zipcode", :name => "person[zipcode]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
21
rails/gerbil/spec/views/people/show.html.erb_spec.rb
Normal file
21
rails/gerbil/spec/views/people/show.html.erb_spec.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe "people/show.html.erb" do
|
||||||
|
before(:each) do
|
||||||
|
@person = assign(:person, stub_model(Person,
|
||||||
|
:name => "Name",
|
||||||
|
:age => 1,
|
||||||
|
:zipcode => "Zipcode"
|
||||||
|
))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders attributes in <p>" do
|
||||||
|
render
|
||||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||||
|
rendered.should match(/Name/)
|
||||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||||
|
rendered.should match(/1/)
|
||||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||||
|
rendered.should match(/Zipcode/)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user