diff --git a/.gitignore b/.gitignore index 5e1422c..ac15da4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ *.gem *.rbc /.config +/config/secrets.yml +/config/database.yml +/log/ /coverage/ /InstalledFiles /pkg/ diff --git a/Gemfile b/Gemfile index 0b9a659..ef69159 100644 --- a/Gemfile +++ b/Gemfile @@ -1,55 +1,33 @@ -source 'https://rubygems.org' +source "https://rubygems.org" git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" end +gem "rails", "~> 5.0.2" -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 5.0.2' -# Use sqlite3 as the database for Active Record -gem 'bcrypt', '3.1.7' -# -gem 'sqlite3' -# Use Puma as the app server -gem 'puma', '~> 3.0' -# 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.2' -# See https://github.com/rails/execjs#readme for more supported runtimes -# gem 'therubyracer', platforms: :ruby +gem "bcrypt", "3.1.7" -# Use jquery as the JavaScript library -gem 'jquery-rails' -# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks -gem 'turbolinks', '~> 5' -# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 2.5' -# Use Redis adapter to run Action Cable in production -# gem 'redis', '~> 3.0' -# Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' - -# Use Capistrano for deployment -# gem 'capistrano-rails', group: :development +gem "bootstrap-sass","3.3.7" +gem "sqlite3" +gem "puma", "~> 3.0" +gem "sass-rails", "~> 5.0" +gem "uglifier", ">= 1.3.0" +gem "coffee-rails", "~> 4.2" +gem "jquery-rails" +gem "turbolinks", "~> 5" +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 "byebug", platform: :mri end group :development do - # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. - gem 'web-console', '>= 3.3.0' - gem 'listen', '~> 3.0.5' - # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring - gem 'spring' - gem 'spring-watcher-listen', '~> 2.0.0' + gem "web-console", ">= 3.3.0" + gem "listen", "~> 3.0.5" + gem "spring" + gem "spring-watcher-listen", "~> 2.0.0" end -# Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/Gemfile.lock b/Gemfile.lock index 9c3aa73..7fb48ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,7 +39,12 @@ GEM minitest (~> 5.1) tzinfo (~> 1.1) arel (7.1.4) + autoprefixer-rails (6.7.7) + execjs bcrypt (3.1.7) + bootstrap-sass (3.3.7) + autoprefixer-rails (>= 5.2.1) + sass (>= 3.3.4) builder (3.2.3) byebug (9.0.6) coffee-rails (4.2.1) @@ -156,6 +161,7 @@ PLATFORMS DEPENDENCIES bcrypt (= 3.1.7) + bootstrap-sass (= 3.3.7) byebug coffee-rails (~> 4.2) jbuilder (~> 2.5) diff --git a/app/assets/images/rails.png b/app/assets/images/rails.png new file mode 100644 index 0000000..f9fa0a0 Binary files /dev/null and b/app/assets/images/rails.png differ diff --git a/app/assets/stylesheets/custom.scss b/app/assets/stylesheets/custom.scss new file mode 100644 index 0000000..d2a9c30 --- /dev/null +++ b/app/assets/stylesheets/custom.scss @@ -0,0 +1,181 @@ +@import "bootstrap-sprockets"; +@import "bootstrap"; + +/* mixins, variables, etc. */ + +$gray-medium-light: #eaeaea; + +@mixin box_sizing +{ + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} + +/* miscellaneous */ + +.debug_dump { + clear: both; + float: left; + width: 100%; + margin-top: 45px; + @include box_sizing; +} + +/* universal */ + +body { + padding-top: 60px; +} + +section { + overflow: auto; +} + +textarea { + resize: vertical; +} + +.center { + text-align: center; + h1 { + margin-bottom: 10px; + } +} + +/* typography */ + +h1, h2, h3, h4, h5, h6 { + line-height: 1; +} + +h1 { + font-size: 3em; + letter-spacing: -2px; + margin-bottom: 30px; + text-align: center; +} + +h2 { + font-size: 1.2em; + letter-spacing: -1px; + margin-bottom: 30px; + text-align: center; + font-weight: normal; + color: $gray-light; +} + +p { + font-size: 1.1em; + line-height: 1.7em; +} + +/* header */ + +#logo +{ + float: left; + margin-right: 10px; + font-size: 1.7em; + color: white; + text-transform: uppercase; + letter-spacing: -1px; + padding-top: 9px; + font-weight: bold; + &:hover { + color: white; + text-decoration: none; + } +} + +/* footer */ + +footer +{ + margin-top: 45px; + padding-top: 5px; + border-top: 1px solid $gray-medium-light; + color: $gray-light; + a { + color: $gray; + &:hover { + color: $gray-darker; + } + } + small { + float: left; + } + ul { + float: right; + list-style: none; + li { + float: left; + margin-left: 15px; + } + } +} + +/* sidebar */ + +aside { + section.user_info { + margin-top: 20px; + } + section { + padding: 10px 0; + margin-top: 20px; + &:first-child { + border: 0; + padding-top: 0; + } + span { + display: block; + margin-bottom: 3px; + line-height: 1; + } + h1 { + font-size: 1.4em; + text-align: left; + letter-spacing: -1px; + margin-bottom: 3px; + margin-top: 0px; + } + } +} + +.gravatar { + float: left; + margin-right: 10px; +} + +.gravatar_edit { + margin-top: 15px; +} + +/* forms */ + +input, textarea, select, .uneditable-input { + border: 1px solid #bbb; + width: 100%; + margin-bottom: 15px; + @include box_sizing; +} + +input { + height: auto !important; +} + +#error_explanation { + color: red; + ul { + color: red; + margin: 0 0 30px 0; + } +} + +.field_with_errors { + @extend .has-error; + .form-control { + color: $state-danger-text; + } +} diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb new file mode 100644 index 0000000..657fed4 --- /dev/null +++ b/app/controllers/static_pages_controller.rb @@ -0,0 +1,13 @@ +class StaticPagesController < ApplicationController + def home + end + + def help + end + + def about + end + + def sign_up + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..4c06243 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,26 @@ +class UsersController < ApplicationController + def new + @user = User.new + end + + def show + @user = User.find params[:id] + end + + def create + @user = User.new user_params + if @user.save + flash[:success] = "Welcome to the Sample App!" + redirect_to @user + else + render :new + end + end + + private + + def user_params + params.require(:user).permit :name, :email, :phonenumber, :birthday, + :password, :password_confirmation + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..3fe034a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,10 @@ module ApplicationHelper + def full_title page_title = "" + base_title = "Ruby on Rails Tutorial Sample App" + if page_title.empty? + base_title + else + page_title + " | " + base_title + end + end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000..a78aef1 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,7 @@ +module UsersHelper + def gravatar_for user, size: 80 + gravatar_id = Digest::MD5::hexdigest user.email.downcase + gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}" + image_tag gravatar_url, alt: user.name, class: "gravatar" + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 0895f08..d6d24a6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,7 +15,7 @@ class User < ApplicationRecord private def check_phonenumber - if self.phonenumber && self.phonenumber[0] != '0' + if self.phonenumber && self.phonenumber[0] != "0" self.errors.add :phonenumber,"Must begin with 0" end if self.phonenumber && self.phonenumber.length != 10 @@ -26,7 +26,7 @@ def check_phonenumber def check_birthday if self.birthday && (self.birthday.year < Time.now.year - 90 || - self.birthday.year > Time.now.year -7) + self.birthday.year > Time.now.year - 7) self.errors.add :birthday, "Year must from 90 years ago to 7 years ago" end end diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb new file mode 100644 index 0000000..ae5eb0e --- /dev/null +++ b/app/views/layouts/_footer.html.erb @@ -0,0 +1,13 @@ + diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb new file mode 100644 index 0000000..d0c7406 --- /dev/null +++ b/app/views/layouts/_header.html.erb @@ -0,0 +1,12 @@ + diff --git a/app/views/layouts/_rails_default.html.erb b/app/views/layouts/_rails_default.html.erb new file mode 100644 index 0000000..c718a11 --- /dev/null +++ b/app/views/layouts/_rails_default.html.erb @@ -0,0 +1,3 @@ +<%= csrf_meta_tags %> +<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track": "reload" %> +<%= javascript_include_tag "application", "data-turbolinks-track": "reload" %> diff --git a/app/views/layouts/_shim.html.erb b/app/views/layouts/_shim.html.erb new file mode 100644 index 0000000..e976db3 --- /dev/null +++ b/app/views/layouts/_shim.html.erb @@ -0,0 +1,4 @@ + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 8f96c78..485a8ee 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,14 +1,21 @@ - TestUserModel - <%= csrf_meta_tags %> - - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= full_title yield :title %> + |Ruby on Rails Tutorial Sample App + <%= render "layouts/rails_default" %> + <%= render "layouts/shim" %> - <%= yield %> + <%= render "layouts/header" %> +
+ <% flash.each do |message_type, message| %> +
<%= message %>
+ <% end %> + <%= yield %> + <%= render "layouts/footer" %> + <%= debug params if Rails.env.development? %> +
diff --git a/app/views/shared/_error_messages.html.erb b/app/views/shared/_error_messages.html.erb new file mode 100644 index 0000000..0a08338 --- /dev/null +++ b/app/views/shared/_error_messages.html.erb @@ -0,0 +1,12 @@ +<% if @user.errors.any? %> +
+
+ The form contains <%= pluralize @user.errors.count, "error" %>. +
+ +
+<% end %> diff --git a/app/views/static_pages/about.html.erb b/app/views/static_pages/about.html.erb new file mode 100644 index 0000000..52424f9 --- /dev/null +++ b/app/views/static_pages/about.html.erb @@ -0,0 +1,10 @@ +

