From db0af7f51fe67a8b7a43d7c2d42f45282d6c771a Mon Sep 17 00:00:00 2001 From: "hisaaki.ito" Date: Thu, 14 Jun 2012 22:48:36 +0900 Subject: [PATCH 1/4] init --- .gitignore | 1 + app/assets/javascripts/boooooooks.js.coffee | 3 + app/assets/stylesheets/boooooooks.css.scss | 3 + app/controllers/boooooooks_controller.rb | 80 +++++++++ app/helpers/boooooooks_helper.rb | 2 + app/models/boooooook.rb | 8 + app/views/boooooooks/_form.html.erb | 29 ++++ app/views/boooooooks/edit.html.erb | 6 + app/views/boooooooks/index.html.erb | 25 +++ app/views/boooooooks/new.html.erb | 5 + app/views/boooooooks/show.html.erb | 20 +++ config/routes.rb | 5 + .../20120614125024_create_boooooooks.rb | 11 ++ db/schema.rb | 10 +- .../controllers/boooooooks_controller_spec.rb | 164 ++++++++++++++++++ spec/factories/boooooooks.rb | 9 + spec/helpers/boooooooks_helper_spec.rb | 15 ++ spec/models/boooooook_spec.rb | 5 + spec/requests/boooooooks_spec.rb | 11 ++ spec/routing/boooooooks_routing_spec.rb | 35 ++++ spec/views/boooooooks/edit.html.erb_spec.rb | 20 +++ spec/views/boooooooks/index.html.erb_spec.rb | 23 +++ spec/views/boooooooks/new.html.erb_spec.rb | 20 +++ spec/views/boooooooks/show.html.erb_spec.rb | 17 ++ 24 files changed, 526 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/boooooooks.js.coffee create mode 100644 app/assets/stylesheets/boooooooks.css.scss create mode 100644 app/controllers/boooooooks_controller.rb create mode 100644 app/helpers/boooooooks_helper.rb create mode 100644 app/models/boooooook.rb create mode 100644 app/views/boooooooks/_form.html.erb create mode 100644 app/views/boooooooks/edit.html.erb create mode 100644 app/views/boooooooks/index.html.erb create mode 100644 app/views/boooooooks/new.html.erb create mode 100644 app/views/boooooooks/show.html.erb create mode 100644 db/migrate/20120614125024_create_boooooooks.rb create mode 100644 spec/controllers/boooooooks_controller_spec.rb create mode 100644 spec/factories/boooooooks.rb create mode 100644 spec/helpers/boooooooks_helper_spec.rb create mode 100644 spec/models/boooooook_spec.rb create mode 100644 spec/requests/boooooooks_spec.rb create mode 100644 spec/routing/boooooooks_routing_spec.rb create mode 100644 spec/views/boooooooks/edit.html.erb_spec.rb create mode 100644 spec/views/boooooooks/index.html.erb_spec.rb create mode 100644 spec/views/boooooooks/new.html.erb_spec.rb create mode 100644 spec/views/boooooooks/show.html.erb_spec.rb diff --git a/.gitignore b/.gitignore index eb3489a..8b90f3f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ # Ignore all logfiles and tempfiles. /log/*.log /tmp +/public/assets diff --git a/app/assets/javascripts/boooooooks.js.coffee b/app/assets/javascripts/boooooooks.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/boooooooks.js.coffee @@ -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/ diff --git a/app/assets/stylesheets/boooooooks.css.scss b/app/assets/stylesheets/boooooooks.css.scss new file mode 100644 index 0000000..1a8492e --- /dev/null +++ b/app/assets/stylesheets/boooooooks.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the boooooooks controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/boooooooks_controller.rb b/app/controllers/boooooooks_controller.rb new file mode 100644 index 0000000..87136a8 --- /dev/null +++ b/app/controllers/boooooooks_controller.rb @@ -0,0 +1,80 @@ +class BoooooooksController < ApplicationController + # GET /boooooooks + # GET /boooooooks.json + def index + @boooooooks = Boooooook.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @boooooooks } + end + end + + # GET /boooooooks/1 + # GET /boooooooks/1.json + #def show + # @boooooook = Boooooook.find(params[:id]) +# +# respond_to do |format| +# format.html # show.html.erb +# format.json { render json: @boooooook } +# end +# end + + # GET /boooooooks/new + # GET /boooooooks/new.json + def new + @boooooook = Boooooook.new + + respond_to do |format| + format.html # new.html.erb + end + end + + # GET /boooooooks/1/edit +# def edit +# @boooooook = Boooooook.find(params[:id]) +# end + + # POST /boooooooks + # POST /boooooooks.json + def create + @boooooook = Boooooook.new(params[:boooooook]) + + if @boooooook.save + logger.debug boooooooks_index_url + #format.html { redirect_to @boooooook, notice: 'Boooooook was successfully created.' } + redirect_to boooooooks_index_url + else + render action: "new" + end + end + + # PUT /boooooooks/1 + # PUT /boooooooks/1.json +# def update +# @boooooook = Boooooook.find(params[:id]) +# +# respond_to do |format| +# if @boooooook.update_attributes(params[:boooooook]) +# format.html { redirect_to @boooooook, notice: 'Boooooook was successfully updated.' } +# format.json { head :no_content } +# else +# format.html { render action: "edit" } +# format.json { render json: @boooooook.errors, status: :unprocessable_entity } +# end +# end +# end + + # DELETE /boooooooks/1 + # DELETE /boooooooks/1.json + def destroy + @boooooook = Boooooook.find(params[:id]) + @boooooook.destroy + + respond_to do |format| + format.html { redirect_to boooooooks_index_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/boooooooks_helper.rb b/app/helpers/boooooooks_helper.rb new file mode 100644 index 0000000..2aab4e8 --- /dev/null +++ b/app/helpers/boooooooks_helper.rb @@ -0,0 +1,2 @@ +module BoooooooksHelper +end diff --git a/app/models/boooooook.rb b/app/models/boooooook.rb new file mode 100644 index 0000000..1a2713b --- /dev/null +++ b/app/models/boooooook.rb @@ -0,0 +1,8 @@ +class Boooooook < ActiveRecord::Base + attr_accessible :desc, :memo, :published + + + validates :desc, :presence => true, :length => {:maximum => 100} + validates :memo, :presence => true, :length => {:maximum => 100} + +end diff --git a/app/views/boooooooks/_form.html.erb b/app/views/boooooooks/_form.html.erb new file mode 100644 index 0000000..f0d77a3 --- /dev/null +++ b/app/views/boooooooks/_form.html.erb @@ -0,0 +1,29 @@ +<%= form_for(@boooooook) do |f| %> + <% if @boooooook.errors.any? %> +
+

