OSDN Git Service

ご恩登録機能のCRUDをscaffoldベースで生成し実装 master
authorS.Isogai <dev@moving-castle-on-the-web.net>
Sun, 17 Apr 2011 07:13:43 +0000 (16:13 +0900)
committerS.Isogai <dev@moving-castle-on-the-web.net>
Sun, 17 Apr 2011 07:17:43 +0000 (16:17 +0900)
    rails g scaffold goon 実施
    rake db:migrate 実施
    goonモデルのテストを作成
    goonモデル実装
    scaffoldで生成されたspecファイル内のデータを、本番データに近い内容の日本語に変更
    長さチェックを行うためにgoonモデル修正,合わせてテストを追記

21 files changed:
app/controllers/goons_controller.rb [new file with mode: 0644]
app/helpers/goons_helper.rb [new file with mode: 0644]
app/models/goon.rb [new file with mode: 0644]
app/views/goons/_form.html.erb [new file with mode: 0644]
app/views/goons/edit.html.erb [new file with mode: 0644]
app/views/goons/index.html.erb [new file with mode: 0644]
app/views/goons/new.html.erb [new file with mode: 0644]
app/views/goons/show.html.erb [new file with mode: 0644]
config/routes.rb
db/migrate/20110416145006_create_goons.rb [new file with mode: 0644]
db/schema.rb
public/stylesheets/scaffold.css [new file with mode: 0644]
spec/controllers/goons_controller_spec.rb [new file with mode: 0644]
spec/helpers/goons_helper_spec.rb [new file with mode: 0644]
spec/models/goon_spec.rb [new file with mode: 0644]
spec/requests/goons_spec.rb [new file with mode: 0644]
spec/routing/goons_routing_spec.rb [new file with mode: 0644]
spec/views/goons/edit.html.erb_spec.rb [new file with mode: 0644]
spec/views/goons/index.html.erb_spec.rb [new file with mode: 0644]
spec/views/goons/new.html.erb_spec.rb [new file with mode: 0644]
spec/views/goons/show.html.erb_spec.rb [new file with mode: 0644]

diff --git a/app/controllers/goons_controller.rb b/app/controllers/goons_controller.rb
new file mode 100644 (file)
index 0000000..b370740
--- /dev/null
@@ -0,0 +1,83 @@
+class GoonsController < ApplicationController
+  # GET /goons
+  # GET /goons.xml
+  def index
+    @goons = Goon.all
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.xml  { render :xml => @goons }
+    end
+  end
+
+  # GET /goons/1
+  # GET /goons/1.xml
+  def show
+    @goon = Goon.find(params[:id])
+
+    respond_to do |format|
+      format.html # show.html.erb
+      format.xml  { render :xml => @goon }
+    end
+  end
+
+  # GET /goons/new
+  # GET /goons/new.xml
+  def new
+    @goon = Goon.new
+
+    respond_to do |format|
+      format.html # new.html.erb
+      format.xml  { render :xml => @goon }
+    end
+  end
+
+  # GET /goons/1/edit
+  def edit
+    @goon = Goon.find(params[:id])
+  end
+
+  # POST /goons
+  # POST /goons.xml
+  def create
+    @goon = Goon.new(params[:goon])
+
+    respond_to do |format|
+      if @goon.save
+        format.html { redirect_to(@goon, :notice => 'Goon was successfully created.') }
+        format.xml  { render :xml => @goon, :status => :created, :location => @goon }
+      else
+        format.html { render :action => "new" }
+        format.xml  { render :xml => @goon.errors, :status => :unprocessable_entity }
+      end
+    end
+  end
+
+  # PUT /goons/1
+  # PUT /goons/1.xml
+  def update
+    @goon = Goon.find(params[:id])
+
+    respond_to do |format|
+      if @goon.update_attributes(params[:goon])
+        format.html { redirect_to(@goon, :notice => 'Goon was successfully updated.') }
+        format.xml  { head :ok }
+      else
+        format.html { render :action => "edit" }
+        format.xml  { render :xml => @goon.errors, :status => :unprocessable_entity }
+      end
+    end
+  end
+
+  # DELETE /goons/1
+  # DELETE /goons/1.xml
+  def destroy
+    @goon = Goon.find(params[:id])
+    @goon.destroy
+
+    respond_to do |format|
+      format.html { redirect_to(goons_url) }
+      format.xml  { head :ok }
+    end
+  end
+end
diff --git a/app/helpers/goons_helper.rb b/app/helpers/goons_helper.rb
new file mode 100644 (file)
index 0000000..771d2d7
--- /dev/null
@@ -0,0 +1,2 @@
+module GoonsHelper
+end
diff --git a/app/models/goon.rb b/app/models/goon.rb
new file mode 100644 (file)
index 0000000..c9c6d22
--- /dev/null
@@ -0,0 +1,7 @@
+class Goon < ActiveRecord::Base
+  validates_presence_of :title, :who, :description
+  validates_length_of :title, :maximum => 255
+  validates_length_of :who, :maximum => 100
+  validates_length_of :where, :maximum => 100
+  validates_length_of :description, :maximum => 1000
+end
diff --git a/app/views/goons/_form.html.erb b/app/views/goons/_form.html.erb
new file mode 100644 (file)
index 0000000..d48981b
--- /dev/null
@@ -0,0 +1,37 @@
+<%= form_for(@goon) do |f| %>
+  <% if @goon.errors.any? %>
+    <div id="error_explanation">
+      <h2><%= pluralize(@goon.errors.count, "error") %> prohibited this goon from being saved:</h2>
+
+      <ul>
+      <% @goon.errors.full_messages.each do |msg| %>
+        <li><%= msg %></li>
+      <% end %>
+      </ul>
+    </div>
+  <% end %>
+
+  <div class="field">
+    <%= f.label :title %><br />
+    <%= f.text_field :title %>
+  </div>
+  <div class="field">
+    <%= f.label :who %><br />
+    <%= f.text_field :who %>
+  </div>
+  <div class="field">
+    <%= f.label :when %><br />
+    <%= f.date_select :when %>
+  </div>
+  <div class="field">
+    <%= f.label :where %><br />
+    <%= f.text_field :where %>
+  </div>
+  <div class="field">
+    <%= f.label :description %><br />
+    <%= f.text_area :description %>
+  </div>
+  <div class="actions">
+    <%= f.submit %>
+  </div>
+<% end %>
diff --git a/app/views/goons/edit.html.erb b/app/views/goons/edit.html.erb
new file mode 100644 (file)
index 0000000..2a2afd2
--- /dev/null
@@ -0,0 +1,6 @@
+<h1>Editing goon</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @goon %> |
+<%= link_to 'Back', goons_path %>
diff --git a/app/views/goons/index.html.erb b/app/views/goons/index.html.erb
new file mode 100644 (file)
index 0000000..a41db87
--- /dev/null
@@ -0,0 +1,31 @@
+<h1>Listing goons</h1>
+
+<table>
+  <tr>
+    <th>Title</th>
+    <th>Who</th>
+    <th>When</th>
+    <th>Where</th>
+    <th>Description</th>
+    <th></th>
+    <th></th>
+    <th></th>
+  </tr>
+
+<% @goons.each do |goon| %>
+  <tr>
+    <td><%= goon.title %></td>
+    <td><%= goon.who %></td>
+    <td><%= goon.when %></td>
+    <td><%= goon.where %></td>
+    <td><%= goon.description %></td>
+    <td><%= link_to 'Show', goon %></td>
+    <td><%= link_to 'Edit', edit_goon_path(goon) %></td>
+    <td><%= link_to 'Destroy', goon, :confirm => 'Are you sure?', :method => :delete %></td>
+  </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Goon', new_goon_path %>
diff --git a/app/views/goons/new.html.erb b/app/views/goons/new.html.erb
new file mode 100644 (file)
index 0000000..f2d19d2
--- /dev/null
@@ -0,0 +1,5 @@
+<h1>New goon</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', goons_path %>
diff --git a/app/views/goons/show.html.erb b/app/views/goons/show.html.erb
new file mode 100644 (file)
index 0000000..84889ce
--- /dev/null
@@ -0,0 +1,30 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+  <b>Title:</b>
+  <%= @goon.title %>
+</p>
+
+<p>
+  <b>Who:</b>
+  <%= @goon.who %>
+</p>
+
+<p>
+  <b>When:</b>
+  <%= @goon.when %>
+</p>
+
+<p>
+  <b>Where:</b>
+  <%= @goon.where %>
+</p>
+
+<p>
+  <b>Description:</b>
+  <%= @goon.description %>
+</p>
+
+
+<%= link_to 'Edit', edit_goon_path(@goon) %> |
+<%= link_to 'Back', goons_path %>
index ff96b2c..a016bed 100644 (file)
@@ -1,4 +1,6 @@
 GoOnKirokuTyo::Application.routes.draw do
+  resources :goons
+
   # The priority is based upon order of creation:
   # first created -> highest priority.
 
diff --git a/db/migrate/20110416145006_create_goons.rb b/db/migrate/20110416145006_create_goons.rb
new file mode 100644 (file)
index 0000000..abbe9a2
--- /dev/null
@@ -0,0 +1,17 @@
+class CreateGoons < ActiveRecord::Migration
+  def self.up
+    create_table :goons do |t|
+      t.string :title, :null => false, :limit => 255
+      t.string :who, :null => false, :limit => 100
+      t.date :when
+      t.string :where, :limit => 100
+      t.text :description, :null => false, :limit => 1000
+
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :goons
+  end
+end
index 671c0da..33b98dd 100644 (file)
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 0) do
+ActiveRecord::Schema.define(:version => 20110416145006) do
+
+  create_table "goons", :force => true do |t|
+    t.string   "title",                      :null => false
+    t.string   "who",         :limit => 100, :null => false
+    t.date     "when"
+    t.string   "where",       :limit => 100
+    t.text     "description",                :null => false
+    t.datetime "created_at"
+    t.datetime "updated_at"
+  end
 
 end
diff --git a/public/stylesheets/scaffold.css b/public/stylesheets/scaffold.css
new file mode 100644 (file)
index 0000000..1ae7000
--- /dev/null
@@ -0,0 +1,56 @@
+body { background-color: #fff; color: #333; }
+
+body, 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; }
+a:visited { color: #666; }
+a:hover { color: #fff; background-color:#000; }
+
+div.field, div.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;
+}
+
+#error_explanation 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;
+}
+
+#error_explanation ul li {
+  font-size: 12px;
+  list-style: square;
+}
diff --git a/spec/controllers/goons_controller_spec.rb b/spec/controllers/goons_controller_spec.rb
new file mode 100644 (file)
index 0000000..f4c8f0c
--- /dev/null
@@ -0,0 +1,125 @@
+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 the Rails when you ran the scaffold generator.
+
+describe GoonsController do
+
+  def mock_goon(stubs={})
+    @mock_goon ||= mock_model(Goon, stubs).as_null_object
+  end
+
+  describe "GET index" do
+    it "assigns all goons as @goons" do
+      Goon.stub(:all) { [mock_goon] }
+      get :index
+      assigns(:goons).should eq([mock_goon])
+    end
+  end
+
+  describe "GET show" do
+    it "assigns the requested goon as @goon" do
+      Goon.stub(:find).with("37") { mock_goon }
+      get :show, :id => "37"
+      assigns(:goon).should be(mock_goon)
+    end
+  end
+
+  describe "GET new" do
+    it "assigns a new goon as @goon" do
+      Goon.stub(:new) { mock_goon }
+      get :new
+      assigns(:goon).should be(mock_goon)
+    end
+  end
+
+  describe "GET edit" do
+    it "assigns the requested goon as @goon" do
+      Goon.stub(:find).with("37") { mock_goon }
+      get :edit, :id => "37"
+      assigns(:goon).should be(mock_goon)
+    end
+  end
+
+  describe "POST create" do
+    describe "with valid params" do
+      it "assigns a newly created goon as @goon" do
+        Goon.stub(:new).with({'these' => 'params'}) { mock_goon(:save => true) }
+        post :create, :goon => {'these' => 'params'}
+        assigns(:goon).should be(mock_goon)
+      end
+
+      it "redirects to the created goon" do
+        Goon.stub(:new) { mock_goon(:save => true) }
+        post :create, :goon => {}
+        response.should redirect_to(goon_url(mock_goon))
+      end
+    end
+
+    describe "with invalid params" do
+      it "assigns a newly created but unsaved goon as @goon" do
+        Goon.stub(:new).with({'these' => 'params'}) { mock_goon(:save => false) }
+        post :create, :goon => {'these' => 'params'}
+        assigns(:goon).should be(mock_goon)
+      end
+
+      it "re-renders the 'new' template" do
+        Goon.stub(:new) { mock_goon(:save => false) }
+        post :create, :goon => {}
+        response.should render_template("new")
+      end
+    end
+  end
+
+  describe "PUT update" do
+    describe "with valid params" do
+      it "updates the requested goon" do
+        Goon.stub(:find).with("37") { mock_goon }
+        mock_goon.should_receive(:update_attributes).with({'these' => 'params'})
+        put :update, :id => "37", :goon => {'these' => 'params'}
+      end
+
+      it "assigns the requested goon as @goon" do
+        Goon.stub(:find) { mock_goon(:update_attributes => true) }
+        put :update, :id => "1"
+        assigns(:goon).should be(mock_goon)
+      end
+
+      it "redirects to the goon" do
+        Goon.stub(:find) { mock_goon(:update_attributes => true) }
+        put :update, :id => "1"
+        response.should redirect_to(goon_url(mock_goon))
+      end
+    end
+
+    describe "with invalid params" do
+      it "assigns the goon as @goon" do
+        Goon.stub(:find) { mock_goon(:update_attributes => false) }
+        put :update, :id => "1"
+        assigns(:goon).should be(mock_goon)
+      end
+
+      it "re-renders the 'edit' template" do
+        Goon.stub(:find) { mock_goon(:update_attributes => false) }
+        put :update, :id => "1"
+        response.should render_template("edit")
+      end
+    end
+  end
+
+  describe "DELETE destroy" do
+    it "destroys the requested goon" do
+      Goon.stub(:find).with("37") { mock_goon }
+      mock_goon.should_receive(:destroy)
+      delete :destroy, :id => "37"
+    end
+
+    it "redirects to the goons list" do
+      Goon.stub(:find) { mock_goon }
+      delete :destroy, :id => "1"
+      response.should redirect_to(goons_url)
+    end
+  end
+
+end
diff --git a/spec/helpers/goons_helper_spec.rb b/spec/helpers/goons_helper_spec.rb
new file mode 100644 (file)
index 0000000..9cb291c
--- /dev/null
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the GoonsHelper. For example:
+#
+# describe GoonsHelper do
+#   describe "string concat" do
+#     it "concats two strings with spaces" do
+#       helper.concat_strings("this","that").should == "this that"
+#     end
+#   end
+# end
+describe GoonsHelper do
+#  pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/models/goon_spec.rb b/spec/models/goon_spec.rb
new file mode 100644 (file)
index 0000000..1eb676a
--- /dev/null
@@ -0,0 +1,94 @@
+#encoding: utf-8
+
+require 'spec_helper'
+
+describe Goon do
+  context "titleとwhoとwhenとwhereとdescriptionを設定したとき" do
+    before do
+      @goon = Goon.new(
+        :title => "田中さんがご飯をおごってくれた",
+        :who => "田中さん",
+        :when => "2011-04-15",
+        :where => "渋谷",
+        :description => "「この前のプロジェクトで頑張ってくれた」とご飯をおごってくれた。"
+      )
+    end
+    it "titleがセットされていること" do
+      @goon.title.should == "田中さんがご飯をおごってくれた"
+    end
+    it "whoがセットされていること" do
+      @goon.who.should == "田中さん"
+    end
+    it "whenがセットされていること" do
+      @goon.when.should == Date.new(2011, 04, 15)
+    end
+    it "whereがセットされていること" do
+      @goon.where.should == "渋谷"
+    end
+    it "descriptionがセットされていること" do
+      @goon.description.should == "「この前のプロジェクトで頑張ってくれた」とご飯をおごってくれた。"
+    end
+  end
+
+  # 必須チェック
+  context "title,who,descriptionが設定されていない場合" do
+    before do
+      @goon = Goon.new
+    end
+    it { @goon.should_not be_valid }
+  end
+  context "title,who,descriptionが設定されている場合" do
+    before do
+      @goon = Goon.new(
+        :title => "田中さんがご飯をおごってくれた",
+        :who => "田中さん",
+        :description => "「この前のプロジェクトで頑張ってくれた」とご飯をおごってくれた。"
+      )
+    end
+    it { @goon.should be_valid }
+  end
+
+  # 長さチェック
+  context "titleが255文字を越える場合" do
+    before do
+      @goon = Goon.new(
+        :title => "a" * 256,
+        :who => "田中さん",
+        :description => "「この前のプロジェクトで頑張ってくれた」とご飯をおごってくれた。"
+      )
+    end
+    it { @goon.should_not be_valid }
+  end
+  context "whoが100文字を越える場合" do
+    before do
+      @goon = Goon.new(
+        :title => "田中さんがご飯をおごってくれた",
+        :who => "a" * 101,
+        :description => "「この前のプロジェクトで頑張ってくれた」とご飯をおごってくれた。"
+      )
+    end
+    it { @goon.should_not be_valid }
+  end
+  context "whereが100文字を越える場合" do
+    before do
+      @goon = Goon.new(
+        :title => "田中さんがご飯をおごってくれた",
+        :who => "田中さん",
+        :where => "a" * 101,
+        :description => "「この前のプロジェクトで頑張ってくれた」とご飯をおごってくれた。"
+      )
+    end
+    it { @goon.should_not be_valid }
+  end
+  context "descriptionが1000文字を越える場合" do
+    before do
+      @goon = Goon.new(
+        :title => "田中さんがご飯をおごってくれた",
+        :who => "田中さん",
+        :description => "a" * 1001
+      )
+    end
+    it { @goon.should_not be_valid }
+  end
+#  pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/requests/goons_spec.rb b/spec/requests/goons_spec.rb
new file mode 100644 (file)
index 0000000..5937678
--- /dev/null
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "Goons" do
+  describe "GET /goons" 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 goons_path
+      response.status.should be(200)
+    end
+  end
+end
diff --git a/spec/routing/goons_routing_spec.rb b/spec/routing/goons_routing_spec.rb
new file mode 100644 (file)
index 0000000..a227c81
--- /dev/null
@@ -0,0 +1,35 @@
+require "spec_helper"
+
+describe GoonsController do
+  describe "routing" do
+
+    it "recognizes and generates #index" do
+      { :get => "/goons" }.should route_to(:controller => "goons", :action => "index")
+    end
+
+    it "recognizes and generates #new" do
+      { :get => "/goons/new" }.should route_to(:controller => "goons", :action => "new")
+    end
+
+    it "recognizes and generates #show" do
+      { :get => "/goons/1" }.should route_to(:controller => "goons", :action => "show", :id => "1")
+    end
+
+    it "recognizes and generates #edit" do
+      { :get => "/goons/1/edit" }.should route_to(:controller => "goons", :action => "edit", :id => "1")
+    end
+
+    it "recognizes and generates #create" do
+      { :post => "/goons" }.should route_to(:controller => "goons", :action => "create")
+    end
+
+    it "recognizes and generates #update" do
+      { :put => "/goons/1" }.should route_to(:controller => "goons", :action => "update", :id => "1")
+    end
+
+    it "recognizes and generates #destroy" do
+      { :delete => "/goons/1" }.should route_to(:controller => "goons", :action => "destroy", :id => "1")
+    end
+
+  end
+end
diff --git a/spec/views/goons/edit.html.erb_spec.rb b/spec/views/goons/edit.html.erb_spec.rb
new file mode 100644 (file)
index 0000000..cd127ad
--- /dev/null
@@ -0,0 +1,26 @@
+#encoding: utf-8
+
+require 'spec_helper'
+
+describe "goons/edit.html.erb" do
+  before(:each) do
+    @goon = assign(:goon, stub_model(Goon,
+      :title => "佐藤さんから誕生日プレゼントを貰った",
+      :who => "佐藤さん",
+      :where => "職場",
+      :description => "リラっくまのぬいぐるみを貰った"
+    ))
+  end
+
+  it "renders the edit goon form" do
+    render
+
+    # Run the generator again with the --webrat flag if you want to use webrat matchers
+    assert_select "form", :action => goon_path(@goon), :method => "post" do
+      assert_select "input#goon_title", :name => "goon[title]"
+      assert_select "input#goon_who", :name => "goon[who]"
+      assert_select "input#goon_where", :name => "goon[where]"
+      assert_select "textarea#goon_description", :name => "goon[description]"
+    end
+  end
+end
diff --git a/spec/views/goons/index.html.erb_spec.rb b/spec/views/goons/index.html.erb_spec.rb
new file mode 100644 (file)
index 0000000..7bdf174
--- /dev/null
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe "goons/index.html.erb" do
+  before(:each) do
+    assign(:goons, [
+      stub_model(Goon,
+        :title => "Title",
+        :who => "Who",
+        :where => "Where",
+        :description => "MyText"
+      ),
+      stub_model(Goon,
+        :title => "Title",
+        :who => "Who",
+        :where => "Where",
+        :description => "MyText"
+      )
+    ])
+  end
+
+  it "renders a list of goons" do
+    render
+    # Run the generator again with the --webrat flag if you want to use webrat matchers
+    assert_select "tr>td", :text => "Title".to_s, :count => 2
+    # Run the generator again with the --webrat flag if you want to use webrat matchers
+    assert_select "tr>td", :text => "Who".to_s, :count => 2
+    # Run the generator again with the --webrat flag if you want to use webrat matchers
+    assert_select "tr>td", :text => "Where".to_s, :count => 2
+    # Run the generator again with the --webrat flag if you want to use webrat matchers
+    assert_select "tr>td", :text => "MyText".to_s, :count => 2
+  end
+end
diff --git a/spec/views/goons/new.html.erb_spec.rb b/spec/views/goons/new.html.erb_spec.rb
new file mode 100644 (file)
index 0000000..fe1843e
--- /dev/null
@@ -0,0 +1,26 @@
+#encoding: utf-8
+
+require 'spec_helper'
+
+describe "goons/new.html.erb" do
+  before(:each) do
+    assign(:goon, stub_model(Goon,
+      :title => "佐藤さんから誕生日プレゼントを貰った",
+      :who => "佐藤さん",
+      :where => "職場",
+      :description => "リラっくまのぬいぐるみを貰った"
+    ).as_new_record)
+  end
+
+  it "renders new goon form" do
+    render
+
+    # Run the generator again with the --webrat flag if you want to use webrat matchers
+    assert_select "form", :action => goons_path, :method => "post" do
+      assert_select "input#goon_title", :name => "goon[title]"
+      assert_select "input#goon_who", :name => "goon[who]"
+      assert_select "input#goon_where", :name => "goon[where]"
+      assert_select "textarea#goon_description", :name => "goon[description]"
+    end
+  end
+end
diff --git a/spec/views/goons/show.html.erb_spec.rb b/spec/views/goons/show.html.erb_spec.rb
new file mode 100644 (file)
index 0000000..5a61a2d
--- /dev/null
@@ -0,0 +1,26 @@
+#encoding: utf-8
+
+require 'spec_helper'
+
+describe "goons/show.html.erb" do
+  before(:each) do
+    @goon = assign(:goon, stub_model(Goon,
+      :title => "佐藤さんから誕生日プレゼントを貰った",
+      :who => "佐藤さん",
+      :where => "職場",
+      :description => "リラっくまのぬいぐるみを貰った"
+    ))
+  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(/佐藤さんから誕生日プレゼントを貰った/)
+    # Run the generator again with the --webrat flag if you want to use webrat matchers
+    rendered.should match(/佐藤さん/)
+    # Run the generator again with the --webrat flag if you want to use webrat matchers
+    rendered.should match(/職場/)
+    # Run the generator again with the --webrat flag if you want to use webrat matchers
+    rendered.should match(/リラっくまのぬいぐるみを貰った/)
+  end
+end