destroy notifications when marked as read
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe NotificationsController do
|
||||
|
||||
describe "#index" do
|
||||
let(:user) { create :user }
|
||||
|
||||
it "mark all notifications as read" do
|
||||
notifications = [create(:notification, user: user), create(:notification, user: user)]
|
||||
Notification.all.each do |notification|
|
||||
expect(notification.read).to be false
|
||||
end
|
||||
|
||||
sign_in user
|
||||
get :index
|
||||
Notification.all.each do |notification|
|
||||
expect(notification.read).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -21,10 +21,10 @@ feature "Notifications" do
|
||||
expect(page).to have_xpath "//a[@class='with_notifications' and @href='#{notifications_path}' and text()='Notificaciones']"
|
||||
|
||||
click_link "Notificaciones"
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
expect(page).to have_content user.username
|
||||
expect(page).to have_content I18n.t("comments.notifications.commented_on_your_debate")
|
||||
expect(page).to_not have_content I18n.t("comments.notifications.replied_to_your_comment")
|
||||
expect(page).to have_link debate.title, href: debate_path(debate)
|
||||
expect(page).to have_content "commented on your debate"
|
||||
expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']"
|
||||
end
|
||||
|
||||
scenario "User replied to my comment", :js do
|
||||
@@ -48,10 +48,10 @@ feature "Notifications" do
|
||||
expect(page).to have_xpath "//a[@class='with_notifications' and @href='#{notifications_path}' and text()='Notificaciones']"
|
||||
|
||||
visit notifications_path
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
expect(page).to have_content user.username
|
||||
expect(page).to have_content I18n.t("comments.notifications.replied_to_your_comment")
|
||||
expect(page).to_not have_content I18n.t("comments.notifications.commented_on_your_debate")
|
||||
expect(page).to have_link debate.title, href: debate_path(debate)
|
||||
expect(page).to have_content "replied to your comment on"
|
||||
expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']"
|
||||
end
|
||||
|
||||
scenario "Author commented on his own debate", :js do
|
||||
@@ -66,10 +66,7 @@ feature "Notifications" do
|
||||
expect(page).to have_xpath "//a[@class='without_notifications' and @href='#{notifications_path}' and text()='Notificaciones']"
|
||||
|
||||
click_link "Notificaciones"
|
||||
expect(page).to_not have_content user.username
|
||||
expect(page).to_not have_content I18n.t("comments.notifications.commented_on_your_debate")
|
||||
expect(page).to_not have_content I18n.t("comments.notifications.replied_to_your_comment")
|
||||
expect(page).to_not have_link debate.title, href: debate_path(debate)
|
||||
expect(page).to have_css ".notification", count: 0
|
||||
end
|
||||
|
||||
scenario "Author replied to his own comment", :js do
|
||||
@@ -89,9 +86,47 @@ feature "Notifications" do
|
||||
expect(page).to have_xpath "//a[@class='without_notifications' and @href='#{notifications_path}' and text()='Notificaciones']"
|
||||
|
||||
visit notifications_path
|
||||
expect(page).to_not have_content user.username
|
||||
expect(page).to_not have_content I18n.t("comments.notifications.replied_to_your_comment")
|
||||
expect(page).to_not have_content I18n.t("comments.notifications.commented_on_your_debate")
|
||||
expect(page).to_not have_link debate.title, href: debate_path(debate)
|
||||
expect(page).to have_css ".notification", count: 0
|
||||
end
|
||||
|
||||
context "mark as read" do
|
||||
|
||||
scenario "mark a single notification as read" do
|
||||
user = create :user
|
||||
notification = create :notification, user: user
|
||||
|
||||
login_as user
|
||||
visit notifications_path
|
||||
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
|
||||
first(".notification a").click
|
||||
visit notifications_path
|
||||
|
||||
expect(page).to have_css ".notification", count: 0
|
||||
end
|
||||
|
||||
scenario "mark all notifications as read" do
|
||||
user = create :user
|
||||
2.times { create :notification, user: user }
|
||||
|
||||
login_as user
|
||||
visit notifications_path
|
||||
|
||||
expect(page).to have_css ".notification", count: 2
|
||||
click_link "Mark all as read"
|
||||
|
||||
expect(page).to have_css ".notification", count: 0
|
||||
expect(current_path).to eq(notifications_path)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
scenario "no notifications" do
|
||||
login_as user
|
||||
visit notifications_path
|
||||
|
||||
expect(page).to have_content "There are no new notifications"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'rails_helper'
|
||||
|
||||
describe NotificationsHelper do
|
||||
|
||||
describe "#notification_text_for" do
|
||||
describe "#notification_action" do
|
||||
let(:debate) { create :debate }
|
||||
let(:debate_comment) { create :comment, commentable: debate }
|
||||
let(:comment_reply) { create :comment, commentable: debate, parent: debate_comment }
|
||||
@@ -10,14 +10,14 @@ describe NotificationsHelper do
|
||||
context "when action was comment on a debate" do
|
||||
it "returns correct text when someone comments on your debate" do
|
||||
notification = create :notification, notifiable: debate_comment
|
||||
expect(notification_text_for(notification)).to eq "commented on your debate"
|
||||
expect(notification_action(notification)).to eq "commented_on_your_debate"
|
||||
end
|
||||
end
|
||||
|
||||
context "when action was comment on a debate" do
|
||||
it "returns correct text when someone replies to your comment" do
|
||||
notification = create :notification, notifiable: comment_reply
|
||||
expect(notification_text_for(notification)).to eq "replied to your comment on"
|
||||
expect(notification_action(notification)).to eq "replied_to_your_comment"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -25,20 +25,13 @@ describe NotificationsHelper do
|
||||
describe "#notifications_class_for" do
|
||||
let(:user) { create :user }
|
||||
|
||||
context "when user doesn't have any notification" do
|
||||
context "when user doesn't have notifications" do
|
||||
it "returns class 'without_notifications'" do
|
||||
expect(notifications_class_for(user)).to eq "without_notifications"
|
||||
end
|
||||
end
|
||||
|
||||
context "when user doesn't have unread notifications" do
|
||||
it "returns class 'without_notifications'" do
|
||||
notification = create :notification, user: user, read: true
|
||||
expect(notifications_class_for(user)).to eq "without_notifications"
|
||||
end
|
||||
end
|
||||
|
||||
context "when user has unread notifications" do
|
||||
context "when user has notifications" do
|
||||
it "returns class 'with_notifications'" do
|
||||
notification = create :notification, user: user
|
||||
expect(notifications_class_for(user)).to eq "with_notifications"
|
||||
|
||||
@@ -4,12 +4,8 @@ describe Notification do
|
||||
|
||||
describe "#unread (scope)" do
|
||||
it "returns only unread notifications" do
|
||||
unread_notification = create :notification
|
||||
read_notification = create :notification, read: true
|
||||
|
||||
unread_notifications = Notification.unread
|
||||
expect(unread_notifications.size).to be 1
|
||||
expect(unread_notifications.first).to eq unread_notification
|
||||
2.times { create :notification }
|
||||
expect(Notification.unread.size).to be 2
|
||||
end
|
||||
end
|
||||
|
||||
@@ -42,12 +38,12 @@ describe Notification do
|
||||
end
|
||||
|
||||
describe "#mark_as_read" do
|
||||
it "set up read flag to true" do
|
||||
it "destroys notification" do
|
||||
notification = create :notification
|
||||
expect(notification.read).to be false
|
||||
expect(Notification.unread.size).to eq 1
|
||||
|
||||
notification.mark_as_read!
|
||||
expect(notification.read).to be true
|
||||
notification.mark_as_read
|
||||
expect(Notification.unread.size).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user