Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rendezvous
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
VeNtura
rendezvous
Commits
e15ce817
Commit
e15ce817
authored
Jul 21, 2014
by
tady
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notification spec
parent
0f79b838
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
75 additions
and
45 deletions
+75
-45
app/models/comment.rb
+14
-4
app/models/post.rb
+17
-2
app/models/tag.rb
+0
-3
app/models/user.rb
+0
-4
spec/controllers/concerns/rv/mailer_spec.rb
+1
-1
spec/factories/posts.rb
+1
-1
spec/factories/users.rb
+5
-5
spec/models/notification_spec.rb
+24
-15
spec/models/post_spec.rb
+8
-6
spec/models/tag_spec.rb
+4
-3
spec/models/user_spec.rb
+1
-1
No files found.
app/models/comment.rb
View file @
e15ce817
...
@@ -11,11 +11,14 @@
...
@@ -11,11 +11,14 @@
#
#
class
Comment
<
ActiveRecord
::
Base
class
Comment
<
ActiveRecord
::
Base
######################################################################
# Associations
######################################################################
belongs_to
:author
,
class_name:
'User'
belongs_to
:author
,
class_name:
'User'
belongs_to
:post
belongs_to
:post
######################################################################
######################################################################
#
v
alidations
#
V
alidations
######################################################################
######################################################################
validates
:author_id
,
presence:
true
validates
:author_id
,
presence:
true
validates
:post_id
,
presence:
true
validates
:post_id
,
presence:
true
...
@@ -24,14 +27,21 @@ class Comment < ActiveRecord::Base
...
@@ -24,14 +27,21 @@ class Comment < ActiveRecord::Base
######################################################################
######################################################################
# Callback
# Callback
######################################################################
######################################################################
after_save
:notify_author
after_save
:set_watcher!
after_save
:notify_watchers!
######################################################################
######################################################################
# Instance method
# Instance method
######################################################################
######################################################################
private
private
def
notify_author
def
notify_watchers!
post
.
author
.
push_notification
(
post
.
decorate
.
show_path
,
"
#{
author
.
name
}
さんがあなたの投稿にコメントしました"
)
post
.
watchers
.
each
do
|
watcher
|
watcher
.
push_notification
(
post
.
decorate
.
show_path
,
"
#{
author
.
name
}
さんが「
#{
post
.
title
}
」にコメントしました。"
)
end
end
def
set_watcher!
author
.
watch!
(
post:
post
)
end
end
end
end
app/models/post.rb
View file @
e15ce817
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
require
'date'
require
'date'
class
Post
<
ActiveRecord
::
Base
class
Post
<
ActiveRecord
::
Base
######################################################################
# Associations
######################################################################
has_many
:post_tags
has_many
:post_tags
has_many
:tags
,
through: :post_tags
has_many
:tags
,
through: :post_tags
belongs_to
:author
,
class_name:
'User'
belongs_to
:author
,
class_name:
'User'
...
@@ -34,7 +37,8 @@ class Post < ActiveRecord::Base
...
@@ -34,7 +37,8 @@ class Post < ActiveRecord::Base
######################################################################
######################################################################
# Callback
# Callback
######################################################################
######################################################################
after_save
:notify_watchers
after_save
:set_watcher!
after_save
:notify_watchers!
######################################################################
######################################################################
# Named scope
# Named scope
...
@@ -107,11 +111,22 @@ class Post < ActiveRecord::Base
...
@@ -107,11 +111,22 @@ class Post < ActiveRecord::Base
footprints
.
select
(
:user_id
).
uniq
.
count
footprints
.
select
(
:user_id
).
uniq
.
count
end
end
# FIXME:
# has_many :watchers, :through => :watches
# 正常に動作しないため動作しないため一時的にメソッドを作成
# def watchers
# watches.map { |watch| watch.watcher }
# end
private
private
def
notify_watchers
def
notify_watchers
!
watchers
.
each
do
|
watcher
|
watchers
.
each
do
|
watcher
|
watcher
.
push_notification
(
decorate
.
show_path
,
"
#{
author
.
name
}
さんが「
#{
title
}
」を編集しました"
)
watcher
.
push_notification
(
decorate
.
show_path
,
"
#{
author
.
name
}
さんが「
#{
title
}
」を編集しました"
)
end
end
end
end
def
set_watcher!
author
.
watch!
(
post:
self
)
end
end
end
app/models/tag.rb
View file @
e15ce817
...
@@ -15,9 +15,6 @@ class Tag < ActiveRecord::Base
...
@@ -15,9 +15,6 @@ class Tag < ActiveRecord::Base
has_many
:post_tags
has_many
:post_tags
has_many
:posts
,
through: :post_tags
has_many
:posts
,
through: :post_tags
has_many
:watches
,
:as
=>
:watchable
,
:dependent
=>
:destroy
has_many
:watchers
,
:through
=>
:watches
# for tree structure
# for tree structure
has_ancestry
has_ancestry
...
...
app/models/user.rb
View file @
e15ce817
...
@@ -40,12 +40,8 @@ class User < ActiveRecord::Base
...
@@ -40,12 +40,8 @@ class User < ActiveRecord::Base
has_many
:notifications
has_many
:notifications
has_many
:footprints
has_many
:footprints
has_many
:watches
,
:as
=>
:watchable
,
:dependent
=>
:destroy
has_many
:watchers
,
:through
=>
:watches
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"
# has_many :watchings, :as => :resource
######################################################################
######################################################################
# scope
# scope
...
...
spec/controllers/concerns/rv/mailer_spec.rb
View file @
e15ce817
...
@@ -6,7 +6,7 @@ describe RV::Mailer do
...
@@ -6,7 +6,7 @@ describe RV::Mailer do
let
(
:klass
)
{
DummyClass
.
new
.
extend
(
RV
::
Mailer
)
}
let
(
:klass
)
{
DummyClass
.
new
.
extend
(
RV
::
Mailer
)
}
let
(
:alice
)
{
FactoryGirl
.
create
(
:alice
)
}
let
(
:alice
)
{
FactoryGirl
.
create
(
:alice
)
}
let
(
:post
)
{
Post
.
create
title:
'ruby rspec'
,
body:
'This is first espec test: ruby'
}
let
(
:post
)
{
Post
.
create
title:
'ruby rspec'
,
body:
'This is first espec test: ruby'
,
author:
create
(
:author
)
}
it
'valid'
do
it
'valid'
do
expect
{
klass
.
compose_mail
(
post
,
user:
alice
,
to:
'dummy@example.com'
)
}.
not_to
raise_error
expect
{
klass
.
compose_mail
(
post
,
user:
alice
,
to:
'dummy@example.com'
)
}.
not_to
raise_error
...
...
spec/factories/posts.rb
View file @
e15ce817
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:post
do
factory
:post
do
association
:author
,
factory: :a
crelice
association
:author
,
factory: :a
uthor
title
'sample title'
title
'sample title'
body
'sample body'
body
'sample body'
specified_date
Date
.
new
(
2014
,
4
,
1
)
specified_date
Date
.
new
(
2014
,
4
,
1
)
...
...
spec/factories/users.rb
View file @
e15ce817
...
@@ -40,12 +40,12 @@ FactoryGirl.define do
...
@@ -40,12 +40,12 @@ FactoryGirl.define do
google_token_expires_at
Time
.
now
-
1
.
hour
google_token_expires_at
Time
.
now
-
1
.
hour
end
end
factory
:
charley
,
class:
User
do
factory
:
author
,
class:
User
do
name
'
Charley
'
name
'
Author
'
email
'
charley
@mail.com'
email
'
author
@mail.com'
nickname
'
charley
'
nickname
'
author
'
password
Devise
.
friendly_token
[
0
,
20
]
password
Devise
.
friendly_token
[
0
,
20
]
google_token_expires_at
Time
.
now
-
1
.
hour
google_token_expires_at
Time
.
now
-
30
.
hour
end
end
factory
:login_user_1
,
class:
User
do
factory
:login_user_1
,
class:
User
do
...
...
spec/models/notification_spec.rb
View file @
e15ce817
...
@@ -16,35 +16,44 @@ require 'rails_helper'
...
@@ -16,35 +16,44 @@ require 'rails_helper'
describe
Notification
do
describe
Notification
do
describe
'Instance method'
do
describe
'Instance method'
do
let
(
:bob
)
{
create
(
:bob
)
}
let
(
:charley
)
{
create
(
:charley
)
}
before
:each
do
let
(
:post
)
{
create
(
:post
)
}
@alice
=
create
(
:alice
)
@bob
=
create
(
:bob
)
@post
=
create
(
:post
)
end
it
"notifies on post edited"
do
it
"notifies on post edited"
do
bob
.
watch!
(
post:
post
)
@bob
.
watch!
(
post:
@post
)
post
.
update!
(
title:
post
.
title
+
' [New!]'
)
expect
(
@bob
.
watching?
(
post:
@post
)).
to
be_truthy
expect
(
bob
.
notifications
.
size
).
to
eq
(
1
)
@post
.
reload
expect
(
@post
.
watchers
).
to
include
(
@bob
)
@post
.
update!
(
title:
@post
.
title
+
' [New!]'
)
expect
(
@bob
.
notifications
.
size
).
to
eq
(
1
)
end
end
it
"notifies on post commented"
do
it
"notifies on post commented"
do
bob
.
watch!
(
post:
post
)
@bob
.
watch!
(
post:
@post
)
post
.
comments
.
build
(
comment_params
.
merge
(
author:
charley
))
expect
(
@bob
.
watching?
(
post:
@post
)).
to
be_truthy
expect
(
bob
.
notifications
.
size
).
to
eq
(
1
)
@post
.
reload
expect
(
@post
.
watchers
).
to
include
(
@bob
)
@post
.
comments
.
create!
(
author:
@alice
,
body:
'new comment'
)
expect
(
@bob
.
notifications
.
size
).
to
eq
(
1
)
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:
new_
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
.
build
(
comment_params
.
merge
(
author:
bob
)
)
@post
.
comments
.
create!
(
author:
@bob
,
body:
'new comment'
)
expect
(
bob
.
watching?
(
post:
new_
post
)).
to
be_truthy
expect
(
@bob
.
watching?
(
post:
@
post
)).
to
be_truthy
end
end
end
end
end
end
spec/models/post_spec.rb
View file @
e15ce817
...
@@ -57,10 +57,11 @@ describe Post do
...
@@ -57,10 +57,11 @@ describe Post do
describe
'scope :search'
do
describe
'scope :search'
do
before
:each
do
before
:each
do
@alice
=
create
(
:alice
)
@alice
=
create
(
:alice
)
@post1
=
Post
.
create
id:
1001
,
title:
'ruby rspec'
,
body:
'This is first espec test: ruby'
@author
=
create
(
:author
)
@post2
=
Post
.
create
id:
1002
,
title:
'php test'
,
body:
'PHP is very easy'
,
author_id:
@alice
.
id
@post1
=
Post
.
create
id:
1001
,
author:
@alice
,
title:
'ruby rspec'
,
body:
'This is first espec test: ruby'
@post3
=
Post
.
create
id:
1003
,
title:
'java java...'
,
body:
'Java is not ruby...'
,
updated_at:
Time
.
new
(
1989
,
2
,
25
,
5
,
30
,
0
)
@post2
=
Post
.
create
id:
1002
,
author:
@alice
,
title:
'php test'
,
body:
'PHP is very easy'
@post4
=
Post
.
create
id:
1004
,
title:
'about ruby TDD'
,
body:
'test is the best ....'
,
is_draft:
true
@post3
=
Post
.
create
id:
1003
,
author:
@author
,
title:
'java java...'
,
body:
'Java is not ruby...'
,
updated_at:
Time
.
new
(
1989
,
2
,
25
,
5
,
30
,
0
)
@post4
=
Post
.
create
id:
1004
,
author:
@author
,
title:
'about ruby TDD'
,
body:
'test is the best ....'
,
is_draft:
true
@tag_java
=
Tag
.
create
(
name:
'java'
)
@tag_java
=
Tag
.
create
(
name:
'java'
)
@post3
.
tags
<<
@tag_java
@post3
.
tags
<<
@tag_java
end
end
...
@@ -81,7 +82,7 @@ describe Post do
...
@@ -81,7 +82,7 @@ describe Post do
end
end
it
'by @<author_name>'
do
it
'by @<author_name>'
do
expect
(
Post
.
search
(
'@Alice'
).
size
).
to
eq
(
1
)
expect
(
Post
.
search
(
'@Alice'
).
size
).
to
eq
(
2
)
expect
(
Post
.
search
(
'@Alice'
)).
to
include
(
@post2
)
expect
(
Post
.
search
(
'@Alice'
)).
to
include
(
@post2
)
end
end
...
@@ -116,10 +117,11 @@ describe Post do
...
@@ -116,10 +117,11 @@ describe Post do
it
do
it
do
@post
.
watchers
<<
@bob
@post
.
watchers
<<
@bob
@post
.
reload
expect
(
@bob
.
watching_posts
.
size
).
to
eq
(
1
)
expect
(
@bob
.
watching_posts
.
size
).
to
eq
(
1
)
expect
(
@bob
.
notifications
.
size
).
to
eq
(
0
)
expect
(
@bob
.
notifications
.
size
).
to
eq
(
0
)
@post
.
update!
(
title:
@post
.
title
+
'+'
)
@post
.
update!
(
title:
@post
.
title
+
'+'
)
@bob
.
reload
expect
(
@bob
.
notifications
.
size
).
to
eq
(
1
)
expect
(
@bob
.
notifications
.
size
).
to
eq
(
1
)
end
end
end
end
...
...
spec/models/tag_spec.rb
View file @
e15ce817
...
@@ -18,9 +18,10 @@ describe Tag do
...
@@ -18,9 +18,10 @@ describe Tag do
before
:each
do
before
:each
do
@tag_ruby
=
Tag
.
create
(
name:
'ruby'
)
@tag_ruby
=
Tag
.
create
(
name:
'ruby'
)
@tag_java
=
Tag
.
create
(
name:
'java'
)
@tag_java
=
Tag
.
create
(
name:
'java'
)
@post1
=
Post
.
create
id:
1001
,
title:
'ruby rspec'
,
body:
'hoge'
,
tags:
[
@tag_ruby
]
@author
=
create
(
:author
)
@post2
=
Post
.
create
id:
1002
,
title:
'ruby is better than java'
,
body:
'hoge'
,
tags:
[
@tag_ruby
,
@tag_java
]
@post1
=
Post
.
create
id:
1001
,
author:
@author
,
title:
'ruby rspec'
,
body:
'hoge'
,
tags:
[
@tag_ruby
]
@post3
=
Post
.
create
id:
1003
,
title:
'java java...'
,
body:
'hoge'
,
tags:
[
@tag_java
]
@post2
=
Post
.
create
id:
1002
,
author:
@author
,
title:
'ruby is better than java'
,
body:
'hoge'
,
tags:
[
@tag_ruby
,
@tag_java
]
@post3
=
Post
.
create
id:
1003
,
author:
@author
,
title:
'java java...'
,
body:
'hoge'
,
tags:
[
@tag_java
]
end
end
it
'successfully moved'
do
it
'successfully moved'
do
...
...
spec/models/user_spec.rb
View file @
e15ce817
...
@@ -29,8 +29,8 @@ describe User do
...
@@ -29,8 +29,8 @@ describe User do
describe
'Instance method'
do
describe
'Instance method'
do
let
(
:alice
)
{
create
(
:alice
)
}
let
(
:bob
)
{
create
(
:bob
)
}
let
(
:bob
)
{
create
(
:bob
)
}
let
(
:alice
)
{
create
(
:alice
)
}
let
(
:post
)
{
create
(
:post
)
}
let
(
:post
)
{
create
(
:post
)
}
describe
'#google_oauth_token_expired?'
do
describe
'#google_oauth_token_expired?'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment