diff --git a/app/assets/javascripts/memos.js.coffee b/app/assets/javascripts/memos.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/memos.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/memos.css.scss b/app/assets/stylesheets/memos.css.scss new file mode 100644 index 0000000..2b49bc5 --- /dev/null +++ b/app/assets/stylesheets/memos.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the memos 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/.books_controller.rb.swp b/app/controllers/.books_controller.rb.swp new file mode 100644 index 0000000..abd17ee Binary files /dev/null and b/app/controllers/.books_controller.rb.swp differ diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index d13ffd9..6f9775a 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -27,7 +27,7 @@ def show # GET /books/new.json def new @book = Book.new - + @book.memos.build respond_to do |format| format.html # new.html.erb format.xml { render xml: @book } @@ -43,7 +43,9 @@ def edit # POST /books.json def create @book = Book.new(params[:book]) - + params[:memos].each do |body| + @book.memos.build(body) + end respond_to do |format| if @book.save format.html { redirect_to @book, notice: 'Book was successfully created.' } diff --git a/app/controllers/books_controller.rb.bak b/app/controllers/books_controller.rb.bak new file mode 100644 index 0000000..d13ffd9 --- /dev/null +++ b/app/controllers/books_controller.rb.bak @@ -0,0 +1,92 @@ +class BooksController < ApplicationController + before_filter :find_book, :only => [:show, :destroy, :edit, :update] + + # GET /books + # GET /books.json + def index + @books = Book.all + + respond_to do |format| + format.html # index.html.erb + format.xml { render xml: @books } + format.json { render json: @books } + end + end + + # GET /books/1 + # GET /books/1.json + def show + respond_to do |format| + format.html # show.html.erb + format.xml { render xml: @book } + format.json { render json: @book } + end + end + + # GET /books/new + # GET /books/new.json + def new + @book = Book.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render xml: @book } + format.json { render json: @book } + end + end + + # GET /books/1/edit + def edit + end + + # POST /books + # POST /books.json + def create + @book = Book.new(params[:book]) + + respond_to do |format| + if @book.save + format.html { redirect_to @book, notice: 'Book was successfully created.' } + format.xml { render xml: @book, status: :created, location: @book } + format.json { render json: @book, status: :created, location: @book } + else + format.html { render action: "new" } + format.xml { render xml: @book.errors, status: :unprocessable_entity } + format.json { render json: @book.errors, status: :unprocessable_entity } + end + end + end + + # PUT /books/1 + # PUT /books/1.json + def update + respond_to do |format| + if @book.update_attributes(params[:book]) + format.html { redirect_to @book, notice: 'Book was successfully updated.' } + format.xml { head :no_content } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.xml { render xml: @book.errors, status: :unprocessable_entity } + format.json { render json: @book.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /books/1 + # DELETE /books/1.json + def destroy + @book.destroy + + respond_to do |format| + format.html { redirect_to books_url } + format.xml { head :no_content } + format.json { head :no_content } + end + end + + private + def find_book + @book = Book.find(params[:id]) + end +end diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb new file mode 100644 index 0000000..74bda4c --- /dev/null +++ b/app/controllers/memos_controller.rb @@ -0,0 +1,83 @@ +class MemosController < ApplicationController + # GET /memos + # GET /memos.json + def index + @memos = Memo.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @memos } + end + end + + # GET /memos/1 + # GET /memos/1.json + def show + @memo = Memo.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @memo } + end + end + + # GET /memos/new + # GET /memos/new.json + def new + @memo = Memo.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @memo } + end + end + + # GET /memos/1/edit + def edit + @memo = Memo.find(params[:id]) + end + + # POST /memos + # POST /memos.json + def create + @memo = Memo.new(params[:memo]) + + respond_to do |format| + if @memo.save + format.html { redirect_to @memo, notice: 'Memo was successfully created.' } + format.json { render json: @memo, status: :created, location: @memo } + else + format.html { render action: "new" } + format.json { render json: @memo.errors, status: :unprocessable_entity } + end + end + end + + # PUT /memos/1 + # PUT /memos/1.json + def update + @memo = Memo.find(params[:id]) + + respond_to do |format| + if @memo.update_attributes(params[:memo]) + format.html { redirect_to @memo, notice: 'Memo was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @memo.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /memos/1 + # DELETE /memos/1.json + def destroy + @memo = Memo.find(params[:id]) + @memo.destroy + + respond_to do |format| + format.html { redirect_to memos_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/memos_controller.rb.bak b/app/controllers/memos_controller.rb.bak new file mode 100644 index 0000000..74bda4c --- /dev/null +++ b/app/controllers/memos_controller.rb.bak @@ -0,0 +1,83 @@ +class MemosController < ApplicationController + # GET /memos + # GET /memos.json + def index + @memos = Memo.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @memos } + end + end + + # GET /memos/1 + # GET /memos/1.json + def show + @memo = Memo.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @memo } + end + end + + # GET /memos/new + # GET /memos/new.json + def new + @memo = Memo.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @memo } + end + end + + # GET /memos/1/edit + def edit + @memo = Memo.find(params[:id]) + end + + # POST /memos + # POST /memos.json + def create + @memo = Memo.new(params[:memo]) + + respond_to do |format| + if @memo.save + format.html { redirect_to @memo, notice: 'Memo was successfully created.' } + format.json { render json: @memo, status: :created, location: @memo } + else + format.html { render action: "new" } + format.json { render json: @memo.errors, status: :unprocessable_entity } + end + end + end + + # PUT /memos/1 + # PUT /memos/1.json + def update + @memo = Memo.find(params[:id]) + + respond_to do |format| + if @memo.update_attributes(params[:memo]) + format.html { redirect_to @memo, notice: 'Memo was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @memo.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /memos/1 + # DELETE /memos/1.json + def destroy + @memo = Memo.find(params[:id]) + @memo.destroy + + respond_to do |format| + format.html { redirect_to memos_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/memos_helper.rb b/app/helpers/memos_helper.rb new file mode 100644 index 0000000..0e732a1 --- /dev/null +++ b/app/helpers/memos_helper.rb @@ -0,0 +1,2 @@ +module MemosHelper +end diff --git a/app/models/book.rb b/app/models/book.rb index 95c42dd..a321f0a 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,11 +1,8 @@ # encoding: UTF-8 class Book < ActiveRecord::Base + has_many :memos attr_accessible :memo, :purchased_on, :title validates :title, :presence => true - before_create :total_books_count - def total_books_count - self.memo += "【 累計冊数#{Book.count + 1} 】" - end end diff --git a/app/models/book.rb.bak b/app/models/book.rb.bak new file mode 100644 index 0000000..95c42dd --- /dev/null +++ b/app/models/book.rb.bak @@ -0,0 +1,11 @@ +# encoding: UTF-8 +class Book < ActiveRecord::Base + attr_accessible :memo, :purchased_on, :title + validates :title, :presence => true + + before_create :total_books_count + + def total_books_count + self.memo += "【 累計冊数#{Book.count + 1} 】" + end +end diff --git a/app/models/memo.rb b/app/models/memo.rb new file mode 100644 index 0000000..a62aa15 --- /dev/null +++ b/app/models/memo.rb @@ -0,0 +1,5 @@ +class Memo < ActiveRecord::Base + belongs_to :book + attr_accessible :body + validates_length_of :body, :maximum => 100 +end diff --git a/app/models/memo.rb.bak b/app/models/memo.rb.bak new file mode 100644 index 0000000..8172102 --- /dev/null +++ b/app/models/memo.rb.bak @@ -0,0 +1,4 @@ +class Memo < ActiveRecord::Base + belongs_to :book + attr_accessible :body +end diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb index da45ee0..b86f033 100644 --- a/app/views/books/_form.html.erb +++ b/app/views/books/_form.html.erb @@ -15,10 +15,11 @@ <%= f.label :title %>
<%= f.text_field :title %> -
- <%= f.label :memo %>
- <%= f.text_area :memo %> +
Memo:
+
+
+
<%= f.label :purchased_on %>
<%= f.date_select :purchased_on %> @@ -27,3 +28,9 @@ <%= f.submit %>
<% end %> + + diff --git a/app/views/books/_form.html.erb.bk b/app/views/books/_form.html.erb.bk new file mode 100644 index 0000000..da45ee0 --- /dev/null +++ b/app/views/books/_form.html.erb.bk @@ -0,0 +1,29 @@ +<%= form_for(@book) do |f| %> + <% if @book.errors.any? %> +
+

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

+ + +
+ <% end %> + +
+ <%= f.label :title %>
+ <%= f.text_field :title %> +
+
+ <%= f.label :memo %>
+ <%= f.text_area :memo %> +
+
+ <%= f.label :purchased_on %>
+ <%= f.date_select :purchased_on %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index 5f03ad6..69b90d3 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -3,20 +3,16 @@ - - <% @books.each do |book| %> - - <% end %> diff --git a/app/views/books/index.html.erb_bk b/app/views/books/index.html.erb_bk new file mode 100644 index 0000000..5f03ad6 --- /dev/null +++ b/app/views/books/index.html.erb_bk @@ -0,0 +1,27 @@ +

Listing books

+ +
TitleMemo Purchased on
<%= book.title %><%= book.memo %> <%= book.purchased_on %> <%= link_to 'Show', book %><%= link_to 'Edit', edit_book_path(book) %> <%= link_to 'Destroy', book, confirm: 'Are you sure?', method: :delete %>
+ + + + + + + + + +<% @books.each do |book| %> + + + + + + + + +<% end %> +
TitleMemoPurchased on
<%= book.title %><%= book.memo %><%= book.purchased_on %><%= link_to 'Show', book %><%= link_to 'Edit', edit_book_path(book) %><%= link_to 'Destroy', book, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Book', new_book_path %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index 23005ab..8066c39 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -6,8 +6,14 @@

