Commit cc5dc7dc by tady

config rubocop

parent 51feadb2
AllCops:
# Rails特有のチェックを実行
RunRailsCops: true
# チェック対象外ディレクトリ
Exclude:
- 'db/**/*'
- 'config/**/*'
- 'script/**/*'
- 'bin/**/*'
- 'vendor/**/*'
- 'Guardfile'
# Ascii文字以外のコメントを許容
Style/AsciiComments:
Enabled: false
LineLength: # 1行の最大文字列長を緩和
Max: 159 Metrics/LineLength:
Max: 160
NumericLiterals: # メソッド定義の行数を緩和
Enabled: false Metrics/MethodLength:
Max: 50
Documentation: # Classの最大長制限
Enabled: false Metrics/ClassLength:
Max: 300
WordArray: # top-classでのコメントを任意に
Style/Documentation:
Enabled: false Enabled: false
MethodLength: # 1行if文を使用可に
Max: 30 Style/IfUnlessModifier:
Enabled: false
IfUnlessModifier: # nestしたclass/moduleを許容
Style/ClassAndModuleChildren:
Enabled: false Enabled: false
CyclomaticComplexity: # 後置rescueを許容
Max: 10 Style/RescueModifier:
Enabled: false
RaiseArgs: # and/orを許容
Style/AndOr:
Enabled: false Enabled: false
...@@ -82,6 +82,8 @@ group :development do ...@@ -82,6 +82,8 @@ group :development do
gem 'capistrano-rails', '~> 1.1' gem 'capistrano-rails', '~> 1.1'
gem 'capistrano-rbenv', '~> 2.0' gem 'capistrano-rbenv', '~> 2.0'
gem 'capistrano3-unicorn' gem 'capistrano3-unicorn'
gem 'travis'
end end
group :development, :test do group :development, :test do
...@@ -139,21 +141,19 @@ gem 'breadcrumble' ...@@ -139,21 +141,19 @@ gem 'breadcrumble'
gem 'slim' gem 'slim'
gem 'annotate', ">=2.6.0" gem 'annotate', '>=2.6.0'
gem 'kaminari', github: 'amatsuda/kaminari' gem 'kaminari', github: 'amatsuda/kaminari'
gem 'jwt', '0.1.11' gem 'jwt', '0.1.11'
# Optional # Optional
# For notifing to HipChat # For notifing to HipChat
gem 'hipchat' gem 'hipchat'
# For PDF upload # For PDF upload
gem 'rmagick', :require => 'RMagick' gem 'rmagick', require: 'RMagick'
# for heroku # for heroku
gem 'rails_12factor', group: :production gem 'rails_12factor', group: :production
......
...@@ -67,6 +67,7 @@ GEM ...@@ -67,6 +67,7 @@ GEM
aws-sdk (1.39.0) aws-sdk (1.39.0)
json (~> 1.4) json (~> 1.4)
nokogiri (>= 1.4.4) nokogiri (>= 1.4.4)
backports (3.6.3)
bcrypt (3.1.9) bcrypt (3.1.9)
better_errors (2.0.0) better_errors (2.0.0)
coderay (>= 1.0.0) coderay (>= 1.0.0)
...@@ -147,6 +148,8 @@ GEM ...@@ -147,6 +148,8 @@ GEM
activesupport (>= 3.0) activesupport (>= 3.0)
request_store (~> 1.0) request_store (~> 1.0)
erubis (2.7.0) erubis (2.7.0)
ethon (0.7.1)
ffi (>= 1.3.0)
eventmachine (1.0.3) eventmachine (1.0.3)
execjs (2.2.2) execjs (2.2.2)
factory_girl (4.5.0) factory_girl (4.5.0)
...@@ -156,8 +159,17 @@ GEM ...@@ -156,8 +159,17 @@ GEM
railties (>= 3.0.0) railties (>= 3.0.0)
faraday (0.9.0) faraday (0.9.0)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
faraday_middleware (0.9.1)
faraday (>= 0.7.4, < 0.10)
ffi (1.9.6) ffi (1.9.6)
formatador (0.2.5) formatador (0.2.5)
gh (0.13.2)
addressable
backports
faraday (~> 0.8)
multi_json (~> 1.0)
net-http-persistent (>= 2.7)
net-http-pipeline
gherkin (2.12.2) gherkin (2.12.2)
multi_json (~> 1.3) multi_json (~> 1.3)
github-markdown (0.6.7) github-markdown (0.6.7)
...@@ -179,6 +191,7 @@ GEM ...@@ -179,6 +191,7 @@ GEM
guard (~> 2.2) guard (~> 2.2)
teaspoon (>= 0.8.0) teaspoon (>= 0.8.0)
hashie (3.3.1) hashie (3.3.1)
highline (1.6.21)
hike (1.2.3) hike (1.2.3)
hipchat (1.4.0) hipchat (1.4.0)
httparty httparty
...@@ -193,111 +206,6 @@ GEM ...@@ -193,111 +206,6 @@ GEM
i18n_generators (1.2.1) i18n_generators (1.2.1)
mechanize mechanize
rails (>= 3.0.0) rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
rails (>= 3.0.0)
jbuilder (2.2.4) jbuilder (2.2.4)
activesupport (>= 3.0.0, < 5) activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2) multi_json (~> 1.2)
...@@ -338,6 +246,7 @@ GEM ...@@ -338,6 +246,7 @@ GEM
mysql2 (0.3.16) mysql2 (0.3.16)
net-http-digest_auth (1.4) net-http-digest_auth (1.4)
net-http-persistent (2.9.4) net-http-persistent (2.9.4)
net-http-pipeline (1.0.1)
net-scp (1.2.1) net-scp (1.2.1)
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5)
net-ssh (2.9.1) net-ssh (2.9.1)
...@@ -386,6 +295,9 @@ GEM ...@@ -386,6 +295,9 @@ GEM
slop (~> 3.4) slop (~> 3.4)
pry-rails (0.3.2) pry-rails (0.3.2)
pry (>= 0.9.10) pry (>= 0.9.10)
pusher-client (0.6.0)
json
websocket (~> 1.0)
rack (1.5.2) rack (1.5.2)
rack-contrib (1.2.0) rack-contrib (1.2.0)
rack (>= 0.9.1) rack (>= 0.9.1)
...@@ -501,9 +413,22 @@ GEM ...@@ -501,9 +413,22 @@ GEM
timers (4.0.1) timers (4.0.1)
hitimes hitimes
tins (1.3.3) tins (1.3.3)
travis (1.6.11)
addressable (~> 2.3)
backports
faraday (~> 0.9)
faraday_middleware (~> 0.9)
gh (~> 0.13)
highline (~> 1.6)
launchy (~> 2.1)
pry (~> 0.9)
pusher-client (~> 0.4)
typhoeus (~> 0.6, >= 0.6.8)
turnip (1.2.4) turnip (1.2.4)
gherkin (>= 2.5) gherkin (>= 2.5)
rspec (>= 2.14.0, < 4.0) rspec (>= 2.14.0, < 4.0)
typhoeus (0.6.9)
ethon (>= 0.7.1)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (2.5.3) uglifier (2.5.3)
...@@ -521,6 +446,7 @@ GEM ...@@ -521,6 +446,7 @@ GEM
warden (1.2.3) warden (1.2.3)
rack (>= 1.0) rack (>= 1.0)
webrobots (0.1.1) webrobots (0.1.1)
websocket (1.2.1)
websocket-driver (0.3.5) websocket-driver (0.3.5)
xpath (2.0.0) xpath (2.0.0)
nokogiri (~> 1.3) nokogiri (~> 1.3)
...@@ -587,6 +513,7 @@ DEPENDENCIES ...@@ -587,6 +513,7 @@ DEPENDENCIES
teaspoon teaspoon
therubyracer therubyracer
thin thin
travis
turnip turnip
uglifier uglifier
unicorn unicorn
......
...@@ -9,16 +9,16 @@ ...@@ -9,16 +9,16 @@
guard :rspec, cmd: 'bundle exec rspec' do guard :rspec, cmd: 'bundle exec rspec' do
watch(%r{^spec/.+_spec\.rb$}) watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" } watch('spec/spec_helper.rb') { 'spec' }
# Rails example # Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" } watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
watch('config/routes.rb') { "spec/routing" } watch('config/routes.rb') { 'spec/routing' }
watch('app/controllers/application_controller.rb') { "spec/controllers" } watch('app/controllers/application_controller.rb') { 'spec/controllers' }
watch('spec/rails_helper.rb') { "spec" } watch('spec/rails_helper.rb') { 'spec' }
# Capybara features specs # Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" } watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
...@@ -28,7 +28,6 @@ guard :rspec, cmd: 'bundle exec rspec' do ...@@ -28,7 +28,6 @@ guard :rspec, cmd: 'bundle exec rspec' do
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end end
# guard :rubocop do # guard :rubocop do
# watch(%r{.+\.rb$}) # watch(%r{.+\.rb$})
# watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } # watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
......
require 'digest/md5' require 'digest/md5'
class ApisController < ApplicationController class ApisController < ApplicationController
# TODO: not to use # TODO: not to use
include ApplicationHelper include ApplicationHelper
...@@ -26,7 +25,7 @@ class ApisController < ApplicationController ...@@ -26,7 +25,7 @@ class ApisController < ApplicationController
# Skip uploading if file ext is not listed. # Skip uploading if file ext is not listed.
next unless file.original_filename =~ /\.(jpe?g|png|gif|pdf)\Z/ next unless file.original_filename =~ /\.(jpe?g|png|gif|pdf)\Z/
object_file_name = "#{Digest::MD5.file(file.path).to_s}#{File.extname(file.original_filename)}" object_file_name = "#{Digest::MD5.file(file.path)}#{File.extname(file.original_filename)}"
res = s3_uploader.upload!(file: file.path, name: object_file_name) res = s3_uploader.upload!(file: file.path, name: object_file_name)
case file.original_filename case file.original_filename
...@@ -34,7 +33,7 @@ class ApisController < ApplicationController ...@@ -34,7 +33,7 @@ class ApisController < ApplicationController
s3_files << { type: 'image', name: file.original_filename, image: res.public_url.to_s } s3_files << { type: 'image', name: file.original_filename, image: res.public_url.to_s }
when /\.pdf\Z/ when /\.pdf\Z/
if Settings.respond_to?(:pdf_uploading) && Settings.pdf_uploading if Settings.respond_to?(:pdf_uploading) && Settings.pdf_uploading
cover_image_name = "#{Digest::MD5.file(file.path).to_s}-cover.png" cover_image_name = "#{Digest::MD5.file(file.path)}-cover.png"
pdf = Magick::ImageList.new(file.path + '[0]') pdf = Magick::ImageList.new(file.path + '[0]')
cover_tmp = Rails.root.join('tmp', cover_image_name) cover_tmp = Rails.root.join('tmp', cover_image_name)
pdf[0].write(cover_tmp) pdf[0].write(cover_tmp)
...@@ -49,7 +48,7 @@ class ApisController < ApplicationController ...@@ -49,7 +48,7 @@ class ApisController < ApplicationController
end end
def user_mention def user_mention
name_list = User.search(params[:q]).map{ |_user| "#{_user.nickname}[#{_user.name}]" } name_list = User.search(params[:q]).map { |_user| "#{_user.nickname}[#{_user.name}]" }
render json: name_list render json: name_list
end end
......
...@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base ...@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
add_breadcrumb("Rendezvous", '/') add_breadcrumb('Rendezvous', '/')
before_action :redirect_unless_signed_in before_action :redirect_unless_signed_in
......
class FlowController < ApplicationController class FlowController < ApplicationController
def show def show
@posts = Post.includes(:tags, :author).where(is_draft: false).order(updated_at: :desc).page(params[:page]).decorate @posts = Post.includes(:tags, :author).where(is_draft: false).order(updated_at: :desc).page(params[:page]).decorate
end end
......
...@@ -11,5 +11,4 @@ class NotificationsController < ApplicationController ...@@ -11,5 +11,4 @@ class NotificationsController < ApplicationController
def set_notification def set_notification
@notification = Notification.find(params[:id]) @notification = Notification.find(params[:id])
end end
end end
class SearchController < ApplicationController class SearchController < ApplicationController
def show def show
if params[:q].present? if params[:q].present?
scope = Post.search(params[:q]) scope = Post.search(params[:q])
......
...@@ -52,7 +52,7 @@ class TagsController < ApplicationController ...@@ -52,7 +52,7 @@ class TagsController < ApplicationController
# すべてのPostを移動先のタグに移動し # すべてのPostを移動先のタグに移動し
# このタグを削除する # このタグを削除する
def merge_to def merge_to
@merge_to_tag = Tag.find_by(name: params[:merge_to_name]) or raise ActiveRecord::RecordNotFound @merge_to_tag = Tag.find_by(name: params[:merge_to_name]) or fail ActiveRecord::RecordNotFound
@tag.move_all_posts_to!(@merge_to_tag) @tag.move_all_posts_to!(@merge_to_tag)
@tag.delete @tag.delete
...@@ -64,7 +64,7 @@ class TagsController < ApplicationController ...@@ -64,7 +64,7 @@ class TagsController < ApplicationController
# このタグを他のタグの下に移動 # このタグを他のタグの下に移動
def move_to def move_to
@move_to_tag = Tag.find_by(name: params[:move_to_name]) or raise ActiveRecord::RecordNotFound @move_to_tag = Tag.find_by(name: params[:move_to_name]) or fail ActiveRecord::RecordNotFound
@tag.set_parent!(@move_to_tag) @tag.set_parent!(@move_to_tag)
...@@ -76,12 +76,11 @@ class TagsController < ApplicationController ...@@ -76,12 +76,11 @@ class TagsController < ApplicationController
private private
def set_tag def set_tag
tag = Tag.find_by(name: params[:name]) or raise ActiveRecord::RecordNotFound tag = Tag.find_by(name: params[:name]) or fail ActiveRecord::RecordNotFound
@tag = tag.decorate @tag = tag.decorate
end end
def tag_params def tag_params
params.require(:tag).permit(:name, :body).to_hash params.require(:tag).permit(:name, :body).to_hash
end end
end end
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
skip_before_action :redirect_unless_signed_in skip_before_action :redirect_unless_signed_in
def google_oauth2 def google_oauth2
email = request.env['omniauth.auth'].info['email'] email = request.env['omniauth.auth'].info['email']
# reject if email is not zigexn nor ventura. # reject if email is not zigexn nor ventura.
......
class UsersController < ApplicationController class UsersController < ApplicationController
before_action :set_user, only: [:edit, :update] before_action :set_user, only: [:edit, :update]
def edit def edit
......
class WelcomeController < ApplicationController class WelcomeController < ApplicationController
skip_before_action :redirect_unless_signed_in skip_before_action :redirect_unless_signed_in
def top def top
......
...@@ -9,5 +9,4 @@ class ApisDecorator < Draper::Decorator ...@@ -9,5 +9,4 @@ class ApisDecorator < Draper::Decorator
# object.created_at.strftime("%a %m/%d/%y") # object.created_at.strftime("%a %m/%d/%y")
# end # end
# end # end
end end
...@@ -9,5 +9,4 @@ class FlowDecorator < Draper::Decorator ...@@ -9,5 +9,4 @@ class FlowDecorator < Draper::Decorator
# object.created_at.strftime("%a %m/%d/%y") # object.created_at.strftime("%a %m/%d/%y")
# end # end
# end # end
end end
...@@ -46,5 +46,4 @@ class PostDecorator < Draper::Decorator ...@@ -46,5 +46,4 @@ class PostDecorator < Draper::Decorator
'' ''
end end
end end
end end
class PostsDecorator < Draper::CollectionDecorator class PostsDecorator < Draper::CollectionDecorator
def related_tags def related_tags
_tags = self.map do |_post| _tags = map(&:tags).flatten.uniq
_post.tags
end.flatten.uniq
TagDecorator.decorate_collection(_tags) TagDecorator.decorate_collection(_tags)
end end
def related_authors def related_authors
self.map do |_post| map(&:author).flatten.uniq.map(&:decorate)
_post.author
end.flatten.uniq.map do |_author|
_author.decorate
end
end end
end end
...@@ -9,5 +9,4 @@ class SearchDecorator < Draper::Decorator ...@@ -9,5 +9,4 @@ class SearchDecorator < Draper::Decorator
# object.created_at.strftime("%a %m/%d/%y") # object.created_at.strftime("%a %m/%d/%y")
# end # end
# end # end
end end
...@@ -9,5 +9,4 @@ class StockDecorator < Draper::Decorator ...@@ -9,5 +9,4 @@ class StockDecorator < Draper::Decorator
# object.created_at.strftime("%a %m/%d/%y") # object.created_at.strftime("%a %m/%d/%y")
# end # end
# end # end
end end
...@@ -30,11 +30,11 @@ class TagDecorator < Draper::Decorator ...@@ -30,11 +30,11 @@ class TagDecorator < Draper::Decorator
def tree_view_node def tree_view_node
_html = '' _html = ''
_html += %Q{ _html += %(
<a href="#{ self.show_path }" data-name="#{model.name}"> <a href="#{ show_path }" data-name="#{model.name}">
#{model.name} <span class="badge">#{model.posts.size}</span> #{model.name} <span class="badge">#{model.posts.size}</span>
</a> </a>
} )
_html += '<ul>' _html += '<ul>'
model.children.each do |_child| model.children.each do |_child|
...@@ -46,5 +46,4 @@ class TagDecorator < Draper::Decorator ...@@ -46,5 +46,4 @@ class TagDecorator < Draper::Decorator
_html.html_safe _html.html_safe
end end
end end
class TagsDecorator < Draper::CollectionDecorator class TagsDecorator < Draper::CollectionDecorator
# tagをtree viewで表示する # tagをtree viewで表示する
def tree_view def tree_view
_html = '' _html = ''
_html += %Q{ _html += %(
<ul class="mod-tag-tree"> <ul class="mod-tag-tree">
<input type="search" class="mod-tag-tree-filter form-control" placeholder="filter..."> <input type="search" class="mod-tag-tree-filter form-control" placeholder="filter...">
} )
self.each do |_node| each do |_node|
_html += %Q{ _html += %(
<li> <li>
#{_node.decorate.tree_view_node} #{_node.decorate.tree_view_node}
</li> </li>
} )
end end
_html += "</ul>" _html += '</ul>'
_html.html_safe _html.html_safe
end end
end end
...@@ -9,5 +9,4 @@ class TemplateDecorator < Draper::Decorator ...@@ -9,5 +9,4 @@ class TemplateDecorator < Draper::Decorator
# object.created_at.strftime("%a %m/%d/%y") # object.created_at.strftime("%a %m/%d/%y")
# end # end
# end # end
end end
...@@ -9,5 +9,4 @@ class UsersDecorator < Draper::Decorator ...@@ -9,5 +9,4 @@ class UsersDecorator < Draper::Decorator
# object.created_at.strftime("%a %m/%d/%y") # object.created_at.strftime("%a %m/%d/%y")
# end # end
# end # end
end end
...@@ -9,5 +9,4 @@ class WatchingDecorator < Draper::Decorator ...@@ -9,5 +9,4 @@ class WatchingDecorator < Draper::Decorator
# object.created_at.strftime("%a %m/%d/%y") # object.created_at.strftime("%a %m/%d/%y")
# end # end
# end # end
end end
module ApplicationHelper module ApplicationHelper
def h_application_format_markdown(text) def h_application_format_markdown(text)
raise "deplicated error" fail 'deplicated error'
text = GitHub::Markdown.render_gfm(text) text = GitHub::Markdown.render_gfm(text)
text.html_safe text.html_safe
end end
end end
...@@ -33,6 +33,7 @@ class Comment < ActiveRecord::Base ...@@ -33,6 +33,7 @@ class Comment < ActiveRecord::Base
###################################################################### ######################################################################
# Instance method # Instance method
###################################################################### ######################################################################
private private
def notify_watchers! def notify_watchers!
......
...@@ -4,14 +4,14 @@ module HipchatIntegration ...@@ -4,14 +4,14 @@ module HipchatIntegration
return if is_draft return if is_draft
client = HipChat::Client.new(Settings.hipchat.token) client = HipChat::Client.new(Settings.hipchat.token)
client[Settings.hipchat.room].send('Rendezvous', notify_hipchat_body, message_format:'text', notify: 1) client[Settings.hipchat.room].send('Rendezvous', notify_hipchat_body, message_format: 'text', notify: 1)
end end
# @return [String] notification body # @return [String] notification body
def notify_hipchat_body def notify_hipchat_body
<<EOF <<EOF
#{author.name}が「#{title}」を投稿しました。 #{author.name}が「#{title}」を投稿しました。
#{self.decorate.show_url} #{decorate.show_url}
-- --
#{body} #{body}
EOF EOF
......
...@@ -6,15 +6,14 @@ class MarkdownRenderer ...@@ -6,15 +6,14 @@ class MarkdownRenderer
# pdf viewerの変換 # pdf viewerの変換
# !slide!(file-url) -> %%slide:0%% -> <iframe>...</iframe> # !slide!(file-url) -> %%slide:0%% -> <iframe>...</iframe>
def render def render
# slideのurlを一時保管 # slideのurlを一時保管
slide_urls = [] slide_urls = []
text = @text.gsub(/!slide!\(([^\)]+)\)/) do |_| text = @text.gsub(/!slide!\(([^\)]+)\)/) do |_|
slide_urls << %Q{ slide_urls << %(
<div class="embed-responsive embed-responsive-4by3"> <div class="embed-responsive embed-responsive-4by3">
<iframe style="text-align:center;" src="/ViewerJS/##{$1}" width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe> <iframe style="text-align:center;" src="/ViewerJS/##{Regexp.last_match[1]}" width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe>
</div> </div>
} )
"%%slide:#{slide_urls.size - 1}%%" "%%slide:#{slide_urls.size - 1}%%"
end end
...@@ -22,7 +21,7 @@ class MarkdownRenderer ...@@ -22,7 +21,7 @@ class MarkdownRenderer
# 保管したslide urlを取り出す # 保管したslide urlを取り出す
text = text.gsub(/%%slide:(\d+)%%/) do |_| text = text.gsub(/%%slide:(\d+)%%/) do |_|
slide_urls[$1.to_i] slide_urls[Regexp.last_match[1].to_i]
end end
text.html_safe text.html_safe
......
...@@ -27,8 +27,8 @@ class Post < ActiveRecord::Base ...@@ -27,8 +27,8 @@ class Post < ActiveRecord::Base
has_many :comments has_many :comments
has_many :footprints has_many :footprints
has_many :watches, :as => :watchable, :dependent => :destroy has_many :watches, as: :watchable, dependent: :destroy
has_many :watchers, :through => :watches has_many :watchers, through: :watches
###################################################################### ######################################################################
# Validations # Validations
...@@ -88,9 +88,8 @@ class Post < ActiveRecord::Base ...@@ -88,9 +88,8 @@ class Post < ActiveRecord::Base
# generate forked post (not saved) # generate forked post (not saved)
def generate_fork(user) def generate_fork(user)
# `id`以外をコピーする # `id`以外をコピーする
_forked_post = Post.new(self.attributes.except('id')) _forked_post = Post.new(attributes.except('id'))
# `%name`をユーザー名に置換 # `%name`をユーザー名に置換
_forked_post.title = _forked_post.title.gsub(/%name/, user.name) _forked_post.title = _forked_post.title.gsub(/%name/, user.name)
...@@ -98,7 +97,7 @@ class Post < ActiveRecord::Base ...@@ -98,7 +97,7 @@ class Post < ActiveRecord::Base
_forked_post.title = Time.now.strftime(_forked_post.title) # TODO _forked_post.title = Time.now.strftime(_forked_post.title) # TODO
_forked_post.title = _forked_post.title _forked_post.title = _forked_post.title
_forked_post.tag_ids = self.tag_ids _forked_post.tag_ids = tag_ids
_forked_post.author = user _forked_post.author = user
_forked_post.specified_date = Date.today _forked_post.specified_date = Date.today
...@@ -107,7 +106,7 @@ class Post < ActiveRecord::Base ...@@ -107,7 +106,7 @@ class Post < ActiveRecord::Base
# slideshow用のbody # slideshow用のbody
def body_for_slideshow def body_for_slideshow
self.body.gsub(/^#/, "---\n\n#") body.gsub(/^#/, "---\n\n#")
end end
def visited_user_count def visited_user_count
......
...@@ -6,7 +6,7 @@ class S3Uploader ...@@ -6,7 +6,7 @@ class S3Uploader
# @param [String] bucket: uploading backet name. # @param [String] bucket: uploading backet name.
def initialize(access_key_id: Settings.s3.access_key_id, def initialize(access_key_id: Settings.s3.access_key_id,
secret_access_key: Settings.s3.secret_access_key, secret_access_key: Settings.s3.secret_access_key,
region: "ap-northeast-1", region: 'ap-northeast-1',
bucket:) bucket:)
@s3 = AWS::S3.new(access_key_id: access_key_id, @s3 = AWS::S3.new(access_key_id: access_key_id,
secret_access_key: secret_access_key, secret_access_key: secret_access_key,
......
...@@ -21,33 +21,29 @@ class Tag < ActiveRecord::Base ...@@ -21,33 +21,29 @@ class Tag < ActiveRecord::Base
# for versioning # for versioning
has_paper_trail has_paper_trail
default_scope { order(:updated_at => :desc) } default_scope { order(updated_at: :desc) }
scope :posts_exist, lambda { scope :posts_exist, lambda {
select('tags.*, count(posts.id) as posts_count'). select('tags.*, count(posts.id) as posts_count')
joins(:posts). .joins(:posts)
group('tags.id'). .group('tags.id')
having('posts_count > 0') .having('posts_count > 0')
} }
class << self class << self
# 最近投稿されたTagを取得 # 最近投稿されたTagを取得
def recent(limit=10) def recent(limit = 10)
Post.recent(20).map do |post| Post.recent(20).map(&:tags).flatten.compact.uniq.take(limit)
post.tags
end.flatten.compact.uniq.take(limit)
end end
end end
def recent_posts(limit = 30) def recent_posts(limit = 30)
self.posts.recent(limit) posts.recent(limit)
end end
# 自分のタグに紐づくPostをすべて`other_tag`へ移動する # 自分のタグに紐づくPostをすべて`other_tag`へ移動する
def move_all_posts_to!(other_tag) def move_all_posts_to!(other_tag)
self.posts.each do |_post| posts.each do |_post|
_post.tags.delete(self) _post.tags.delete(self)
_post.tags << other_tag unless _post.tags.include?(other_tag) _post.tags << other_tag unless _post.tags.include?(other_tag)
end end
......
...@@ -41,7 +41,7 @@ class User < ActiveRecord::Base ...@@ -41,7 +41,7 @@ class User < ActiveRecord::Base
has_many :footprints has_many :footprints
has_many :watchings, class_name: 'Watch', foreign_key: 'watcher_id' has_many :watchings, class_name: 'Watch', foreign_key: 'watcher_id'
has_many :watching_posts, :through => :watchings, :source => :watchable, :source_type => "Post" has_many :watching_posts, through: :watchings, source: :watchable, source_type: 'Post'
###################################################################### ######################################################################
# scope # scope
...@@ -54,7 +54,6 @@ class User < ActiveRecord::Base ...@@ -54,7 +54,6 @@ class User < ActiveRecord::Base
where('name LIKE ? OR nickname LIKE ?', "%#{_query}%", "%#{_query}%") where('name LIKE ? OR nickname LIKE ?', "%#{_query}%", "%#{_query}%")
end) end)
###################################################################### ######################################################################
# Validations # Validations
###################################################################### ######################################################################
...@@ -66,13 +65,12 @@ class User < ActiveRecord::Base ...@@ -66,13 +65,12 @@ class User < ActiveRecord::Base
validates :nickname, uniqueness: true validates :nickname, uniqueness: true
# Device # 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)
user = where(email: access_token.info['email']).first_or_create do |_user|
user = self.where(email: access_token.info['email']).first_or_create do |_user|
_user.name = access_token.info['name'] _user.name = access_token.info['name']
_user.image_url = access_token.info['image'] _user.image_url = access_token.info['image']
_user.password = Devise.friendly_token[0, 20] _user.password = Devise.friendly_token[0, 20]
_user.nickname = (("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a).shuffle[0..4].join _user.nickname = (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle[0..4].join
end end
user.update( user.update(
...@@ -129,11 +127,11 @@ class User < ActiveRecord::Base ...@@ -129,11 +127,11 @@ class User < ActiveRecord::Base
if hash[:post] if hash[:post]
watching_posts << hash[:post] unless watching_posts.include?(hash[:post]) watching_posts << hash[:post] unless watching_posts.include?(hash[:post])
elsif hash[:tag] elsif hash[:tag]
raise 'Not Implemented.' fail 'Not Implemented.'
elsif hash[:user] elsif hash[:user]
raise 'Not Implemented.' fail 'Not Implemented.'
else else
raise 'No hash argument set.' fail 'No hash argument set.'
end end
end end
...@@ -141,11 +139,11 @@ class User < ActiveRecord::Base ...@@ -141,11 +139,11 @@ class User < ActiveRecord::Base
if hash[:post] if hash[:post]
hash[:post].watches.where(watcher: self).destroy_all hash[:post].watches.where(watcher: self).destroy_all
elsif hash[:tag] elsif hash[:tag]
raise 'Not Implemented.' fail 'Not Implemented.'
elsif hash[:user] elsif hash[:user]
raise 'Not Implemented.' fail 'Not Implemented.'
else else
raise 'No hash argument set.' fail 'No hash argument set.'
end end
end end
...@@ -155,11 +153,11 @@ class User < ActiveRecord::Base ...@@ -155,11 +153,11 @@ class User < ActiveRecord::Base
if hash[:post] if hash[:post]
hash[:post].watches.where(watcher: self).exists? hash[:post].watches.where(watcher: self).exists?
elsif hash[:tag] elsif hash[:tag]
raise 'Not Implemented.' fail 'Not Implemented.'
elsif hash[:user] elsif hash[:user]
raise 'Not Implemented.' fail 'Not Implemented.'
else else
raise 'No hash argument set.' fail 'No hash argument set.'
end end
end end
......
class Watch < ActiveRecord::Base class Watch < ActiveRecord::Base
###################################################################### ######################################################################
# Associations # Associations
###################################################################### ######################################################################
...@@ -10,5 +9,4 @@ class Watch < ActiveRecord::Base ...@@ -10,5 +9,4 @@ class Watch < ActiveRecord::Base
# Validations # Validations
###################################################################### ######################################################################
validates :watcher_id, uniqueness: { scope: [:watchable_type, :watchable_id] } validates :watcher_id, uniqueness: { scope: [:watchable_type, :watchable_id] }
end end
...@@ -35,8 +35,7 @@ module Rendezvous ...@@ -35,8 +35,7 @@ module Rendezvous
# IP restriction. # IP restriction.
if Rails.env.production? && ENV['RV_ALLOW_IPS'] if Rails.env.production? && ENV['RV_ALLOW_IPS']
config.middleware.use Rack::Access, { "/" => ENV['RV_ALLOW_IPS'].split(/,/) } config.middleware.use Rack::Access, '/' => ENV['RV_ALLOW_IPS'].split(/,/)
end end
end end
end end
# Set up gems listed in the Gemfile. # Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
...@@ -24,10 +24,10 @@ set :deploy_to, '/var/www/rendezvous' ...@@ -24,10 +24,10 @@ set :deploy_to, '/var/www/rendezvous'
# set :pty, true # set :pty, true
# Default value for :linked_files is [] # Default value for :linked_files is []
set :linked_files, %w{config/database.yml config/settings.yml} set :linked_files, %w(config/database.yml config/settings.yml)
# Default value for linked_dirs is [] # Default value for linked_dirs is []
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} set :linked_dirs, %w(bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system)
# Default value for default_env is {} # Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" } # set :default_env, { path: "/opt/ruby/bin:$PATH" }
...@@ -38,7 +38,7 @@ set :keep_releases, 5 ...@@ -38,7 +38,7 @@ set :keep_releases, 5
set :rbenv_type, :system set :rbenv_type, :system
set :rbenv_ruby, '2.1.2' set :rbenv_ruby, '2.1.2'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec" set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails} set :rbenv_map_bins, %w(rake gem bundle ruby rails)
set :rbenv_roles, :all # default value set :rbenv_roles, :all # default value
# namespace :deploy do # namespace :deploy do
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
# server in each group is considered to be the first # server in each group is considered to be the first
# unless any hosts have the primary property set. # unless any hosts have the primary property set.
# Don't declare `role :all`, it's a meta role # Don't declare `role :all`, it's a meta role
role :app, %w{rendezvous} role :app, %w(rendezvous)
role :web, %w{rendezvous} role :web, %w(rendezvous)
role :db, %w{rendezvous} role :db, %w(rendezvous)
# Extended Server Syntax # Extended Server Syntax
# ====================== # ======================
...@@ -20,11 +20,11 @@ role :db, %w{rendezvous} ...@@ -20,11 +20,11 @@ role :db, %w{rendezvous}
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options # it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start) # you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally # set it globally
set :ssh_options, { set :ssh_options,
keys: %w(~/.ssh/id_rsa), keys: %w(~/.ssh/id_rsa),
forward_agent: true, forward_agent: true,
auth_methods: %w(publickey) auth_methods: %w(publickey)
}
# and/or per server # and/or per server
# server 'example.com', # server 'example.com',
# user: 'user_name', # user: 'user_name',
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
# server in each group is considered to be the first # server in each group is considered to be the first
# unless any hosts have the primary property set. # unless any hosts have the primary property set.
# Don't declare `role :all`, it's a meta role # Don't declare `role :all`, it's a meta role
role :app, %w{rendezvous} role :app, %w(rendezvous)
role :web, %w{rendezvous} role :web, %w(rendezvous)
role :db, %w{rendezvous} role :db, %w(rendezvous)
# Extended Server Syntax # Extended Server Syntax
# ====================== # ======================
...@@ -14,7 +14,7 @@ role :db, %w{rendezvous} ...@@ -14,7 +14,7 @@ role :db, %w{rendezvous}
# definition into the server list. The second argument # definition into the server list. The second argument
# something that quacks like a hash can be used to set # something that quacks like a hash can be used to set
# extended properties on the server. # extended properties on the server.
server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value server 'example.com', user: 'deploy', roles: %w(web app), my_property: :my_value
# you can set custom ssh options # you can set custom ssh options
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options # it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
......
...@@ -25,7 +25,7 @@ Rendezvous::Application.routes.draw do ...@@ -25,7 +25,7 @@ Rendezvous::Application.routes.draw do
post 'tags/:name/merge_to/:merge_to_name' => 'tags#merge_to', as: 'merge_to_tag' post 'tags/:name/merge_to/:merge_to_name' => 'tags#merge_to', as: 'merge_to_tag'
post 'tags/:name/move_to/:move_to_name' => 'tags#move_to', as: 'move_to_tag' post 'tags/:name/move_to/:move_to_name' => 'tags#move_to', as: 'move_to_tag'
resources :tags, :param => :name, except: [:index] resources :tags, param: :name, except: [:index]
devise_for :users, devise_for :users,
controllers: { controllers: {
...@@ -34,12 +34,11 @@ Rendezvous::Application.routes.draw do ...@@ -34,12 +34,11 @@ Rendezvous::Application.routes.draw do
}, },
skip: [ skip: [
:passwords, :passwords,
:registrations, :registrations
] ]
resource :user resource :user
# The priority is based upon order of creation: first created -> highest priority. # The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes". # See how all your routes lay out with "rake routes".
......
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) worker_processes Integer(ENV['WEB_CONCURRENCY'] || 3)
timeout 15 timeout 15
preload_app true preload_app true
before_fork do |server, worker| before_fork do |_server, _worker|
Signal.trap 'TERM' do Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead' puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid Process.kill 'QUIT', Process.pid
end end
defined?(ActiveRecord::Base) and defined?(ActiveRecord::Base) &&
ActiveRecord::Base.connection.disconnect! ActiveRecord::Base.connection.disconnect!
end end
after_fork do |server, worker| after_fork do |_server, _worker|
Signal.trap 'TERM' do Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end end
defined?(ActiveRecord::Base) and defined?(ActiveRecord::Base) &&
ActiveRecord::Base.establish_connection ActiveRecord::Base.establish_connection
end end
# paths # paths
app_path = "/var/www/rendezvous" app_path = '/var/www/rendezvous'
working_directory "#{app_path}/current" working_directory "#{app_path}/current"
pid "#{app_path}/current/tmp/pids/unicorn.pid" pid "#{app_path}/current/tmp/pids/unicorn.pid"
# listen # listen
listen "/tmp/unicorn-rendezvous.socket", :backlog => 64 listen '/tmp/unicorn-rendezvous.socket', backlog: 64
# logging # logging
stderr_path "log/unicorn.stderr.log" stderr_path 'log/unicorn.stderr.log'
stdout_path "log/unicorn.stdout.log" stdout_path 'log/unicorn.stdout.log'
# workers # workers
worker_processes 3 worker_processes 3
# use correct Gemfile on restarts # use correct Gemfile on restarts
before_exec do |server| before_exec do |_server|
ENV['BUNDLE_GEMFILE'] = "#{app_path}/current/Gemfile" ENV['BUNDLE_GEMFILE'] = "#{app_path}/current/Gemfile"
end end
# preload # preload
preload_app true preload_app true
before_fork do |server, worker| before_fork do |server, _worker|
# the following is highly recomended for Rails + "preload_app true" # the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection # as there's no need for the master process to hold a connection
if defined?(ActiveRecord::Base) if defined?(ActiveRecord::Base)
...@@ -31,16 +31,16 @@ before_fork do |server, worker| ...@@ -31,16 +31,16 @@ before_fork do |server, worker|
# Before forking, kill the master process that belongs to the .oldbin PID. # Before forking, kill the master process that belongs to the .oldbin PID.
# This enables 0 downtime deploys. # This enables 0 downtime deploys.
old_pid = "#{server.config[:pid]}.oldbin" old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid if File.exist?(old_pid) && server.pid != old_pid
begin begin
Process.kill("QUIT", File.read(old_pid).to_i) Process.kill('QUIT', File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us # someone else did our job for us
end end
end end
end end
after_fork do |server, worker| after_fork do |_server, _worker|
if defined?(ActiveRecord::Base) if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection ActiveRecord::Base.establish_connection
end end
......
class CreateVersions < ActiveRecord::Migration class CreateVersions < ActiveRecord::Migration
def self.up def self.up
create_table :versions do |t| create_table :versions do |t|
t.string :item_type, :null => false t.string :item_type, null: false
t.integer :item_id, :null => false t.integer :item_id, null: false
t.string :event, :null => false t.string :event, null: false
t.string :whodunnit t.string :whodunnit
t.text :object t.text :object
t.datetime :created_at t.datetime :created_at
......
...@@ -2,6 +2,6 @@ class AddNicknameToUsers < ActiveRecord::Migration ...@@ -2,6 +2,6 @@ class AddNicknameToUsers < ActiveRecord::Migration
def change def change
add_column :users, :nickname, :string, default: '', null: false add_column :users, :nickname, :string, default: '', null: false
add_index "users", ["nickname"] add_index 'users', ['nickname']
end end
end end
...@@ -13,117 +13,117 @@ ...@@ -13,117 +13,117 @@
ActiveRecord::Schema.define(version: 20140719145016) do ActiveRecord::Schema.define(version: 20140719145016) do
create_table "comments", force: true do |t| create_table 'comments', force: true do |t|
t.integer "author_id" t.integer 'author_id'
t.integer "post_id" t.integer 'post_id'
t.text "body" t.text 'body'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "comments", ["author_id", "updated_at"], name: "index_comments_on_author_id_and_updated_at", using: :btree add_index 'comments', ['author_id', 'updated_at'], name: 'index_comments_on_author_id_and_updated_at', using: :btree
add_index "comments", ["post_id", "updated_at"], name: "index_comments_on_post_id_and_updated_at", using: :btree add_index 'comments', ['post_id', 'updated_at'], name: 'index_comments_on_post_id_and_updated_at', using: :btree
create_table "footprints", force: true do |t| create_table 'footprints', force: true do |t|
t.integer "user_id", null: false t.integer 'user_id', null: false
t.integer "post_id", null: false t.integer 'post_id', null: false
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "footprints", ["post_id"], name: "index_footprints_on_post_id", using: :btree add_index 'footprints', ['post_id'], name: 'index_footprints_on_post_id', using: :btree
add_index "footprints", ["user_id", "post_id"], name: "index_footprints_on_user_id_and_post_id", using: :btree add_index 'footprints', ['user_id', 'post_id'], name: 'index_footprints_on_user_id_and_post_id', using: :btree
create_table "notifications", force: true do |t| create_table 'notifications', force: true do |t|
t.integer "user_id" t.integer 'user_id'
t.datetime "read_at" t.datetime 'read_at'
t.boolean "is_read", default: false, null: false t.boolean 'is_read', default: false, null: false
t.string "detail_path" t.string 'detail_path'
t.text "body" t.text 'body'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "notifications", ["user_id", "is_read", "read_at"], name: "index_notifications_on_user_id_and_is_read_and_read_at", using: :btree add_index 'notifications', ['user_id', 'is_read', 'read_at'], name: 'index_notifications_on_user_id_and_is_read_and_read_at', using: :btree
create_table "post_tags", force: true do |t| create_table 'post_tags', force: true do |t|
t.integer "post_id", null: false t.integer 'post_id', null: false
t.integer "tag_id", null: false t.integer 'tag_id', null: false
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "post_tags", ["post_id"], name: "index_post_tags_on_post_id", using: :btree add_index 'post_tags', ['post_id'], name: 'index_post_tags_on_post_id', using: :btree
add_index "post_tags", ["tag_id"], name: "index_post_tags_on_tag_id", using: :btree add_index 'post_tags', ['tag_id'], name: 'index_post_tags_on_tag_id', using: :btree
create_table "posts", force: true do |t| create_table 'posts', force: true do |t|
t.string "title" t.string 'title'
t.text "body" t.text 'body'
t.integer "author_id" t.integer 'author_id'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
t.boolean "is_draft", default: false t.boolean 'is_draft', default: false
t.date "specified_date" t.date 'specified_date'
end end
add_index "posts", ["is_draft"], name: "index_posts_on_is_draft", using: :btree add_index 'posts', ['is_draft'], name: 'index_posts_on_is_draft', using: :btree
create_table "tags", force: true do |t| create_table 'tags', force: true do |t|
t.string "name" t.string 'name'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
t.string "ancestry" t.string 'ancestry'
t.text "body" t.text 'body'
t.integer "posts_count", default: 0, null: false t.integer 'posts_count', default: 0, null: false
end end
add_index "tags", ["ancestry"], name: "index_tags_on_ancestry", using: :btree add_index 'tags', ['ancestry'], name: 'index_tags_on_ancestry', using: :btree
create_table "users", force: true do |t| create_table 'users', force: true do |t|
t.string "name" t.string 'name'
t.string "image_url" t.string 'image_url'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
t.string "email", default: "", null: false t.string 'email', default: '', null: false
t.string "encrypted_password", default: "", null: false t.string 'encrypted_password', default: '', null: false
t.string "reset_password_token" t.string 'reset_password_token'
t.datetime "reset_password_sent_at" t.datetime 'reset_password_sent_at'
t.datetime "remember_created_at" t.datetime 'remember_created_at'
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 'current_sign_in_at'
t.datetime "last_sign_in_at" t.datetime 'last_sign_in_at'
t.string "current_sign_in_ip" t.string 'current_sign_in_ip'
t.string "last_sign_in_ip" t.string 'last_sign_in_ip'
t.string "google_auth_token" t.string 'google_auth_token'
t.string "google_refresh_token" t.string 'google_refresh_token'
t.datetime "google_token_expires_at" t.datetime 'google_token_expires_at'
t.string "nickname", default: "", null: false t.string 'nickname', default: '', null: false
end end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index 'users', ['email'], name: 'index_users_on_email', unique: true, using: :btree
add_index "users", ["nickname"], name: "index_users_on_nickname", using: :btree add_index 'users', ['nickname'], name: 'index_users_on_nickname', using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree add_index 'users', ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true, using: :btree
create_table "versions", force: true do |t| create_table 'versions', force: true do |t|
t.string "item_type", null: false t.string 'item_type', null: false
t.integer "item_id", null: false t.integer 'item_id', null: false
t.string "event", null: false t.string 'event', null: false
t.string "whodunnit" t.string 'whodunnit'
t.text "object" t.text 'object'
t.datetime "created_at" t.datetime 'created_at'
end end
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree add_index 'versions', ['item_type', 'item_id'], name: 'index_versions_on_item_type_and_item_id', using: :btree
create_table "watches", force: true do |t| create_table 'watches', force: true do |t|
t.integer "watcher_id", null: false t.integer 'watcher_id', null: false
t.string "watchable_type", null: false t.string 'watchable_type', null: false
t.integer "watchable_id", null: false t.integer 'watchable_id', null: false
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "watches", ["watchable_type", "watchable_id"], name: "index_watches_on_watchable_type_and_watchable_id", using: :btree add_index 'watches', ['watchable_type', 'watchable_id'], name: 'index_watches_on_watchable_type_and_watchable_id', using: :btree
add_index "watches", ["watcher_id", "watchable_type", "watchable_id"], name: "index_watches_on_watcher_id_and_watchable_type_and_watchable_id", unique: true, using: :btree add_index 'watches', ['watcher_id', 'watchable_type', 'watchable_id'], name: 'index_watches_on_watcher_id_and_watchable_type_and_watchable_id', unique: true, using: :btree
end end
...@@ -24,7 +24,7 @@ _tag_tree = [ ...@@ -24,7 +24,7 @@ _tag_tree = [
['OS', 'CentOS'], ['OS', 'CentOS'],
['OS', 'Ubuntu'], ['OS', 'Ubuntu'],
['OS', 'MacOS'], ['OS', 'MacOS'],
['OS', 'Windows'], ['OS', 'Windows']
] ]
tags = [] tags = []
......
...@@ -4,10 +4,8 @@ namespace :batch do ...@@ -4,10 +4,8 @@ namespace :batch do
desc 'Tagに関連するPostのcounter_cacheの再生成' desc 'Tagに関連するPostのcounter_cacheの再生成'
task reset_counters: :environment do task reset_counters: :environment do
puts "\t[START] batch:reset_counters" puts "\t[START] batch:reset_counters"
Tag.all.each{|t| Tag.reset_counters(t.id, :posts) } Tag.all.each { |t| Tag.reset_counters(t.id, :posts) }
puts "\t[FINISH] batch:reset_counters" puts "\t[FINISH] batch:reset_counters"
end end
end end
...@@ -6,7 +6,7 @@ namespace :migrations do ...@@ -6,7 +6,7 @@ namespace :migrations do
User.all.each do |_user| User.all.each do |_user|
next if _user.nickname.present? next if _user.nickname.present?
new_nickname = (("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a).shuffle[0..4].join new_nickname = (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle[0..4].join
_user.update_attributes!(nickname: new_nickname) _user.update_attributes!(nickname: new_nickname)
end end
end end
......
require "digest" require 'digest'
require "fog" require 'fog'
bucket_name = ENV["AWS_S3_BUCKET"] bucket_name = ENV['AWS_S3_BUCKET']
architecture = `uname -m`.strip architecture = `uname -m`.strip
file_name = "#{ENV['BUNDLE_ARCHIVE']}-#{architecture}.tgz" file_name = "#{ENV['BUNDLE_ARCHIVE']}-#{architecture}.tgz"
file_path = File.expand_path("~/#{file_name}") file_path = File.expand_path("~/#{file_name}")
lock_file = File.join(File.expand_path(ENV["TRAVIS_BUILD_DIR"]), "Gemfile.lock") lock_file = File.join(File.expand_path(ENV['TRAVIS_BUILD_DIR']), 'Gemfile.lock')
digest_filename = "#{file_name}.sha2" digest_filename = "#{file_name}.sha2"
old_digest = File.expand_path("~/remote_#{digest_filename}") old_digest = File.expand_path("~/remote_#{digest_filename}")
puts "Checking for changes" puts 'Checking for changes'
bundle_digest = Digest::SHA2.file(lock_file).hexdigest bundle_digest = Digest::SHA2.file(lock_file).hexdigest
old_digest = File.exists?(old_digest) ? File.read(old_digest) : "" old_digest = File.exist?(old_digest) ? File.read(old_digest) : ''
if bundle_digest == old_digest if bundle_digest == old_digest
puts "=> There were no changes, doing nothing" puts '=> There were no changes, doing nothing'
else else
if old_digest == "" if old_digest == ''
puts "=> There was no existing digest, uploading a new version of the archive" puts '=> There was no existing digest, uploading a new version of the archive'
else else
puts "=> There were changes, uploading a new version of the archive" puts '=> There were changes, uploading a new version of the archive'
puts " => Old checksum: #{old_digest}" puts " => Old checksum: #{old_digest}"
puts " => New checksum: #{bundle_digest}" puts " => New checksum: #{bundle_digest}"
end end
puts "=> Preparing bundle archive" puts '=> Preparing bundle archive'
`cd ~ && tar -cjf #{file_name} .bundle && split -b 5m -a 3 #{file_name} #{file_name}.` `cd ~ && tar -cjf #{file_name} .bundle && split -b 5m -a 3 #{file_name} #{file_name}.`
parts_pattern = File.expand_path(File.join("~", "#{file_name}.*")) parts_pattern = File.expand_path(File.join('~', "#{file_name}.*"))
parts = Dir.glob(parts_pattern).sort parts = Dir.glob(parts_pattern).sort
storage = Fog::Storage.new({ storage = Fog::Storage.new(
:provider => "AWS", provider: 'AWS',
:aws_access_key_id => ENV["AWS_S3_KEY"], aws_access_key_id: ENV['AWS_S3_KEY'],
:aws_secret_access_key => ENV["AWS_S3_SECRET"], aws_secret_access_key: ENV['AWS_S3_SECRET'],
:region => ENV["AWS_S3_REGION"] || "us-east-1" region: ENV['AWS_S3_REGION'] || 'us-east-1'
}) )
puts "=> Uploading the bundle" puts '=> Uploading the bundle'
puts " => Beginning multipart upload" puts ' => Beginning multipart upload'
response = storage.initiate_multipart_upload bucket_name, file_name, { "x-amz-acl" => "public-read" } response = storage.initiate_multipart_upload bucket_name, file_name, 'x-amz-acl' => 'public-read'
upload_id = response.body['UploadId'] upload_id = response.body['UploadId']
puts " => Upload ID: #{upload_id}" puts " => Upload ID: #{upload_id}"
...@@ -53,22 +53,22 @@ else ...@@ -53,22 +53,22 @@ else
File.open part do |part_file| File.open part do |part_file|
response = storage.upload_part bucket_name, file_name, upload_id, part_number, part_file response = storage.upload_part bucket_name, file_name, upload_id, part_number, part_file
part_ids << response.headers['ETag'] part_ids << response.headers['ETag']
puts " => Uploaded" puts ' => Uploaded'
end end
end end
puts " => Completing multipart upload" puts ' => Completing multipart upload'
storage.complete_multipart_upload bucket_name, file_name, upload_id, part_ids storage.complete_multipart_upload bucket_name, file_name, upload_id, part_ids
puts "=> Uploading the digest file" puts '=> Uploading the digest file'
bucket = storage.directories.new(key: bucket_name) bucket = storage.directories.new(key: bucket_name)
bucket.files.create({ bucket.files.create(
:body => bundle_digest, body: bundle_digest,
:key => digest_filename, key: digest_filename,
:public => true, public: true,
:content_type => "text/plain" content_type: 'text/plain'
}) )
end end
puts "All done now." puts 'All done now.'
exit 0 exit 0
...@@ -3,14 +3,14 @@ require 'rails_helper' ...@@ -3,14 +3,14 @@ require 'rails_helper'
describe ApisController, type: :controller do describe ApisController, type: :controller do
describe "GET 'markdown_preview'" do describe "GET 'markdown_preview'" do
it "returns http redirect" do it 'returns http redirect' do
get 'markdown_preview' get 'markdown_preview'
expect(response).to redirect_to('/') expect(response).to redirect_to('/')
end end
end end
describe "GET 'markdown_preview'" do describe "GET 'markdown_preview'" do
it "returns http success" do it 'returns http success' do
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
get 'markdown_preview' get 'markdown_preview'
......
...@@ -3,14 +3,14 @@ require 'rails_helper' ...@@ -3,14 +3,14 @@ require 'rails_helper'
describe FlowController, type: :controller do describe FlowController, type: :controller do
describe "GET 'show' without login" do describe "GET 'show' without login" do
it "returns http redirect" do it 'returns http redirect' do
get 'show' get 'show'
expect(response).to redirect_to('/') expect(response).to redirect_to('/')
end end
end end
describe "GET 'show' with login" do describe "GET 'show' with login" do
it "returns http success" do it 'returns http success' do
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
get 'show' get 'show'
......
...@@ -5,7 +5,7 @@ describe PostsController, type: :controller do ...@@ -5,7 +5,7 @@ describe PostsController, type: :controller do
let(:post) { FactoryGirl.create(:post) } let(:post) { FactoryGirl.create(:post) }
describe "GET 'show' without login" do describe "GET 'show' without login" do
it "returns http redirect" do it 'returns http redirect' do
get 'show', id: post.id get 'show', id: post.id
expect(response).to redirect_to('/') expect(response).to redirect_to('/')
end end
...@@ -15,14 +15,14 @@ describe PostsController, type: :controller do ...@@ -15,14 +15,14 @@ describe PostsController, type: :controller do
let(:alice) { FactoryGirl.create(:alice) } let(:alice) { FactoryGirl.create(:alice) }
it "returns http success" do it 'returns http success' do
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
get 'show', id: post.id get 'show', id: post.id
expect(response).to be_success expect(response).to be_success
end end
it "returns http success" do it 'returns http success' do
sign_in alice sign_in alice
get 'show', id: post.id get 'show', id: post.id
......
...@@ -3,14 +3,14 @@ require 'rails_helper' ...@@ -3,14 +3,14 @@ require 'rails_helper'
describe SearchController, type: :controller do describe SearchController, type: :controller do
describe "GET 'show' without login" do describe "GET 'show' without login" do
it "returns http redirect" do it 'returns http redirect' do
get 'show' get 'show'
expect(response).to redirect_to('/') expect(response).to redirect_to('/')
end end
end end
describe "GET 'show' with login" do describe "GET 'show' with login" do
it "returns http success" do it 'returns http success' do
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
get 'show' get 'show'
......
...@@ -3,14 +3,14 @@ require 'rails_helper' ...@@ -3,14 +3,14 @@ require 'rails_helper'
describe StockController, type: :controller do describe StockController, type: :controller do
describe "GET 'show' without login" do describe "GET 'show' without login" do
it "returns http redirect" do it 'returns http redirect' do
get 'show' get 'show'
expect(response).to redirect_to('/') expect(response).to redirect_to('/')
end end
end end
describe "GET 'show' with login" do describe "GET 'show' with login" do
it "returns http success" do it 'returns http success' do
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
get 'show' get 'show'
......
...@@ -5,14 +5,14 @@ describe TagsController, type: :controller do ...@@ -5,14 +5,14 @@ describe TagsController, type: :controller do
let(:tag) { FactoryGirl.create(:tag_ruby) } let(:tag) { FactoryGirl.create(:tag_ruby) }
describe "GET 'show' without login" do describe "GET 'show' without login" do
it "returns http redirect" do it 'returns http redirect' do
get 'show', name: tag.name get 'show', name: tag.name
expect(response).to redirect_to('/') expect(response).to redirect_to('/')
end end
end end
describe "GET 'show' with login" do describe "GET 'show' with login" do
it "returns http success" do it 'returns http success' do
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
get 'show', name: tag.name get 'show', name: tag.name
......
require 'rails_helper' require 'rails_helper'
RSpec.describe TemplatesController, :type => :controller do RSpec.describe TemplatesController, type: :controller do
describe "GET 'show' without template" do describe "GET 'show' without template" do
it "returns http success" do it 'returns http success' do
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
get 'show' get 'show'
...@@ -12,7 +12,7 @@ RSpec.describe TemplatesController, :type => :controller do ...@@ -12,7 +12,7 @@ RSpec.describe TemplatesController, :type => :controller do
end end
describe "GET 'show' with template" do describe "GET 'show' with template" do
it "returns http success" do it 'returns http success' do
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
get 'show' get 'show'
......
...@@ -3,7 +3,7 @@ require 'rails_helper' ...@@ -3,7 +3,7 @@ require 'rails_helper'
describe UsersController, type: :controller do describe UsersController, type: :controller do
describe "GET 'edit'" do describe "GET 'edit'" do
it "returns http success" do it 'returns http success' do
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
get :edit get :edit
...@@ -12,7 +12,7 @@ describe UsersController, type: :controller do ...@@ -12,7 +12,7 @@ describe UsersController, type: :controller do
end end
describe "GET 'update'" do describe "GET 'update'" do
it "returns http success" do it 'returns http success' do
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
patch :update, user: { nickname: 'bob' } patch :update, user: { nickname: 'bob' }
......
require 'rails_helper' require 'rails_helper'
RSpec.describe WatchingsController, :type => :controller do RSpec.describe WatchingsController, type: :controller do
describe "GET 'show' without login" do describe "GET 'show' without login" do
it "returns http redirect" do it 'returns http redirect' do
get 'show' get 'show'
expect(response).to redirect_to('/') expect(response).to redirect_to('/')
end end
end end
describe "GET 'show' with login" do describe "GET 'show' with login" do
it "returns http success" do it 'returns http success' do
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
get 'show' get 'show'
......
...@@ -10,6 +10,6 @@ require 'rails_helper' ...@@ -10,6 +10,6 @@ require 'rails_helper'
# end # end
# end # end
# end # end
RSpec.describe TemplatesHelper, :type => :helper do RSpec.describe TemplatesHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}" pending "add some examples to (or delete) #{__FILE__}"
end end
...@@ -10,6 +10,6 @@ require 'rails_helper' ...@@ -10,6 +10,6 @@ require 'rails_helper'
# end # end
# end # end
# end # end
RSpec.describe WatchingsHelper, :type => :helper do RSpec.describe WatchingsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}" pending "add some examples to (or delete) #{__FILE__}"
end end
...@@ -11,6 +11,6 @@ ...@@ -11,6 +11,6 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Footprint, :type => :model do RSpec.describe Footprint, type: :model do
pending "add some examples to (or delete) #{__FILE__}" pending "add some examples to (or delete) #{__FILE__}"
end end
require 'rails_helper' require 'rails_helper'
RSpec.describe MarkdownRenderer, :type => :model do RSpec.describe MarkdownRenderer, type: :model do
it "tests #render" do it 'tests #render' do
renderer = MarkdownRenderer.new(<<EOS) renderer = MarkdownRenderer.new(<<EOS)
# title # title
...@@ -18,7 +18,7 @@ EOS ...@@ -18,7 +18,7 @@ EOS
EOS EOS
end end
it "tests #render with slides" do it 'tests #render with slides' do
renderer = MarkdownRenderer.new(<<EOS) renderer = MarkdownRenderer.new(<<EOS)
!slide!(http://test.com/slide-1.pdf) !slide!(http://test.com/slide-1.pdf)
!slide!(http://test.com/slide-2.pdf) !slide!(http://test.com/slide-2.pdf)
......
...@@ -23,7 +23,7 @@ describe Notification do ...@@ -23,7 +23,7 @@ describe Notification do
@post = create(:post) @post = create(:post)
end end
it "notifies on post edited" do it 'notifies on post edited' do
@bob.watch!(post: @post) @bob.watch!(post: @post)
expect(@bob.watching?(post: @post)).to be_truthy expect(@bob.watching?(post: @post)).to be_truthy
@post.reload @post.reload
...@@ -32,7 +32,7 @@ describe Notification do ...@@ -32,7 +32,7 @@ describe Notification do
expect(@bob.notifications.size).to eq(1) expect(@bob.notifications.size).to eq(1)
end end
it "not duplicated notifies on post edited" do it 'not duplicated notifies on post edited' do
@bob.watch!(post: @post) @bob.watch!(post: @post)
expect(@bob.watching?(post: @post)).to be_truthy expect(@bob.watching?(post: @post)).to be_truthy
@post.reload @post.reload
...@@ -42,14 +42,14 @@ describe Notification do ...@@ -42,14 +42,14 @@ describe Notification do
expect(@bob.notifications.size).to eq(1) expect(@bob.notifications.size).to eq(1)
end end
it "not notifies on post edited by him" do it 'not notifies on post edited by him' do
@bob.watch!(post: @post) @bob.watch!(post: @post)
@post.reload @post.reload
@post.update!(title: @post.title + ' [New!]', author: @bob) @post.update!(title: @post.title + ' [New!]', author: @bob)
expect(@bob.notifications.size).to eq(0) expect(@bob.notifications.size).to eq(0)
end end
it "notifies on post commented" do it 'notifies on post commented' do
@bob.watch!(post: @post) @bob.watch!(post: @post)
expect(@bob.watching?(post: @post)).to be_truthy expect(@bob.watching?(post: @post)).to be_truthy
@post.reload @post.reload
...@@ -58,24 +58,24 @@ describe Notification do ...@@ -58,24 +58,24 @@ describe Notification do
expect(@bob.notifications.size).to eq(1) expect(@bob.notifications.size).to eq(1)
end end
it "not notifies on post commented by him" do it 'not notifies on post commented by him' do
@bob.watch!(post: @post) @bob.watch!(post: @post)
@post.reload @post.reload
@post.comments.create!(author: @bob, body: 'new comment') @post.comments.create!(author: @bob, body: 'new comment')
expect(@bob.notifications.size).to eq(0) expect(@bob.notifications.size).to eq(0)
end end
it "set watch on user create a new post" do it 'set watch on user create a new post' do
new_post = Post.create!(author: @bob, title: 'title', body: 'body') new_post = Post.create!(author: @bob, title: 'title', body: 'body')
expect(@bob.watching?(post: new_post)).to be_truthy expect(@bob.watching?(post: new_post)).to be_truthy
end end
it "set watch on user edit a post" do it 'set watch on user edit a post' do
@post.update!(author: @bob, title: 'new title') @post.update!(author: @bob, title: 'new title')
expect(@bob.watching?(post: @post)).to be_truthy expect(@bob.watching?(post: @post)).to be_truthy
end end
it "set watch on user comment a post" do it 'set watch on user comment a post' do
@post.comments.create!(author: @bob, body: 'new comment') @post.comments.create!(author: @bob, body: 'new comment')
expect(@bob.watching?(post: @post)).to be_truthy expect(@bob.watching?(post: @post)).to be_truthy
end end
......
...@@ -88,7 +88,7 @@ describe User do ...@@ -88,7 +88,7 @@ describe User do
end 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 = %w(user@foo.com THE_USER@foo.bar.org first.last@foo.jp)
addresses.each do |address| 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 valid_email_user.should be_valid
...@@ -96,7 +96,7 @@ describe User do ...@@ -96,7 +96,7 @@ describe User do
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 = %w(user@foo,com user_at_foo.org example.user@foo.)
addresses.each do |address| 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 invalid_email_user.should_not be_valid
......
require 'rails_helper' require 'rails_helper'
RSpec.describe Watch, :type => :model do RSpec.describe Watch, type: :model do
# describe "validations" do # describe "validations" do
# let(:alice) { create(:alice) } # let(:alice) { create(:alice) }
# let(:post) { create(:post) } # let(:post) { create(:post) }
......
...@@ -6,7 +6,7 @@ Coveralls.wear! ...@@ -6,7 +6,7 @@ Coveralls.wear!
ENV['RAILS_ENV'] ||= 'test' ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__) require File.expand_path('../../config/environment', __FILE__)
Dir["./spec/support/**/*.rb"].sort.each { |f| require f } Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
require 'rspec/rails' require 'rspec/rails'
require 'rspec/autorun' require 'rspec/autorun'
...@@ -16,11 +16,10 @@ require 'factory_girl' ...@@ -16,11 +16,10 @@ require 'factory_girl'
require 'capybara' require 'capybara'
require 'capybara/rspec' require 'capybara/rspec'
## Setting for polterguist. ## Setting for polterguist.
require 'capybara/poltergeist' require 'capybara/poltergeist'
def register_poltergeist(config) def register_poltergeist(_config)
Capybara.register_driver :poltergeist do |app| Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, timeout: 60, js_errors: false) Capybara::Poltergeist::Driver.new(app, timeout: 60, js_errors: false)
end end
...@@ -38,9 +37,8 @@ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } ...@@ -38,9 +37,8 @@ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# If you are not using ActiveRecord, you can remove this line. # If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
# Setting for turnip. # Setting for turnip.
Dir.glob("spec/steps/**/*steps.rb") { |f| load f, true } Dir.glob('spec/steps/**/*steps.rb') { |f| load f, true }
require 'turnip' require 'turnip'
require 'turnip/capybara' require 'turnip/capybara'
...@@ -94,18 +92,18 @@ RSpec.configure do |config| ...@@ -94,18 +92,18 @@ RSpec.configure do |config|
DatabaseRewinder.clean DatabaseRewinder.clean
end end
config.include Devise::TestHelpers, :type => :controller config.include Devise::TestHelpers, type: :controller
# config.extend ControllerMacros, :type => :controller # config.extend ControllerMacros, :type => :controller
# Capybara.app_host = "http://127.0.0.1/" # Capybara.app_host = "http://127.0.0.1/"
register_poltergeist(config) register_poltergeist(config)
OmniAuth.config.test_mode = true OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:google_oauth2, { OmniAuth.config.add_mock(:google_oauth2,
'uid' => '12345', 'uid' => '12345',
'provider' => 'google_oauth2', 'provider' => 'google_oauth2',
'info' => {'name' => 'Taro Yamada', 'email' => 'taro@zigexn.co.jp'}, 'info' => { 'name' => 'Taro Yamada', 'email' => 'taro@zigexn.co.jp' },
'credentials' => {'token' => 'aaaaa', 'refresh_token' => 'bbbbb', 'expires_at' => 9999999999} 'credentials' => { 'token' => 'aaaaa', 'refresh_token' => 'bbbbb', 'expires_at' => 9_999_999_999 }
}) )
end end
...@@ -37,8 +37,8 @@ step 'create post :title' do |title| ...@@ -37,8 +37,8 @@ step 'create post :title' do |title|
end end
step 'search by :query' do |query| step 'search by :query' do |query|
within("#app-search-form") do within('#app-search-form') do
fill_in 'q', :with => query fill_in 'q', with: query
end end
first(:css, "#app-search-form button[type='submit']").click first(:css, "#app-search-form button[type='submit']").click
end end
......
...@@ -2,7 +2,7 @@ module ControllerMacros ...@@ -2,7 +2,7 @@ module ControllerMacros
def login_user def login_user
before(:each) do before(:each) do
controller.stub(:authenticate_user!).and_return true controller.stub(:authenticate_user!).and_return true
@request.env["devise.mapping"] = Devise.mappings[:user] @request.env['devise.mapping'] = Devise.mappings[:user]
sign_in FactoryGirl.create(:alice) sign_in FactoryGirl.create(:alice)
end end
end end
......
# Set RAILS_ROOT and load the environment if it's not already loaded. # Set RAILS_ROOT and load the environment if it's not already loaded.
unless defined?(Rails) unless defined?(Rails)
ENV["RAILS_ROOT"] = File.expand_path("../../", __FILE__) ENV['RAILS_ROOT'] = File.expand_path('../../', __FILE__)
require File.expand_path("../../config/environment", __FILE__) require File.expand_path('../../config/environment', __FILE__)
end end
Teaspoon.configure do |config| Teaspoon.configure do |config|
# Determines where the Teaspoon routes will be mounted. Changing this to "/jasmine" would allow you to browse to # Determines where the Teaspoon routes will be mounted. Changing this to "/jasmine" would allow you to browse to
# `http://localhost:3000/jasmine` to run your tests. # `http://localhost:3000/jasmine` to run your tests.
#config.mount_at = "/teaspoon" # config.mount_at = "/teaspoon"
# Specifies the root where Teaspoon will look for files. If you're testing an engine using a dummy application it can # Specifies the root where Teaspoon will look for files. If you're testing an engine using a dummy application it can
# be useful to set this to your engines root (e.g. `Teaspoon::Engine.root`). # be useful to set this to your engines root (e.g. `Teaspoon::Engine.root`).
# Note: Defaults to `Rails.root` if nil. # Note: Defaults to `Rails.root` if nil.
#config.root = nil # config.root = nil
# Paths that will be appended to the Rails assets paths # Paths that will be appended to the Rails assets paths
# Note: Relative to `config.root`. # Note: Relative to `config.root`.
#config.asset_paths = ["spec/javascripts", "spec/javascripts/stylesheets"] # config.asset_paths = ["spec/javascripts", "spec/javascripts/stylesheets"]
# Fixtures are rendered through a controller, which allows using HAML, RABL/JBuilder, etc. Files in these paths will # Fixtures are rendered through a controller, which allows using HAML, RABL/JBuilder, etc. Files in these paths will
# be rendered as fixtures. # be rendered as fixtures.
#config.fixture_paths = ["spec/javascripts/fixtures"] # config.fixture_paths = ["spec/javascripts/fixtures"]
# SUITES # SUITES
# #
...@@ -46,47 +46,47 @@ Teaspoon.configure do |config| ...@@ -46,47 +46,47 @@ Teaspoon.configure do |config|
# Specify a file matcher as a regular expression and all matching files will be loaded when the suite is run. These # Specify a file matcher as a regular expression and all matching files will be loaded when the suite is run. These
# files need to be within an asset path. You can add asset paths using the `config.asset_paths`. # files need to be within an asset path. You can add asset paths using the `config.asset_paths`.
#suite.matcher = "{spec/javascripts,app/assets}/**/*_spec.{js,js.coffee,coffee}" # suite.matcher = "{spec/javascripts,app/assets}/**/*_spec.{js,js.coffee,coffee}"
# This suites spec helper, which can require additional support files. This file is loaded before any of your test # This suites spec helper, which can require additional support files. This file is loaded before any of your test
# files are loaded. # files are loaded.
#suite.helper = "spec_helper" # suite.helper = "spec_helper"
# The core Teaspoon javascripts. It's recommended to include only the base files here, as you can require support # The core Teaspoon javascripts. It's recommended to include only the base files here, as you can require support
# libraries from your spec helper. # libraries from your spec helper.
# Note: For CoffeeScript files use `"teaspoon/jasmine"` etc. # Note: For CoffeeScript files use `"teaspoon/jasmine"` etc.
# #
# Available: teaspoon-jasmine, teaspoon-mocha, teaspoon-qunit # Available: teaspoon-jasmine, teaspoon-mocha, teaspoon-qunit
#suite.javascripts = ["mocha/1.17.1", "teaspoon-mocha"] # suite.javascripts = ["mocha/1.17.1", "teaspoon-mocha"]
# You can include your own stylesheets if you want to change how Teaspoon looks. # You can include your own stylesheets if you want to change how Teaspoon looks.
# Note: Spec related CSS can and should be loaded using fixtures. # Note: Spec related CSS can and should be loaded using fixtures.
#suite.stylesheets = ["teaspoon"] # suite.stylesheets = ["teaspoon"]
# Partial to be rendered in the head tag of the runner. You can use the provided ones or define your own by creating # Partial to be rendered in the head tag of the runner. You can use the provided ones or define your own by creating
# a `_boot.html.erb` in your fixtures path, and adjust the config to `"/boot"` for instance. # a `_boot.html.erb` in your fixtures path, and adjust the config to `"/boot"` for instance.
# #
# Available: boot, boot_require_js # Available: boot, boot_require_js
#suite.boot_partial = "boot" # suite.boot_partial = "boot"
# Partial to be rendered in the body tag of the runner. You can define your own to create a custom body structure. # Partial to be rendered in the body tag of the runner. You can define your own to create a custom body structure.
#suite.body_partial = "body" # suite.body_partial = "body"
# Assets to be ignored when generating coverage reports. Accepts an array of filenames or regular expressions. The # Assets to be ignored when generating coverage reports. Accepts an array of filenames or regular expressions. The
# default excludes assets from vendor, gems and support libraries.<br/><br/> # default excludes assets from vendor, gems and support libraries.<br/><br/>
#suite.no_coverage = [%r{/lib/ruby/gems/}, %r{/vendor/assets/}, %r{/support/}, %r{/(.+)_helper.}] # suite.no_coverage = [%r{/lib/ruby/gems/}, %r{/vendor/assets/}, %r{/support/}, %r{/(.+)_helper.}]
# Hooks allow you to use `Teaspoon.hook("fixtures")` before, after, or during your spec run. This will make a # Hooks allow you to use `Teaspoon.hook("fixtures")` before, after, or during your spec run. This will make a
# synchronous Ajax request to the server that will call all of the blocks you've defined for that hook name. # synchronous Ajax request to the server that will call all of the blocks you've defined for that hook name.
#suite.hook :fixtures, proc{ } # suite.hook :fixtures, proc{ }
end end
# Example suite. Since we're just filtering to files already within the root test/javascripts, these files will also # Example suite. Since we're just filtering to files already within the root test/javascripts, these files will also
# be run in the default suite -- but can be focused into a more specific suite. # be run in the default suite -- but can be focused into a more specific suite.
#config.suite :targeted do |suite| # config.suite :targeted do |suite|
# suite.matcher = "test/javascripts/targeted/*_test.{js,js.coffee,coffee}" # suite.matcher = "test/javascripts/targeted/*_test.{js,js.coffee,coffee}"
#end # end
# CONSOLE RUNNER SPECIFIC # CONSOLE RUNNER SPECIFIC
# #
...@@ -105,44 +105,44 @@ Teaspoon.configure do |config| ...@@ -105,44 +105,44 @@ Teaspoon.configure do |config|
# Available: phantomjs, selenium # Available: phantomjs, selenium
# PhantomJS: https://github.com/modeset/teaspoon/wiki/Using-PhantomJS # PhantomJS: https://github.com/modeset/teaspoon/wiki/Using-PhantomJS
# Selenium Webdriver: https://github.com/modeset/teaspoon/wiki/Using-Selenium-WebDriver # Selenium Webdriver: https://github.com/modeset/teaspoon/wiki/Using-Selenium-WebDriver
#config.driver = "phantomjs" # config.driver = "phantomjs"
# Specify additional options for the driver. # Specify additional options for the driver.
# #
# PhantomJS: https://github.com/modeset/teaspoon/wiki/Using-PhantomJS # PhantomJS: https://github.com/modeset/teaspoon/wiki/Using-PhantomJS
# Selenium Webdriver: https://github.com/modeset/teaspoon/wiki/Using-Selenium-WebDriver # Selenium Webdriver: https://github.com/modeset/teaspoon/wiki/Using-Selenium-WebDriver
#config.driver_options = nil # config.driver_options = nil
# Specify the timeout for the driver. Specs are expected to complete within this time frame or the run will be # Specify the timeout for the driver. Specs are expected to complete within this time frame or the run will be
# considered a failure. This is to avoid issues that can arise where tests stall. # considered a failure. This is to avoid issues that can arise where tests stall.
#config.driver_timeout = 180 # config.driver_timeout = 180
# Specify a server to use with Rack (e.g. thin, mongrel). If nil is provided Rack::Server is used. # Specify a server to use with Rack (e.g. thin, mongrel). If nil is provided Rack::Server is used.
#config.server = nil # config.server = nil
# Specify a port to run on a specific port, otherwise Teaspoon will use a random available port. # Specify a port to run on a specific port, otherwise Teaspoon will use a random available port.
#config.server_port = nil # config.server_port = nil
# Timeout for starting the server in seconds. If your server is slow to start you may have to bump this, or you may # Timeout for starting the server in seconds. If your server is slow to start you may have to bump this, or you may
# want to lower this if you know it shouldn't take long to start. # want to lower this if you know it shouldn't take long to start.
#config.server_timeout = 20 # config.server_timeout = 20
# Force Teaspoon to fail immediately after a failing suite. Can be useful to make Teaspoon fail early if you have # Force Teaspoon to fail immediately after a failing suite. Can be useful to make Teaspoon fail early if you have
# several suites, but in environments like CI this may not be desirable. # several suites, but in environments like CI this may not be desirable.
#config.fail_fast = true # config.fail_fast = true
# Specify the formatters to use when outputting the results. # Specify the formatters to use when outputting the results.
# Note: Output files can be specified by using `"junit>/path/to/output.xml"`. # Note: Output files can be specified by using `"junit>/path/to/output.xml"`.
# #
# Available: dot, documentation, clean, json, junit, pride, snowday, swayze_or_oprah, tap, tap_y, teamcity # Available: dot, documentation, clean, json, junit, pride, snowday, swayze_or_oprah, tap, tap_y, teamcity
#config.formatters = ["dot"] # config.formatters = ["dot"]
# Specify if you want color output from the formatters. # Specify if you want color output from the formatters.
#config.color = true # config.color = true
# Teaspoon pipes all console[log/debug/error] to $stdout. This is useful to catch places where you've forgotten to # Teaspoon pipes all console[log/debug/error] to $stdout. This is useful to catch places where you've forgotten to
# remove them, but in verbose applications this may not be desirable. # remove them, but in verbose applications this may not be desirable.
#config.suppress_log = false # config.suppress_log = false
# COVERAGE REPORTS / THRESHOLD ASSERTIONS # COVERAGE REPORTS / THRESHOLD ASSERTIONS
# #
...@@ -157,25 +157,25 @@ Teaspoon.configure do |config| ...@@ -157,25 +157,25 @@ Teaspoon.configure do |config|
# - with the cli: teaspoon --coverage=[coverage_name] # - with the cli: teaspoon --coverage=[coverage_name]
# Specify that you always want a coverage configuration to be used. # Specify that you always want a coverage configuration to be used.
#config.use_coverage = nil # config.use_coverage = nil
config.coverage do |coverage| config.coverage do |_coverage|
# Which coverage reports Instanbul should generate. Correlates directly to what Istanbul supports. # Which coverage reports Instanbul should generate. Correlates directly to what Istanbul supports.
# #
# Available: text-summary, text, html, lcov, lcovonly, cobertura, teamcity # Available: text-summary, text, html, lcov, lcovonly, cobertura, teamcity
#coverage.reports = ["text-summary", "html"] # coverage.reports = ["text-summary", "html"]
# The path that the coverage should be written to - when there's an artifact to write to disk. # The path that the coverage should be written to - when there's an artifact to write to disk.
# Note: Relative to `config.root`. # Note: Relative to `config.root`.
#coverage.output_dir = "coverage" # coverage.output_dir = "coverage"
# Various thresholds requirements can be defined, and those thresholds will be checked at the end of a run. If any # Various thresholds requirements can be defined, and those thresholds will be checked at the end of a run. If any
# aren't met the run will fail with a message. Thresholds can be defined as a percentage (0-100), or nil. # aren't met the run will fail with a message. Thresholds can be defined as a percentage (0-100), or nil.
#coverage.statements = nil # coverage.statements = nil
#coverage.functions = nil # coverage.functions = nil
#coverage.branches = nil # coverage.branches = nil
#coverage.lines = nil # coverage.lines = nil
end end
......
require 'rails_helper' require 'rails_helper'
RSpec.describe "watchings/show.html.erb", :type => :view do RSpec.describe 'watchings/show.html.erb', type: :view do
pending "add some examples to (or delete) #{__FILE__}" pending "add some examples to (or delete) #{__FILE__}"
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment