diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index ab346e802..99f401f7b 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -1,4 +1,6 @@ class NotificationsController < ApplicationController + include CustomUrlsHelper + before_action :authenticate_user! after_action :mark_as_read, only: :show skip_authorization_check diff --git a/app/helpers/custom_urls_helper.rb b/app/helpers/custom_urls_helper.rb new file mode 100644 index 000000000..1519e771e --- /dev/null +++ b/app/helpers/custom_urls_helper.rb @@ -0,0 +1,9 @@ +module CustomUrlsHelper + def legislation_question_url(question) + legislation_process_question_url(question.process, question) + end + + def legislation_annotation_url(annotation) + legislation_process_question_url(annotation.draft_version.process, annotation.draft_version, annotation) + end +end diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index 5fbc51736..08ba7d3a7 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -1,10 +1,17 @@ require 'rails_helper' feature "Notifications" do + let(:admin_user) { create :user } + let(:administrator) do + create(:administrator, user: admin_user) + admin_user + end let(:author) { create :user } let(:user) { create :user } let(:debate) { create :debate, author: author } let(:proposal) { create :proposal, author: author } + let(:legislation_question) { create(:legislation_question, author: administrator) } + let(:legislation_annotation) { create(:legislation_annotation, author: author) } scenario "User commented on my debate", :js do login_as user @@ -28,6 +35,28 @@ feature "Notifications" do expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']" end + scenario "User commented on my legislation question", :js do + login_as user + visit legislation_process_question_path legislation_question.process, legislation_question + + fill_in "comment-body-legislation_question_#{legislation_question.id}", with: "I answered your question" + click_button "Publish answer" + within "#comments" do + expect(page).to have_content "I answered your question" + end + + logout + login_as administrator + visit root_path + + find(".icon-notification").click + + expect(page).to have_css ".notification", count: 1 + + expect(page).to have_content "Someone commented on" + expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']" + end + scenario "Multiple comments on my proposal", :js do login_as user visit proposal_path proposal