- Memo: - <%= @book.memo %> + Memos:
+ + <% @book.memos.each do |m| %> + + + + <% end %> +
<%= m.body %>

@@ -16,5 +22,4 @@

-<%= link_to 'Edit', edit_book_path(@book) %> | <%= link_to 'Back', books_path %> diff --git a/app/views/books/show.html.erb_bk b/app/views/books/show.html.erb_bk new file mode 100644 index 0000000..23005ab --- /dev/null +++ b/app/views/books/show.html.erb_bk @@ -0,0 +1,20 @@ +

<%= notice %>

+ +

+ Title: + <%= @book.title %> +

+ +

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

+ +

+ Purchased on: + <%= @book.purchased_on %> +

+ + +<%= link_to 'Edit', edit_book_path(@book) %> | +<%= link_to 'Back', books_path %> diff --git a/app/views/memos/_form.html.erb b/app/views/memos/_form.html.erb new file mode 100644 index 0000000..4b242c2 --- /dev/null +++ b/app/views/memos/_form.html.erb @@ -0,0 +1,25 @@ +<%= form_for(@memo) do |f| %> + <% if @memo.errors.any? %> +
+

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

+ + +
+ <% end %> + +
+ <%= f.label :book %>
+ <%= f.text_field :book %> +
+
+ <%= f.label :body %>
+ <%= f.text_area :body %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/memos/edit.html.erb b/app/views/memos/edit.html.erb new file mode 100644 index 0000000..11d58b3 --- /dev/null +++ b/app/views/memos/edit.html.erb @@ -0,0 +1,6 @@ +

Editing memo

+ +<%= render 'form' %> + +<%= link_to 'Show', @memo %> | +<%= link_to 'Back', memos_path %> diff --git a/app/views/memos/index.html.erb b/app/views/memos/index.html.erb new file mode 100644 index 0000000..843e610 --- /dev/null +++ b/app/views/memos/index.html.erb @@ -0,0 +1,25 @@ +

Listing memos

+ + + + + + + + + + +<% @memos.each do |memo| %> + + + + + + + +<% end %> +
BookBody
<%= memo.book %><%= memo.body %><%= link_to 'Show', memo %><%= link_to 'Edit', edit_memo_path(memo) %><%= link_to 'Destroy', memo, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Memo', new_memo_path %> diff --git a/app/views/memos/new.html.erb b/app/views/memos/new.html.erb new file mode 100644 index 0000000..cb923d7 --- /dev/null +++ b/app/views/memos/new.html.erb @@ -0,0 +1,5 @@ +

New memo

+ +<%= render 'form' %> + +<%= link_to 'Back', memos_path %> diff --git a/app/views/memos/show.html.erb b/app/views/memos/show.html.erb new file mode 100644 index 0000000..2a8f46b --- /dev/null +++ b/app/views/memos/show.html.erb @@ -0,0 +1,15 @@ +

<%= notice %>

+ +

+ Book: + <%= @memo.book %> +

+ +

+ Body: + <%= @memo.body %> +

+ + +<%= link_to 'Edit', edit_memo_path(@memo) %> | +<%= link_to 'Back', memos_path %> diff --git a/config/routes.rb b/config/routes.rb index f3d38ab..af79db9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ BookMemo2::Application.routes.draw do + resources :memos + resources :books # The priority is based upon order of creation: diff --git a/db/migrate/20120627071739_create_memos.rb b/db/migrate/20120627071739_create_memos.rb new file mode 100644 index 0000000..67feaef --- /dev/null +++ b/db/migrate/20120627071739_create_memos.rb @@ -0,0 +1,11 @@ +class CreateMemos < ActiveRecord::Migration + def change + create_table :memos do |t| + t.references :book + t.text :body + + t.timestamps + end + add_index :memos, :book_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 5fc61c2..9a511bc 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 => 20120627071739) do create_table "books", :force => true do |t| t.string "title" @@ -21,4 +21,13 @@ t.datetime "updated_at", :null => false end + create_table "memos", :force => true do |t| + t.integer "book_id" + t.text "body" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "memos", ["book_id"], :name => "index_memos_on_book_id" + end diff --git a/spec/controllers/memos_controller_spec.rb b/spec/controllers/memos_controller_spec.rb new file mode 100644 index 0000000..f3781ca --- /dev/null +++ b/spec/controllers/memos_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 MemosController do + + # This should return the minimal set of attributes required to create a valid + # Memo. As you add validations to Memo, 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 + # MemosController. Be sure to keep this updated too. + def valid_session + {} + end + + describe "GET index" do + it "assigns all memos as @memos" do + memo = Memo.create! valid_attributes + get :index, {}, valid_session + assigns(:memos).should eq([memo]) + end + end + + describe "GET show" do + it "assigns the requested memo as @memo" do + memo = Memo.create! valid_attributes + get :show, {:id => memo.to_param}, valid_session + assigns(:memo).should eq(memo) + end + end + + describe "GET new" do + it "assigns a new memo as @memo" do + get :new, {}, valid_session + assigns(:memo).should be_a_new(Memo) + end + end + + describe "GET edit" do + it "assigns the requested memo as @memo" do + memo = Memo.create! valid_attributes + get :edit, {:id => memo.to_param}, valid_session + assigns(:memo).should eq(memo) + end + end + + describe "POST create" do + describe "with valid params" do + it "creates a new Memo" do + expect { + post :create, {:memo => valid_attributes}, valid_session + }.to change(Memo, :count).by(1) + end + + it "assigns a newly created memo as @memo" do + post :create, {:memo => valid_attributes}, valid_session + assigns(:memo).should be_a(Memo) + assigns(:memo).should be_persisted + end + + it "redirects to the created memo" do + post :create, {:memo => valid_attributes}, valid_session + response.should redirect_to(Memo.last) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved memo as @memo" do + # Trigger the behavior that occurs when invalid params are submitted + Memo.any_instance.stub(:save).and_return(false) + post :create, {:memo => {}}, valid_session + assigns(:memo).should be_a_new(Memo) + end + + it "re-renders the 'new' template" do + # Trigger the behavior that occurs when invalid params are submitted + Memo.any_instance.stub(:save).and_return(false) + post :create, {:memo => {}}, valid_session + response.should render_template("new") + end + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested memo" do + memo = Memo.create! valid_attributes + # Assuming there are no other memos in the database, this + # specifies that the Memo created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + Memo.any_instance.should_receive(:update_attributes).with({'these' => 'params'}) + put :update, {:id => memo.to_param, :memo => {'these' => 'params'}}, valid_session + end + + it "assigns the requested memo as @memo" do + memo = Memo.create! valid_attributes + put :update, {:id => memo.to_param, :memo => valid_attributes}, valid_session + assigns(:memo).should eq(memo) + end + + it "redirects to the memo" do + memo = Memo.create! valid_attributes + put :update, {:id => memo.to_param, :memo => valid_attributes}, valid_session + response.should redirect_to(memo) + end + end + + describe "with invalid params" do + it "assigns the memo as @memo" do + memo = Memo.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Memo.any_instance.stub(:save).and_return(false) + put :update, {:id => memo.to_param, :memo => {}}, valid_session + assigns(:memo).should eq(memo) + end + + it "re-renders the 'edit' template" do + memo = Memo.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Memo.any_instance.stub(:save).and_return(false) + put :update, {:id => memo.to_param, :memo => {}}, valid_session + response.should render_template("edit") + end + end + end + + describe "DELETE destroy" do + it "destroys the requested memo" do + memo = Memo.create! valid_attributes + expect { + delete :destroy, {:id => memo.to_param}, valid_session + }.to change(Memo, :count).by(-1) + end + + it "redirects to the memos list" do + memo = Memo.create! valid_attributes + delete :destroy, {:id => memo.to_param}, valid_session + response.should redirect_to(memos_url) + end + end + +end diff --git a/spec/factories/memos.rb b/spec/factories/memos.rb new file mode 100644 index 0000000..acdc7f7 --- /dev/null +++ b/spec/factories/memos.rb @@ -0,0 +1,8 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :memo do + book nil + body "MyText" + end +end diff --git a/spec/helpers/memos_helper_spec.rb b/spec/helpers/memos_helper_spec.rb new file mode 100644 index 0000000..48b8f0a --- /dev/null +++ b/spec/helpers/memos_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the MemosHelper. For example: +# +# describe MemosHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe MemosHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb index f820855..72ab30e 100644 --- a/spec/models/book_spec.rb +++ b/spec/models/book_spec.rb @@ -11,11 +11,4 @@ end end - describe '#total_books_count' do - let(:book){ FactoryGirl.build :book } - before { book.save } - it "memoに累計冊数が表示されること" do - book.memo.should include "【 累計冊数#{Book.count} 】" - end - end end diff --git a/spec/models/memo_spec.rb b/spec/models/memo_spec.rb new file mode 100644 index 0000000..ec9497f --- /dev/null +++ b/spec/models/memo_spec.rb @@ -0,0 +1,13 @@ +# coding:utf-8 + +require 'spec_helper' + +describe Memo do + let(:memo){FactoryGirl.build :memo} + before {memo.save} + describe 'validation' do + it "メモの長さは100を超えるとエラー" do + memo.body.size.should < 100 + end + end +end diff --git a/spec/requests/memos_spec.rb b/spec/requests/memos_spec.rb new file mode 100644 index 0000000..a086909 --- /dev/null +++ b/spec/requests/memos_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe "Memos" do + describe "GET /memos" 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 memos_path + response.status.should be(200) + end + end +end diff --git a/spec/routing/memos_routing_spec.rb b/spec/routing/memos_routing_spec.rb new file mode 100644 index 0000000..b0f68f9 --- /dev/null +++ b/spec/routing/memos_routing_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe MemosController do + describe "routing" do + + it "routes to #index" do + get("/memos").should route_to("memos#index") + end + + it "routes to #new" do + get("/memos/new").should route_to("memos#new") + end + + it "routes to #show" do + get("/memos/1").should route_to("memos#show", :id => "1") + end + + it "routes to #edit" do + get("/memos/1/edit").should route_to("memos#edit", :id => "1") + end + + it "routes to #create" do + post("/memos").should route_to("memos#create") + end + + it "routes to #update" do + put("/memos/1").should route_to("memos#update", :id => "1") + end + + it "routes to #destroy" do + delete("/memos/1").should route_to("memos#destroy", :id => "1") + end + + end +end diff --git a/spec/views/memos/edit.html.erb_spec.rb b/spec/views/memos/edit.html.erb_spec.rb new file mode 100644 index 0000000..d01a69e --- /dev/null +++ b/spec/views/memos/edit.html.erb_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe "memos/edit" do + before(:each) do + @memo = assign(:memo, stub_model(Memo, + :book => nil, + :body => "MyText" + )) + end + + it "renders the edit memo form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => memos_path(@memo), :method => "post" do + assert_select "input#memo_book", :name => "memo[book]" + assert_select "textarea#memo_body", :name => "memo[body]" + end + end +end diff --git a/spec/views/memos/index.html.erb_spec.rb b/spec/views/memos/index.html.erb_spec.rb new file mode 100644 index 0000000..ea0820f --- /dev/null +++ b/spec/views/memos/index.html.erb_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe "memos/index" do + before(:each) do + assign(:memos, [ + stub_model(Memo, + :book => nil, + :body => "MyText" + ), + stub_model(Memo, + :book => nil, + :body => "MyText" + ) + ]) + end + + it "renders a list of memos" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => nil.to_s, :count => 2 + assert_select "tr>td", :text => "MyText".to_s, :count => 2 + end +end diff --git a/spec/views/memos/new.html.erb_spec.rb b/spec/views/memos/new.html.erb_spec.rb new file mode 100644 index 0000000..fada45f --- /dev/null +++ b/spec/views/memos/new.html.erb_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe "memos/new" do + before(:each) do + assign(:memo, stub_model(Memo, + :book => nil, + :body => "MyText" + ).as_new_record) + end + + it "renders new memo form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => memos_path, :method => "post" do + assert_select "input#memo_book", :name => "memo[book]" + assert_select "textarea#memo_body", :name => "memo[body]" + end + end +end diff --git a/spec/views/memos/show.html.erb_spec.rb b/spec/views/memos/show.html.erb_spec.rb new file mode 100644 index 0000000..4bfed0d --- /dev/null +++ b/spec/views/memos/show.html.erb_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe "memos/show" do + before(:each) do + @memo = assign(:memo, stub_model(Memo, + :book => nil, + :body => "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(//) + rendered.should match(/MyText/) + end +end