<%= pluralize(@boooooook.errors.count, "error") %> prohibited this boooooook from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :desc %>
+ <%= f.text_area :desc %> +
+
+ <%= f.label :memo %>
+ <%= f.text_area :memo %> +
+
+ <%= f.label :published %>
+ <%= f.date_select :published %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/boooooooks/edit.html.erb b/app/views/boooooooks/edit.html.erb new file mode 100644 index 0000000..4349e7d --- /dev/null +++ b/app/views/boooooooks/edit.html.erb @@ -0,0 +1,6 @@ +

Editing boooooook

+ +<%= render 'form' %> + +<%= link_to 'Show', @boooooook %> | +<%= link_to 'Back', boooooooks_path %> diff --git a/app/views/boooooooks/index.html.erb b/app/views/boooooooks/index.html.erb new file mode 100644 index 0000000..9e18cbd --- /dev/null +++ b/app/views/boooooooks/index.html.erb @@ -0,0 +1,25 @@ +

Listing boooooooks

+ + + + + + + + + + + +<% @boooooooks.each do |boooooook| %> + + + + + + +<% end %> +
DescMemoPublished
<%= boooooook.desc %><%= boooooook.memo %><%= boooooook.published %><%= link_to 'Destroy', 'boooooooks/' + boooooook.id.to_s, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Boooooook', 'boooooooks/new' %> diff --git a/app/views/boooooooks/new.html.erb b/app/views/boooooooks/new.html.erb new file mode 100644 index 0000000..3c466ad --- /dev/null +++ b/app/views/boooooooks/new.html.erb @@ -0,0 +1,5 @@ +