About

+

+ The Ruby on Rails + Tutorial is a + book and + screencast series + to teach web development with + Ruby on Rails. + This is the sample application for the tutorial. +

diff --git a/app/views/static_pages/help.html.erb b/app/views/static_pages/help.html.erb new file mode 100644 index 0000000..1f99a56 --- /dev/null +++ b/app/views/static_pages/help.html.erb @@ -0,0 +1,9 @@ +<% provide :title, "Help" %> +

Help

+

+ Get help on the Ruby on Rails Tutorial at the + Rails Tutorial help section. + + To get help on this sample app, see the + Ruby on Rails Tutorialbook. +

diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb new file mode 100644 index 0000000..e6df456 --- /dev/null +++ b/app/views/static_pages/home.html.erb @@ -0,0 +1,11 @@ +<%provide :title, "Home"%> +
+

Welcome to Sample App

+

+ This is the home page for the + Ruby on Rails Tutorial sample application. +

+ <%= link_to "Sign up now!", "#", class: "btn btn-lg btn-primary"%> +
+<%= link_to image_tag("rails.png", alt: "Rails logo"), + "http://rubyonrails.org/" %> diff --git a/log/.keep b/app/views/static_pages/sign_up.html.erb similarity index 100% rename from log/.keep rename to app/views/static_pages/sign_up.html.erb diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 0000000..c0d5def --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,30 @@ +<% provide :title, "Sign up" %> +

