Kouhei Sutou
null+****@clear*****
Mon Mar 21 11:17:17 JST 2016
Kouhei Sutou 2016-03-21 11:17:17 +0900 (Mon, 21 Mar 2016) New Revision: 09d6d9c16eb6fe385fec3ed26f77e866a66ecb8c https://github.com/ranguba/groonga-client-rails/commit/09d6d9c16eb6fe385fec3ed26f77e866a66ecb8c Message: Generate scaffold for posts % bin/rails generate scaffold post title:string body:text --timestamp Added files: test/fixtures/rails4-mongoid/app/assets/javascripts/posts.coffee test/fixtures/rails4-mongoid/app/assets/stylesheets/posts.scss test/fixtures/rails4-mongoid/app/assets/stylesheets/scaffolds.scss test/fixtures/rails4-mongoid/app/controllers/posts_controller.rb test/fixtures/rails4-mongoid/app/helpers/posts_helper.rb test/fixtures/rails4-mongoid/app/models/post.rb test/fixtures/rails4-mongoid/app/views/posts/_form.html.erb test/fixtures/rails4-mongoid/app/views/posts/edit.html.erb test/fixtures/rails4-mongoid/app/views/posts/index.html.erb test/fixtures/rails4-mongoid/app/views/posts/index.json.jbuilder test/fixtures/rails4-mongoid/app/views/posts/new.html.erb test/fixtures/rails4-mongoid/app/views/posts/show.html.erb test/fixtures/rails4-mongoid/app/views/posts/show.json.jbuilder test/fixtures/rails4-mongoid/test/controllers/posts_controller_test.rb test/fixtures/rails4-mongoid/test/fixtures/posts.yml test/fixtures/rails4-mongoid/test/models/post_test.rb Modified files: test/fixtures/rails4-mongoid/config/routes.rb Added: test/fixtures/rails4-mongoid/app/assets/javascripts/posts.coffee (+3 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/assets/javascripts/posts.coffee 2016-03-21 11:17:17 +0900 (24f83d1) @@ -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://coffeescript.org/ Added: test/fixtures/rails4-mongoid/app/assets/stylesheets/posts.scss (+3 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/assets/stylesheets/posts.scss 2016-03-21 11:17:17 +0900 (1a7e153) @@ -0,0 +1,3 @@ +// Place all the styles related to the posts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ Added: test/fixtures/rails4-mongoid/app/assets/stylesheets/scaffolds.scss (+73 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/assets/stylesheets/scaffolds.scss 2016-03-21 11:17:17 +0900 (ed7a765) @@ -0,0 +1,73 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + + &:visited { + color: #666; + } + + &:hover { + color: #fff; + background-color: #000; + } +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + + ul li { + font-size: 12px; + list-style: square; + } +} Added: test/fixtures/rails4-mongoid/app/controllers/posts_controller.rb (+74 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/controllers/posts_controller.rb 2016-03-21 11:17:17 +0900 (16bba99) @@ -0,0 +1,74 @@ +class PostsController < ApplicationController + before_action :set_post, only: [:show, :edit, :update, :destroy] + + # GET /posts + # GET /posts.json + def index + @posts = Post.all + end + + # GET /posts/1 + # GET /posts/1.json + def show + end + + # GET /posts/new + def new + @post = Post.new + end + + # GET /posts/1/edit + def edit + end + + # POST /posts + # POST /posts.json + def create + @post = Post.new(post_params) + + respond_to do |format| + if****@post***** + format.html { redirect_to @post, notice: 'Post was successfully created.' } + format.json { render :show, status: :created, location: @post } + else + format.html { render :new } + format.json { render json: @post.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /posts/1 + # PATCH/PUT /posts/1.json + def update + respond_to do |format| + if****@post*****(post_params) + format.html { redirect_to @post, notice: 'Post was successfully updated.' } + format.json { render :show, status: :ok, location: @post } + else + format.html { render :edit } + format.json { render json: @post.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /posts/1 + # DELETE /posts/1.json + def destroy + @post.destroy + respond_to do |format| + format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_post + @post = Post.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def post_params + params.require(:post).permit(:title, :body) + end +end Added: test/fixtures/rails4-mongoid/app/helpers/posts_helper.rb (+2 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/helpers/posts_helper.rb 2016-03-21 11:17:17 +0900 (a7b8cec) @@ -0,0 +1,2 @@ +module PostsHelper +end Added: test/fixtures/rails4-mongoid/app/models/post.rb (+5 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/models/post.rb 2016-03-21 11:17:17 +0900 (e930b91) @@ -0,0 +1,5 @@ +class Post + include Mongoid::Document + field :title, type: String + field :body, type: String +end Added: test/fixtures/rails4-mongoid/app/views/posts/_form.html.erb (+25 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/views/posts/_form.html.erb 2016-03-21 11:17:17 +0900 (71b34f3) @@ -0,0 +1,25 @@ +<%= form_for(@post) do |f| %> + <% if****@post*****? %> + <div id="error_explanation"> + <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2> + + <ul> + <% @post.errors.full_messages.each do |message| %> + <li><%= message %></li> + <% end %> + </ul> + </div> + <% end %> + + <div class="field"> + <%= f.label :title %><br> + <%= f.text_field :title %> + </div> + <div class="field"> + <%= f.label :body %><br> + <%= f.text_area :body %> + </div> + <div class="actions"> + <%= f.submit %> + </div> +<% end %> Added: test/fixtures/rails4-mongoid/app/views/posts/edit.html.erb (+6 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/views/posts/edit.html.erb 2016-03-21 11:17:17 +0900 (f1e9acb) @@ -0,0 +1,6 @@ +<h1>Editing Post</h1> + +<%= render 'form' %> + +<%= link_to 'Show', @post %> | +<%= link_to 'Back', posts_path %> Added: test/fixtures/rails4-mongoid/app/views/posts/index.html.erb (+29 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/views/posts/index.html.erb 2016-03-21 11:17:17 +0900 (9985e4f) @@ -0,0 +1,29 @@ +<p id="notice"><%= notice %></p> + +<h1>Listing Posts</h1> + +<table> + <thead> + <tr> + <th>Title</th> + <th>Body</th> + <th colspan="3"></th> + </tr> + </thead> + + <tbody> + <% @posts.each do |post| %> + <tr> + <td><%= post.title %></td> + <td><%= post.body %></td> + <td><%= link_to 'Show', post %></td> + <td><%= link_to 'Edit', edit_post_path(post) %></td> + <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td> + </tr> + <% end %> + </tbody> +</table> + +<br> + +<%= link_to 'New Post', new_post_path %> Added: test/fixtures/rails4-mongoid/app/views/posts/index.json.jbuilder (+4 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/views/posts/index.json.jbuilder 2016-03-21 11:17:17 +0900 (09fc9c2) @@ -0,0 +1,4 @@ +json.array!(@posts) do |post| + json.extract! post, :id, :title, :body + json.url post_url(post, format: :json) +end Added: test/fixtures/rails4-mongoid/app/views/posts/new.html.erb (+5 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/views/posts/new.html.erb 2016-03-21 11:17:17 +0900 (3e5f187) @@ -0,0 +1,5 @@ +<h1>New Post</h1> + +<%= render 'form' %> + +<%= link_to 'Back', posts_path %> Added: test/fixtures/rails4-mongoid/app/views/posts/show.html.erb (+14 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/views/posts/show.html.erb 2016-03-21 11:17:17 +0900 (c14ef10) @@ -0,0 +1,14 @@ +<p id="notice"><%= notice %></p> + +<p> + <strong>Title:</strong> + <%=****@post***** %> +</p> + +<p> + <strong>Body:</strong> + <%=****@post***** %> +</p> + +<%= link_to 'Edit', edit_post_path(@post) %> | +<%= link_to 'Back', posts_path %> Added: test/fixtures/rails4-mongoid/app/views/posts/show.json.jbuilder (+1 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/app/views/posts/show.json.jbuilder 2016-03-21 11:17:17 +0900 (6017ecd) @@ -0,0 +1 @@ +json.extract! @post, :id, :title, :body, :created_at, :updated_at Modified: test/fixtures/rails4-mongoid/config/routes.rb (+1 -0) =================================================================== --- test/fixtures/rails4-mongoid/config/routes.rb 2016-03-21 11:16:50 +0900 (3f66539) +++ test/fixtures/rails4-mongoid/config/routes.rb 2016-03-21 11:17:17 +0900 (7f88317) @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :posts # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". Added: test/fixtures/rails4-mongoid/test/controllers/posts_controller_test.rb (+49 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/test/controllers/posts_controller_test.rb 2016-03-21 11:17:17 +0900 (e8efadf) @@ -0,0 +1,49 @@ +require 'test_helper' + +class PostsControllerTest < ActionController::TestCase + setup do + @post = posts(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:posts) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create post" do + assert_difference('Post.count') do + post :create, post: { body: @post.body, title: @post.title } + end + + assert_redirected_to post_path(assigns(:post)) + end + + test "should show post" do + get :show, id: @post + assert_response :success + end + + test "should get edit" do + get :edit, id: @post + assert_response :success + end + + test "should update post" do + patch :update, id: @post, post: { body: @post.body, title: @post.title } + assert_redirected_to post_path(assigns(:post)) + end + + test "should destroy post" do + assert_difference('Post.count', -1) do + delete :destroy, id: @post + end + + assert_redirected_to posts_path + end +end Added: test/fixtures/rails4-mongoid/test/fixtures/posts.yml (+9 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/test/fixtures/posts.yml 2016-03-21 11:17:17 +0900 (e192dee) @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + title: MyString + body: MyText + +two: + title: MyString + body: MyText Added: test/fixtures/rails4-mongoid/test/models/post_test.rb (+7 -0) 100644 =================================================================== --- /dev/null +++ test/fixtures/rails4-mongoid/test/models/post_test.rb 2016-03-21 11:17:17 +0900 (6d9d463) @@ -0,0 +1,7 @@ +require 'test_helper' + +class PostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end -------------- next part -------------- HTML����������������������������... 下载