--- /dev/null
+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
--- /dev/null
+module GoonsHelper
+end
--- /dev/null
+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
--- /dev/null
+<%= 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 %>
--- /dev/null
+<h1>Editing goon</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @goon %> |
+<%= link_to 'Back', goons_path %>
--- /dev/null
+<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 %>
--- /dev/null
+<h1>New goon</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', goons_path %>
--- /dev/null
+<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 %>
GoOnKirokuTyo::Application.routes.draw do
+ resources :goons
+
# The priority is based upon order of creation:
# first created -> highest priority.
--- /dev/null
+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
#
# 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
--- /dev/null
+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;
+}
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+#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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+#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
--- /dev/null
+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
--- /dev/null
+#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
--- /dev/null
+#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