Commit 174b1847 by tady

通知view修正

parent e15ce817
......@@ -21,3 +21,5 @@
_.mixin(_.string.exports());
// $('[data-toggle="tooltip"]').tooltip();
// $('[data-toggle="popover"]').popover();
......@@ -26,3 +26,7 @@ a .text-link {
a:visited .text-link {
color: #609;
}
.popover {
max-width: 400px;
}
......@@ -4,5 +4,4 @@ class UserDecorator < Draper::Decorator
def draft_count
model.posts.where(is_draft: true).count
end
end
......@@ -37,6 +37,8 @@ class Comment < ActiveRecord::Base
def notify_watchers!
post.watchers.each do |watcher|
next if watcher == author
watcher.push_notification(post.decorate.show_path, "#{author.name}さんが「#{post.title}」にコメントしました。")
end
end
......
......@@ -122,6 +122,8 @@ class Post < ActiveRecord::Base
def notify_watchers!
watchers.each do |watcher|
next if watcher == author
watcher.push_notification(decorate.show_path, "#{author.name}さんが「#{title}」を編集しました")
end
end
......
......@@ -24,6 +24,11 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
ul.nav.navbar-nav.navbar-right
li
a#notifications data-container="body" data-toggle="popover" data-placement="bottom"
span.glyphicon.glyphicon-flag
- if current_user.notifications.unread.any?
span.badge = current_user.notifications.unread.count
li
form
a.btn.btn-primary.navbar-btn href=new_post_path
| New Post&nbsp;&nbsp;
......@@ -46,21 +51,24 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
li.divider
li
a href=destroy_user_session_path data-method="delete" rel="nofollow" SignOut
li.dropdown
a.dropdown-toggle data-toggle="dropdown"
| 通知
- if current_user.notifications.unread.any?
span.badge = current_user.notifications.unread.count
b.caret
ul.dropdown-menu
script#notification-content type="text/template"
- if current_user.notifications.unread.any?
h4 通知一覧
.list-group
- current_user.notifications.unread.each do |notification|
li
a href=notification_bridge_path(notification.id)
a.list-group-item href=notification_bridge_path(notification.id)
spen.small
| [#{notification.created_at.strftime('%m/%d %H:%M')}]&nbsp;
= notification.body
- else
li
a 通知はありません
h4 通知はありません
- content_for :footer_js do
javascript:
$('#notifications').popover({
html: true,
content: $('#notification-content').html()
});
......@@ -32,6 +32,13 @@ describe Notification do
expect(@bob.notifications.size).to eq(1)
end
it "not notifies on post edited by him" do
@bob.watch!(post: @post)
@post.reload
@post.update!(title: @post.title + ' [New!]', author: @bob)
expect(@bob.notifications.size).to eq(0)
end
it "notifies on post commented" do
@bob.watch!(post: @post)
expect(@bob.watching?(post: @post)).to be_truthy
......@@ -41,6 +48,13 @@ describe Notification do
expect(@bob.notifications.size).to eq(1)
end
it "not notifies on post commented by him" do
@bob.watch!(post: @post)
@post.reload
@post.comments.create!(author: @bob, body: 'new comment')
expect(@bob.notifications.size).to eq(0)
end
it "set watch on user create a new post" do
new_post = Post.create!(author: @bob, title: 'title', body: 'body')
expect(@bob.watching?(post: new_post)).to be_truthy
......
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