diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 0000000..6a881d0
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,21 @@
+
+LineLength:
+ Max: 159
+
+NumericLiterals:
+ Enabled: false
+
+Documentation:
+ Enabled: false
+
+WordArray:
+ Enabled: false
+
+MethodLength:
+ Max: 30
+
+IfUnlessModifier:
+ Enabled: false
+
+CyclomaticComplexity:
+ Max: 10
diff --git a/Gemfile b/Gemfile
index e387318..2f35f53 100644
--- a/Gemfile
+++ b/Gemfile
@@ -70,6 +70,10 @@ group :development do
# profiler
gem 'rack-mini-profiler'
+
+ # rubocop
+ gem 'rubocop'
+ gem 'guard-rubocop'
end
group :development, :test do
diff --git a/Gemfile.lock b/Gemfile.lock
index 733957e..423b0c9 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -45,6 +45,7 @@ GEM
ancestry (2.0.0)
activerecord (>= 3.0.0)
arel (4.0.1)
+ ast (1.1.0)
atomic (1.1.14)
bcrypt-ruby (3.1.2)
better_errors (1.1.0)
@@ -104,6 +105,9 @@ GEM
guard-rspec (4.2.0)
guard (>= 2.1.1)
rspec (>= 2.14, < 4.0)
+ guard-rubocop (1.0.0)
+ guard (~> 2.0)
+ rubocop (~> 0.10)
guard-spring (0.0.4)
guard
spring
@@ -151,7 +155,11 @@ GEM
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
orm_adapter (0.5.0)
+ parser (2.0.0)
+ ast (~> 1.1)
+ slop (~> 3.4, >= 3.4.5)
polyglot (0.3.3)
+ powerpack (0.0.9)
premailer (1.7.9)
css_parser (>= 1.1.9)
htmlentities (>= 4.0.0)
@@ -179,6 +187,7 @@ GEM
activesupport (= 4.0.2)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
+ rainbow (1.1.4)
rake (10.1.1)
rb-fsevent (0.9.3)
rb-inotify (0.9.3)
@@ -202,6 +211,10 @@ GEM
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
+ rubocop (0.15.0)
+ parser (~> 2.0)
+ powerpack (~> 0.0.6)
+ rainbow (>= 1.1.4)
sass (3.2.13)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
@@ -264,6 +277,7 @@ DEPENDENCIES
factory_girl_rails
faraday
guard-rspec
+ guard-rubocop
guard-spring
jbuilder
mail
@@ -275,6 +289,7 @@ DEPENDENCIES
rails (~> 4.0.2)
redcarpet!
rspec-rails
+ rubocop
sass-rails
sdoc
spring
diff --git a/Guardfile b/Guardfile
index 6ebd0ef..4684d50 100644
--- a/Guardfile
+++ b/Guardfile
@@ -10,3 +10,8 @@ guard :rspec, spring: true do
watch('config/routes.rb') { 'spec/routing' }
watch('app/controllers/application_controller.rb') { 'spec/controllers' }
end
+
+guard :rubocop, cli: ['--rails', '--auto-correct'] do
+ watch(%r{.+\.rb$})
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
+end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 9965d8f..5363a3c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -9,5 +9,4 @@ def require_login
redirect_to root_path
end
end
-
end
diff --git a/app/controllers/concerns/rv/mail-template.html b/app/controllers/concerns/rv/mail-template.html
new file mode 100644
index 0000000..2ded396
--- /dev/null
+++ b/app/controllers/concerns/rv/mail-template.html
@@ -0,0 +1,346 @@
+
+
+
+
+
+
+
+ 2 columns to rows template | Antwort
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ __HTML_BODY__
+
+
+
+ |
+
+
+
+
+
+
+
+ このメールはRendezvousから送信されています。
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+
diff --git a/app/controllers/concerns/rv/mailer.rb b/app/controllers/concerns/rv/mailer.rb
index 4596ea1..d10ff44 100644
--- a/app/controllers/concerns/rv/mailer.rb
+++ b/app/controllers/concerns/rv/mailer.rb
@@ -3,7 +3,6 @@
require 'premailer'
module RV::Mailer
-
include ApplicationHelper
def compose_mail(post, user)
@@ -15,7 +14,6 @@ def compose_mail(post, user)
subject post.title
body post.body
-
html_part do
content_type 'text/html; charset=UTF-8'
body html_body
@@ -33,362 +31,12 @@ def compose_mail(post, user)
end
def generate_html_mail(body)
- html_body = <<'__HTML__'
-
-
-
-
-
-
-
- 2 columns to rows template | Antwort
-
-
-
-
+ path = File.expand_path(File.dirname(__FILE__) + '/mail-template.html')
+ template = File.open(path).read
-
+ html_body = template.sub('__HTML_BODY__', h_application_format_markdown(body))
-
-
-
-
-
-
-
-
-
-
-
-__HTML__
-
- html_body += h_application_format_markdown(body)
-
- html_body += <<'__HTML__'
-
-
-
- |
-
-
-
-
-
-
-
- このメールはRendezvousから送信されています。
-
-
-
- |
-
-
-
-
- |
-
-
-
-
-
-
-
-__HTML__
-
- premailer = Premailer.new(html_body, :with_html_string => true, :adapter => :nokogiri)
+ premailer = Premailer.new(html_body, with_html_string: true, adapter: :nokogiri)
premailer.to_inline_css
end
-
end
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index d10bbaa..565a892 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -1,5 +1,4 @@
class HomeController < ApplicationController
-
skip_before_action :require_login
def top
@@ -9,6 +8,4 @@ def top
render template: 'home/login'
end
end
-
-
end
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index ab03fe3..00c5ce3 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -2,7 +2,6 @@
require 'rv/mailer'
class PostsController < ApplicationController
-
before_action :set_post, only: [:show, :edit, :update, :destroy]
before_action :require_login
@@ -28,7 +27,6 @@ def show_fragment
render layout: false, partial: 'posts/show_fragment'
end
-
# GET /posts/1
# GET /posts/1.json
def show
@@ -104,26 +102,26 @@ def destroy
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
- @post_params ||= begin
- _param_hash = params.require(:post).permit(:title, :body, :tags).to_hash
+ # Use callbacks to share common setup or constraints between actions.
+ def set_post
+ @post = Post.find(params[:id])
+ end
- # tags_text == 'Javascript,Ruby'
- tags_text = _param_hash.delete('tags')
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def post_params
+ @post_params ||= begin
+ _param_hash = params.require(:post).permit(:title, :body, :tags).to_hash
- tags = tags_text.split(',').map do |_tag_name|
- Tag.find_or_create_by(name: _tag_name)
- end
- _param_hash["tag_ids"] = tags.map(&:id)
+ # tags_text == 'Javascript,Ruby'
+ tags_text = _param_hash.delete('tags')
- _param_hash
+ tags = tags_text.split(',').map do |_tag_name|
+ Tag.find_or_create_by(name: _tag_name)
end
- end
+ _param_hash['tag_ids'] = tags.map(&:id)
+ _param_hash
+ end
+ end
end
diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb
index 6b94573..3d11773 100644
--- a/app/controllers/users/omniauth_callbacks_controller.rb
+++ b/app/controllers/users/omniauth_callbacks_controller.rb
@@ -1,16 +1,14 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
-
def google_oauth2
# You need to implement the method below in your model (e.g. app/models/user.rb)
- @user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)
+ @user = User.find_for_google_oauth2(request.env['omniauth.auth'], current_user)
if @user.persisted?
- flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
- sign_in_and_redirect @user, :event => :authentication
+ flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Google'
+ sign_in_and_redirect @user, event: :authentication
else
- session["devise.google_data"] = request.env["omniauth.auth"]
+ session['devise.google_data'] = request.env['omniauth.auth']
redirect_to new_user_registration_url
end
end
-
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a1b30f3..1c1f11d 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,14 +1,13 @@
module ApplicationHelper
-
class HtmlWithPrettyPrint < Redcarpet::Render::HTML
def postprocess(full_document)
- full_document.gsub("prettyprint", "prettyprint linenums")
+ full_document.gsub('prettyprint', 'prettyprint linenums')
end
end
def h_application_format_markdown(text)
# html_render = HTMLwithCoderay.new(filter_html: true, hard_wrap: true, prettify: true)
- html_render = HtmlWithPrettyPrint.new(:prettify => true)
+ html_render = HtmlWithPrettyPrint.new(prettify: true)
options = {
autolink: true,
space_after_headers: true,
@@ -18,5 +17,4 @@ def h_application_format_markdown(text)
markdown = Redcarpet::Markdown.new(html_render, options)
markdown.render(text).html_safe
end
-
end
diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb
index e6bafd3..5bdad8e 100644
--- a/app/helpers/posts_helper.rb
+++ b/app/helpers/posts_helper.rb
@@ -1,5 +1,4 @@
module PostsHelper
-
# @param {ActiveRecord::Relation} node
def h_display_tree(node)
_html = ''
@@ -10,7 +9,7 @@ def h_display_tree(node)
_html << h_display_tree(_child)
end
_html << '
'
+
_html.html_safe
end
-
end
diff --git a/app/models/post.rb b/app/models/post.rb
index 6a41ed0..9d3bffe 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -6,9 +6,9 @@ class Post < ActiveRecord::Base
# Named scope
def self.build_query(params)
- _where_list = self.includes(:author, :tags)
+ _where_list = includes(:author, :tags)
- # 空白を一つに変換
+ # Convert spaces to one space.
query_string = params[:q].gsub(/[\s ]+/, ' ')
query_list = query_string.split(' ')
@@ -16,17 +16,17 @@ def self.build_query(params)
query_list.each do |_query|
case _query
when /^post:(.+)/
- _where_list = _where_list.where('id = ?', $1)
+ _where_list = _where_list.where('id = ?', Regexp.last_match[1])
when /^title:(.+)/
- _where_list = _where_list.where('title LIKE ?', "%#{$1}%")
+ _where_list = _where_list.where('title LIKE ?', "%#{Regexp.last_match[1]}%")
when /^body:(.+)/
- _where_list = _where_list.where('body LIKE ?', "%#{$1}%")
+ _where_list = _where_list.where('body LIKE ?', "%#{Regexp.last_match[1]}%")
when /^@(.+)/
- _where_list = _where_list.where('users.name = ?', $1)
+ _where_list = _where_list.where('users.name = ?', Regexp.last_match[1])
when /^#(.+)/
- _where_list = _where_list.where('tags.name = ?', $1)
+ _where_list = _where_list.where('tags.name = ?', Regexp.last_match[1])
when /^date:(\d+)-(\d+)-(\d+)/
- _date = Time.new($1, $2, $3)
+ _date = Time.new(Regexp.last_match[1], Regexp.last_match[2], Regexp.last_match[3])
_where_list = _where_list.where('updated_at > ? AND updated_at < ?', _date, _date + 1.day)
else
_where_list = _where_list.where('title LIKE ? OR body LIKE ?', "%#{_query}%", "%#{_query}%")
@@ -34,17 +34,15 @@ def self.build_query(params)
end
_where_list
-
end
# generate forked post (not saved)
def generate_fork(user)
- forked_post = self.clone
+ forked_post = clone
forked_post.title = forked_post.title.gsub(/%Name/, user.name)
forked_post.title = Time.now.strftime(forked_post.title) # TODO
forked_post.author = user
forked_post
end
-
end
diff --git a/app/models/tag.rb b/app/models/tag.rb
index 38dbc3b..42f0a64 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -3,5 +3,4 @@ class Tag < ActiveRecord::Base
has_many :posts, through: :post_tags
has_ancestry
-
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 09ad265..3b87ab0 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -5,20 +5,20 @@ class User < ActiveRecord::Base
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
- devise :omniauthable, :omniauth_providers => [:google_oauth2]
+ devise :omniauthable, omniauth_providers: [:google_oauth2]
has_many :posts
# Device
- def self.find_for_google_oauth2(access_token, signed_in_resource=nil)
+ def self.find_for_google_oauth2(access_token, signed_in_resource = nil)
data = access_token.info
- user = User.where(email: data["email"]).first
+ user = User.where(email: data['email']).first
unless user
- user = User.create(name: data["name"],
- image_url: data["image"],
- email: data["email"],
- password: Devise.friendly_token[0,20]
+ user = User.create(name: data['name'],
+ image_url: data['image'],
+ email: data['email'],
+ password: Devise.friendly_token[0, 20]
)
end
@@ -33,7 +33,7 @@ def self.find_for_google_oauth2(access_token, signed_in_resource=nil)
# check if google oauth token is expired
def google_oauth_token_expired?
- self.google_token_expires_at < Time.now
+ google_token_expires_at < Time.now
end
# refresh google oauth token
@@ -42,18 +42,17 @@ def google_oauth_token_refresh!
builder.request :url_encoded
builder.adapter :net_http
end
- response = conn.post '/o/oauth2/token', {
- client_id: ENV["GOOGLE_KEY"],
- client_secret: ENV["GOOGLE_SECRET"],
- refresh_token: self.google_refresh_token,
- grant_type: "refresh_token"
- }
+ response = conn.post '/o/oauth2/token',
+ client_id: ENV['GOOGLE_KEY'],
+ client_secret: ENV['GOOGLE_SECRET'],
+ refresh_token: google_refresh_token,
+ grant_type: 'refresh_token'
+
res_json = JSON.parse(response.body)
- self.update_attributes(
+ update_attributes(
google_auth_token: res_json['access_token'],
google_token_expires_at: Time.now + res_json['expires_in'].seconds
)
end
-
end
diff --git a/bin/spring b/bin/spring
index 38fee6f..94b784e 100755
--- a/bin/spring
+++ b/bin/spring
@@ -7,8 +7,8 @@
#
require 'pathname'
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
- Pathname.new(__FILE__).realpath)
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
+ Pathname.new(__FILE__).realpath)
require 'rubygems'
require 'bundler/setup'
diff --git a/config/application.rb b/config/application.rb
index db21dac..4d38ee8 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -22,7 +22,6 @@ class Application < Rails::Application
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = :ja
-
# config.action_mailer.delivery_method = :action_gmailer
config.action_mailer.smtp_settings = {
smtp_host: 'smtp.gmail.com',
@@ -32,7 +31,5 @@ class Application < Rails::Application
# oauth2_token: 'FIXME',
# account: 'FIXME'
}
-
-
end
end
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 4d46aa6..cbc68e3 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -28,5 +28,5 @@
config.assets.debug = true
# Devise
- config.action_mailer.default_url_options = { :host => 'localhost:3000' }
+ config.action_mailer.default_url_options = { host: 'localhost:3000' }
end
diff --git a/config/environments/test.rb b/config/environments/test.rb
index 6740b64..c36dbc9 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -14,7 +14,7 @@
# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
- config.static_cache_control = "public, max-age=3600"
+ config.static_cache_control = 'public, max-age=3600'
# Show full error reports and disable caching.
config.consider_all_requests_local = true
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb
index 543c2b0..3a7f97c 100644
--- a/config/initializers/devise.rb
+++ b/config/initializers/devise.rb
@@ -41,12 +41,12 @@
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
- config.case_insensitive_keys = [ :email ]
+ config.case_insensitive_keys = [:email]
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
- config.strip_whitespace_keys = [ :email ]
+ config.strip_whitespace_keys = [:email]
# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb
index 7571d9f..12f3f8d 100644
--- a/config/initializers/omniauth.rb
+++ b/config/initializers/omniauth.rb
@@ -1,11 +1,11 @@
Rails.application.config.middleware.use OmniAuth::Builder do
- provider :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"],
- {
- :name => "google_oauth2",
- :scope => "https://mail.google.com/, userinfo.email, userinfo.profile",
- access_type: 'offline',
- :prompt => "select_account consent",
- :image_aspect_ratio => "square",
- :image_size => 50
- }
+
+ provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'],
+ name: 'google_oauth2',
+ scope: 'https://mail.google.com/, userinfo.email, userinfo.profile',
+ access_type: 'offline',
+ prompt: 'select_account consent',
+ image_aspect_ratio: 'square',
+ image_size: 50
+
end
diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb
index eabaa0b..2cacc7e 100644
--- a/config/initializers/secret_token.rb
+++ b/config/initializers/secret_token.rb
@@ -9,4 +9,5 @@
# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
-Rendezvous::Application.config.secret_key_base = 'd8e487b60856000161a94ea764b38e7492512bbbeeca2f4cec068c8cc6618cacb54172ec54afc61675684f01bf02c74bf1e93dfe6971247d75ff001b1584d987'
+Rendezvous::Application.config.secret_key_base = \
+ 'd8e487b60856000161a94ea764b38e7492512bbbeeca2f4cec068c8cc6618cacb54172ec54afc61675684f01bf02c74bf1e93dfe6971247d75ff001b1584d987'
diff --git a/config/routes.rb b/config/routes.rb
index 6a5ff36..e4b96e4 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -8,8 +8,7 @@
get 'posts/:id/mail' => 'posts#mail', as: 'mail_post'
resources :posts
- devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
-
+ devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
diff --git a/db/migrate/20131130111339_add_devise_to_users.rb b/db/migrate/20131130111339_add_devise_to_users.rb
index 4f9da13..8e8066f 100644
--- a/db/migrate/20131130111339_add_devise_to_users.rb
+++ b/db/migrate/20131130111339_add_devise_to_users.rb
@@ -2,8 +2,8 @@ class AddDeviseToUsers < ActiveRecord::Migration
def self.up
change_table(:users) do |t|
## Database authenticatable
- t.string :email, :null => false, :default => ""
- t.string :encrypted_password, :null => false, :default => ""
+ t.string :email, null: false, default: ''
+ t.string :encrypted_password, null: false, default: ''
## Recoverable
t.string :reset_password_token
@@ -13,7 +13,7 @@ def self.up
t.datetime :remember_created_at
## Trackable
- t.integer :sign_in_count, :default => 0, :null => false
+ t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
@@ -30,13 +30,12 @@ def self.up
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
-
# Uncomment below if timestamps were not included in your original model.
# t.timestamps
end
- add_index :users, :email, :unique => true
- add_index :users, :reset_password_token, :unique => true
+ add_index :users, :email, unique: true
+ add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
end
@@ -44,6 +43,6 @@ def self.up
def self.down
# By default, we don't want to make any assumption about how to roll back a migration when your
# model already existed. Please edit below which fields you would like to remove in this migration.
- raise ActiveRecord::IrreversibleMigration
+ fail ActiveRecord::IrreversibleMigration
end
end
diff --git a/db/schema.rb b/db/schema.rb
index 94c188b..c9d2072 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -13,54 +13,54 @@
ActiveRecord::Schema.define(version: 20131228110818) do
- create_table "post_tags", force: true do |t|
- t.integer "post_id", null: false
- t.integer "tag_id", null: false
- t.datetime "created_at"
- t.datetime "updated_at"
+ create_table 'post_tags', force: true do |t|
+ t.integer 'post_id', null: false
+ t.integer 'tag_id', null: false
+ t.datetime 'created_at'
+ t.datetime 'updated_at'
end
- add_index "post_tags", ["post_id"], name: "index_post_tags_on_post_id"
- add_index "post_tags", ["tag_id"], name: "index_post_tags_on_tag_id"
+ add_index 'post_tags', ['post_id'], name: 'index_post_tags_on_post_id'
+ add_index 'post_tags', ['tag_id'], name: 'index_post_tags_on_tag_id'
- create_table "posts", force: true do |t|
- t.string "title"
- t.text "body"
- t.integer "author_id"
- t.datetime "created_at"
- t.datetime "updated_at"
+ create_table 'posts', force: true do |t|
+ t.string 'title'
+ t.text 'body'
+ t.integer 'author_id'
+ t.datetime 'created_at'
+ t.datetime 'updated_at'
end
- create_table "tags", force: true do |t|
- t.string "name"
- t.datetime "created_at"
- t.datetime "updated_at"
- t.string "ancestry"
+ create_table 'tags', force: true do |t|
+ t.string 'name'
+ t.datetime 'created_at'
+ t.datetime 'updated_at'
+ t.string 'ancestry'
end
- add_index "tags", ["ancestry"], name: "index_tags_on_ancestry"
+ add_index 'tags', ['ancestry'], name: 'index_tags_on_ancestry'
- create_table "users", force: true do |t|
- t.string "name"
- t.string "image_url"
- t.datetime "created_at"
- t.datetime "updated_at"
- t.string "email", default: "", null: false
- t.string "encrypted_password", default: "", null: false
- t.string "reset_password_token"
- t.datetime "reset_password_sent_at"
- t.datetime "remember_created_at"
- t.integer "sign_in_count", default: 0, null: false
- t.datetime "current_sign_in_at"
- t.datetime "last_sign_in_at"
- t.string "current_sign_in_ip"
- t.string "last_sign_in_ip"
- t.string "google_auth_token"
- t.string "google_refresh_token"
- t.datetime "google_token_expires_at"
+ create_table 'users', force: true do |t|
+ t.string 'name'
+ t.string 'image_url'
+ t.datetime 'created_at'
+ t.datetime 'updated_at'
+ t.string 'email', default: '', null: false
+ t.string 'encrypted_password', default: '', null: false
+ t.string 'reset_password_token'
+ t.datetime 'reset_password_sent_at'
+ t.datetime 'remember_created_at'
+ t.integer 'sign_in_count', default: 0, null: false
+ t.datetime 'current_sign_in_at'
+ t.datetime 'last_sign_in_at'
+ t.string 'current_sign_in_ip'
+ t.string 'last_sign_in_ip'
+ t.string 'google_auth_token'
+ t.string 'google_refresh_token'
+ t.datetime 'google_token_expires_at'
end
- add_index "users", ["email"], name: "index_users_on_email", unique: true
- add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
+ add_index 'users', ['email'], name: 'index_users_on_email', unique: true
+ add_index 'users', ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true
end
diff --git a/db/seeds.rb b/db/seeds.rb
index 9e56983..7387ccc 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -6,7 +6,6 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
-
# Tag
_tag_tree = [
@@ -31,7 +30,7 @@
tags = []
_tag_tree.each do |_parent, _child|
- puts "[Seed Tag] #{_parent} => #{_child}"
+ Rails.logger.debug "[Seed Tag] #{_parent} => #{_child}"
parent = Tag.find_or_create_by(name: _parent) if _parent
child = Tag.find_or_initialize_by(name: _child)
child.parent = parent if _parent
@@ -39,28 +38,27 @@
tags << child
end
-
# User
User.find_or_create_by(name: '山田太郎') do |_u|
- _u.email = "#{Devise.friendly_token[0,20]}@example.com"
- _u.password = Devise.friendly_token[0,20]
+ _u.email = "#{Devise.friendly_token[0, 20]}@example.com"
+ _u.password = Devise.friendly_token[0, 20]
end
User.find_or_create_by(name: '鈴木二郎') do |_u|
- _u.email = "#{Devise.friendly_token[0,20]}@example.com"
- _u.password = Devise.friendly_token[0,20]
+ _u.email = "#{Devise.friendly_token[0, 20]}@example.com"
+ _u.password = Devise.friendly_token[0, 20]
end
User.find_or_create_by(name: '田中三郎') do |_u|
- _u.email = "#{Devise.friendly_token[0,20]}@example.com"
- _u.password = Devise.friendly_token[0,20]
+ _u.email = "#{Devise.friendly_token[0, 20]}@example.com"
+ _u.password = Devise.friendly_token[0, 20]
end
# Post
users = User.all
Dir.glob(Rails.root.join('db', 'seeds').to_s + '/*').each do |file_name|
- puts "[Post Tag] #{file_name}"
+ Rails.logger.debug "[Post Tag] #{file_name}"
title = file_name.split('/').last
post = Post.find_or_initialize_by(title: title)
@@ -69,4 +67,3 @@
post.tags = [tags.sample, tags.sample]
post.save!
end
-
diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb
index 83dd659..9950db5 100644
--- a/spec/controllers/home_controller_spec.rb
+++ b/spec/controllers/home_controller_spec.rb
@@ -3,29 +3,29 @@
describe HomeController do
describe "GET 'top'" do
- it "should be successful" do
- get :top
- expect(response).to be_success
- expect(response.code).to eq("200")
+ it 'should be successful' do
+ get :top
+ expect(response).to be_success
+ expect(response.code).to eq('200')
end
end
describe 'Login' do
- before (:each) do
+ before(:each) do
@user = FactoryGirl.create(:login_user_1)
sign_in @user
end
describe "GET 'top'" do
- it "should be successful" do
+ it 'should be successful' do
get :top
expect(subject).to redirect_to controller: 'posts',
- action: 'index'
+ action: 'index'
end
- it "should find the right user" do
+ it 'should find the right user' do
get :top
expect(assigns(:current_user)).to eq(@user)
end
diff --git a/spec/factories/users.rb b/spec/factories/users.rb
index 5a9f64a..807bde4 100644
--- a/spec/factories/users.rb
+++ b/spec/factories/users.rb
@@ -1,15 +1,15 @@
FactoryGirl.define do
factory :alice, class: User do
name 'Alice'
- email "alice@mail.com"
- password Devise.friendly_token[0,20]
+ email 'alice@mail.com'
+ password Devise.friendly_token[0, 20]
google_token_expires_at Time.now + 30.minutes
end
factory :bob, class: User do
name 'Bob'
- email "bob@mail.com"
- password Devise.friendly_token[0,20]
+ email 'bob@mail.com'
+ password Devise.friendly_token[0, 20]
google_token_expires_at Time.now - 1.hour
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index d643182..e314e6a 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -24,102 +24,99 @@
describe 'validation' do
before(:each) do
@attr = {
- :name => "Example User",
- :email => "user@example.com",
- :password => "changeme",
- :password_confirmation => "changeme"
+ name: 'Example User',
+ email: 'user@example.com',
+ password: 'changeme',
+ password_confirmation: 'changeme'
}
end
- it "should create a new instance given a valid attribute" do
+ it 'should create a new instance given a valid attribute' do
User.create!(@attr)
end
- it "should require an email address" do
- no_email_user = User.new(@attr.merge(:email => ""))
+ it 'should require an email address' do
+ no_email_user = User.new(@attr.merge(email: ''))
no_email_user.should_not be_valid
end
- it "should accept valid email addresses" do
+ it 'should accept valid email addresses' do
addresses = %w[user@foo.com THE_USER@foo.bar.org first.last@foo.jp]
addresses.each do |address|
- valid_email_user = User.new(@attr.merge(:email => address))
+ valid_email_user = User.new(@attr.merge(email: address))
valid_email_user.should be_valid
end
end
- it "should reject invalid email addresses" do
+ it 'should reject invalid email addresses' do
addresses = %w[user@foo,com user_at_foo.org example.user@foo.]
addresses.each do |address|
- invalid_email_user = User.new(@attr.merge(:email => address))
+ invalid_email_user = User.new(@attr.merge(email: address))
invalid_email_user.should_not be_valid
end
end
- it "should reject duplicate email addresses" do
+ it 'should reject duplicate email addresses' do
User.create!(@attr)
user_with_duplicate_email = User.new(@attr)
user_with_duplicate_email.should_not be_valid
end
- it "should reject email addresses identical up to case" do
+ it 'should reject email addresses identical up to case' do
upcased_email = @attr[:email].upcase
- User.create!(@attr.merge(:email => upcased_email))
+ User.create!(@attr.merge(email: upcased_email))
user_with_duplicate_email = User.new(@attr)
user_with_duplicate_email.should_not be_valid
end
- describe "passwords" do
+ describe 'passwords' do
before(:each) do
@user = User.new(@attr)
end
- it "should have a password attribute" do
+ it 'should have a password attribute' do
@user.should respond_to(:password)
end
- it "should have a password confirmation attribute" do
+ it 'should have a password confirmation attribute' do
@user.should respond_to(:password_confirmation)
end
end
- describe "password validations" do
+ describe 'password validations' do
- it "should require a password" do
- User.new(@attr.merge(:password => "", :password_confirmation => "")).
- should_not be_valid
+ it 'should require a password' do
+ User.new(@attr.merge(password: '', password_confirmation: '')).should_not be_valid
end
- it "should require a matching password confirmation" do
- User.new(@attr.merge(:password_confirmation => "invalid")).
- should_not be_valid
+ it 'should require a matching password confirmation' do
+ User.new(@attr.merge(password_confirmation: 'invalid')).should_not be_valid
end
- it "should reject short passwords" do
- short = "a" * 5
- hash = @attr.merge(:password => short, :password_confirmation => short)
+ it 'should reject short passwords' do
+ short = 'a' * 5
+ hash = @attr.merge(password: short, password_confirmation: short)
User.new(hash).should_not be_valid
end
end
- describe "password encryption" do
+ describe 'password encryption' do
before(:each) do
@user = User.create!(@attr)
end
- it "should have an encrypted password attribute" do
+ it 'should have an encrypted password attribute' do
@user.should respond_to(:encrypted_password)
end
- it "should set the encrypted password attribute" do
+ it 'should set the encrypted password attribute' do
@user.encrypted_password.should_not be_blank
end
end
end
-
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index d73cd49..3086ced 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,12 +1,10 @@
-
# coveralls
require 'coveralls'
Coveralls.wear!
-
# This file is copied to spec/ when you run 'rails generate rspec:install'
-ENV["RAILS_ENV"] ||= 'test'
-require File.expand_path("../../config/environment", __FILE__)
+ENV['RAILS_ENV'] ||= 'test'
+require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# require 'email_spec'
@@ -14,7 +12,7 @@
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
-Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
+Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
@@ -46,16 +44,14 @@
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
- config.order = "random"
+ config.order = 'random'
config.include FactoryGirl::Syntax::Methods
# config.include(EmailSpec::Helpers)
# config.include(EmailSpec::Matchers)
-
config.before(:all) do
FactoryGirl.reload
end
end
-
diff --git a/spec/support/devise.rb b/spec/support/devise.rb
index 3552bea..7999895 100644
--- a/spec/support/devise.rb
+++ b/spec/support/devise.rb
@@ -1,3 +1,3 @@
RSpec.configure do |config|
- config.include Devise::TestHelpers, :type => :controller
+ config.include Devise::TestHelpers, type: :controller
end