Skip to content

Instantly share code, notes, and snippets.

@woshidan

woshidan/Gemfile Secret

Last active August 29, 2015 14:22
Show Gist options
  • Save woshidan/4accbbb17997f89669ff to your computer and use it in GitHub Desktop.
Save woshidan/4accbbb17997f89669ff to your computer and use it in GitHub Desktop.
test-date-travel_to
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module DateTest
class Application < Rails::Application
config.active_record.raise_in_transactional_callbacks = true
config.time_zone = 'Tokyo' # http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html
config.active_record.default_timezone = :local
end
end
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# 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'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'factory_girl_rails'
gem 'pry-rails'
end
ActiveRecord::Schema.define(version: 20150612124831) do
create_table "users", force: :cascade do |t|
t.string "name"
t.datetime "birth_day"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
# mysql
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "is only a travel_to test (travel to time)" do
# Time.now
# => 2015-06-12 22:48:36 +0900
# Time.current
# => Fri, 12 Jun 2015 22:48:43 JST +09:00
# Time.new
# => 2015-06-12 22:48:50 +0900
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0900
travel_to Time.new(2012, 1, 1, 1, 1, 1) do
# Time.now
# => 2012-01-01 01:01:01 +0900
# Time.current
# => Sun, 01 Jan 2012 01:01:01 JST +09:00
# Time.new
# => 2015-06-12 22:49:37 +0900
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0900
# Date.today
# => Sun, 01 Jan 2012
end
# Time.now
# => 2015-06-12 22:51:50 +0900
# Time.current
# => Fri, 12 Jun 2015 22:51:56 JST +09:00
# Time.new
# => 2015-06-12 22:52:04 +0900
end
test "is only a travel_to test (travel to date)" do
# Time.now
# => 2015-06-12 22:45:41 +0900
# Time.current
# => Fri, 12 Jun 2015 22:45:49 JST +09:00
# Time.new
# => 2015-06-12 22:45:54 +0900
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0900
travel_to Date.today + 3.days do
# Time.now
# => 2015-06-15 00:00:00 +0900
# Time.current
# => Mon, 15 Jun 2015 00:00:00 JST +09:00
# Time.new
# => 2015-06-12 22:46:32 +0900
# Date.today
# => Mon, 15 Jun 2015
# user = build(:user, birth_day: Date.today)
# => #<User:0x007fba851aff08
# id: nil,
# name: "John Doe",
# birth_day: Mon, 15 Jun 2015 00:00:00 JST +09:00,
# created_at: nil,
# updated_at: nil>
end
# Time.now
# => 2015-06-12 22:47:22 +0900
# Time.current
# => Fri, 12 Jun 2015 22:47:25 JST +09:00
# Time.new
# => 2015-06-12 22:47:30 +0900
end
end
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "is only a travel_to test (travel to time)" do
binding.pry
# Time.now
# => 2015-06-12 15:53:50 +0100
# Time.current
# => Fri, 12 Jun 2015 23:53:59 JST +09:00
# Time.new
# => 2015-06-12 15:54:10 +0100
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0000
travel_to Time.new(2012, 1, 1, 1, 1, 1) do
binding.pry
# Time.now
# => 2012-01-01 01:01:01 +0000
# Time.current
# => Sun, 01 Jan 2012 10:01:01 JST +09:00
# Time.new
# => 2015-06-12 15:59:09 +0100
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0000
# Date.today
# => Sun, 01 Jan 2012
# user = create(:user, birth_day: Date.today)
# #<User:0x007ff5ba225e40
# id: 6,
# name: "John Doe",
# birth_day: Sun, 01 Jan 2012 00:00:00 JST +09:00,
# created_at: Sun, 01 Jan 2012 10:01:01 JST +09:00,
# updated_at: Sun, 01 Jan 2012 10:01:01 JST +09:00>
end
binding.pry
# User.last.birth_day
# => Sun, 01 Jan 2012 00:00:00 JST +09:00
# Time.now
# => 2015-06-12 16:00:49 +0100
# Time.current
# => Sat, 13 Jun 2015 00:00:58 JST +09:00
# Time.new
# => 2015-06-12 16:01:05 +0100
end
test "is only a travel_to test (travel to date)" do
binding.pry
# Time.now
# => 2015-06-12 15:48:11 +0100
# Time.current
# => Fri, 12 Jun 2015 23:49:11 JST +09:00
# Time.new
# => 2015-06-12 15:49:25 +0100
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0000
travel_to Date.today + 3.days do
binding.pry
# Time.now
# => 2015-06-14 16:00:00 +0100
# Time.current
# => Mon, 15 Jun 2015 00:00:00 JST +09:00
# Time.new
# => 2015-06-12 15:50:04 +0100
# Date.to
# mysql
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "is only a travel_to test (travel to time)" do
binding.pry
# Time.now
# => 2015-06-12 23:56:16 +0900
# Time.current
# => Fri, 12 Jun 2015 23:56:26 JST +09:00
# Time.new
# => 2015-06-12 23:56:31 +0900
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0900
travel_to Time.new(2012, 1, 1, 1, 1, 1) do
binding.pry
# Time.now
# => 2012-01-01 01:01:01 +0900
# Time.current
# => Sun, 01 Jan 2012 01:01:01 JST +09:00
# Time.new
# => 2015-06-12 23:57:07 +0900
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0900
# Date.today
# => Sun, 01 Jan 2012
# user = create(:user, birth_day: Date.today)
#<User:0x007fb7dfdacc28
# id: 4,
# name: "John Doe",
# birth_day: Sun, 01 Jan 2012 00:00:00 JST +09:00,
# created_at: Sun, 01 Jan 2012 01:01:01 JST +09:00,
# updated_at: Sun, 01 Jan 2012 01:01:01 JST +09:00>
end
binding.pry
# User.last.birth_day
# => Sun, 01 Jan 2012 00:00:00 JST +09:00
# Time.now
# => 2015-06-12 23:58:06 +0900
# Time.current
# => Fri, 12 Jun 2015 23:58:15 JST +09:00
# Time.new
# => 2015-06-12 23:58:24 +0900
end
test "is only a travel_to test (travel to date)" do
binding.pry
# Time.now
# => 2015-06-12 23:47:01 +0900
# Time.current
# => Fri, 12 Jun 2015 23:47:12 JST +09:00
# Time.new
# => 2015-06-12 23:47:21 +0900
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0900
travel_to Date.today + 3.days do
binding.pry
# Time.now
# => 2015-06-15 00:00:00 +0900
# Time.current
# => Mon, 15 Jun 2015 00:00:00 JST +09:00
# Time.new
# => 2015-06-12 23:47:49 +0900
# Date.today
# =>
# user = create(:user, birth_day: Date.today)
# => #<User:0x007ffd80ccbae8
# id: 2,
# name: "John Doe",
# birth_day: Mon, 15 Jun 2015 00:00:00 JST +09:00,
# created_at: Mon, 15 Jun 2015 00:00:00 JST +09:00,
# updated_at: Mon, 15 Jun 2015 00:00:00 JST +09:00>
end
binding.pry
# Time.now
# => 2015-06-12 23:49:54 +0900
# Time.current
# => Fri, 12 Jun 2015 23:50:10 JST +09:00
# Time.new
# => 2015-06-12 23:50:16 +0900
# User.last
# => #<User:0x007ffd7e6fa620
# id: 2,
# name: "John Doe",
# birth_day: Mon, 15 Jun 2015 00:00:00 JST +09:00,
# created_at: Mon, 15 Jun 2015 00:00:00 JST +09:00,
# updated_at: Mon, 15 Jun 2015 00:00:00 JST +09:00>
end
end
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "is only a travel_to test (travel to time)" do
# Time.now
# => 2015-06-12 22:15:38 +0900
# Time.current
# => Fri, 12 Jun 2015 22:15:42 JST +09:00
# Time.new
# => 2015-06-12 22:16:08 +0900
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0900
travel_to Time.new(2012, 1, 1, 1, 1, 1) do
# Time.now
# => 2012-01-01 01:01:01 +0900
# Time.current
# => Sun, 01 Jan 2012 01:01:01 JST +09:00
# Time.new
# => 2015-06-12 22:18:32 +0900
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0900
end
# Time.now
# => 2015-06-12 22:19:37 +0900
# Time.current
# => Fri, 12 Jun 2015 22:19:43 JST +09:00
# Time.new
# => 2015-06-12 22:19:49 +0900
end
test "is only a travel_to test (travel to date)" do
# Time.now
# => 2015-06-12 22:15:38 +0900
# Time.current
# => Fri, 12 Jun 2015 22:15:42 JST +09:00
# Time.new
# => 2015-06-12 22:16:08 +0900
# Time.new(2012, 1, 1, 1, 1, 1)
# => 2012-01-01 01:01:01 +0900
travel_to Date.today + 3.days do
binding.pry
# Time.now
# => 2015-06-15 00:00:00 +0900
# Time.current
# => Mon, 15 Jun 2015 00:00:00 JST +09:00
# Time.new
# => 2015-06-12 22:23:22 +0900
# Date.today
# => 2012-01-01 01:01:01 +0900
# user = build(:user, birth_day: Date.today)
# => #<User:0x007fb937c09e58
# id: nil,
# name: "John Doe",
# birth_day: Mon, 15 Jun 2015 00:00:00 JST +09:00,
# created_at: nil,
# updated_at: nil>
end
# Time.now
# => 2015-06-12 22:19:37 +0900
# Time.current
# => Fri, 12 Jun 2015 22:19:43 JST +09:00
# Time.new
# => 2015-06-12 22:19:49 +0900
end
end
FactoryGirl.define do
factory :user do
name 'John Doe'
birth_day '2015-01-01 10:30:05'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment