Commit 14c8b331 by tadyjp

Merge pull request #7 from tadyjp/wip/1228_rubocop

rubocop
parents b55a6775 29026b02
......@@ -17,4 +17,6 @@
/bin/set-env.sh
/coverage/*
*.bk
LineLength:
Max: 159
NumericLiterals:
Enabled: false
Documentation:
Enabled: false
WordArray:
Enabled: false
MethodLength:
Max: 30
IfUnlessModifier:
Enabled: false
CyclomaticComplexity:
Max: 10
......@@ -70,6 +70,10 @@ group :development do
# profiler
gem 'rack-mini-profiler'
# rubocop
gem 'rubocop'
gem 'guard-rubocop'
end
group :development, :test do
......
......@@ -45,6 +45,7 @@ GEM
ancestry (2.0.0)
activerecord (>= 3.0.0)
arel (4.0.1)
ast (1.1.0)
atomic (1.1.14)
bcrypt-ruby (3.1.2)
better_errors (1.1.0)
......@@ -104,6 +105,9 @@ GEM
guard-rspec (4.2.0)
guard (>= 2.1.1)
rspec (>= 2.14, < 4.0)
guard-rubocop (1.0.0)
guard (~> 2.0)
rubocop (~> 0.10)
guard-spring (0.0.4)
guard
spring
......@@ -151,7 +155,11 @@ GEM
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
orm_adapter (0.5.0)
parser (2.0.0)
ast (~> 1.1)
slop (~> 3.4, >= 3.4.5)
polyglot (0.3.3)
powerpack (0.0.9)
premailer (1.7.9)
css_parser (>= 1.1.9)
htmlentities (>= 4.0.0)
......@@ -179,6 +187,7 @@ GEM
activesupport (= 4.0.2)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (1.1.4)
rake (10.1.1)
rb-fsevent (0.9.3)
rb-inotify (0.9.3)
......@@ -202,6 +211,10 @@ GEM
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rubocop (0.15.0)
parser (~> 2.0)
powerpack (~> 0.0.6)
rainbow (>= 1.1.4)
sass (3.2.13)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
......@@ -264,6 +277,7 @@ DEPENDENCIES
factory_girl_rails
faraday
guard-rspec
guard-rubocop
guard-spring
jbuilder
mail
......@@ -275,6 +289,7 @@ DEPENDENCIES
rails (~> 4.0.2)
redcarpet!
rspec-rails
rubocop
sass-rails
sdoc
spring
......
......@@ -10,3 +10,8 @@ guard :rspec, spring: true do
watch('config/routes.rb') { 'spec/routing' }
watch('app/controllers/application_controller.rb') { 'spec/controllers' }
end
guard :rubocop, cli: ['--rails', '--auto-correct'] do
watch(%r{.+\.rb$})
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end
......@@ -9,5 +9,4 @@ class ApplicationController < ActionController::Base
redirect_to root_path
end
end
end
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1.0"> <!-- So that mobile webkit will display zoomed in -->
<meta name="format-detection" content="telephone=no"> <!-- disable auto telephone linking in iOS -->
<title>2 columns to rows template | Antwort</title>
<style type="text/css">
/* Resets: see reset.css for details */
.ReadMsgBody { width: 100%; background-color: #ebebeb;}
.ExternalClass {width: 100%; background-color: #ebebeb;}
.ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height:100%;}
body {-webkit-text-size-adjust:none; -ms-text-size-adjust:none;}
body {margin:0; padding:0;}
table {border-spacing:0;}
table td {border-collapse:collapse;}
.yshortcuts a {border-bottom: none !important;}
/* Constrain email width for small screens */
@media screen and (max-width: 600px) {
table[class="container"] {
width: 95% !important;
}
}
/* Give content more room on mobile */
@media screen and (max-width: 480px) {
td[class="container-padding"] {
padding-left: 12px !important;
padding-right: 12px !important;
}
}
/* Styles for forcing columns to rows */
@media only screen and (max-width : 600px) {
/* force container columns to (horizontal) blocks */
td[class="force-col"] {
display: block;
padding-right: 0 !important;
}
table[class="col-2"] {
/* unset table align="left/right" */
float: none !important;
width: 100% !important;
/* change left/right padding and margins to top/bottom ones */
margin-bottom: 12px;
padding-bottom: 12px;
border-bottom: 1px solid #eee;
}
/* remove bottom border for last column/row */
table[id="last-col-2"] {
border-bottom: none !important;
margin-bottom: 0;
}
/* align images right and shrink them a bit */
img[class="col-2-img"] {
float: right;
margin-left: 6px;
max-width: 130px;
}
}
.viewer.github a {
color: #4183C4; }
.viewer.github a.absent {
color: #cc0000; }
.viewer.github a.anchor {
display: block;
padding-left: 30px;
margin-left: -30px;
cursor: pointer;
position: absolute;
top: 0;
left: 0;
bottom: 0; }
.viewer.github h1, .viewer.github h2, .viewer.github h3, .viewer.github h4, .viewer.github h5, .viewer.github h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
cursor: text;
position: relative; }
.viewer.github h1:hover a.anchor, .viewer.github h2:hover a.anchor, .viewer.github h3:hover a.anchor, .viewer.github h4:hover a.anchor, .viewer.github h5:hover a.anchor, .viewer.github h6:hover a.anchor {
background: url("../../images/modules/styleguide/para.png") no-repeat 10px center;
text-decoration: none; }
.viewer.github h1 tt, .viewer.github h1 code {
font-size: inherit; }
.viewer.github h2 tt, .viewer.github h2 code {
font-size: inherit; }
.viewer.github h3 tt, .viewer.github h3 code {
font-size: inherit; }
.viewer.github h4 tt, .viewer.github h4 code {
font-size: inherit; }
.viewer.github h5 tt, .viewer.github h5 code {
font-size: inherit; }
.viewer.github h6 tt, .viewer.github h6 code {
font-size: inherit; }
.viewer.github h1 {
font-size: 28px;
color: black; }
.viewer.github h2 {
font-size: 24px;
border-bottom: 1px solid #cccccc;
color: black; }
.viewer.github h3 {
font-size: 18px; }
.viewer.github h4 {
font-size: 16px; }
.viewer.github h5 {
font-size: 14px; }
.viewer.github h6 {
color: #777777;
font-size: 14px; }
.viewer.github p, .viewer.github blockquote, .viewer.github ul, .viewer.github ol, .viewer.github dl, .viewer.github li, .viewer.github table, .viewer.github pre {
margin: 15px 0; }
.viewer.github hr {
background: transparent url("../../images/modules/pulls/dirty-shade.png") repeat-x 0 0;
border: 0 none;
color: #cccccc;
height: 4px;
padding: 0; }
.viewer.github body > h2:first-child {
margin-top: 0;
padding-top: 0; }
.viewer.github body > h1:first-child {
margin-top: 0;
padding-top: 0; }
.viewer.github body > h1:first-child + h2 {
margin-top: 0;
padding-top: 0; }
.viewer.github body > h3:first-child, .viewer.github body > h4:first-child, .viewer.github body > h5:first-child, .viewer.github body > h6:first-child {
margin-top: 0;
padding-top: 0; }
.viewer.github a:first-child h1, .viewer.github a:first-child h2, .viewer.github a:first-child h3, .viewer.github a:first-child h4, .viewer.github a:first-child h5, .viewer.github a:first-child h6 {
margin-top: 0;
padding-top: 0; }
.viewer.github h1 p, .viewer.github h2 p, .viewer.github h3 p, .viewer.github h4 p, .viewer.github h5 p, .viewer.github h6 p {
margin-top: 0; }
.viewer.github li p.first {
display: inline-block; }
.viewer.github ul, .viewer.github ol {
padding-left: 30px; }
.viewer.github ul :first-child, .viewer.github ol :first-child {
margin-top: 0; }
.viewer.github ul :last-child, .viewer.github ol :last-child {
margin-bottom: 0; }
.viewer.github dl {
padding: 0; }
.viewer.github dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px; }
.viewer.github dl dt:first-child {
padding: 0; }
.viewer.github dl dt > :first-child {
margin-top: 0; }
.viewer.github dl dt > :last-child {
margin-bottom: 0; }
.viewer.github dl dd {
margin: 0 0 15px;
padding: 0 15px; }
.viewer.github dl dd > :first-child {
margin-top: 0; }
.viewer.github dl dd > :last-child {
margin-bottom: 0; }
.viewer.github blockquote {
border-left: 4px solid #dddddd;
padding: 0 15px;
color: #777777; }
.viewer.github blockquote > :first-child {
margin-top: 0; }
.viewer.github blockquote > :last-child {
margin-bottom: 0; }
.viewer.github table {
padding: 0; }
.viewer.github table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0; }
.viewer.github table tr:nth-child(2n) {
background-color: #f8f8f8; }
.viewer.github table tr th {
font-weight: bold;
border: 1px solid #cccccc;
text-align: left;
margin: 0;
padding: 6px 13px; }
.viewer.github table tr td {
border: 1px solid #cccccc;
text-align: left;
margin: 0;
padding: 6px 13px; }
.viewer.github table tr th :first-child, .viewer.github table tr td :first-child {
margin-top: 0; }
.viewer.github table tr th :last-child, .viewer.github table tr td :last-child {
margin-bottom: 0; }
.viewer.github img {
max-width: 100%; }
.viewer.github span.frame {
display: block;
overflow: hidden; }
.viewer.github span.frame > span {
border: 1px solid #dddddd;
display: block;
float: left;
overflow: hidden;
margin: 13px 0 0;
padding: 7px;
width: auto; }
.viewer.github span.frame span img {
display: block;
float: left; }
.viewer.github span.frame span span {
clear: both;
color: #333333;
display: block;
padding: 5px 0 0; }
.viewer.github span.align-center {
display: block;
overflow: hidden;
clear: both; }
.viewer.github span.align-center > span {
display: block;
overflow: hidden;
margin: 13px auto 0;
text-align: center; }
.viewer.github span.align-center span img {
margin: 0 auto;
text-align: center; }
.viewer.github span.align-right {
display: block;
overflow: hidden;
clear: both; }
.viewer.github span.align-right > span {
display: block;
overflow: hidden;
margin: 13px 0 0;
text-align: right; }
.viewer.github span.align-right span img {
margin: 0;
text-align: right; }
.viewer.github span.float-left {
display: block;
margin-right: 13px;
overflow: hidden;
float: left; }
.viewer.github span.float-left span {
margin: 13px 0 0; }
.viewer.github span.float-right {
display: block;
margin-left: 13px;
overflow: hidden;
float: right; }
.viewer.github span.float-right > span {
display: block;
overflow: hidden;
margin: 13px auto 0;
text-align: right; }
.viewer.github code, .viewer.github tt {
margin: 0 2px;
padding: 0 5px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px; }
.viewer.github pre code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent; }
.viewer.github .highlight pre {
background-color: #f8f8f8;
border: 1px solid #cccccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px; }
.viewer.github pre {
background-color: #f8f8f8;
border: 1px solid #cccccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px; }
.viewer.github pre code, .viewer.github pre tt {
background-color: transparent;
border: none; }
</style>
</head>
<body style="margin:0; padding:10px 0;" bgcolor="#ebebeb" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br>
<!-- 100% wrapper (grey background) -->
<table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0" bgcolor="#ebebeb">
<tr>
<td align="center" valign="top" bgcolor="#ebebeb" style="background-color: #ebebeb;">
<!-- 600px container (white background) -->
<table border="0" width="600" cellpadding="0" cellspacing="0" class="container" bgcolor="#ffffff">
<tr>
<td class="container-padding" bgcolor="#ffffff" style="background-color: #ffffff; padding-left: 30px; padding-right: 30px; font-size: 14px; line-height: 20px; font-family: Helvetica, sans-serif; color: #333;">
<br>
__HTML_BODY__
<br>
</td>
</tr>
<tr>
<td class="container-padding" bgcolor="#ffffff" style="background-color: #ffffff; padding-left: 30px; padding-right: 30px; font-size: 13px; line-height: 20px; font-family: Helvetica, sans-serif; color: #333;" align="left">
<br>
<hr>
このメールは<a href="#">Rendezvous</a>から送信されています。
<br><br>
</td>
</tr>
</table>
<!--/600px container -->
</td>
</tr>
</table>
<!--/100% wrapper-->
<br>
<br>
</body>
</html>
......@@ -3,7 +3,6 @@ require 'action_gmailer'
require 'premailer'
module RV::Mailer
include ApplicationHelper
def compose_mail(post, user)
......@@ -15,7 +14,6 @@ module RV::Mailer
subject post.title
body post.body
html_part do
content_type 'text/html; charset=UTF-8'
body html_body
......@@ -33,362 +31,12 @@ module RV::Mailer
end
def generate_html_mail(body)
html_body = <<'__HTML__'
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1.0"> <!-- So that mobile webkit will display zoomed in -->
<meta name="format-detection" content="telephone=no"> <!-- disable auto telephone linking in iOS -->
<title>2 columns to rows template | Antwort</title>
<style type="text/css">
/* Resets: see reset.css for details */
.ReadMsgBody { width: 100%; background-color: #ebebeb;}
.ExternalClass {width: 100%; background-color: #ebebeb;}
.ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height:100%;}
body {-webkit-text-size-adjust:none; -ms-text-size-adjust:none;}
body {margin:0; padding:0;}
table {border-spacing:0;}
table td {border-collapse:collapse;}
.yshortcuts a {border-bottom: none !important;}
/* Constrain email width for small screens */
@media screen and (max-width: 600px) {
table[class="container"] {
width: 95% !important;
}
}
/* Give content more room on mobile */
@media screen and (max-width: 480px) {
td[class="container-padding"] {
padding-left: 12px !important;
padding-right: 12px !important;
}
}
/* Styles for forcing columns to rows */
@media only screen and (max-width : 600px) {
/* force container columns to (horizontal) blocks */
td[class="force-col"] {
display: block;
padding-right: 0 !important;
}
table[class="col-2"] {
/* unset table align="left/right" */
float: none !important;
width: 100% !important;
/* change left/right padding and margins to top/bottom ones */
margin-bottom: 12px;
padding-bottom: 12px;
border-bottom: 1px solid #eee;
}
/* remove bottom border for last column/row */
table[id="last-col-2"] {
border-bottom: none !important;
margin-bottom: 0;
}
/* align images right and shrink them a bit */
img[class="col-2-img"] {
float: right;
margin-left: 6px;
max-width: 130px;
}
}
.viewer.github a {
color: #4183C4; }
.viewer.github a.absent {
color: #cc0000; }
.viewer.github a.anchor {
display: block;
padding-left: 30px;
margin-left: -30px;
cursor: pointer;
position: absolute;
top: 0;
left: 0;
bottom: 0; }
.viewer.github h1, .viewer.github h2, .viewer.github h3, .viewer.github h4, .viewer.github h5, .viewer.github h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
cursor: text;
position: relative; }
.viewer.github h1:hover a.anchor, .viewer.github h2:hover a.anchor, .viewer.github h3:hover a.anchor, .viewer.github h4:hover a.anchor, .viewer.github h5:hover a.anchor, .viewer.github h6:hover a.anchor {
background: url("../../images/modules/styleguide/para.png") no-repeat 10px center;
text-decoration: none; }
.viewer.github h1 tt, .viewer.github h1 code {
font-size: inherit; }
.viewer.github h2 tt, .viewer.github h2 code {
font-size: inherit; }
.viewer.github h3 tt, .viewer.github h3 code {
font-size: inherit; }
.viewer.github h4 tt, .viewer.github h4 code {
font-size: inherit; }
.viewer.github h5 tt, .viewer.github h5 code {
font-size: inherit; }
.viewer.github h6 tt, .viewer.github h6 code {
font-size: inherit; }
.viewer.github h1 {
font-size: 28px;
color: black; }
.viewer.github h2 {
font-size: 24px;
border-bottom: 1px solid #cccccc;
color: black; }
.viewer.github h3 {
font-size: 18px; }
.viewer.github h4 {
font-size: 16px; }
.viewer.github h5 {
font-size: 14px; }
.viewer.github h6 {
color: #777777;
font-size: 14px; }
.viewer.github p, .viewer.github blockquote, .viewer.github ul, .viewer.github ol, .viewer.github dl, .viewer.github li, .viewer.github table, .viewer.github pre {
margin: 15px 0; }
.viewer.github hr {
background: transparent url("../../images/modules/pulls/dirty-shade.png") repeat-x 0 0;
border: 0 none;
color: #cccccc;
height: 4px;
padding: 0; }
.viewer.github body > h2:first-child {
margin-top: 0;
padding-top: 0; }
.viewer.github body > h1:first-child {
margin-top: 0;
padding-top: 0; }
.viewer.github body > h1:first-child + h2 {
margin-top: 0;
padding-top: 0; }
.viewer.github body > h3:first-child, .viewer.github body > h4:first-child, .viewer.github body > h5:first-child, .viewer.github body > h6:first-child {
margin-top: 0;
padding-top: 0; }
.viewer.github a:first-child h1, .viewer.github a:first-child h2, .viewer.github a:first-child h3, .viewer.github a:first-child h4, .viewer.github a:first-child h5, .viewer.github a:first-child h6 {
margin-top: 0;
padding-top: 0; }
.viewer.github h1 p, .viewer.github h2 p, .viewer.github h3 p, .viewer.github h4 p, .viewer.github h5 p, .viewer.github h6 p {
margin-top: 0; }
.viewer.github li p.first {
display: inline-block; }
.viewer.github ul, .viewer.github ol {
padding-left: 30px; }
.viewer.github ul :first-child, .viewer.github ol :first-child {
margin-top: 0; }
.viewer.github ul :last-child, .viewer.github ol :last-child {
margin-bottom: 0; }
.viewer.github dl {
padding: 0; }
.viewer.github dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px; }
.viewer.github dl dt:first-child {
padding: 0; }
.viewer.github dl dt > :first-child {
margin-top: 0; }
.viewer.github dl dt > :last-child {
margin-bottom: 0; }
.viewer.github dl dd {
margin: 0 0 15px;
padding: 0 15px; }
.viewer.github dl dd > :first-child {
margin-top: 0; }
.viewer.github dl dd > :last-child {
margin-bottom: 0; }
.viewer.github blockquote {
border-left: 4px solid #dddddd;
padding: 0 15px;
color: #777777; }
.viewer.github blockquote > :first-child {
margin-top: 0; }
.viewer.github blockquote > :last-child {
margin-bottom: 0; }
.viewer.github table {
padding: 0; }
.viewer.github table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0; }
.viewer.github table tr:nth-child(2n) {
background-color: #f8f8f8; }
.viewer.github table tr th {
font-weight: bold;
border: 1px solid #cccccc;
text-align: left;
margin: 0;
padding: 6px 13px; }
.viewer.github table tr td {
border: 1px solid #cccccc;
text-align: left;
margin: 0;
padding: 6px 13px; }
.viewer.github table tr th :first-child, .viewer.github table tr td :first-child {
margin-top: 0; }
.viewer.github table tr th :last-child, .viewer.github table tr td :last-child {
margin-bottom: 0; }
.viewer.github img {
max-width: 100%; }
.viewer.github span.frame {
display: block;
overflow: hidden; }
.viewer.github span.frame > span {
border: 1px solid #dddddd;
display: block;
float: left;
overflow: hidden;
margin: 13px 0 0;
padding: 7px;
width: auto; }
.viewer.github span.frame span img {
display: block;
float: left; }
.viewer.github span.frame span span {
clear: both;
color: #333333;
display: block;
padding: 5px 0 0; }
.viewer.github span.align-center {
display: block;
overflow: hidden;
clear: both; }
.viewer.github span.align-center > span {
display: block;
overflow: hidden;
margin: 13px auto 0;
text-align: center; }
.viewer.github span.align-center span img {
margin: 0 auto;
text-align: center; }
.viewer.github span.align-right {
display: block;
overflow: hidden;
clear: both; }
.viewer.github span.align-right > span {
display: block;
overflow: hidden;
margin: 13px 0 0;
text-align: right; }
.viewer.github span.align-right span img {
margin: 0;
text-align: right; }
.viewer.github span.float-left {
display: block;
margin-right: 13px;
overflow: hidden;
float: left; }
.viewer.github span.float-left span {
margin: 13px 0 0; }
.viewer.github span.float-right {
display: block;
margin-left: 13px;
overflow: hidden;
float: right; }
.viewer.github span.float-right > span {
display: block;
overflow: hidden;
margin: 13px auto 0;
text-align: right; }
.viewer.github code, .viewer.github tt {
margin: 0 2px;
padding: 0 5px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px; }
.viewer.github pre code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent; }
.viewer.github .highlight pre {
background-color: #f8f8f8;
border: 1px solid #cccccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px; }
.viewer.github pre {
background-color: #f8f8f8;
border: 1px solid #cccccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px; }
.viewer.github pre code, .viewer.github pre tt {
background-color: transparent;
border: none; }
</style>
</head>
<body style="margin:0; padding:10px 0;" bgcolor="#ebebeb" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
path = File.expand_path(File.dirname(__FILE__) + '/mail-template.html')
template = File.open(path).read
<br>
html_body = template.sub('__HTML_BODY__', h_application_format_markdown(body))
<!-- 100% wrapper (grey background) -->
<table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0" bgcolor="#ebebeb">
<tr>
<td align="center" valign="top" bgcolor="#ebebeb" style="background-color: #ebebeb;">
<!-- 600px container (white background) -->
<table border="0" width="600" cellpadding="0" cellspacing="0" class="container" bgcolor="#ffffff">
<tr>
<td class="container-padding" bgcolor="#ffffff" style="background-color: #ffffff; padding-left: 30px; padding-right: 30px; font-size: 14px; line-height: 20px; font-family: Helvetica, sans-serif; color: #333;">
<br>
__HTML__
html_body += h_application_format_markdown(body)
html_body += <<'__HTML__'
<br>
</td>
</tr>
<tr>
<td class="container-padding" bgcolor="#ffffff" style="background-color: #ffffff; padding-left: 30px; padding-right: 30px; font-size: 13px; line-height: 20px; font-family: Helvetica, sans-serif; color: #333;" align="left">
<br>
<hr>
このメールは<a href="#">Rendezvous</a>から送信されています。
<br><br>
</td>
</tr>
</table>
<!--/600px container -->
</td>
</tr>
</table>
<!--/100% wrapper-->
<br>
<br>
</body>
</html>
__HTML__
premailer = Premailer.new(html_body, :with_html_string => true, :adapter => :nokogiri)
premailer = Premailer.new(html_body, with_html_string: true, adapter: :nokogiri)
premailer.to_inline_css
end
end
class HomeController < ApplicationController
skip_before_action :require_login
def top
......@@ -9,6 +8,4 @@ class HomeController < ApplicationController
render template: 'home/login'
end
end
end
......@@ -2,7 +2,6 @@ require 'nkf'
require 'rv/mailer'
class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy]
before_action :require_login
......@@ -28,7 +27,6 @@ class PostsController < ApplicationController
render layout: false, partial: 'posts/show_fragment'
end
# GET /posts/1
# GET /posts/1.json
def show
......@@ -104,6 +102,7 @@ class PostsController < ApplicationController
end
private
# Use callbacks to share common setup or constraints between actions.
def set_post
@post = Post.find(params[:id])
......@@ -120,10 +119,9 @@ class PostsController < ApplicationController
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
end
end
end
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)
@user = User.find_for_google_oauth2(request.env['omniauth.auth'], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication
flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Google'
sign_in_and_redirect @user, event: :authentication
else
session["devise.google_data"] = request.env["omniauth.auth"]
session['devise.google_data'] = request.env['omniauth.auth']
redirect_to new_user_registration_url
end
end
end
module ApplicationHelper
class HtmlWithPrettyPrint < Redcarpet::Render::HTML
def postprocess(full_document)
full_document.gsub("prettyprint", "prettyprint linenums")
full_document.gsub('prettyprint', 'prettyprint linenums')
end
end
def h_application_format_markdown(text)
# html_render = HTMLwithCoderay.new(filter_html: true, hard_wrap: true, prettify: true)
html_render = HtmlWithPrettyPrint.new(:prettify => true)
html_render = HtmlWithPrettyPrint.new(prettify: true)
options = {
autolink: true,
space_after_headers: true,
......@@ -18,5 +17,4 @@ module ApplicationHelper
markdown = Redcarpet::Markdown.new(html_render, options)
markdown.render(text).html_safe
end
end
module PostsHelper
# @param {ActiveRecord::Relation} node
def h_display_tree(node)
_html = '<ul>'
......@@ -10,7 +9,7 @@ module PostsHelper
_html << h_display_tree(_child)
end
_html << '</ul>'
_html.html_safe
end
end
......@@ -6,9 +6,9 @@ class Post < ActiveRecord::Base
# Named scope
def self.build_query(params)
_where_list = self.includes(:author, :tags)
_where_list = includes(:author, :tags)
# 空白を一つに変換
# Convert spaces to one space.
query_string = params[:q].gsub(/[\s ]+/, ' ')
query_list = query_string.split(' ')
......@@ -16,17 +16,17 @@ class Post < ActiveRecord::Base
query_list.each do |_query|
case _query
when /^post:(.+)/
_where_list = _where_list.where('id = ?', $1)
_where_list = _where_list.where('id = ?', Regexp.last_match[1])
when /^title:(.+)/
_where_list = _where_list.where('title LIKE ?', "%#{$1}%")
_where_list = _where_list.where('title LIKE ?', "%#{Regexp.last_match[1]}%")
when /^body:(.+)/
_where_list = _where_list.where('body LIKE ?', "%#{$1}%")
_where_list = _where_list.where('body LIKE ?', "%#{Regexp.last_match[1]}%")
when /^@(.+)/
_where_list = _where_list.where('users.name = ?', $1)
_where_list = _where_list.where('users.name = ?', Regexp.last_match[1])
when /^#(.+)/
_where_list = _where_list.where('tags.name = ?', $1)
_where_list = _where_list.where('tags.name = ?', Regexp.last_match[1])
when /^date:(\d+)-(\d+)-(\d+)/
_date = Time.new($1, $2, $3)
_date = Time.new(Regexp.last_match[1], Regexp.last_match[2], Regexp.last_match[3])
_where_list = _where_list.where('updated_at > ? AND updated_at < ?', _date, _date + 1.day)
else
_where_list = _where_list.where('title LIKE ? OR body LIKE ?', "%#{_query}%", "%#{_query}%")
......@@ -34,17 +34,15 @@ class Post < ActiveRecord::Base
end
_where_list
end
# generate forked post (not saved)
def generate_fork(user)
forked_post = self.clone
forked_post = clone
forked_post.title = forked_post.title.gsub(/%Name/, user.name)
forked_post.title = Time.now.strftime(forked_post.title) # TODO
forked_post.author = user
forked_post
end
end
......@@ -3,5 +3,4 @@ class Tag < ActiveRecord::Base
has_many :posts, through: :post_tags
has_ancestry
end
......@@ -5,20 +5,20 @@ class User < ActiveRecord::Base
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
devise :omniauthable, :omniauth_providers => [:google_oauth2]
devise :omniauthable, omniauth_providers: [:google_oauth2]
has_many :posts
# Device
def self.find_for_google_oauth2(access_token, signed_in_resource=nil)
def self.find_for_google_oauth2(access_token, signed_in_resource = nil)
data = access_token.info
user = User.where(email: data["email"]).first
user = User.where(email: data['email']).first
unless user
user = User.create(name: data["name"],
image_url: data["image"],
email: data["email"],
password: Devise.friendly_token[0,20]
user = User.create(name: data['name'],
image_url: data['image'],
email: data['email'],
password: Devise.friendly_token[0, 20]
)
end
......@@ -33,7 +33,7 @@ class User < ActiveRecord::Base
# check if google oauth token is expired
def google_oauth_token_expired?
self.google_token_expires_at < Time.now
google_token_expires_at < Time.now
end
# refresh google oauth token
......@@ -42,18 +42,17 @@ class User < ActiveRecord::Base
builder.request :url_encoded
builder.adapter :net_http
end
response = conn.post '/o/oauth2/token', {
client_id: ENV["GOOGLE_KEY"],
client_secret: ENV["GOOGLE_SECRET"],
refresh_token: self.google_refresh_token,
grant_type: "refresh_token"
}
response = conn.post '/o/oauth2/token',
client_id: ENV['GOOGLE_KEY'],
client_secret: ENV['GOOGLE_SECRET'],
refresh_token: google_refresh_token,
grant_type: 'refresh_token'
res_json = JSON.parse(response.body)
self.update_attributes(
update_attributes(
google_auth_token: res_json['access_token'],
google_token_expires_at: Time.now + res_json['expires_in'].seconds
)
end
end
......@@ -7,7 +7,7 @@
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
Pathname.new(__FILE__).realpath)
require 'rubygems'
......
......@@ -22,7 +22,6 @@ module Rendezvous
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = :ja
# config.action_mailer.delivery_method = :action_gmailer
config.action_mailer.smtp_settings = {
smtp_host: 'smtp.gmail.com',
......@@ -32,7 +31,5 @@ module Rendezvous
# oauth2_token: 'FIXME',
# account: 'FIXME'
}
end
end
......@@ -28,5 +28,5 @@ Rendezvous::Application.configure do
config.assets.debug = true
# Devise
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.default_url_options = { host: 'localhost:3000' }
end
......@@ -14,7 +14,7 @@ Rendezvous::Application.configure do
# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
config.static_cache_control = 'public, max-age=3600'
# Show full error reports and disable caching.
config.consider_all_requests_local = true
......
......@@ -41,12 +41,12 @@ Devise.setup do |config|
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [ :email ]
config.case_insensitive_keys = [:email]
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [ :email ]
config.strip_whitespace_keys = [:email]
# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
......
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"],
{
:name => "google_oauth2",
:scope => "https://mail.google.com/, userinfo.email, userinfo.profile",
provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'],
name: 'google_oauth2',
scope: 'https://mail.google.com/, userinfo.email, userinfo.profile',
access_type: 'offline',
:prompt => "select_account consent",
:image_aspect_ratio => "square",
:image_size => 50
}
prompt: 'select_account consent',
image_aspect_ratio: 'square',
image_size: 50
end
......@@ -9,4 +9,5 @@
# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
Rendezvous::Application.config.secret_key_base = 'd8e487b60856000161a94ea764b38e7492512bbbeeca2f4cec068c8cc6618cacb54172ec54afc61675684f01bf02c74bf1e93dfe6971247d75ff001b1584d987'
Rendezvous::Application.config.secret_key_base = \
'd8e487b60856000161a94ea764b38e7492512bbbeeca2f4cec068c8cc6618cacb54172ec54afc61675684f01bf02c74bf1e93dfe6971247d75ff001b1584d987'
......@@ -8,8 +8,7 @@ Rendezvous::Application.routes.draw do
get 'posts/:id/mail' => 'posts#mail', as: 'mail_post'
resources :posts
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
......
{
"RSpec": {
"coverage": {
"/Users/tady/data/projects/rendezvous/config/environment.rb": [
null,
1,
null,
null,
1
],
"/Users/tady/data/projects/rendezvous/config/application.rb": [
1,
null,
1,
null,
null,
null,
1,
null,
1,
1,
null,
null,
null,
null,
null,
null,
1,
null,
1,
null,
null,
null,
1,
null,
null,
null,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/config/boot.rb": [
null,
1,
null,
1
],
"/Users/tady/data/projects/rendezvous/config/environments/test.rb": [
1,
null,
null,
null,
null,
null,
null,
1,
null,
null,
null,
null,
1,
null,
null,
1,
1,
null,
null,
1,
1,
null,
null,
1,
null,
null,
1,
null,
null,
null,
null,
1,
null,
null,
1,
null
],
"/Users/tady/data/projects/rendezvous/config/initializers/backtrace_silencers.rb": [
null,
null,
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/config/initializers/devise.rb": [
null,
null,
1,
null,
null,
null,
1,
null,
null,
null,
null,
null,
1,
null,
null,
null,
null,
null,
null,
null,
null,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1,
null,
null,
null,
null,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/config/initializers/filter_parameter_logging.rb": [
null,
null,
null,
1
],
"/Users/tady/data/projects/rendezvous/config/initializers/inflections.rb": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/config/initializers/mime_types.rb": [
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/config/initializers/omniauth.rb": [
1,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/config/initializers/secret_token.rb": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1
],
"/Users/tady/data/projects/rendezvous/config/initializers/session_store.rb": [
null,
null,
1
],
"/Users/tady/data/projects/rendezvous/config/initializers/wrap_parameters.rb": [
null,
null,
null,
null,
null,
null,
1,
1,
null,
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/spec/factories/posts.rb": [
null,
null,
1,
1,
1,
1,
null,
1,
0,
null,
null,
null,
1,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/spec/factories/tags.rb": [
null,
null,
1,
1,
1,
null,
null
],
"/Users/tady/data/projects/rendezvous/app/models/tag.rb": [
1,
1,
1,
null,
1,
null,
null
],
"/Users/tady/data/projects/rendezvous/spec/factories/users.rb": [
1,
1,
1,
1,
1,
1,
null,
null,
1,
1,
1,
1,
1,
null,
null,
1,
1,
1,
1,
1,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/app/models/user.rb": [
1,
null,
1,
null,
null,
1,
null,
1,
null,
1,
null,
null,
1,
0,
0,
null,
0,
0,
null,
null,
null,
null,
null,
null,
0,
null,
null,
null,
null,
null,
0,
null,
null,
null,
1,
2,
null,
null,
null,
1,
0,
0,
0,
null,
0,
null,
null,
null,
null,
null,
0,
null,
0,
null,
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/config/routes.rb": [
1,
null,
1,
null,
1,
1,
1,
1,
1,
null,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/app/helpers/application_helper.rb": [
1,
null,
1,
1,
0,
null,
null,
null,
1,
null,
0,
0,
null,
null,
null,
null,
null,
0,
0,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/app/helpers/home_helper.rb": [
1,
null
],
"/Users/tady/data/projects/rendezvous/app/helpers/posts_helper.rb": [
1,
null,
null,
1,
0,
0,
0,
null,
0,
0,
null,
0,
0,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/spec/support/devise.rb": [
1,
1,
null
],
"/Users/tady/data/projects/rendezvous/app/controllers/home_controller.rb": [
1,
null,
1,
null,
1,
3,
2,
null,
1,
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/app/controllers/application_controller.rb": [
1,
null,
null,
1,
null,
1,
0,
0,
0,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/spec/models/post_spec.rb": [
1,
null,
1,
null,
1,
1,
4,
4,
null,
null,
1,
null,
5,
null,
1,
1,
null,
null,
1,
1,
null,
null,
1,
1,
null,
null,
1,
1,
null,
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/app/models/post.rb": [
1,
1,
1,
1,
null,
null,
null,
1,
0,
null,
null,
0,
null,
0,
null,
0,
0,
null,
0,
null,
0,
null,
0,
null,
0,
null,
0,
null,
0,
0,
null,
0,
null,
null,
null,
0,
null,
null,
null,
null,
1,
4,
4,
4,
4,
null,
4,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/spec/models/tag_spec.rb": [
1,
null,
1,
1,
null
],
"/Users/tady/data/projects/rendezvous/spec/models/user_spec.rb": [
1,
null,
1,
null,
1,
1,
2,
2,
null,
null,
1,
null,
1,
1,
null,
null,
1,
1,
null,
null,
null,
null,
null,
1,
1,
13,
null,
null,
null,
null,
null,
null,
null,
1,
1,
null,
null,
1,
1,
1,
null,
null,
1,
1,
1,
3,
3,
null,
null,
null,
1,
1,
1,
3,
3,
null,
null,
null,
1,
1,
1,
1,
null,
null,
1,
1,
1,
1,
1,
null,
null,
1,
null,
1,
2,
null,
null,
1,
1,
null,
null,
1,
1,
null,
null,
null,
1,
null,
1,
1,
null,
null,
null,
1,
1,
null,
null,
null,
1,
1,
1,
1,
null,
null,
null,
null,
1,
null,
1,
2,
null,
null,
1,
1,
null,
null,
1,
1,
null,
null,
null,
null,
null,
null,
null
],
"/Users/tady/data/projects/rendezvous/app/models/post_tag.rb": [
1,
1,
1,
null
]
},
"timestamp": 1388292345
}
}
......@@ -2,8 +2,8 @@ class AddDeviseToUsers < ActiveRecord::Migration
def self.up
change_table(:users) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
t.string :email, null: false, default: ''
t.string :encrypted_password, null: false, default: ''
## Recoverable
t.string :reset_password_token
......@@ -13,7 +13,7 @@ class AddDeviseToUsers < ActiveRecord::Migration
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0, :null => false
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
......@@ -30,13 +30,12 @@ class AddDeviseToUsers < ActiveRecord::Migration
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
# Uncomment below if timestamps were not included in your original model.
# t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
end
......@@ -44,6 +43,6 @@ class AddDeviseToUsers < ActiveRecord::Migration
def self.down
# By default, we don't want to make any assumption about how to roll back a migration when your
# model already existed. Please edit below which fields you would like to remove in this migration.
raise ActiveRecord::IrreversibleMigration
fail ActiveRecord::IrreversibleMigration
end
end
......@@ -13,54 +13,54 @@
ActiveRecord::Schema.define(version: 20131228110818) do
create_table "post_tags", force: true do |t|
t.integer "post_id", null: false
t.integer "tag_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
create_table 'post_tags', force: true do |t|
t.integer 'post_id', null: false
t.integer 'tag_id', null: false
t.datetime 'created_at'
t.datetime 'updated_at'
end
add_index "post_tags", ["post_id"], name: "index_post_tags_on_post_id"
add_index "post_tags", ["tag_id"], name: "index_post_tags_on_tag_id"
add_index 'post_tags', ['post_id'], name: 'index_post_tags_on_post_id'
add_index 'post_tags', ['tag_id'], name: 'index_post_tags_on_tag_id'
create_table "posts", force: true do |t|
t.string "title"
t.text "body"
t.integer "author_id"
t.datetime "created_at"
t.datetime "updated_at"
create_table 'posts', force: true do |t|
t.string 'title'
t.text 'body'
t.integer 'author_id'
t.datetime 'created_at'
t.datetime 'updated_at'
end
create_table "tags", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.string "ancestry"
create_table 'tags', force: true do |t|
t.string 'name'
t.datetime 'created_at'
t.datetime 'updated_at'
t.string 'ancestry'
end
add_index "tags", ["ancestry"], name: "index_tags_on_ancestry"
add_index 'tags', ['ancestry'], name: 'index_tags_on_ancestry'
create_table "users", force: true do |t|
t.string "name"
t.string "image_url"
t.datetime "created_at"
t.datetime "updated_at"
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "google_auth_token"
t.string "google_refresh_token"
t.datetime "google_token_expires_at"
create_table 'users', force: true do |t|
t.string 'name'
t.string 'image_url'
t.datetime 'created_at'
t.datetime 'updated_at'
t.string 'email', default: '', null: false
t.string 'encrypted_password', default: '', null: false
t.string 'reset_password_token'
t.datetime 'reset_password_sent_at'
t.datetime 'remember_created_at'
t.integer 'sign_in_count', default: 0, null: false
t.datetime 'current_sign_in_at'
t.datetime 'last_sign_in_at'
t.string 'current_sign_in_ip'
t.string 'last_sign_in_ip'
t.string 'google_auth_token'
t.string 'google_refresh_token'
t.datetime 'google_token_expires_at'
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
add_index 'users', ['email'], name: 'index_users_on_email', unique: true
add_index 'users', ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true
end
......@@ -6,7 +6,6 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
# Tag
_tag_tree = [
......@@ -31,7 +30,7 @@ _tag_tree = [
tags = []
_tag_tree.each do |_parent, _child|
puts "[Seed Tag] #{_parent} => #{_child}"
Rails.logger.debug "[Seed Tag] #{_parent} => #{_child}"
parent = Tag.find_or_create_by(name: _parent) if _parent
child = Tag.find_or_initialize_by(name: _child)
child.parent = parent if _parent
......@@ -39,28 +38,27 @@ _tag_tree.each do |_parent, _child|
tags << child
end
# User
User.find_or_create_by(name: '山田太郎') do |_u|
_u.email = "#{Devise.friendly_token[0,20]}@example.com"
_u.password = Devise.friendly_token[0,20]
_u.email = "#{Devise.friendly_token[0, 20]}@example.com"
_u.password = Devise.friendly_token[0, 20]
end
User.find_or_create_by(name: '鈴木二郎') do |_u|
_u.email = "#{Devise.friendly_token[0,20]}@example.com"
_u.password = Devise.friendly_token[0,20]
_u.email = "#{Devise.friendly_token[0, 20]}@example.com"
_u.password = Devise.friendly_token[0, 20]
end
User.find_or_create_by(name: '田中三郎') do |_u|
_u.email = "#{Devise.friendly_token[0,20]}@example.com"
_u.password = Devise.friendly_token[0,20]
_u.email = "#{Devise.friendly_token[0, 20]}@example.com"
_u.password = Devise.friendly_token[0, 20]
end
# Post
users = User.all
Dir.glob(Rails.root.join('db', 'seeds').to_s + '/*').each do |file_name|
puts "[Post Tag] #{file_name}"
Rails.logger.debug "[Post Tag] #{file_name}"
title = file_name.split('/').last
post = Post.find_or_initialize_by(title: title)
......@@ -69,4 +67,3 @@ Dir.glob(Rails.root.join('db', 'seeds').to_s + '/*').each do |file_name|
post.tags = [tags.sample, tags.sample]
post.save!
end
......@@ -3,29 +3,29 @@ require 'spec_helper'
describe HomeController do
describe "GET 'top'" do
it "should be successful" do
it 'should be successful' do
get :top
expect(response).to be_success
expect(response.code).to eq("200")
expect(response.code).to eq('200')
end
end
describe 'Login' do
before (:each) do
before(:each) do
@user = FactoryGirl.create(:login_user_1)
sign_in @user
end
describe "GET 'top'" do
it "should be successful" do
it 'should be successful' do
get :top
expect(subject).to redirect_to controller: 'posts',
action: 'index'
end
it "should find the right user" do
it 'should find the right user' do
get :top
expect(assigns(:current_user)).to eq(@user)
end
......
FactoryGirl.define do
factory :alice, class: User do
name 'Alice'
email "alice@mail.com"
password Devise.friendly_token[0,20]
email 'alice@mail.com'
password Devise.friendly_token[0, 20]
google_token_expires_at Time.now + 30.minutes
end
factory :bob, class: User do
name 'Bob'
email "bob@mail.com"
password Devise.friendly_token[0,20]
email 'bob@mail.com'
password Devise.friendly_token[0, 20]
google_token_expires_at Time.now - 1.hour
end
......
......@@ -24,102 +24,99 @@ describe User do
describe 'validation' do
before(:each) do
@attr = {
:name => "Example User",
:email => "user@example.com",
:password => "changeme",
:password_confirmation => "changeme"
name: 'Example User',
email: 'user@example.com',
password: 'changeme',
password_confirmation: 'changeme'
}
end
it "should create a new instance given a valid attribute" do
it 'should create a new instance given a valid attribute' do
User.create!(@attr)
end
it "should require an email address" do
no_email_user = User.new(@attr.merge(:email => ""))
it 'should require an email address' do
no_email_user = User.new(@attr.merge(email: ''))
no_email_user.should_not be_valid
end
it "should accept valid email addresses" do
it 'should accept valid email addresses' do
addresses = %w[user@foo.com THE_USER@foo.bar.org first.last@foo.jp]
addresses.each do |address|
valid_email_user = User.new(@attr.merge(:email => address))
valid_email_user = User.new(@attr.merge(email: address))
valid_email_user.should be_valid
end
end
it "should reject invalid email addresses" do
it 'should reject invalid email addresses' do
addresses = %w[user@foo,com user_at_foo.org example.user@foo.]
addresses.each do |address|
invalid_email_user = User.new(@attr.merge(:email => address))
invalid_email_user = User.new(@attr.merge(email: address))
invalid_email_user.should_not be_valid
end
end
it "should reject duplicate email addresses" do
it 'should reject duplicate email addresses' do
User.create!(@attr)
user_with_duplicate_email = User.new(@attr)
user_with_duplicate_email.should_not be_valid
end
it "should reject email addresses identical up to case" do
it 'should reject email addresses identical up to case' do
upcased_email = @attr[:email].upcase
User.create!(@attr.merge(:email => upcased_email))
User.create!(@attr.merge(email: upcased_email))
user_with_duplicate_email = User.new(@attr)
user_with_duplicate_email.should_not be_valid
end
describe "passwords" do
describe 'passwords' do
before(:each) do
@user = User.new(@attr)
end
it "should have a password attribute" do
it 'should have a password attribute' do
@user.should respond_to(:password)
end
it "should have a password confirmation attribute" do
it 'should have a password confirmation attribute' do
@user.should respond_to(:password_confirmation)
end
end
describe "password validations" do
describe 'password validations' do
it "should require a password" do
User.new(@attr.merge(:password => "", :password_confirmation => "")).
should_not be_valid
it 'should require a password' do
User.new(@attr.merge(password: '', password_confirmation: '')).should_not be_valid
end
it "should require a matching password confirmation" do
User.new(@attr.merge(:password_confirmation => "invalid")).
should_not be_valid
it 'should require a matching password confirmation' do
User.new(@attr.merge(password_confirmation: 'invalid')).should_not be_valid
end
it "should reject short passwords" do
short = "a" * 5
hash = @attr.merge(:password => short, :password_confirmation => short)
it 'should reject short passwords' do
short = 'a' * 5
hash = @attr.merge(password: short, password_confirmation: short)
User.new(hash).should_not be_valid
end
end
describe "password encryption" do
describe 'password encryption' do
before(:each) do
@user = User.create!(@attr)
end
it "should have an encrypted password attribute" do
it 'should have an encrypted password attribute' do
@user.should respond_to(:encrypted_password)
end
it "should set the encrypted password attribute" do
it 'should set the encrypted password attribute' do
@user.encrypted_password.should_not be_blank
end
end
end
end
# coveralls
require 'coveralls'
Coveralls.wear!
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# require 'email_spec'
......@@ -14,7 +12,7 @@ require 'factory_girl'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
......@@ -46,16 +44,14 @@ RSpec.configure do |config|
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.order = 'random'
config.include FactoryGirl::Syntax::Methods
# config.include(EmailSpec::Helpers)
# config.include(EmailSpec::Matchers)
config.before(:all) do
FactoryGirl.reload
end
end
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
config.include Devise::TestHelpers, type: :controller
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