Kouhei Sutou
null+****@clear*****
Fri Feb 17 00:09:25 JST 2017
Kouhei Sutou 2017-02-17 00:09:25 +0900 (Fri, 17 Feb 2017) New Revision: e156febecdd28cd357bbdbe0c5c7b1e72e706990 https://github.com/ranguba/ranguba-server/commit/e156febecdd28cd357bbdbe0c5c7b1e72e706990 Message: Create Entry Added files: app/assets/javascripts/entries.coffee app/assets/stylesheets/entries.scss app/assets/stylesheets/scaffolds.scss app/controllers/entries_controller.rb app/helpers/entries_helper.rb app/models/application_groonga_record.rb app/models/entry.rb app/views/entries/_entry.json.jbuilder app/views/entries/_form.html.erb app/views/entries/edit.html.erb app/views/entries/index.html.erb app/views/entries/index.json.jbuilder app/views/entries/new.html.erb app/views/entries/show.html.erb app/views/entries/show.json.jbuilder db/schema.grn test/controllers/entries_controller_test.rb test/factories/entries.rb test/models/entry_test.rb Modified files: Gemfile Gemfile.lock config/routes.rb test/test_helper.rb Modified: Gemfile (+2 -0) =================================================================== --- Gemfile 2017-02-16 23:39:36 +0900 (8f06839) +++ Gemfile 2017-02-17 00:09:25 +0900 (88f3b53) @@ -34,6 +34,8 @@ 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' + gem 'test-unit-rails' end group :development do Modified: Gemfile.lock (+42 -0) =================================================================== --- Gemfile.lock 2017-02-16 23:39:36 +0900 (dec236a) +++ Gemfile.lock 2017-02-17 00:09:25 +0900 (966f6e5) @@ -38,9 +38,18 @@ GEM i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) + addressable (2.5.0) + public_suffix (~> 2.0, >= 2.0.2) arel (7.1.4) builder (3.2.3) byebug (9.0.6) + capybara (2.11.0) + addressable + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) coffee-rails (4.2.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.2.x) @@ -52,6 +61,11 @@ 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.17) globalid (0.3.7) activesupport (>= 4.1.0) @@ -98,6 +112,8 @@ GEM nio4r (1.2.1) nokogiri (1.7.0.1) mini_portile2 (~> 2.1.0) + power_assert (0.4.1) + public_suffix (2.0.5) puma (3.7.0) rack (2.0.1) rack-test (0.6.3) @@ -129,6 +145,7 @@ GEM rb-fsevent (0.9.8) rb-inotify (0.9.8) ffi (>= 0.5.0) + rr (1.2.0) sass (3.4.23) sass-rails (5.0.6) railties (>= 4.0.0, < 6) @@ -148,6 +165,27 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + test-unit (3.2.3) + power_assert + test-unit-activesupport (1.0.6) + activesupport + test-unit + test-unit-capybara (1.0.5) + capybara (>= 2.1.0) + json + test-unit (>= 2.5.3) + test-unit-notify (1.0.4) + test-unit (>= 2.4.9) + test-unit-rails (5.0.2) + rails (>= 4.0.2) + test-unit (>= 3.1.7) + test-unit-activesupport (>= 1.0.2) + test-unit-capybara (>= 1.0.5) + test-unit-notify + test-unit-rr (>= 1.0.4) + test-unit-rr (1.0.5) + rr (>= 1.1.1) + test-unit (>= 2.5.2) thor (0.19.4) thread_safe (0.3.5) tilt (2.0.6) @@ -163,6 +201,8 @@ GEM websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) + xpath (2.0.0) + nokogiri (~> 1.3) PLATFORMS ruby @@ -170,6 +210,7 @@ PLATFORMS DEPENDENCIES byebug coffee-rails (~> 4.2) + factory_girl_rails groonga-client-model jbuilder (~> 2.5) jquery-rails @@ -179,6 +220,7 @@ DEPENDENCIES sass-rails (~> 5.0) spring spring-watcher-listen (~> 2.0.0) + test-unit-rails tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) Added: app/assets/javascripts/entries.coffee (+3 -0) 100644 =================================================================== --- /dev/null +++ app/assets/javascripts/entries.coffee 2017-02-17 00:09:25 +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: app/assets/stylesheets/entries.scss (+3 -0) 100644 =================================================================== --- /dev/null +++ app/assets/stylesheets/entries.scss 2017-02-17 00:09:25 +0900 (53d6246) @@ -0,0 +1,3 @@ +// Place all the styles related to the entries controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ Added: app/assets/stylesheets/scaffolds.scss (+89 -0) 100644 =================================================================== --- /dev/null +++ app/assets/stylesheets/scaffolds.scss 2017-02-17 00:09:25 +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: app/controllers/entries_controller.rb (+74 -0) 100644 =================================================================== --- /dev/null +++ app/controllers/entries_controller.rb 2017-02-17 00:09:25 +0900 (d3e00db) @@ -0,0 +1,74 @@ +class EntriesController < ApplicationController + before_action :set_entry, only: [:show, :edit, :update, :destroy] + + # GET /entries + # GET /entries.json + def index + @entries = Entry.all + end + + # GET /entries/1 + # GET /entries/1.json + def show + end + + # GET /entries/new + def new + @entry = Entry.new + end + + # GET /entries/1/edit + def edit + end + + # POST /entries + # POST /entries.json + def create + @entry = Entry.new(entry_params) + + respond_to do |format| + if****@entry***** + format.html { redirect_to @entry, notice: 'Entry was successfully created.' } + format.json { render :show, status: :created, location: @entry } + else + format.html { render :new } + format.json { render json: @entry.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /entries/1 + # PATCH/PUT /entries/1.json + def update + respond_to do |format| + if****@entry*****(entry_params) + format.html { redirect_to @entry, notice: 'Entry was successfully updated.' } + format.json { render :show, status: :ok, location: @entry } + else + format.html { render :edit } + format.json { render json: @entry.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /entries/1 + # DELETE /entries/1.json + def destroy + @entry.destroy + respond_to do |format| + format.html { redirect_to entries_url, notice: 'Entry was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_entry + @entry = Entry.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def entry_params + params.require(:entry).permit(:_key, :title, :body, :size) + end +end Added: app/helpers/entries_helper.rb (+2 -0) 100644 =================================================================== --- /dev/null +++ app/helpers/entries_helper.rb 2017-02-17 00:09:25 +0900 (ed8c595) @@ -0,0 +1,2 @@ +module EntriesHelper +end Added: app/models/application_groonga_record.rb (+2 -0) 100644 =================================================================== --- /dev/null +++ app/models/application_groonga_record.rb 2017-02-17 00:09:25 +0900 (f860df4) @@ -0,0 +1,2 @@ +class ApplicationGroongaRecord < GroongaClientModel::Record +end Added: app/models/entry.rb (+2 -0) 100644 =================================================================== --- /dev/null +++ app/models/entry.rb 2017-02-17 00:09:25 +0900 (da671f6) @@ -0,0 +1,2 @@ +class Entry < ApplicationGroongaRecord +end Added: app/views/entries/_entry.json.jbuilder (+2 -0) 100644 =================================================================== --- /dev/null +++ app/views/entries/_entry.json.jbuilder 2017-02-17 00:09:25 +0900 (f60ac0a) @@ -0,0 +1,2 @@ +json.extract! entry, :id, :_key, :title, :body, :size, :created_at, :updated_at +json.url entry_url(entry, format: :json) \ No newline at end of file Added: app/views/entries/_form.html.erb (+37 -0) 100644 =================================================================== --- /dev/null +++ app/views/entries/_form.html.erb 2017-02-17 00:09:25 +0900 (2863cd6) @@ -0,0 +1,37 @@ +<%= form_for(entry) do |f| %> + <% if entry.errors.any? %> + <div id="error_explanation"> + <h2><%= pluralize(entry.errors.count, "error") %> prohibited this entry from being saved:</h2> + + <ul> + <% entry.errors.full_messages.each do |message| %> + <li><%= message %></li> + <% end %> + </ul> + </div> + <% end %> + + <div class="field"> + <%= f.label :_key %> + <%= f.text_field :_key %> + </div> + + <div class="field"> + <%= f.label :title %> + <%= f.text_field :title %> + </div> + + <div class="field"> + <%= f.label :body %> + <%= f.text_area :body %> + </div> + + <div class="field"> + <%= f.label :size %> + <%= f.number_field :size %> + </div> + + <div class="actions"> + <%= f.submit %> + </div> +<% end %> Added: app/views/entries/edit.html.erb (+6 -0) 100644 =================================================================== --- /dev/null +++ app/views/entries/edit.html.erb 2017-02-17 00:09:25 +0900 (16b9377) @@ -0,0 +1,6 @@ +<h1>Editing Entry</h1> + +<%= render 'form', entry: @entry %> + +<%= link_to 'Show', @entry %> | +<%= link_to 'Back', entries_path %> Added: app/views/entries/index.html.erb (+33 -0) 100644 =================================================================== --- /dev/null +++ app/views/entries/index.html.erb 2017-02-17 00:09:25 +0900 (ceb4440) @@ -0,0 +1,33 @@ +<p id="notice"><%= notice %></p> + +<h1>Entries</h1> + +<table> + <thead> + <tr> + <th>Key</th> + <th>Title</th> + <th>Body</th> + <th>Size</th> + <th colspan="3"></th> + </tr> + </thead> + + <tbody> + <% @entries.each do |entry| %> + <tr> + <td><%= entry._key %></td> + <td><%= entry.title %></td> + <td><%= entry.body %></td> + <td><%= entry.size %></td> + <td><%= link_to 'Show', entry %></td> + <td><%= link_to 'Edit', edit_entry_path(entry) %></td> + <td><%= link_to 'Destroy', entry, method: :delete, data: { confirm: 'Are you sure?' } %></td> + </tr> + <% end %> + </tbody> +</table> + +<br> + +<%= link_to 'New Entry', new_entry_path %> Added: app/views/entries/index.json.jbuilder (+1 -0) 100644 =================================================================== --- /dev/null +++ app/views/entries/index.json.jbuilder 2017-02-17 00:09:25 +0900 (db09f73) @@ -0,0 +1 @@ +json.array! @entries, partial: 'entries/entry', as: :entry \ No newline at end of file Added: app/views/entries/new.html.erb (+5 -0) 100644 =================================================================== --- /dev/null +++ app/views/entries/new.html.erb 2017-02-17 00:09:25 +0900 (a37c9ec) @@ -0,0 +1,5 @@ +<h1>New Entry</h1> + +<%= render 'form', entry: @entry %> + +<%= link_to 'Back', entries_path %> Added: app/views/entries/show.html.erb (+24 -0) 100644 =================================================================== --- /dev/null +++ app/views/entries/show.html.erb 2017-02-17 00:09:25 +0900 (20eda88) @@ -0,0 +1,24 @@ +<p id="notice"><%= notice %></p> + +<p> + <strong>Key:</strong> + <%= @entry._key %> +</p> + +<p> + <strong>Title:</strong> + <%=****@entry***** %> +</p> + +<p> + <strong>Body:</strong> + <%=****@entry***** %> +</p> + +<p> + <strong>Size:</strong> + <%=****@entry***** %> +</p> + +<%= link_to 'Edit', edit_entry_path(@entry) %> | +<%= link_to 'Back', entries_path %> Added: app/views/entries/show.json.jbuilder (+1 -0) 100644 =================================================================== --- /dev/null +++ app/views/entries/show.json.jbuilder 2017-02-17 00:09:25 +0900 (c6bcb6d) @@ -0,0 +1 @@ +json.partial! "entries/entry", entry: @entry \ No newline at end of file Modified: config/routes.rb (+1 -0) =================================================================== --- config/routes.rb 2017-02-16 23:39:36 +0900 (787824f) +++ config/routes.rb 2017-02-17 00:09:25 +0900 (b69de7e) @@ -1,3 +1,4 @@ Rails.application.routes.draw do + resources :entries # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end Added: db/schema.grn (+14 -0) 100644 =================================================================== --- /dev/null +++ db/schema.grn 2017-02-17 00:09:25 +0900 (eb2db2a) @@ -0,0 +1,14 @@ +table_create entries TABLE_HASH_KEY ShortText +column_create entries title COLUMN_SCALAR ShortText +column_create entries body COLUMN_SCALAR|COMPRESS_ZSTD LongText +column_create entries size COLUMN_SCALAR UInt64 + +table_create terms TABLE_PAT_KEY ShortText \ + --default_tokenizer TokenBigram \ + --normalizer NormalizerAuto +column_create terms entries_title \ + COLUMN_INDEX|WITH_POSITION \ + entries title +column_create terms entries_body \ + COLUMN_INDEX|WITH_POSITION \ + entries body Added: test/controllers/entries_controller_test.rb (+55 -0) 100644 =================================================================== --- /dev/null +++ test/controllers/entries_controller_test.rb 2017-02-17 00:09:25 +0900 (0860265) @@ -0,0 +1,55 @@ +require 'test_helper' + +class EntriesControllerTest < ActionDispatch::IntegrationTest + setup do + @entry = create(:entry) + end + + test "should get index" do + get entries_url + assert_response :success + end + + test "should get new" do + get new_entry_url + assert_response :success + end + + test "should create entry" do + assert_difference('Entry.count') do + post entries_url, params: { + entry: { + _key: "#{@entry._key}-new", + body: @entry.body, + size: @entry.size, + title: @entry.title + } + } + end + + assert_redirected_to entry_url(Entry.last) + end + + test "should show entry" do + get entry_url(@entry) + assert_response :success + end + + test "should get edit" do + get edit_entry_url(@entry) + assert_response :success + end + + test "should update entry" do + patch entry_url(@entry), params: { entry: { _key: @entry._key, body: @entry.body, size: @entry.size, title: @entry.title } } + assert_redirected_to entry_url(@entry) + end + + test "should destroy entry" do + assert_difference('Entry.count', -1) do + delete entry_url(@entry) + end + + assert_redirected_to entries_url + end +end Added: test/factories/entries.rb (+8 -0) 100644 =================================================================== --- /dev/null +++ test/factories/entries.rb 2017-02-17 00:09:25 +0900 (4bc59e3) @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :entry do + _key "http://example.com/" + title "Example.com" + body "Hello!" + size {body.bytesize} + end +end Added: test/models/entry_test.rb (+7 -0) 100644 =================================================================== --- /dev/null +++ test/models/entry_test.rb 2017-02-17 00:09:25 +0900 (d3293bc) @@ -0,0 +1,7 @@ +require 'test_helper' + +class EntryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end Modified: test/test_helper.rb (+4 -1) =================================================================== --- test/test_helper.rb 2017-02-16 23:39:36 +0900 (3acf9ae) +++ test/test_helper.rb 2017-02-17 00:09:25 +0900 (1f9deb0) @@ -1,7 +1,10 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) -require 'rails/test_help' +require 'test/unit/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 + include GroongaClientModel::TestHelper end -------------- next part -------------- HTML����������������������������...下载