Kouhei Sutou
null+****@clear*****
Tue Dec 27 15:08:24 JST 2016
Kouhei Sutou 2016-12-27 15:08:24 +0900 (Tue, 27 Dec 2016) New Revision: 71a0d7c8db9dc9d543ac3f0de2fdd2cc8972ea83 https://github.com/ranguba/groonga-client-model/commit/71a0d7c8db9dc9d543ac3f0de2fdd2cc8972ea83 Message: test rails4: add a model Added files: test/apps/rails4/app/assets/javascripts/posts.coffee test/apps/rails4/app/assets/stylesheets/posts.scss test/apps/rails4/app/assets/stylesheets/scaffolds.scss test/apps/rails4/app/controllers/posts_controller.rb test/apps/rails4/app/helpers/posts_helper.rb test/apps/rails4/app/models/post.rb test/apps/rails4/app/views/posts/_form.html.erb test/apps/rails4/app/views/posts/_post.json.jbuilder test/apps/rails4/app/views/posts/edit.html.erb test/apps/rails4/app/views/posts/index.html.erb test/apps/rails4/app/views/posts/index.json.jbuilder test/apps/rails4/app/views/posts/new.html.erb test/apps/rails4/app/views/posts/show.html.erb test/apps/rails4/app/views/posts/show.json.jbuilder test/apps/rails4/config/groonga.yml test/apps/rails4/db/schema.grn test/apps/rails4/test/controllers/posts_controller_test.rb test/apps/rails4/test/factories/posts.rb Modified files: test/apps/rails4/Gemfile test/apps/rails4/Gemfile.lock test/apps/rails4/config/routes.rb test/apps/rails4/test/test_helper.rb Modified: test/apps/rails4/Gemfile (+4 -0) =================================================================== --- test/apps/rails4/Gemfile 2016-12-27 15:08:10 +0900 (913f53f) +++ test/apps/rails4/Gemfile 2016-12-27 15:08:24 +0900 (502a520) @@ -36,6 +36,7 @@ gem 'jbuilder', '~> 2.5' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri + gem 'factory_girl_rails' end group :development do @@ -49,3 +50,6 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem 'groonga-client-model', path: '../../../' +gem 'groonga-client', path: '../../../../groonga-client' Modified: test/apps/rails4/Gemfile.lock (+34 -0) =================================================================== --- test/apps/rails4/Gemfile.lock 2016-12-27 15:08:10 +0900 (21756eb) +++ test/apps/rails4/Gemfile.lock 2016-12-27 15:08:24 +0900 (04b9de4) @@ -1,3 +1,20 @@ +PATH + remote: ../../../../groonga-client + specs: + groonga-client (0.4.0) + gqtp (>= 1.0.4) + groonga-command (>= 1.2.8) + groonga-command-parser (>= 1.0.7) + hashie + +PATH + remote: ../../../ + specs: + groonga-client-model (0.9.5) + activemodel + groonga-client (>= 0.3.7) + groonga-command-parser + GEM remote: https://rubygems.org/ specs: @@ -52,9 +69,21 @@ GEM debug_inspector (0.0.2) erubis (2.7.0) execjs (2.7.0) + factory_girl (4.8.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.8.0) + factory_girl (~> 4.8.0) + railties (>= 3.0.0) ffi (1.9.14) globalid (0.3.7) activesupport (>= 4.1.0) + gqtp (1.0.6) + groonga-command (1.3.1) + json + groonga-command-parser (1.0.7) + groonga-command (>= 1.0.9) + json-stream + hashie (3.4.6) i18n (0.7.0) jbuilder (2.6.1) activesupport (>= 3.0.0, < 5.1) @@ -63,6 +92,8 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + json (2.0.2) + json-stream (0.2.1) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -155,6 +186,9 @@ PLATFORMS DEPENDENCIES byebug coffee-rails (~> 4.2) + factory_girl_rails + groonga-client! + groonga-client-model! jbuilder (~> 2.5) jquery-rails listen (~> 3.0.5) Added: test/apps/rails4/app/assets/javascripts/posts.coffee (+3 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/assets/javascripts/posts.coffee 2016-12-27 15:08:24 +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/rails4/app/assets/stylesheets/posts.scss (+3 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/assets/stylesheets/posts.scss 2016-12-27 15:08:24 +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/rails4/app/assets/stylesheets/scaffolds.scss (+89 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/assets/stylesheets/scaffolds.scss 2016-12-27 15:08:24 +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/rails4/app/controllers/posts_controller.rb (+74 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/controllers/posts_controller.rb 2016-12-27 15:08:24 +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/rails4/app/helpers/posts_helper.rb (+2 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/helpers/posts_helper.rb 2016-12-27 15:08:24 +0900 (a7b8cec) @@ -0,0 +1,2 @@ +module PostsHelper +end Added: test/apps/rails4/app/models/post.rb (+2 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/models/post.rb 2016-12-27 15:08:24 +0900 (90666d2) @@ -0,0 +1,2 @@ +class Post < GroongaClientModel::Record +end Added: test/apps/rails4/app/views/posts/_form.html.erb (+27 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/views/posts/_form.html.erb 2016-12-27 15:08:24 +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/rails4/app/views/posts/_post.json.jbuilder (+2 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/views/posts/_post.json.jbuilder 2016-12-27 15:08:24 +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/rails4/app/views/posts/edit.html.erb (+6 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/views/posts/edit.html.erb 2016-12-27 15:08:24 +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/rails4/app/views/posts/index.html.erb (+29 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/views/posts/index.html.erb 2016-12-27 15:08:24 +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/rails4/app/views/posts/index.json.jbuilder (+1 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/views/posts/index.json.jbuilder 2016-12-27 15:08:24 +0900 (af157a6) @@ -0,0 +1 @@ +json.array! @posts, partial: 'posts/post', as: :post \ No newline at end of file Added: test/apps/rails4/app/views/posts/new.html.erb (+5 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/views/posts/new.html.erb 2016-12-27 15:08:24 +0900 (fb1e2a1) @@ -0,0 +1,5 @@ +<h1>New Post</h1> + +<%= render 'form', post: @post %> + +<%= link_to 'Back', posts_path %> Added: test/apps/rails4/app/views/posts/show.html.erb (+14 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/views/posts/show.html.erb 2016-12-27 15:08:24 +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/rails4/app/views/posts/show.json.jbuilder (+1 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/app/views/posts/show.json.jbuilder 2016-12-27 15:08:24 +0900 (2c7bc27) @@ -0,0 +1 @@ +json.partial! "posts/post", post: @post \ No newline at end of file Added: test/apps/rails4/config/groonga.yml (+8 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/config/groonga.yml 2016-12-27 15:08:24 +0900 (6bd3460) @@ -0,0 +1,8 @@ +development: + url: http://127.0.0.1:10041 + +test: + url: http://127.0.0.1:20041 + +production: + url: http://127.0.0.1:10041 Modified: test/apps/rails4/config/routes.rb (+1 -0) =================================================================== --- test/apps/rails4/config/routes.rb 2016-12-27 15:08:10 +0900 (787824f) +++ test/apps/rails4/config/routes.rb 2016-12-27 15:08:24 +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/rails4/db/schema.grn (+9 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/db/schema.grn 2016-12-27 15:08:24 +0900 (aaf10e5) @@ -0,0 +1,9 @@ +table_create posts TABLE_NO_KEY + +column_create posts title COLUMN_SCALAR ShortText +column_create posts body COLUMN_SCALAR Text + +table_create terms TABLE_PAT_KEY ShortText \ + --default_tokenizer TokenBigram \ + --normalizer NormalizerAuto +column_create terms posts_body COLUMN_INDEX|WITH_POSITION posts body Added: test/apps/rails4/test/controllers/posts_controller_test.rb (+50 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/test/controllers/posts_controller_test.rb 2016-12-27 15:08:24 +0900 (dc8397e) @@ -0,0 +1,50 @@ +require 'test_helper' + +class PostsControllerTest < ActionDispatch::IntegrationTest + include GroongaClientModel::TestHelper + + setup do + @post = create(:post) + 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/rails4/test/factories/posts.rb (+6 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails4/test/factories/posts.rb 2016-12-27 15:08:24 +0900 (5700297) @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :post do + title "Hello" + body "World" + end +end Modified: test/apps/rails4/test/test_helper.rb (+2 -0) =================================================================== --- test/apps/rails4/test/test_helper.rb 2016-12-27 15:08:10 +0900 (3acf9ae) +++ test/apps/rails4/test/test_helper.rb 2016-12-27 15:08:24 +0900 (66f92f8) @@ -1,7 +1,9 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' +require 'groonga_client_model/test_helper' class ActiveSupport::TestCase # Add more helper methods to be used by all tests here... + include FactoryGirl::Syntax::Methods end -------------- next part -------------- HTML����������������������������...Download