Sign up

+ +
+
+ <%= form_for @user do |f| %> + <%= render "shared/error_messages" %> + + <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> + + <%= f.label :email %> + <%= f.text_field :email, class: "form-control" %> + + <%= f.label :phonenumber %> + <%= f.text_field :phonenumber, class: "form-control" %> + + <%= f.label :birthday %> + <%= f.date_field :birthday, class: "form-control" %> + + <%= f.label :password %> + <%= f.password_field :password, class: "form-control" %> + + <%= f.label :password_confirmation, "Confirmation" %> + <%= f.password_field :password_confirmation, class: "form-control" %> + + <%= f.submit "Create my account", class: "btn btn-primary" %> + <% end %> +
+
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000..3142684 --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,11 @@ +<% provide :title, @user.name %> +
+ +
diff --git a/config/database.yml b/config/database.yml.example similarity index 100% rename from config/database.yml rename to config/database.yml.example diff --git a/config/environments/production.rb b/config/environments/production.rb index ddc7e07..0561bfc 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,6 +1,6 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - + config.force_ssl = true # Code is not reloaded between requests. config.cache_classes = true diff --git a/config/routes.rb b/config/routes.rb index 787824f..6c33e8c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,9 @@ Rails.application.routes.draw do - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + get "static_pages/signup", to: "users#new" + get "static_pages/home" + get "static_pages/help" + get "static_pages/about" + root "static_pages#home" + resources :users + end diff --git a/config/secrects.yml~ b/config/secrects.yml~ new file mode 100644 index 0000000..0eff340 --- /dev/null +++ b/config/secrects.yml~ @@ -0,0 +1,10 @@ +/home/quang/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/application.rb:513:in `validate_secret_key_config!' +/home/quang/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/application.rb:246:in `env_config' +/home/quang/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/engine.rb:693:in `build_request' +/home/quang/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/application.rb:521:in `build_request' +/home/quang/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/engine.rb:521:in `call' +/home/quang/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.2/lib/puma/configuration.rb:224:in `call' +/home/quang/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.2/lib/puma/server.rb:600:in `handle_request' +/home/quang/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.2/lib/puma/server.rb:435:in `process_client' +/home/quang/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.2/lib/puma/server.rb:299:in `block in run' +/home/quang/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.2/lib/puma/thread_pool.rb:120:in `block in spawn_thread' diff --git a/config/secrets.yml b/config/secrets.yml deleted file mode 100644 index 7b70bd8..0000000 --- a/config/secrets.yml +++ /dev/null @@ -1,22 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key is used for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! - -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -# You can use `rails secret` to generate a secure secret key. - -# Make sure the secrets in this file are kept private -# if you're sharing your code publicly. - -development: - secret_key_base: 2f9644582e2d4ab50af8ed88505ea810972bf455c644ead1dae013520252527b3ec038649dce0e6bd2b30be7c64e80d26bf6d54c4dc20b267ed7bdf0e8f2006a - -test: - secret_key_base: dbac5f18c96226db82cc67df6add2b0affaa83186d960d92891d8a9fb4f0e35d69d0d2585fcb925eb9dc951b8ae8e9bf04e85f0256060066fa2053eb1f65ec55 - -# Do not keep production secrets in the repository, -# instead read values from the environment. -production: - secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 7c9be1f..043ff33 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ diff --git a/db/production.sqlite3 b/db/production.sqlite3 new file mode 100644 index 0000000..deaa17a Binary files /dev/null and b/db/production.sqlite3 differ diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2a..c9479a5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,3 @@ -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). -# -# Examples: -# -# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) -# Character.create(name: 'Luke', movie: movies.first) +10.times do |n| + User.create! name: "User #{n}", email: "email-#{n}@gmail.com" +end diff --git a/log/development.log b/log/development.log deleted file mode 100644 index 5cb6ae6..0000000 --- a/log/development.log +++ /dev/null @@ -1,108 +0,0 @@ -  (109.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY) -  (89.7ms) CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) - ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" -Migrating to CreateUsers (20170316013402) -  (0.1ms) begin transaction -  (0.6ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "email" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) - SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20170316013402"]] -  (95.8ms) commit transaction - ActiveRecord::InternalMetadata Load (0.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", :environment], ["LIMIT", 1]] -  (0.1ms) begin transaction - SQL (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["key", "environment"], ["value", "development"], ["created_at", 2017-03-16 01:34:13 UTC], ["updated_at", 2017-03-16 01:34:13 UTC]] -  (104.5ms) commit transaction - ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" - ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" -Migrating to AddPhonenumberAndBirthdayToUser (20170316013440) -  (0.1ms) begin transaction -  (0.1ms) rollback transaction - ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" -Migrating to AddPhonenumberAndBirthdayToUser (20170316013440) -  (1.7ms) begin transaction -  (0.5ms) ALTER TABLE "user" ADD "phonenumber" varchar -  (0.1ms) rollback transaction - ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" -Migrating to AddPhonenumberAndBirthdayToUser (20170316013440) -  (0.1ms) begin transaction -  (4.3ms) ALTER TABLE "users" ADD "phonenumber" varchar -  (0.5ms) ALTER TABLE "users" ADD "birthday" varchar - SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20170316013440"]] -  (120.6ms) commit transaction - ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", :environment], ["LIMIT", 1]] -  (0.1ms) begin transaction -  (0.1ms) commit transaction - ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" -  (0.1ms) begin transaction -  (0.1ms) rollback transaction - ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" - ActiveRecord::InternalMetadata Load (0.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", :environment], ["LIMIT", 1]] -  (0.1ms) begin transaction -  (0.1ms) commit transaction - ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" -  (0.1ms) begin transaction -  (0.1ms) rollback transaction - ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" - ActiveRecord::InternalMetadata Load (0.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", :environment], ["LIMIT", 1]] -  (0.1ms) begin transaction -  (0.1ms) commit transaction - ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" - ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" -Migrating to ChangeBirthdayColumn (20170316014713) -  (1.7ms) begin transaction -  (0.4ms) CREATE TEMPORARY TABLE "ausers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "email" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "phonenumber" varchar, "birthday" varchar) -  (0.2ms) INSERT INTO "ausers" ("id","name","email","created_at","updated_at","phonenumber","birthday") - SELECT "id","name","email","created_at","updated_at","phonenumber","birthday" FROM "users" -  (0.3ms) DROP TABLE "users" -  (0.2ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "email" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "phonenumber" varchar) -  (0.1ms) INSERT INTO "users" ("id","name","email","created_at","updated_at","phonenumber") - SELECT "id","name","email","created_at","updated_at","phonenumber" FROM "ausers" -  (0.1ms) DROP TABLE "ausers" -  (0.2ms) ALTER TABLE "users" ADD "birthday" date - SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20170316014713"]] -  (113.4ms) commit transaction - ActiveRecord::InternalMetadata Load (0.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", :environment], ["LIMIT", 1]] -  (0.1ms) begin transaction -  (0.1ms) commit transaction - ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" -  (0.1ms) begin transaction - SQL (0.5ms) INSERT INTO "users" ("name", "created_at", "updated_at", "phonenumber", "birthday") VALUES (?, ?, ?, ?, ?) [["name", "Dao Bao Quang"], ["created_at", 2017-03-16 01:48:16 UTC], ["updated_at", 2017-03-16 01:48:16 UTC], ["phonenumber", "0988858354"], ["birthday", Sat, 20 Jul 1996]] -  (443.9ms) commit transaction - ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations" -Migrating to AddIndexToUserEmail (20170316110357) -  (0.1ms) begin transaction -  (0.1ms) select sqlite_version(*) -  (15.8ms) CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email") - SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20170316110357"]] -  (122.7ms) commit transaction - ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", :environment], ["LIMIT", 1]] -  (0.1ms) begin transaction -  (0.1ms) commit transaction - ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" -  (0.2ms)  SELECT sql - FROM sqlite_master - WHERE name='index_users_on_email' AND type='index' - UNION ALL - SELECT sql - FROM sqlite_temp_master - WHERE name='index_users_on_email' AND type='index' - - ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" -Migrating to AddPasswordDigestToUsers (20170316110714) -  (0.1ms) begin transaction -  (1.4ms) ALTER TABLE "users" ADD "password_digest" varchar - SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20170316110714"]] -  (134.3ms) commit transaction - ActiveRecord::InternalMetadata Load (0.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", :environment], ["LIMIT", 1]] -  (0.1ms) begin transaction -  (0.0ms) commit transaction - ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" -  (0.1ms)  SELECT sql - FROM sqlite_master - WHERE name='index_users_on_email' AND type='index' - UNION ALL - SELECT sql - FROM sqlite_temp_master - WHERE name='index_users_on_email' AND type='index' - -  (0.1ms) begin transaction - User Exists (0.4ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER(?) LIMIT ? [["email", "khanhbklc12@gmail.com"], ["LIMIT", 1]] -  (0.1ms) rollback transaction diff --git a/static_page/db/seeds.rb b/static_page/db/seeds.rb index 1beea2a..460e377 100644 --- a/static_page/db/seeds.rb +++ b/static_page/db/seeds.rb @@ -1,7 +1,3 @@ -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). -# -# Examples: -# -# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) -# Character.create(name: 'Luke', movie: movies.first) +10.times do |n| + User.create name: "User #{n}", email: "email-#{n}@gmail.com" +end diff --git a/test/controllers/static_pages_controller_test.rb b/test/controllers/static_pages_controller_test.rb new file mode 100644 index 0000000..402e30d --- /dev/null +++ b/test/controllers/static_pages_controller_test.rb @@ -0,0 +1,14 @@ +require "test_helper" + +class StaticPagesControllerTest < ActionDispatch::IntegrationTest + test "should get home" do + get static_pages_home_url + assert_response :success + end + + test "should get help" do + get static_pages_help_url + assert_response :success + end + +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000..0737a5b --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +class UsersControllerTest < ActionDispatch::IntegrationTest + test "should get new" do + get users_new_url + assert_response :success + end + +end