Commit 3a981ef7 by tady

conform to rubocop

parent cc5dc7dc
......@@ -47,3 +47,11 @@ Style/RescueModifier:
# and/orを許容
Style/AndOr:
Enabled: false
# ABCチェックを無効
Metrics/AbcSize:
Enabled: false
# ???
Style/RaiseArgs:
Enabled: false
......@@ -22,4 +22,4 @@ before_script:
- mysql -e 'CREATE DATABASE rendezvous_test;'
after_script:
- ruby script/travis/bundle_cache.rb
script: bundle exec rake db:create db:test:load spec teaspoon
script: bundle exec rake db:create db:test:load spec teaspoon; bundle exec rubocop
......@@ -48,7 +48,7 @@ class ApisController < ApplicationController
end
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
end
......
......@@ -8,11 +8,11 @@ class ApplicationController < ActionController::Base
before_action :redirect_unless_signed_in
def redirect_unless_signed_in
unless user_signed_in?
flash[:alert] = 'You need Login!'
session[:login_redirect_to] = request.url
redirect_to root_path
end
return if user_signed_in?
flash[:alert] = 'You need Login!'
session[:login_redirect_to] = request.url
redirect_to root_path
end
def after_sign_in_path_for(resource)
......
......@@ -10,8 +10,8 @@ class PostsController < ApplicationController
def show
current_user.visit_post!(@post)
@post.tags.each do |_tag|
add_breadcrumb("##{_tag.name}", _tag.decorate.show_path)
@post.tags.each do |tag|
add_breadcrumb("##{tag.name}", tag.decorate.show_path)
end
add_breadcrumb(@post.title)
end
......@@ -131,17 +131,17 @@ class PostsController < ApplicationController
# 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, :is_draft, :specified_date).to_hash
param_hash = params.require(:post).permit(:title, :body, :tags, :is_draft, :specified_date).to_hash
# tags_text == 'Javascript,Ruby'
tags_text = _param_hash.delete('tags')
tags_text = param_hash.delete('tags')
tags = tags_text.split(',').map do |_tag_name|
Tag.find_or_create_by(name: _tag_name)
tags = tags_text.split(',').map do |tag_name|
Tag.find_or_create_by(name: tag_name)
end
_param_hash['tag_ids'] = tags.map(&:id)
param_hash['tag_ids'] = tags.map(&:id)
_param_hash
param_hash
end
end
......
......@@ -66,7 +66,7 @@ class TagsController < ApplicationController
def move_to
@move_to_tag = Tag.find_by(name: params[:move_to_name]) or fail ActiveRecord::RecordNotFound
@tag.set_parent!(@move_to_tag)
@tag.parent_tag = @move_to_tag
flash[:notice] = "「#{@tag.name}」は「#{@move_to_tag.name}」の下に移動しました"
......
......@@ -12,12 +12,12 @@ class PostDecorator < Draper::Decorator
# 読了時間
# 500文字/1分換算
def read_time
_time_min = model.body.length / 500
case _time_min
time_min = model.body.length / 500
case time_min
when 0
'< 1 min.'
when 1..10
"#{_time_min} min."
"#{time_min} min."
else
'> 10 min.'
end
......
class PostsDecorator < Draper::CollectionDecorator
def related_tags
_tags = map(&:tags).flatten.uniq
tags = map(&:tags).flatten.uniq
TagDecorator.decorate_collection(_tags)
TagDecorator.decorate_collection(tags)
end
def related_authors
......
......@@ -28,22 +28,22 @@ class TagDecorator < Draper::Decorator
# tagをtree viewで表示する
def tree_view_node
_html = ''
html = ''
_html += %(
html += %(
<a href="#{ show_path }" data-name="#{model.name}">
#{model.name} <span class="badge">#{model.posts.size}</span>
</a>
)
_html += '<ul>'
model.children.each do |_child|
_html += '<li>'
_html << _child.decorate.tree_view_node
_html += '</li>'
html += '<ul>'
model.children.each do |child|
html += '<li>'
html << child.decorate.tree_view_node
html += '</li>'
end
_html += '</ul>'
html += '</ul>'
_html.html_safe
html.html_safe
end
end
class TagsDecorator < Draper::CollectionDecorator
# tagをtree viewで表示する
def tree_view
_html = ''
_html += %(
html = ''
html += %(
<ul class="mod-tag-tree">
<input type="search" class="mod-tag-tree-filter form-control" placeholder="filter...">
)
each do |_node|
_html += %(
each do |node|
html += %(
<li>
#{_node.decorate.tree_view_node}
#{node.decorate.tree_view_node}
</li>
)
end
_html += '</ul>'
html += '</ul>'
_html.html_safe
html.html_safe
end
end
module ApplicationHelper
def h_application_format_markdown(text)
fail 'deplicated error'
text = GitHub::Markdown.render_gfm(text)
text.html_safe
end
end
......@@ -11,7 +11,8 @@ class MarkdownRenderer
text = @text.gsub(/!slide!\(([^\)]+)\)/) do |_|
slide_urls << %(
<div class="embed-responsive embed-responsive-4by3">
<iframe style="text-align:center;" src="/ViewerJS/##{Regexp.last_match[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>
)
"%%slide:#{slide_urls.size - 1}%%"
......
......@@ -19,13 +19,13 @@ class Notification < ActiveRecord::Base
# Named scope
######################################################################
scope :unread, -> {
scope :unread, (lambda do
where(is_read: false)
}
end)
scope :recent, -> {
scope :recent, (lambda do
where(arel_table[:created_at].gt 7.day.ago)
}
end)
######################################################################
# Instance method
......
......@@ -47,40 +47,40 @@ class Post < ActiveRecord::Base
# Named scope
######################################################################
scope :search, (lambda do |query|
_where_list = includes(:author, :tags).order(updated_at: :desc)
where_list = includes(:author, :tags).order(updated_at: :desc)
# Convert spaces to one space.
query_list = query.split(/[\s ]+/)
query_list.each do |_query|
case _query
query_list.each do |where_query|
case where_query
when /\Aid:(.+)/
_where_list = _where_list.where(id: Regexp.last_match[1])
where_list = where_list.where(id: Regexp.last_match[1])
when /\Atitle:(.+)/
_where_list = _where_list.where('posts.title LIKE ?', "%#{Regexp.last_match[1]}%")
where_list = where_list.where('posts.title LIKE ?', "%#{Regexp.last_match[1]}%")
when /\Abody:(.+)/
_where_list = _where_list.where('posts.body LIKE ?', "%#{Regexp.last_match[1]}%")
where_list = where_list.where('posts.body LIKE ?', "%#{Regexp.last_match[1]}%")
when /\A@(.+)/
_where_list = _where_list.where(users: { nickname: Regexp.last_match[1] })
where_list = where_list.where(users: { nickname: Regexp.last_match[1] })
when /\A#(.+)/
_where_list = _where_list.where(tags: { name: Regexp.last_match[1] })
where_list = where_list.where(tags: { name: Regexp.last_match[1] })
when /\Adate:(\d+)-(\d+)-(\d+)/
_date = Time.new(Regexp.last_match[1], Regexp.last_match[2], Regexp.last_match[3])
_where_list = _where_list.where('posts.updated_at > ? AND posts.updated_at < ?', _date, _date + 1.day)
date = Time.new(Regexp.last_match[1], Regexp.last_match[2], Regexp.last_match[3])
where_list = where_list.where('posts.updated_at > ? AND posts.updated_at < ?', date, date + 1.day)
when /\Adraft:1/
_where_list = _where_list.where(is_draft: true)
where_list = where_list.where(is_draft: true)
else
_where_list = _where_list.where('posts.title LIKE ? OR posts.body LIKE ?', "%#{_query}%", "%#{_query}%")
where_list = where_list.where('posts.title LIKE ? OR posts.body LIKE ?', "%#{where_query}%", "%#{where_query}%")
end
end
_where_list
where_list
end)
# 最新のPostを取得
scope :recent, -> (limit = 10) {
scope :recent, (lambda do |limit = 10|
order(updated_at: :desc).limit(limit)
}
end)
######################################################################
# Instance method
......@@ -89,19 +89,19 @@ class Post < ActiveRecord::Base
# generate forked post (not saved)
def generate_fork(user)
# `id`以外をコピーする
_forked_post = Post.new(attributes.except('id'))
forked_post = Post.new(attributes.except('id'))
# `%name`をユーザー名に置換
_forked_post.title = _forked_post.title.gsub(/%name/, user.name)
forked_post.title = forked_post.title.gsub(/%name/, user.name)
# `%Y`などを日付に変換
_forked_post.title = Time.now.strftime(_forked_post.title) # TODO
_forked_post.title = _forked_post.title
forked_post.title = Time.now.strftime(forked_post.title) # TODO
forked_post.title = forked_post.title
_forked_post.tag_ids = tag_ids
_forked_post.author = user
_forked_post.specified_date = Date.today
forked_post.tag_ids = tag_ids
forked_post.author = user
forked_post.specified_date = Date.today
_forked_post
forked_post
end
# slideshow用のbody
......@@ -113,9 +113,9 @@ class Post < ActiveRecord::Base
footprints.select(:user_id).uniq.count
end
# FIXME:
# FIXME: 正常に動作しないため動作しないため一時的にメソッドを作成
# has_many :watchers, :through => :watches
# 正常に動作しないため動作しないため一時的にメソッドを作成
#
# def watchers
# watches.map { |watch| watch.watcher }
# end
......
......@@ -43,14 +43,14 @@ class Tag < ActiveRecord::Base
# 自分のタグに紐づくPostをすべて`other_tag`へ移動する
def move_all_posts_to!(other_tag)
posts.each do |_post|
_post.tags.delete(self)
_post.tags << other_tag unless _post.tags.include?(other_tag)
posts.each do |moving_post|
moving_post.tags.delete(self)
moving_post.tags << other_tag unless moving_post.tags.include?(other_tag)
end
end
# 親タグを設定する
def set_parent!(other_tag)
def parent_tag=(other_tag)
self.parent = other_tag
self.save!
end
......
......@@ -46,12 +46,12 @@ class User < ActiveRecord::Base
######################################################################
# scope
######################################################################
scope :post_recently, -> {
scope :post_recently, (lambda do
User.joins(:posts).group('id').order('posts.updated_at desc')
}
end)
scope :search, (lambda do |_query|
where('name LIKE ? OR nickname LIKE ?', "%#{_query}%", "%#{_query}%")
scope :search, (lambda do |query|
where('name LIKE ? OR nickname LIKE ?', "%#{query}%", "%#{query}%")
end)
######################################################################
......@@ -66,11 +66,11 @@ class User < ActiveRecord::Base
# Device
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.name = access_token.info['name']
_user.image_url = access_token.info['image']
_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 = where(email: access_token.info['email']).first_or_create do |u|
u.name = access_token.info['name']
u.image_url = access_token.info['image']
u.password = Devise.friendly_token[0, 20]
u.nickname = (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle[0..4].join
end
user.update(
......@@ -113,9 +113,9 @@ class User < ActiveRecord::Base
# push通知を追加
def push_notification(detail_path, body)
unless notifications.where(detail_path: detail_path).unread.exists?
notifications.create(detail_path: detail_path, body: body, is_read: false)
end
return if notifications.where(detail_path: detail_path).unread.exists?
notifications.create(detail_path: detail_path, body: body, is_read: false)
end
# record footprint
......
......@@ -3,11 +3,11 @@ namespace :migrations do
desc '001 nicknameを自動付与'
task task_001_user_nickname: :environment do
User.all.each do |_user|
next if _user.nickname.present?
User.all.each do |user|
next if user.nickname.present?
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
......
......@@ -8,6 +8,7 @@ RSpec.describe MarkdownRenderer, type: :model do
- body
- test
EOS
expect(renderer.render.to_s.gsub(/^ +/, '')).to eq(<<EOS)
<h1>title</h1>
......@@ -26,12 +27,14 @@ EOS
expect(renderer.render.to_s.gsub(/^ +/, '')).to eq(<<EOS)
<p>
<div class="embed-responsive embed-responsive-4by3">
<iframe style="text-align:center;" src="/ViewerJS/#http://test.com/slide-1.pdf" width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe>
<iframe style="text-align:center;" src="/ViewerJS/#http://test.com/slide-1.pdf"
width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe>
</div>
<br>
<div class="embed-responsive embed-responsive-4by3">
<iframe style="text-align:center;" src="/ViewerJS/#http://test.com/slide-2.pdf" width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe>
<iframe style="text-align:center;" src="/ViewerJS/#http://test.com/slide-2.pdf"
width="400" height="300" allowfullscreen="true" webkitallowfullscreen="true"></iframe>
</div>
</p>
EOS
......
......@@ -33,7 +33,7 @@ describe Tag do
end
end
describe '#set_parent!' do
describe '#parent_tag=' do
before :each do
@tag_ruby = Tag.create(name: 'ruby')
@tag_lang = Tag.create(name: 'lang')
......@@ -42,7 +42,7 @@ describe Tag do
it 'successfully moved' do
expect(@tag_ruby.parent).not_to eq(@tag_lang)
expect(@tag_lang.children).not_to include(@tag_ruby)
@tag_ruby.set_parent!(@tag_lang)
@tag_ruby.parent_tag = @tag_lang
expect(@tag_ruby.parent).to eq(@tag_lang)
expect(@tag_lang.children).to include(@tag_ruby)
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