Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Merge branch 'pr/745' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Miles Gould committed Jun 16, 2015
2 parents 7cedd98 + 4cb3444 commit 5bb04dc
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 15 additions & 0 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ def new
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])
Expand Down
7 changes: 1 addition & 6 deletions app/helpers/notifications_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ def reply_link(notification)
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
1 change: 1 addition & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def initialize(member)
# 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
Expand Down
13 changes: 13 additions & 0 deletions app/views/notifications/_notification.html.haml
Original file line number Diff line number Diff line change
@@ -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) }
6 changes: 6 additions & 0 deletions app/views/notifications/reply.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
= content_for :title, "Send a message to #{@recipient}"

= render @sender_notification

=render 'form'

14 changes: 1 addition & 13 deletions app/views/notifications/show.html.haml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
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'
Expand Down
12 changes: 0 additions & 12 deletions spec/controllers/notifications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ def valid_session
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)

Expand Down
25 changes: 25 additions & 0 deletions spec/features/notifications_spec.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 1 addition & 4 deletions spec/helpers/notifications_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@

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
Expand Down

0 comments on commit 5bb04dc

Please sign in to comment.