-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/pull/5535'
- Loading branch information
Showing
17 changed files
with
232 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class ChangesetSubscriptionsController < ApplicationController | ||
layout "site" | ||
|
||
before_action :authorize_web | ||
before_action :set_locale | ||
before_action :check_database_writable | ||
|
||
authorize_resource :class => :changeset_subscription | ||
|
||
around_action :web_timeout | ||
|
||
def show | ||
@changeset = Changeset.find(params[:changeset_id]) | ||
@subscribed = @changeset.subscribed?(current_user) | ||
rescue ActiveRecord::RecordNotFound | ||
render :action => "no_such_entry", :status => :not_found | ||
end | ||
|
||
def create | ||
@changeset = Changeset.find(params[:changeset_id]) | ||
|
||
@changeset.subscribe(current_user) unless @changeset.subscribed?(current_user) | ||
|
||
redirect_to changeset_path(@changeset) | ||
rescue ActiveRecord::RecordNotFound | ||
render :action => "no_such_entry", :status => :not_found | ||
end | ||
|
||
def destroy | ||
@changeset = Changeset.find(params[:changeset_id]) | ||
|
||
@changeset.unsubscribe(current_user) | ||
|
||
redirect_to changeset_path(@changeset) | ||
rescue ActiveRecord::RecordNotFound | ||
render :action => "no_such_entry", :status => :not_found | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% content_for :heading do %> | ||
<h1><%= t ".heading", :id => h(params[:changeset_id]) %></h1> | ||
<% end %> | ||
|
||
<p><%= t ".body", :id => h(params[:changeset_id]) %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<% content_for :heading do %> | ||
<h1><%= @subscribed ? t(".unsubscribe.heading") : t(".subscribe.heading") %></h1> | ||
<% end %> | ||
|
||
<%= render :partial => "heading", :object => @changeset, :as => "changeset" %> | ||
|
||
<%= bootstrap_form_tag :method => (@subscribed ? :delete : :post) do |f| %> | ||
<% if params[:referer] -%> | ||
<%= f.hidden_field :referer, :value => params[:referer] %> | ||
<% end -%> | ||
<%= f.primary @subscribed ? t(".unsubscribe.button") : t(".subscribe.button") %> | ||
<% end %> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
test/controllers/changeset_subscriptions_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
require "test_helper" | ||
|
||
class ChangesetSubscriptionsControllerTest < ActionDispatch::IntegrationTest | ||
## | ||
# test all routes which lead to this controller | ||
def test_routes | ||
assert_routing( | ||
{ :path => "/changeset/1/subscription", :method => :get }, | ||
{ :controller => "changeset_subscriptions", :action => "show", :changeset_id => "1" } | ||
) | ||
assert_routing( | ||
{ :path => "/changeset/1/subscription", :method => :post }, | ||
{ :controller => "changeset_subscriptions", :action => "create", :changeset_id => "1" } | ||
) | ||
assert_routing( | ||
{ :path => "/changeset/1/subscription", :method => :delete }, | ||
{ :controller => "changeset_subscriptions", :action => "destroy", :changeset_id => "1" } | ||
) | ||
|
||
get "/changeset/1/subscribe" | ||
assert_redirected_to "/changeset/1/subscription" | ||
|
||
get "/changeset/1/unsubscribe" | ||
assert_redirected_to "/changeset/1/subscription" | ||
end | ||
|
||
def test_show_as_anonymous | ||
changeset = create(:changeset) | ||
|
||
get changeset_subscription_path(changeset) | ||
assert_redirected_to login_path(:referer => changeset_subscription_path(changeset)) | ||
end | ||
|
||
def test_show_when_not_subscribed | ||
user = create(:user) | ||
other_user = create(:user) | ||
changeset = create(:changeset, :user => user) | ||
|
||
session_for(other_user) | ||
get changeset_subscription_path(changeset) | ||
|
||
assert_response :success | ||
assert_dom ".content-body" do | ||
assert_dom "a[href='#{changeset_path(changeset)}']", :text => "Changeset #{changeset.id}" | ||
assert_dom "a[href='#{user_path(user)}']", :text => user.display_name | ||
assert_dom "form" do | ||
assert_dom "> @action", changeset_subscription_path(changeset) | ||
assert_dom "input[type=submit]" do | ||
assert_dom "> @value", "Subscribe to discussion" | ||
end | ||
end | ||
end | ||
end | ||
|
||
def test_show_when_subscribed | ||
user = create(:user) | ||
other_user = create(:user) | ||
changeset = create(:changeset, :user => user) | ||
changeset.subscribers << other_user | ||
|
||
session_for(other_user) | ||
get changeset_subscription_path(changeset) | ||
|
||
assert_response :success | ||
assert_dom ".content-body" do | ||
assert_dom "a[href='#{changeset_path(changeset)}']", :text => "Changeset #{changeset.id}" | ||
assert_dom "a[href='#{user_path(user)}']", :text => user.display_name | ||
assert_dom "form" do | ||
assert_dom "> @action", changeset_subscription_path(changeset) | ||
assert_dom "input[type=submit]" do | ||
assert_dom "> @value", "Unsubscribe from discussion" | ||
end | ||
end | ||
end | ||
end | ||
|
||
def test_create_success | ||
user = create(:user) | ||
other_user = create(:user) | ||
changeset = create(:changeset, :user => user) | ||
|
||
session_for(other_user) | ||
assert_difference "changeset.subscribers.count", 1 do | ||
post changeset_subscription_path(changeset) | ||
end | ||
assert_redirected_to changeset_path(changeset) | ||
assert changeset.reload.subscribed?(other_user) | ||
end | ||
|
||
def test_create_fail | ||
user = create(:user) | ||
other_user = create(:user) | ||
changeset = create(:changeset, :user => user) | ||
changeset.subscribers << other_user | ||
|
||
# not signed in | ||
assert_no_difference "changeset.subscribers.count" do | ||
post changeset_subscription_path(changeset) | ||
end | ||
assert_response :forbidden | ||
|
||
session_for(other_user) | ||
|
||
# bad diary id | ||
post changeset_subscription_path(999111) | ||
assert_response :not_found | ||
|
||
# trying to subscribe when already subscribed | ||
assert_no_difference "changeset.subscribers.count" do | ||
post changeset_subscription_path(changeset) | ||
end | ||
end | ||
|
||
def test_destroy_success | ||
user = create(:user) | ||
other_user = create(:user) | ||
changeset = create(:changeset, :user => user) | ||
changeset.subscribers << other_user | ||
|
||
session_for(other_user) | ||
assert_difference "changeset.subscribers.count", -1 do | ||
delete changeset_subscription_path(changeset) | ||
end | ||
assert_redirected_to changeset_path(changeset) | ||
assert_not changeset.reload.subscribed?(other_user) | ||
end | ||
|
||
def test_unsubscribe_fail | ||
user = create(:user) | ||
other_user = create(:user) | ||
changeset = create(:changeset, :user => user) | ||
|
||
# not signed in | ||
assert_no_difference "changeset.subscribers.count" do | ||
delete changeset_subscription_path(changeset) | ||
end | ||
assert_response :forbidden | ||
|
||
session_for(other_user) | ||
|
||
# bad diary id | ||
delete changeset_subscription_path(999111) | ||
assert_response :not_found | ||
|
||
# trying to unsubscribe when not subscribed | ||
assert_no_difference "changeset.subscribers.count" do | ||
delete changeset_subscription_path(changeset) | ||
end | ||
end | ||
end |
Oops, something went wrong.