From 686fb3d5b3b4d05a32276c7bddb54e996bbc33ba Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Thu, 19 Nov 2015 11:36:53 +0900 Subject: [PATCH] Create Rails testing environment --- sample/rails/Gemfile | 37 ++-------- sample/rails/Gemfile.lock | 19 +++-- .../rails/app/assets/javascripts/users.coffee | 3 + .../app/assets/stylesheets/scaffolds.scss | 73 ++++++++++++++++++ .../rails/app/assets/stylesheets/users.scss | 3 + .../rails/app/controllers/users_controller.rb | 74 +++++++++++++++++++ sample/rails/app/helpers/users_helper.rb | 2 + sample/rails/app/models/user.rb | 2 + .../app/views/layouts/application.html.erb | 14 ---- .../app/views/layouts/application.html.haml | 9 +++ sample/rails/app/views/users/_form.html.haml | 11 +++ sample/rails/app/views/users/edit.html.haml | 5 ++ sample/rails/app/views/users/index.html.haml | 19 +++++ sample/rails/app/views/users/new.html.haml | 5 ++ sample/rails/app/views/users/show.html.haml | 3 + sample/rails/config/routes.rb | 56 +------------- .../db/migrate/20151119022746_create_users.rb | 8 ++ sample/rails/db/schema.rb | 21 ++++++ 18 files changed, 260 insertions(+), 104 deletions(-) create mode 100644 sample/rails/app/assets/javascripts/users.coffee create mode 100644 sample/rails/app/assets/stylesheets/scaffolds.scss create mode 100644 sample/rails/app/assets/stylesheets/users.scss create mode 100644 sample/rails/app/controllers/users_controller.rb create mode 100644 sample/rails/app/helpers/users_helper.rb create mode 100644 sample/rails/app/models/user.rb delete mode 100644 sample/rails/app/views/layouts/application.html.erb create mode 100644 sample/rails/app/views/layouts/application.html.haml create mode 100644 sample/rails/app/views/users/_form.html.haml create mode 100644 sample/rails/app/views/users/edit.html.haml create mode 100644 sample/rails/app/views/users/index.html.haml create mode 100644 sample/rails/app/views/users/new.html.haml create mode 100644 sample/rails/app/views/users/show.html.haml create mode 100644 sample/rails/db/migrate/20151119022746_create_users.rb create mode 100644 sample/rails/db/schema.rb diff --git a/sample/rails/Gemfile b/sample/rails/Gemfile index caf17eee..bfea3230 100644 --- a/sample/rails/Gemfile +++ b/sample/rails/Gemfile @@ -1,45 +1,20 @@ source 'https://rubygems.org' - -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.4' -# Use sqlite3 as the database for Active Record -gem 'sqlite3' -# Use SCSS for stylesheets -gem 'sass-rails', '~> 5.0' -# Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '>= 1.3.0' -# Use CoffeeScript for .coffee assets and views + gem 'coffee-rails', '~> 4.1.0' -# See https://github.com/rails/execjs#readme for more supported runtimes -# gem 'therubyracer', platforms: :ruby - -# Use jquery as the JavaScript library -gem 'jquery-rails' -# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'hamlit', path: '../../' gem 'jbuilder', '~> 2.0' -# bundle exec rake doc:rails generates the API under doc/api. -gem 'sdoc', '~> 0.4.0', group: :doc - -# Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' - -# Use Unicorn as the app server -# gem 'unicorn' - -# Use Capistrano for deployment -# gem 'capistrano-rails', group: :development +gem 'jquery-rails' +gem 'sass-rails', '~> 5.0' +gem 'sqlite3' +gem 'uglifier', '>= 1.3.0' group :development, :test do - # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' end group :development do - # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' - - # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end - diff --git a/sample/rails/Gemfile.lock b/sample/rails/Gemfile.lock index f0e87cf4..e23458a0 100644 --- a/sample/rails/Gemfile.lock +++ b/sample/rails/Gemfile.lock @@ -1,3 +1,12 @@ +PATH + remote: ../../ + specs: + hamlit (0.1.0) + escape_utils + haml (>= 4.0.7, < 5.0) + temple (~> 0.7.6) + tilt + GEM remote: https://rubygems.org/ specs: @@ -50,9 +59,12 @@ GEM coffee-script-source (1.10.0) debug_inspector (0.0.2) erubis (2.7.0) + escape_utils (1.1.0) execjs (2.6.0) globalid (0.3.6) activesupport (>= 4.1.0) + haml (4.0.7) + tilt i18n (0.7.0) jbuilder (2.3.2) activesupport (>= 3.0.0, < 5) @@ -100,7 +112,6 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.4.2) - rdoc (4.2.0) sass (3.4.19) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -108,9 +119,6 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sdoc (0.4.1) - json (~> 1.7, >= 1.7.7) - rdoc (~> 4.0) spring (1.4.3) sprockets (3.4.0) rack (> 1, < 3) @@ -119,6 +127,7 @@ GEM activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) sqlite3 (1.3.11) + temple (0.7.6) thor (0.19.1) thread_safe (0.3.5) tilt (2.0.1) @@ -139,11 +148,11 @@ PLATFORMS DEPENDENCIES byebug coffee-rails (~> 4.1.0) + hamlit! jbuilder (~> 2.0) jquery-rails rails (= 4.2.4) sass-rails (~> 5.0) - sdoc (~> 0.4.0) spring sqlite3 uglifier (>= 1.3.0) diff --git a/sample/rails/app/assets/javascripts/users.coffee b/sample/rails/app/assets/javascripts/users.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/sample/rails/app/assets/javascripts/users.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://coffeescript.org/ diff --git a/sample/rails/app/assets/stylesheets/scaffolds.scss b/sample/rails/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 00000000..ed7a765d --- /dev/null +++ b/sample/rails/app/assets/stylesheets/scaffolds.scss @@ -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; + } +} diff --git a/sample/rails/app/assets/stylesheets/users.scss b/sample/rails/app/assets/stylesheets/users.scss new file mode 100644 index 00000000..1efc835c --- /dev/null +++ b/sample/rails/app/assets/stylesheets/users.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/sample/rails/app/controllers/users_controller.rb b/sample/rails/app/controllers/users_controller.rb new file mode 100644 index 00000000..cdd92ad1 --- /dev/null +++ b/sample/rails/app/controllers/users_controller.rb @@ -0,0 +1,74 @@ +class UsersController < ApplicationController + before_action :set_user, only: [:show, :edit, :update, :destroy] + + # GET /users + # GET /users.json + def index + @users = User.all + end + + # GET /users/1 + # GET /users/1.json + def show + end + + # GET /users/new + def new + @user = User.new + end + + # GET /users/1/edit + def edit + end + + # POST /users + # POST /users.json + def create + @user = User.new(user_params) + + respond_to do |format| + if @user.save + format.html { redirect_to @user, notice: 'User was successfully created.' } + format.json { render :show, status: :created, location: @user } + else + format.html { render :new } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /users/1 + # PATCH/PUT /users/1.json + def update + respond_to do |format| + if @user.update(user_params) + format.html { redirect_to @user, notice: 'User was successfully updated.' } + format.json { render :show, status: :ok, location: @user } + else + format.html { render :edit } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /users/1 + # DELETE /users/1.json + def destroy + @user.destroy + respond_to do |format| + format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_user + @user = User.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def user_params + params[:user] + end +end diff --git a/sample/rails/app/helpers/users_helper.rb b/sample/rails/app/helpers/users_helper.rb new file mode 100644 index 00000000..2310a240 --- /dev/null +++ b/sample/rails/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/sample/rails/app/models/user.rb b/sample/rails/app/models/user.rb new file mode 100644 index 00000000..4a57cf07 --- /dev/null +++ b/sample/rails/app/models/user.rb @@ -0,0 +1,2 @@ +class User < ActiveRecord::Base +end diff --git a/sample/rails/app/views/layouts/application.html.erb b/sample/rails/app/views/layouts/application.html.erb deleted file mode 100644 index 5467272d..00000000 --- a/sample/rails/app/views/layouts/application.html.erb +++ /dev/null @@ -1,14 +0,0 @@ - - - - Dummy - <%= stylesheet_link_tag 'application', media: 'all' %> - <%= javascript_include_tag 'application' %> - <%= csrf_meta_tags %> - - - -<%= yield %> - - - diff --git a/sample/rails/app/views/layouts/application.html.haml b/sample/rails/app/views/layouts/application.html.haml new file mode 100644 index 00000000..795cc3d6 --- /dev/null +++ b/sample/rails/app/views/layouts/application.html.haml @@ -0,0 +1,9 @@ +!!! +%html + %head + %title Dummy + = stylesheet_link_tag 'application', media: 'all' + = javascript_include_tag 'application' + = csrf_meta_tags + %body + = yield diff --git a/sample/rails/app/views/users/_form.html.haml b/sample/rails/app/views/users/_form.html.haml new file mode 100644 index 00000000..5ae63f9e --- /dev/null +++ b/sample/rails/app/views/users/_form.html.haml @@ -0,0 +1,11 @@ += form_for(@user) do |f| + - if @user.errors.any? + #error_explanation + %h2 #{pluralize(@user.errors.count, "error")} prohibited this user from being saved: + + %ul + - @user.errors.full_messages.each do |message| + %li= message + + .actions + = f.submit diff --git a/sample/rails/app/views/users/edit.html.haml b/sample/rails/app/views/users/edit.html.haml new file mode 100644 index 00000000..78452dcc --- /dev/null +++ b/sample/rails/app/views/users/edit.html.haml @@ -0,0 +1,5 @@ +%h1 Editing User + += render 'form' + +#{link_to 'Show', @user} | #{link_to 'Back', users_path} diff --git a/sample/rails/app/views/users/index.html.haml b/sample/rails/app/views/users/index.html.haml new file mode 100644 index 00000000..fb1d4515 --- /dev/null +++ b/sample/rails/app/views/users/index.html.haml @@ -0,0 +1,19 @@ +%p#notice= notice + +%h1 Listing Users + +%table + %thead + %tr + %th{ colspan: "3" } + + %tbody + - @users.each do |user| + %tr + %td= link_to 'Show', user + %td= link_to 'Edit', edit_user_path(user) + %td= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } + +%br + += link_to 'New User', new_user_path diff --git a/sample/rails/app/views/users/new.html.haml b/sample/rails/app/views/users/new.html.haml new file mode 100644 index 00000000..37603979 --- /dev/null +++ b/sample/rails/app/views/users/new.html.haml @@ -0,0 +1,5 @@ +%h1 New User + += render 'form' + += link_to 'Back', users_path diff --git a/sample/rails/app/views/users/show.html.haml b/sample/rails/app/views/users/show.html.haml new file mode 100644 index 00000000..4dae5aca --- /dev/null +++ b/sample/rails/app/views/users/show.html.haml @@ -0,0 +1,3 @@ +#notice= notice + +#{link_to 'Edit', edit_user_path(@user)} | #{link_to 'Back', users_path} diff --git a/sample/rails/config/routes.rb b/sample/rails/config/routes.rb index 3f66539d..3dc8a443 100644 --- a/sample/rails/config/routes.rb +++ b/sample/rails/config/routes.rb @@ -1,56 +1,4 @@ Rails.application.routes.draw do - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". - - # You can have the root of your site routed with "root" - # root 'welcome#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end + resources :users + root to: 'users#index' end diff --git a/sample/rails/db/migrate/20151119022746_create_users.rb b/sample/rails/db/migrate/20151119022746_create_users.rb new file mode 100644 index 00000000..e6f0ee54 --- /dev/null +++ b/sample/rails/db/migrate/20151119022746_create_users.rb @@ -0,0 +1,8 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + + t.timestamps null: false + end + end +end diff --git a/sample/rails/db/schema.rb b/sample/rails/db/schema.rb new file mode 100644 index 00000000..6d7aef82 --- /dev/null +++ b/sample/rails/db/schema.rb @@ -0,0 +1,21 @@ +# encoding: UTF-8 +# 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: 20151119022746) do + + create_table "users", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end