Skip to content

Commit

Permalink
通知view修正
Browse files Browse the repository at this point in the history
  • Loading branch information
tadyjp committed Jul 21, 2014
1 parent e15ce81 commit 174b184
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 16 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -21,3 +21,5 @@

_.mixin(_.string.exports());

// $('[data-toggle="tooltip"]').tooltip();
// $('[data-toggle="popover"]').popover();
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.css
Expand Up @@ -26,3 +26,7 @@ a .text-link {
a:visited .text-link {
color: #609;
}

.popover {
max-width: 400px;
}
1 change: 0 additions & 1 deletion app/decorators/user_decorator.rb
Expand Up @@ -4,5 +4,4 @@ class UserDecorator < Draper::Decorator
def draft_count
model.posts.where(is_draft: true).count
end

end
2 changes: 2 additions & 0 deletions app/models/comment.rb
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/post.rb
Expand Up @@ -122,6 +122,8 @@ def visited_user_count

def notify_watchers!
watchers.each do |watcher|
next if watcher == author

watcher.push_notification(decorate.show_path, "#{author.name}さんが「#{title}」を編集しました")
end
end
Expand Down
38 changes: 23 additions & 15 deletions app/views/partials/_app_header.html.slim
Expand Up @@ -23,6 +23,11 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
| Templates

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
Expand All @@ -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
- if current_user.notifications.unread.any?
- current_user.notifications.unread.each do |notification|
li
a href=notification_bridge_path(notification.id)
= notification.body
- else
li
a 通知はありません

script#notification-content type="text/template"
- if current_user.notifications.unread.any?
h4 通知一覧
.list-group
- current_user.notifications.unread.each do |notification|
a.list-group-item href=notification_bridge_path(notification.id)
spen.small
| [#{notification.created_at.strftime('%m/%d %H:%M')}]&nbsp;
= notification.body
- else
h4 通知はありません

- content_for :footer_js do
javascript:
$('#notifications').popover({
html: true,
content: $('#notification-content').html()
});
14 changes: 14 additions & 0 deletions spec/models/notification_spec.rb
Expand Up @@ -32,6 +32,13 @@
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
Expand All @@ -41,6 +48,13 @@
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
Expand Down

0 comments on commit 174b184

Please sign in to comment.