Merge branch 'pr/745' into dev

This commit is contained in:
Miles Gould
2015-06-16 19:54:33 +01:00
11 changed files with 67 additions and 37 deletions

View File

@@ -56,4 +56,4 @@ submit the change with your pull request.
- Savant Krishna / [sksavant](https://github.com/sksavant)
- Jake Yesbeck / [yez](https://github.com/yez)
- Mauricio Gonzalez / [mauricio-gonzalez](https://github.com/mauricio-gonzalez)
- Andrey Bazhutkin / [andrba](https://github.com/andrba)

View File

@@ -36,6 +36,21 @@ class NotificationsController < ApplicationController
end
end
# GET /notifications/1/reply
def reply
@notification = Notification.new
@sender_notification = Notification.find(params[:id])
@recipient = @sender_notification.sender
@subject = @sender_notification.subject =~ /^Re: / ?
@sender_notification.subject :
"Re: " + @sender_notification.subject
respond_to do |format|
format.html # reply.html.haml
end
end
# DELETE /notifications/1
def destroy
@notification = Notification.find(params[:id])

View File

@@ -5,12 +5,7 @@ module NotificationsHelper
new_comment_url(:post_id => notification.post.id)
else
# by default, reply link sends a PM in return
new_notification_url(
:recipient_id => notification.sender.id,
:subject => notification.subject =~ /^Re: / ?
notification.subject :
"Re: " + notification.subject
)
reply_notification_url(notification)
end
end
end

View File

@@ -46,6 +46,7 @@ class Ability
# can read/delete notifications that were sent to them
can :read, Notification, :recipient_id => member.id
can :destroy, Notification, :recipient_id => member.id
can :reply, Notification, :recipient_id => member.id
# can send a private message to anyone but themselves
# note: sadly, we can't test for this from the view, but it works
# for the model/controller

View File

@@ -0,0 +1,13 @@
%p
From
= link_to notification.sender, notification.sender
on
= notification.created_at
- if notification.post_id
in response to:
= link_to notification.post.subject, notification.post
.well
:growstuff_markdown
#{ strip_tags(notification.body) }

View File

@@ -0,0 +1,6 @@
= content_for :title, "Send a message to #{@recipient}"
= render @sender_notification
=render 'form'

View File

@@ -1,18 +1,6 @@
= content_for :title, @notification.subject
%p
From
= link_to @notification.sender, @notification.sender
on
= @notification.created_at
- if @notification.post_id
in response to:
= link_to @notification.post.subject, @notification.post
.well
:growstuff_markdown
#{ strip_tags(@notification.body) }
= render @notification
%p
=link_to 'Delete', @notification, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default'

View File

@@ -41,7 +41,9 @@ Growstuff::Application.routes.draw do
resources :comments
resources :roles
resources :forums
resources :notifications
resources :notifications do
get 'reply', on: :member
end
resources :follows, :only => [:create, :destroy]
get '/members/:login_name/follows' => 'members#view_follows', :as => 'member_follows'

View File

@@ -60,18 +60,6 @@ describe NotificationsController do
assigns(:notification).should eq(notification)
end
it "assigns the reply link for a PM" do
notification = FactoryGirl.create(:notification, :recipient_id => subject.current_member.id, :post_id => nil)
subject = "Re: " + notification.subject
get :show, {:id => notification.to_param}
assigns(:reply_link).should_not be_nil
assigns(:reply_link).should eq new_notification_url(
:recipient_id => notification.sender_id,
:subject => subject
)
end
it "assigns the reply link for a post comment" do
notification = FactoryGirl.create(:notification, :recipient_id => subject.current_member.id)

View File

@@ -0,0 +1,25 @@
require 'rails_helper'
feature "Notifications", :js => true do
let(:sender) { FactoryGirl.create(:member) }
let(:recipient) { FactoryGirl.create(:member) }
context "On existing notification" do
let!(:notification) { FactoryGirl.create(:notification, sender: sender, recipient: recipient, body: "Notification body", :post_id => nil) }
background do
login_as(recipient)
visit notification_path(notification)
end
scenario "Replying to the notification" do
click_link "Reply"
expect(page).to have_content "Notification body"
fill_in 'notification_body', with: "Response body"
click_button "Send"
expect(page).to have_content "Message was successfully sent"
end
end
end

View File

@@ -13,10 +13,7 @@ describe NotificationsHelper do
link = helper.reply_link(notification)
link.should_not be_nil
link.should eq new_notification_url(
:recipient_id => notification.sender_id,
:subject => subject
)
link.should eq reply_notification_url(notification)
end
it "replies to post comments with post comments" do