New boooooook

+ +<%= render 'form' %> + +<%= link_to 'Back', boooooooks_path %> diff --git a/app/views/boooooooks/show.html.erb b/app/views/boooooooks/show.html.erb new file mode 100644 index 0000000..7a471a0 --- /dev/null +++ b/app/views/boooooooks/show.html.erb @@ -0,0 +1,20 @@ +

<%= notice %>

+ +

+ Desc: + <%= @boooooook.desc %> +

+ +

+ Memo: + <%= @boooooook.memo %> +

+ +

+ Published: + <%= @boooooook.published %> +

+ + +<%= link_to 'Edit', edit_boooooook_path(@boooooook) %> | +<%= link_to 'Back', boooooooks_path %> diff --git a/config/routes.rb b/config/routes.rb index f3d38ab..626f597 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,9 @@ BookMemo2::Application.routes.draw do + # resources :boooooooks + get '/boooooooks', :to => "boooooooks#index", :as => :boooooooks_index + post '/boooooooks', :to => "boooooooks#create" + get '/boooooooks/new', :to => "boooooooks#new", :as => :boooooooks_new + delete '/boooooooks/:id', :to => "boooooooks#destroy" resources :books # The priority is based upon order of creation: diff --git a/db/migrate/20120614125024_create_boooooooks.rb b/db/migrate/20120614125024_create_boooooooks.rb new file mode 100644 index 0000000..b038680 --- /dev/null +++ b/db/migrate/20120614125024_create_boooooooks.rb @@ -0,0 +1,11 @@ +class CreateBoooooooks < ActiveRecord::Migration + def change + create_table :boooooooks do |t| + t.text :desc + t.text :memo + t.date :published + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 5fc61c2..fcabc73 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120526050801) do +ActiveRecord::Schema.define(:version => 20120614125024) do create_table "books", :force => true do |t| t.string "title" @@ -21,4 +21,12 @@ t.datetime "updated_at", :null => false end + create_table "boooooooks", :force => true do |t| + t.text "desc" + t.text "memo" + t.date "published" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + end diff --git a/spec/controllers/boooooooks_controller_spec.rb b/spec/controllers/boooooooks_controller_spec.rb new file mode 100644 index 0000000..99cad8b --- /dev/null +++ b/spec/controllers/boooooooks_controller_spec.rb @@ -0,0 +1,164 @@ +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 BoooooooksController do + + # This should return the minimal set of attributes required to create a valid + # Boooooook. As you add validations to Boooooook, be sure to + # update the return value of this method accordingly. + def valid_attributes + {} + end + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # BoooooooksController. Be sure to keep this updated too. + def valid_session + {} + end + + describe "GET index" do + it "assigns all boooooooks as @boooooooks" do + boooooook = Boooooook.create! valid_attributes + get :index, {}, valid_session + assigns(:boooooooks).should eq([boooooook]) + end + end + + describe "GET show" do + it "assigns the requested boooooook as @boooooook" do + boooooook = Boooooook.create! valid_attributes + get :show, {:id => boooooook.to_param}, valid_session + assigns(:boooooook).should eq(boooooook) + end + end + + describe "GET new" do + it "assigns a new boooooook as @boooooook" do + get :new, {}, valid_session + assigns(:boooooook).should be_a_new(Boooooook) + end + end + + describe "GET edit" do + it "assigns the requested boooooook as @boooooook" do + boooooook = Boooooook.create! valid_attributes + get :edit, {:id => boooooook.to_param}, valid_session + assigns(:boooooook).should eq(boooooook) + end + end + + describe "POST create" do + describe "with valid params" do + it "creates a new Boooooook" do + expect { + post :create, {:boooooook => valid_attributes}, valid_session + }.to change(Boooooook, :count).by(1) + end + + it "assigns a newly created boooooook as @boooooook" do + post :create, {:boooooook => valid_attributes}, valid_session + assigns(:boooooook).should be_a(Boooooook) + assigns(:boooooook).should be_persisted + end + + it "redirects to the created boooooook" do + post :create, {:boooooook => valid_attributes}, valid_session + response.should redirect_to(Boooooook.last) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved boooooook as @boooooook" do + # Trigger the behavior that occurs when invalid params are submitted + Boooooook.any_instance.stub(:save).and_return(false) + post :create, {:boooooook => {}}, valid_session + assigns(:boooooook).should be_a_new(Boooooook) + end + + it "re-renders the 'new' template" do + # Trigger the behavior that occurs when invalid params are submitted + Boooooook.any_instance.stub(:save).and_return(false) + post :create, {:boooooook => {}}, valid_session + response.should render_template("new") + end + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested boooooook" do + boooooook = Boooooook.create! valid_attributes + # Assuming there are no other boooooooks in the database, this + # specifies that the Boooooook created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + Boooooook.any_instance.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, {:id => boooooook.to_param, :boooooook => {'these' => 'params'}}, valid_session + end + + it "assigns the requested boooooook as @boooooook" do + boooooook = Boooooook.create! valid_attributes + put :update, {:id => boooooook.to_param, :boooooook => valid_attributes}, valid_session + assigns(:boooooook).should eq(boooooook) + end + + it "redirects to the boooooook" do + boooooook = Boooooook.create! valid_attributes + put :update, {:id => boooooook.to_param, :boooooook => valid_attributes}, valid_session + response.should redirect_to(boooooook) + end + end + + describe "with invalid params" do + it "assigns the boooooook as @boooooook" do + boooooook = Boooooook.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Boooooook.any_instance.stub(:save).and_return(false) + put :update, {:id => boooooook.to_param, :boooooook => {}}, valid_session + assigns(:boooooook).should eq(boooooook) + end + + it "re-renders the 'edit' template" do + boooooook = Boooooook.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Boooooook.any_instance.stub(:save).and_return(false) + put :update, {:id => boooooook.to_param, :boooooook => {}}, valid_session + response.should render_template("edit") + end + end + end + + describe "DELETE destroy" do + it "destroys the requested boooooook" do + boooooook = Boooooook.create! valid_attributes + expect { + delete :destroy, {:id => boooooook.to_param}, valid_session + }.to change(Boooooook, :count).by(-1) + end + + it "redirects to the boooooooks list" do + boooooook = Boooooook.create! valid_attributes + delete :destroy, {:id => boooooook.to_param}, valid_session + response.should redirect_to(boooooooks_url) + end + end + +end diff --git a/spec/factories/boooooooks.rb b/spec/factories/boooooooks.rb new file mode 100644 index 0000000..008dbc0 --- /dev/null +++ b/spec/factories/boooooooks.rb @@ -0,0 +1,9 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :boooooook do + desc "MyText" + memo "MyText" + published "2012-06-14" + end +end diff --git a/spec/helpers/boooooooks_helper_spec.rb b/spec/helpers/boooooooks_helper_spec.rb new file mode 100644 index 0000000..13b331f --- /dev/null +++ b/spec/helpers/boooooooks_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the BoooooooksHelper. For example: +# +# describe BoooooooksHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe BoooooooksHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/boooooook_spec.rb b/spec/models/boooooook_spec.rb new file mode 100644 index 0000000..6a3a7d2 --- /dev/null +++ b/spec/models/boooooook_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Boooooook do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/boooooooks_spec.rb b/spec/requests/boooooooks_spec.rb new file mode 100644 index 0000000..98e1bc5 --- /dev/null +++ b/spec/requests/boooooooks_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe "Boooooooks" do + describe "GET /boooooooks" 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 boooooooks_path + response.status.should be(200) + end + end +end diff --git a/spec/routing/boooooooks_routing_spec.rb b/spec/routing/boooooooks_routing_spec.rb new file mode 100644 index 0000000..efead3e --- /dev/null +++ b/spec/routing/boooooooks_routing_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe BoooooooksController do + describe "routing" do + + it "routes to #index" do + get("/boooooooks").should route_to("boooooooks#index") + end + + it "routes to #new" do + get("/boooooooks/new").should route_to("boooooooks#new") + end + + it "routes to #show" do + get("/boooooooks/1").should route_to("boooooooks#show", :id => "1") + end + + it "routes to #edit" do + get("/boooooooks/1/edit").should route_to("boooooooks#edit", :id => "1") + end + + it "routes to #create" do + post("/boooooooks").should route_to("boooooooks#create") + end + + it "routes to #update" do + put("/boooooooks/1").should route_to("boooooooks#update", :id => "1") + end + + it "routes to #destroy" do + delete("/boooooooks/1").should route_to("boooooooks#destroy", :id => "1") + end + + end +end diff --git a/spec/views/boooooooks/edit.html.erb_spec.rb b/spec/views/boooooooks/edit.html.erb_spec.rb new file mode 100644 index 0000000..42f6449 --- /dev/null +++ b/spec/views/boooooooks/edit.html.erb_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe "boooooooks/edit" do + before(:each) do + @boooooook = assign(:boooooook, stub_model(Boooooook, + :desc => "MyText", + :memo => "MyText" + )) + end + + it "renders the edit boooooook form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => boooooooks_path(@boooooook), :method => "post" do + assert_select "textarea#boooooook_desc", :name => "boooooook[desc]" + assert_select "textarea#boooooook_memo", :name => "boooooook[memo]" + end + end +end diff --git a/spec/views/boooooooks/index.html.erb_spec.rb b/spec/views/boooooooks/index.html.erb_spec.rb new file mode 100644 index 0000000..325bd64 --- /dev/null +++ b/spec/views/boooooooks/index.html.erb_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe "boooooooks/index" do + before(:each) do + assign(:boooooooks, [ + stub_model(Boooooook, + :desc => "MyText", + :memo => "MyText" + ), + stub_model(Boooooook, + :desc => "MyText", + :memo => "MyText" + ) + ]) + end + + it "renders a list of boooooooks" do + render + # 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 + assert_select "tr>td", :text => "MyText".to_s, :count => 2 + end +end diff --git a/spec/views/boooooooks/new.html.erb_spec.rb b/spec/views/boooooooks/new.html.erb_spec.rb new file mode 100644 index 0000000..cc1462e --- /dev/null +++ b/spec/views/boooooooks/new.html.erb_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe "boooooooks/new" do + before(:each) do + assign(:boooooook, stub_model(Boooooook, + :desc => "MyText", + :memo => "MyText" + ).as_new_record) + end + + it "renders new boooooook form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => boooooooks_path, :method => "post" do + assert_select "textarea#boooooook_desc", :name => "boooooook[desc]" + assert_select "textarea#boooooook_memo", :name => "boooooook[memo]" + end + end +end diff --git a/spec/views/boooooooks/show.html.erb_spec.rb b/spec/views/boooooooks/show.html.erb_spec.rb new file mode 100644 index 0000000..b1faf74 --- /dev/null +++ b/spec/views/boooooooks/show.html.erb_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe "boooooooks/show" do + before(:each) do + @boooooook = assign(:boooooook, stub_model(Boooooook, + :desc => "MyText", + :memo => "MyText" + )) + end + + it "renders attributes in

" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/MyText/) + rendered.should match(/MyText/) + end +end From 0828e9683c2b1cace64106150cbeba64f0e448c5 Mon Sep 17 00:00:00 2001 From: "hisaaki.ito" Date: Fri, 15 Jun 2012 02:00:16 +0900 Subject: [PATCH 2/4] Create rspec for model --- spec/models/boooooook_spec.rb | 49 ++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/spec/models/boooooook_spec.rb b/spec/models/boooooook_spec.rb index 6a3a7d2..89e93aa 100644 --- a/spec/models/boooooook_spec.rb +++ b/spec/models/boooooook_spec.rb @@ -1,5 +1,52 @@ +# coding:utf-8 require 'spec_helper' describe Boooooook do - pending "add some examples to (or delete) #{__FILE__}" + describe 'validation' do + describe 'desc' do + before do + @bk = Boooooook.new + @bk.memo = 'a' * 100 + end + it '未入力の場合はエラー' do + @bk.valid?.should be_false + end + it '文字数が100byte以上の場合はエラー' do + @bk.desc = 'a' * 101 + @bk.valid?.should be_false + end + end + describe 'memo' do + before do + @bk = Boooooook.new + @bk.desc = 'a' * 100 + end + it '未入力の場合はエラー' do + @bk.valid?.should be_false + end + it '文字数が100byte以上の場合はエラー' do + @bk.memo = 'a' * 101 + @bk.valid?.should be_false + end + end + end + + + describe '#total_books_count' do + let(:boooooook){ FactoryGirl.build :boooooook } + before do + @bk = Boooooook.new + @bk.desc = 'a' * 100 + @bk.memo = 'a' * 100 + end + it "Boooooookを保存できること" do + @bk.save.should be_true + end + end end + + + + + + From b9f5eda25a7d30aa4fbeb9fec1d2238149d9132a Mon Sep 17 00:00:00 2001 From: "hisaaki.ito" Date: Fri, 15 Jun 2012 02:14:18 +0900 Subject: [PATCH 3/4] I'm sleepy. --- spec/requests/boooooooks_spec.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/spec/requests/boooooooks_spec.rb b/spec/requests/boooooooks_spec.rb index 98e1bc5..cee7586 100644 --- a/spec/requests/boooooooks_spec.rb +++ b/spec/requests/boooooooks_spec.rb @@ -1,11 +1,33 @@ +# -*- coding: utf-8 -*- require 'spec_helper' describe "Boooooooks" do describe "GET /boooooooks" 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 boooooooks_path + get boooooooks_index_url response.status.should be(200) end end + + describe 'POST /boooooooks' do + context "with create" do + let(:update_desc){ 'upd desc' } + let(:update_memo){ 'upd memo' } + + before do + visit boooooooks_new_url + fill_in "boooooook[desc]", with: update_desc + fill_in "boooooook[memo]", with: update_memo + click_on 'Create Boooooook' + end + + it "ページが遷移されていること" do + current_path.should == boooooooks_index_url + end + + end + + + end end From 48c1e5eedae186c2e430210604747af0d7ad53d7 Mon Sep 17 00:00:00 2001 From: "hisaaki.ito" Date: Fri, 15 Jun 2012 09:24:23 +0900 Subject: [PATCH 4/4] create capybara test --- spec/requests/boooooooks_spec.rb | 47 ++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/spec/requests/boooooooks_spec.rb b/spec/requests/boooooooks_spec.rb index cee7586..6c35ac9 100644 --- a/spec/requests/boooooooks_spec.rb +++ b/spec/requests/boooooooks_spec.rb @@ -12,20 +12,45 @@ describe 'POST /boooooooks' do context "with create" do - let(:update_desc){ 'upd desc' } - let(:update_memo){ 'upd memo' } - - before do - visit boooooooks_new_url - fill_in "boooooook[desc]", with: update_desc - fill_in "boooooook[memo]", with: update_memo - click_on 'Create Boooooook' - end + describe 'success' do + let(:update_desc){ 'upd desc' } + let(:update_memo){ 'upd memo' } + + before do + visit boooooooks_new_url + fill_in "boooooook[desc]", with: update_desc + fill_in "boooooook[memo]", with: update_memo + select "2012", :from =>"boooooook[published(1i)]" + select "June", :from =>"boooooook[published(2i)]" + select "15", :from =>"boooooook[published(3i)]" + click_on 'Create Boooooook' + end - it "ページが遷移されていること" do - current_path.should == boooooooks_index_url + it "ページが遷移されていること" do + page.should have_content("Listing boooooooks") + end end + describe 'failed' do + let(:update_desc){ '' } + let(:update_memo){ '' } + + before do + visit boooooooks_new_url + fill_in "boooooook[desc]", with: update_desc + fill_in "boooooook[memo]", with: update_memo + select "2012", :from =>"boooooook[published(1i)]" + select "June", :from =>"boooooook[published(2i)]" + select "15", :from =>"boooooook[published(3i)]" + click_on 'Create Boooooook' + end + + it "エラーが表示されていること" do + page.should have_content("2 errors prohibited this boooooook from being saved:") + end + end + + end