[Groonga-commit] ranguba/groonga-client-rails at 35fe03b [master] test rails5 activerecord: create application

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Dec 12 09:48:05 JST 2016


Kouhei Sutou	2016-12-12 09:48:05 +0900 (Mon, 12 Dec 2016)

  New Revision: 35fe03b025afb01e07a7da36a408c0eaa4e7b327
  https://github.com/ranguba/groonga-client-rails/commit/35fe03b025afb01e07a7da36a408c0eaa4e7b327

  Message:
    test rails5 activerecord: create application
    
        % bin/rails generate scaffold post title:string body:text

  Added files:
    test/apps/rails5-activerecord/app/assets/javascripts/posts.coffee
    test/apps/rails5-activerecord/app/assets/stylesheets/posts.scss
    test/apps/rails5-activerecord/app/assets/stylesheets/scaffolds.scss
    test/apps/rails5-activerecord/app/controllers/posts_controller.rb
    test/apps/rails5-activerecord/app/helpers/posts_helper.rb
    test/apps/rails5-activerecord/app/models/post.rb
    test/apps/rails5-activerecord/app/views/posts/_form.html.erb
    test/apps/rails5-activerecord/app/views/posts/_post.json.jbuilder
    test/apps/rails5-activerecord/app/views/posts/edit.html.erb
    test/apps/rails5-activerecord/app/views/posts/index.html.erb
    test/apps/rails5-activerecord/app/views/posts/index.json.jbuilder
    test/apps/rails5-activerecord/app/views/posts/new.html.erb
    test/apps/rails5-activerecord/app/views/posts/show.html.erb
    test/apps/rails5-activerecord/app/views/posts/show.json.jbuilder
    test/apps/rails5-activerecord/db/migrate/20161212004726_create_posts.rb
    test/apps/rails5-activerecord/db/schema.rb
    test/apps/rails5-activerecord/test/controllers/posts_controller_test.rb
    test/apps/rails5-activerecord/test/fixtures/posts.yml
    test/apps/rails5-activerecord/test/models/post_test.rb
  Modified files:
    test/apps/rails5-activerecord/config/routes.rb

  Added: test/apps/rails5-activerecord/app/assets/javascripts/posts.coffee (+3 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/assets/javascripts/posts.coffee    2016-12-12 09:48:05 +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/apps/rails5-activerecord/app/assets/stylesheets/posts.scss (+3 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/assets/stylesheets/posts.scss    2016-12-12 09:48:05 +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/apps/rails5-activerecord/app/assets/stylesheets/scaffolds.scss (+89 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/assets/stylesheets/scaffolds.scss    2016-12-12 09:48:05 +0900 (4ce4266)
@@ -0,0 +1,89 @@
+body {
+  background-color: #fff;
+  color: #333;
+  font-family: verdana, arial, helvetica, sans-serif;
+  font-size: 13px;
+  line-height: 18px;
+  margin: 33px;
+}
+
+p, ol, ul, td {
+  font-family: verdana, arial, helvetica, sans-serif;
+  font-size: 13px;
+  line-height: 18px;
+  margin: 33px;
+}
+
+pre {
+  background-color: #eee;
+  padding: 10px;
+  font-size: 11px;
+}
+
+a {
+  color: #000;
+
+  &:visited {
+    color: #666;
+  }
+
+  &:hover {
+    color: #fff;
+    background-color: #000;
+  }
+}
+
+th {
+  padding-bottom: 5px;
+}
+
+td {
+  padding-bottom: 7px;
+  padding-left: 5px;
+  padding-right: 5px;
+}
+
+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: 0;
+    background-color: #c00;
+    color: #fff;
+  }
+
+  ul li {
+    font-size: 12px;
+    list-style: square;
+  }
+}
+
+label {
+  display: block;
+}

  Added: test/apps/rails5-activerecord/app/controllers/posts_controller.rb (+74 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/controllers/posts_controller.rb    2016-12-12 09:48:05 +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/apps/rails5-activerecord/app/helpers/posts_helper.rb (+2 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/helpers/posts_helper.rb    2016-12-12 09:48:05 +0900 (a7b8cec)
@@ -0,0 +1,2 @@
+module PostsHelper
+end

  Added: test/apps/rails5-activerecord/app/models/post.rb (+2 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/models/post.rb    2016-12-12 09:48:05 +0900 (b2a8b46)
@@ -0,0 +1,2 @@
+class Post < ApplicationRecord
+end

  Added: test/apps/rails5-activerecord/app/views/posts/_form.html.erb (+27 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/views/posts/_form.html.erb    2016-12-12 09:48:05 +0900 (8733928)
@@ -0,0 +1,27 @@
+<%= form_for(post) do |f| %>
+  <% if post.errors.any? %>
+    <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 %>
+    <%= f.text_field :title %>
+  </div>
+
+  <div class="field">
+    <%= f.label :body %>
+    <%= f.text_area :body %>
+  </div>
+
+  <div class="actions">
+    <%= f.submit %>
+  </div>
+<% end %>

  Added: test/apps/rails5-activerecord/app/views/posts/_post.json.jbuilder (+2 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/views/posts/_post.json.jbuilder    2016-12-12 09:48:05 +0900 (084ca51)
@@ -0,0 +1,2 @@
+json.extract! post, :id, :title, :body, :created_at, :updated_at
+json.url post_url(post, format: :json)
\ No newline at end of file

  Added: test/apps/rails5-activerecord/app/views/posts/edit.html.erb (+6 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/views/posts/edit.html.erb    2016-12-12 09:48:05 +0900 (ded33f7)
@@ -0,0 +1,6 @@
+<h1>Editing Post</h1>
+
+<%= render 'form', post: @post %>
+
+<%= link_to 'Show', @post %> |
+<%= link_to 'Back', posts_path %>

  Added: test/apps/rails5-activerecord/app/views/posts/index.html.erb (+29 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/views/posts/index.html.erb    2016-12-12 09:48:05 +0900 (dd12307)
@@ -0,0 +1,29 @@
+<p id="notice"><%= notice %></p>
+
+<h1>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/apps/rails5-activerecord/app/views/posts/index.json.jbuilder (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/views/posts/index.json.jbuilder    2016-12-12 09:48:05 +0900 (af157a6)
@@ -0,0 +1 @@
+json.array! @posts, partial: 'posts/post', as: :post
\ No newline at end of file

  Added: test/apps/rails5-activerecord/app/views/posts/new.html.erb (+5 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/views/posts/new.html.erb    2016-12-12 09:48:05 +0900 (fb1e2a1)
@@ -0,0 +1,5 @@
+<h1>New Post</h1>
+
+<%= render 'form', post: @post %>
+
+<%= link_to 'Back', posts_path %>

  Added: test/apps/rails5-activerecord/app/views/posts/show.html.erb (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/views/posts/show.html.erb    2016-12-12 09:48:05 +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/apps/rails5-activerecord/app/views/posts/show.json.jbuilder (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/app/views/posts/show.json.jbuilder    2016-12-12 09:48:05 +0900 (2c7bc27)
@@ -0,0 +1 @@
+json.partial! "posts/post", post: @post
\ No newline at end of file

  Modified: test/apps/rails5-activerecord/config/routes.rb (+1 -0)
===================================================================
--- test/apps/rails5-activerecord/config/routes.rb    2016-12-12 09:46:34 +0900 (787824f)
+++ test/apps/rails5-activerecord/config/routes.rb    2016-12-12 09:48:05 +0900 (abba78d)
@@ -1,3 +1,4 @@
 Rails.application.routes.draw do
+  resources :posts
   # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
 end

  Added: test/apps/rails5-activerecord/db/migrate/20161212004726_create_posts.rb (+10 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/db/migrate/20161212004726_create_posts.rb    2016-12-12 09:48:05 +0900 (bc17bc7)
@@ -0,0 +1,10 @@
+class CreatePosts < ActiveRecord::Migration[5.0]
+  def change
+    create_table :posts do |t|
+      t.string :title
+      t.text :body
+
+      t.timestamps
+    end
+  end
+end

  Added: test/apps/rails5-activerecord/db/schema.rb (+22 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/db/schema.rb    2016-12-12 09:48:05 +0900 (16ea23c)
@@ -0,0 +1,22 @@
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 20161212004726) do
+
+  create_table "posts", force: :cascade do |t|
+    t.string   "title"
+    t.text     "body"
+    t.datetime "created_at", null: false
+    t.datetime "updated_at", null: false
+  end
+
+end

  Added: test/apps/rails5-activerecord/test/controllers/posts_controller_test.rb (+48 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/test/controllers/posts_controller_test.rb    2016-12-12 09:48:05 +0900 (8cd9d5d)
@@ -0,0 +1,48 @@
+require 'test_helper'
+
+class PostsControllerTest < ActionDispatch::IntegrationTest
+  setup do
+    @post = posts(:one)
+  end
+
+  test "should get index" do
+    get posts_url
+    assert_response :success
+  end
+
+  test "should get new" do
+    get new_post_url
+    assert_response :success
+  end
+
+  test "should create post" do
+    assert_difference('Post.count') do
+      post posts_url, params: { post: { body: @post.body, title: @post.title } }
+    end
+
+    assert_redirected_to post_url(Post.last)
+  end
+
+  test "should show post" do
+    get post_url(@post)
+    assert_response :success
+  end
+
+  test "should get edit" do
+    get edit_post_url(@post)
+    assert_response :success
+  end
+
+  test "should update post" do
+    patch post_url(@post), params: { post: { body: @post.body, title: @post.title } }
+    assert_redirected_to post_url(@post)
+  end
+
+  test "should destroy post" do
+    assert_difference('Post.count', -1) do
+      delete post_url(@post)
+    end
+
+    assert_redirected_to posts_url
+  end
+end

  Added: test/apps/rails5-activerecord/test/fixtures/posts.yml (+9 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/test/fixtures/posts.yml    2016-12-12 09:48:05 +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/apps/rails5-activerecord/test/models/post_test.rb (+7 -0) 100644
===================================================================
--- /dev/null
+++ test/apps/rails5-activerecord/test/models/post_test.rb    2016-12-12 09:48:05 +0900 (6d9d463)
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PostTest < ActiveSupport::TestCase
+  # test "the truth" do
+  #   assert true
+  # end
+end
-------------- next part --------------
HTML����������������������������...
下載 



More information about the Groonga-commit mailing list
Back to archive index