]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5533'
authorTom Hughes <tom@compton.nu>
Wed, 22 Jan 2025 18:11:48 +0000 (18:11 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 22 Jan 2025 18:11:48 +0000 (18:11 +0000)
21 files changed:
.rubocop_todo.yml
app/abilities/ability.rb
app/assets/javascripts/osm.js.erb
app/controllers/changeset_subscriptions_controller.rb [new file with mode: 0644]
app/controllers/changesets_controller.rb
app/controllers/traces_controller.rb
app/controllers/user_blocks_controller.rb
app/mailers/user_mailer.rb
app/views/changeset_subscriptions/_heading.html.erb [moved from app/views/changesets/_heading.html.erb with 100% similarity]
app/views/changeset_subscriptions/no_such_entry.html.erb [new file with mode: 0644]
app/views/changeset_subscriptions/show.html.erb [new file with mode: 0644]
app/views/changesets/no_such_entry.html.erb [deleted file]
app/views/changesets/subscribe.html.erb [deleted file]
app/views/changesets/unsubscribe.html.erb [deleted file]
app/views/user_mailer/changeset_comment_notification.html.erb
app/views/user_mailer/changeset_comment_notification.text.erb
config/locales/en.yml
config/routes.rb
test/controllers/changeset_subscriptions_controller_test.rb [new file with mode: 0644]
test/controllers/changesets_controller_test.rb
test/mailers/user_mailer_test.rb

index fa15ea90a0d5a1ba00019d93f94bc52a157a7fda..3d7cea500fec5826176e028bf5e13d19ec0ae79a 100644 (file)
@@ -106,19 +106,6 @@ Minitest/EmptyLineBeforeAssertionMethods:
 Minitest/MultipleAssertions:
   Max: 60
 
-# Offense count: 10
-# This cop supports unsafe autocorrection (--autocorrect-all).
-Rails/ActionControllerFlashBeforeRender:
-  Exclude:
-    - 'app/controllers/application_controller.rb'
-    - 'app/controllers/confirmations_controller.rb'
-    - 'app/controllers/issue_comments_controller.rb'
-    - 'app/controllers/messages_controller.rb'
-    - 'app/controllers/passwords_controller.rb'
-    - 'app/controllers/traces_controller.rb'
-    - 'app/controllers/user_blocks_controller.rb'
-    - 'app/controllers/users_controller.rb'
-
 # Offense count: 2
 # Configuration parameters: Include.
 # Include: app/models/**/*.rb
index 3ba2ab7071cf763a5fe37b50e277aa7914ab1a47..d4172bfd16470ea9091123c72591161bd0dfcfca 100644 (file)
@@ -32,7 +32,7 @@ class Ability
       can :read, [:deletion, :account_terms]
 
       if Settings.status != "database_offline"
-        can [:subscribe, :unsubscribe], Changeset
+        can [:read, :create, :destroy], :changeset_subscription
         can [:read, :create, :update, :destroy], :oauth2_application
         can [:read, :destroy], :oauth2_authorized_application
         can [:read, :create, :destroy], :oauth2_authorization
index e9c09c79f9ae995575030ad9231167c64983f974..3edd9b451d3decc9c88d19435f43655badd7b335 100644 (file)
@@ -80,7 +80,7 @@ OSM = {
   },
 
   mapParams: function (search) {
-    var params = OSM.params(search), mapParams = {}, loc, match;
+    var params = OSM.params(search), mapParams = {}, match;
 
     if (params.mlon && params.mlat) {
       mapParams.marker = true;
@@ -101,6 +101,8 @@ OSM = {
 
     var hash = OSM.parseHash(location.hash);
 
+    const loc = Cookies.get('_osm_location')?.split("|");
+
     // Decide on a map starting position. Various ways of doing this.
     if (hash.center) {
       mapParams.lon = hash.center.lng;
@@ -119,8 +121,7 @@ OSM = {
       mapParams.lon = parseFloat(params.mlon);
       mapParams.lat = parseFloat(params.mlat);
       mapParams.zoom = parseInt(params.zoom || 12);
-    } else if (loc = Cookies.get('_osm_location')) {
-      loc = loc.split("|");
+    } else if (loc) {
       mapParams.lon = parseFloat(loc[0]);
       mapParams.lat = parseFloat(loc[1]);
       mapParams.zoom = parseInt(loc[2]);
diff --git a/app/controllers/changeset_subscriptions_controller.rb b/app/controllers/changeset_subscriptions_controller.rb
new file mode 100644 (file)
index 0000000..6e0ad52
--- /dev/null
@@ -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
index aa9d81343a1c61764bb8637d3b4d7e7a6421a080..d5ac49d4ccc04dafa68534158470872c3132f3b9 100644 (file)
@@ -7,9 +7,8 @@ class ChangesetsController < ApplicationController
 
   before_action :authorize_web
   before_action :set_locale
-  before_action -> { check_database_readable(:need_api => true) }, :only => [:index, :feed, :show]
+  before_action -> { check_database_readable(:need_api => true) }
   before_action :require_oauth, :only => :show
-  before_action :check_database_writable, :only => [:subscribe, :unsubscribe]
 
   authorize_resource
 
@@ -107,34 +106,6 @@ class ChangesetsController < ApplicationController
     render :template => "browse/not_found", :status => :not_found, :layout => map_layout
   end
 
-  ##
-  # subscribe to a changeset
-  def subscribe
-    @changeset = Changeset.find(params[:id])
-
-    if request.post?
-      @changeset.subscribe(current_user) unless @changeset.subscribed?(current_user)
-
-      redirect_to changeset_path(@changeset)
-    end
-  rescue ActiveRecord::RecordNotFound
-    render :action => "no_such_entry", :status => :not_found
-  end
-
-  ##
-  # unsubscribe from a changeset
-  def unsubscribe
-    @changeset = Changeset.find(params[:id])
-
-    if request.post?
-      @changeset.unsubscribe(current_user)
-
-      redirect_to changeset_path(@changeset)
-    end
-  rescue ActiveRecord::RecordNotFound
-    render :action => "no_such_entry", :status => :not_found
-  end
-
   private
 
   #------------------------------------------------------------
index 14648dc9c37eea68d78bb9b255ede055cbca15c1..075b5a8649493bc216ba3b84faa6e56df0af015c 100644 (file)
@@ -116,7 +116,7 @@ class TracesController < ApplicationController
         @trace.schedule_import
         redirect_to :action => :index, :display_name => current_user.display_name
       else
-        flash[:error] = t(".upload_failed") if @trace.valid?
+        flash.now[:error] = t(".upload_failed") if @trace.valid?
 
         render :action => "new"
       end
index a526f529e9e1fb2da92e982708106898e56b9e46..ec85aef38407be690f68781f02626bf2643a1626 100644 (file)
@@ -37,7 +37,7 @@ class UserBlocksController < ApplicationController
   end
 
   def new
-    @user_block = UserBlock.new
+    @user_block = UserBlock.new(:needs_view => true)
   end
 
   def edit
index 6098162852039a0078c927b7fce5b717e681196c..e466b694a76f204ec23d6334f3a480dc037680e0 100644 (file)
@@ -177,7 +177,7 @@ class UserMailer < ApplicationMailer
       @changeset_comment = comment.changeset.tags["comment"].presence
       @time = comment.created_at
       @changeset_author = comment.changeset.user.display_name
-      @unsubscribe_url = unsubscribe_changeset_url(comment.changeset)
+      @changeset_subscription_url = changeset_subscription_url(comment.changeset)
       @author = @commenter
 
       subject = if @owner
@@ -193,8 +193,8 @@ class UserMailer < ApplicationMailer
       set_list_headers(
         "#{comment.changeset.id}.changeset.www.openstreetmap.org",
         t(".description", :id => comment.changeset.id),
-        :subscribe => subscribe_changeset_url(comment.changeset),
-        :unsubscribe => @unsubscribe_url,
+        :subscribe => @changeset_subscription_url,
+        :unsubscribe => @changeset_subscription_url,
         :archive => @changeset_url
       )
 
diff --git a/app/views/changeset_subscriptions/no_such_entry.html.erb b/app/views/changeset_subscriptions/no_such_entry.html.erb
new file mode 100644 (file)
index 0000000..ff7d98f
--- /dev/null
@@ -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>
diff --git a/app/views/changeset_subscriptions/show.html.erb b/app/views/changeset_subscriptions/show.html.erb
new file mode 100644 (file)
index 0000000..e3ddb73
--- /dev/null
@@ -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 %>
diff --git a/app/views/changesets/no_such_entry.html.erb b/app/views/changesets/no_such_entry.html.erb
deleted file mode 100644 (file)
index da7d185..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<% content_for :heading do %>
-  <h1><%= t ".heading", :id => h(params[:id]) %></h1>
-<% end %>
-
-<p><%= t ".body", :id => h(params[:id]) %></p>
diff --git a/app/views/changesets/subscribe.html.erb b/app/views/changesets/subscribe.html.erb
deleted file mode 100644 (file)
index 6a65e5f..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<% content_for :heading do %>
-  <h1><%= t ".heading" %></h1>
-<% end %>
-
-<%= render :partial => "heading", :object => @changeset, :as => "changeset" %>
-
-<%= bootstrap_form_tag do |f| %>
-  <% if params[:referer] -%>
-  <%= f.hidden_field :referer, :value => params[:referer] %>
-  <% end -%>
-  <%= f.primary t(".button") %>
-<% end %>
diff --git a/app/views/changesets/unsubscribe.html.erb b/app/views/changesets/unsubscribe.html.erb
deleted file mode 100644 (file)
index 6a65e5f..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<% content_for :heading do %>
-  <h1><%= t ".heading" %></h1>
-<% end %>
-
-<%= render :partial => "heading", :object => @changeset, :as => "changeset" %>
-
-<%= bootstrap_form_tag do |f| %>
-  <% if params[:referer] -%>
-  <%= f.hidden_field :referer, :value => params[:referer] %>
-  <% end -%>
-  <%= f.primary t(".button") %>
-<% end %>
index efba71eb651d47a865a9b99059fbb347e8881fe2..d0f27a1438445cab94d9f8140b0e6d7402b490dc 100644 (file)
@@ -24,6 +24,6 @@
 
 <% content_for :footer do %>
   <p>
-    <%= t ".unsubscribe_html", :url => link_to(@unsubscribe_url, @unsubscribe_url) %>
+    <%= t ".unsubscribe_html", :url => link_to(@changeset_subscription_url, @changeset_subscription_url) %>
   </p>
 <% end %>
index 8c0727583a717552655460944dd7389b64aca07a..91278a3c17959a9e6f970a83178abb398ed6fa38 100644 (file)
@@ -17,4 +17,4 @@
 
 <%= t '.details', :url => @changeset_url %>
 
-<%= t '.unsubscribe', :url => @unsubscribe_url %>
+<%= t '.unsubscribe', :url => @changeset_subscription_url %>
index 50c9cc754da25a053298903e39272b3e9f4697d0..a7125a3a7d5c8602597b14d29604bdf2fba3ec01 100644 (file)
@@ -484,18 +484,6 @@ en:
         created: "Created"
         closed: "Closed"
         belongs_to: "Author"
-    subscribe:
-      heading: Subscribe to the following changeset discussion?
-      button: Subscribe to discussion
-    unsubscribe:
-      heading: Unsubscribe from the following changeset discussion?
-      button: Unsubscribe from discussion
-    heading:
-      title: "Changeset %{id}"
-      created_by_html: "Created by %{link_user} on %{created}."
-    no_such_entry:
-      heading: "No entry with the id: %{id}"
-      body: "Sorry, there is no changeset with the id %{id}. Please check your spelling, or maybe the link you clicked is wrong."
     show:
       title: "Changeset: %{id}"
       created: "Created: %{when}"
@@ -527,6 +515,20 @@ en:
       sorry: "Sorry, changeset #%{id} could not be found."
     timeout:
       sorry: "Sorry, the list of changesets you requested took too long to retrieve."
+  changeset_subscriptions:
+    show:
+      subscribe:
+        heading: Subscribe to the following changeset discussion?
+        button: Subscribe to discussion
+      unsubscribe:
+        heading: Unsubscribe from the following changeset discussion?
+        button: Unsubscribe from discussion
+    heading:
+      title: "Changeset %{id}"
+      created_by_html: "Created by %{link_user} on %{created}."
+    no_such_entry:
+      heading: "No entry with the id: %{id}"
+      body: "Sorry, there is no changeset with the id %{id}. Please check your spelling, or maybe the link you clicked is wrong."
   dashboards:
     contact:
       km away: "%{count}km away"
index 242423996f5687e75b13ac1cdb05f9c62f21accf..dae870a0768d005425cbe4c5f65af2f1119e7ff0 100644 (file)
@@ -124,14 +124,16 @@ OpenStreetMap::Application.routes.draw do
   get "/relation/:id" => "relations#show", :id => /\d+/, :as => :relation
   get "/relation/:id/history" => "old_relations#index", :id => /\d+/, :as => :relation_history
   resources :old_relations, :path => "/relation/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
-  resources :changesets, :path => "changeset", :id => /\d+/, :only => :show do
-    match :subscribe, :on => :member, :via => [:get, :post]
-    match :unsubscribe, :on => :member, :via => [:get, :post]
 
+  resources :changesets, :path => "changeset", :id => /\d+/, :only => :show do
+    resource :subscription, :controller => :changeset_subscriptions, :only => [:show, :create, :destroy]
     namespace :changeset_comments, :as => :comments, :path => :comments do
       resource :feed, :only => :show, :defaults => { :format => "rss" }
     end
   end
+  get "/changeset/:id/subscribe", :id => /\d+/, :to => redirect(:path => "/changeset/%{id}/subscription")
+  get "/changeset/:id/unsubscribe", :id => /\d+/, :to => redirect(:path => "/changeset/%{id}/subscription")
+
   resources :notes, :path => "note", :id => /\d+/, :only => [:show, :new]
 
   get "/user/:display_name/history" => "changesets#index"
diff --git a/test/controllers/changeset_subscriptions_controller_test.rb b/test/controllers/changeset_subscriptions_controller_test.rb
new file mode 100644 (file)
index 0000000..7d899ac
--- /dev/null
@@ -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
index 9bbca2ab170c7e0cfecd8b2536d8e96c446cb12a..2e701f248ae0863a7cce1af500125e36e953a30e 100644 (file)
@@ -32,22 +32,6 @@ class ChangesetsControllerTest < ActionDispatch::IntegrationTest
       { :path => "/history/feed", :method => :get },
       { :controller => "changesets", :action => "feed", :format => :atom }
     )
-    assert_routing(
-      { :path => "/changeset/1/subscribe", :method => :get },
-      { :controller => "changesets", :action => "subscribe", :id => "1" }
-    )
-    assert_routing(
-      { :path => "/changeset/1/subscribe", :method => :post },
-      { :controller => "changesets", :action => "subscribe", :id => "1" }
-    )
-    assert_routing(
-      { :path => "/changeset/1/unsubscribe", :method => :get },
-      { :controller => "changesets", :action => "unsubscribe", :id => "1" }
-    )
-    assert_routing(
-      { :path => "/changeset/1/unsubscribe", :method => :post },
-      { :controller => "changesets", :action => "unsubscribe", :id => "1" }
-    )
   end
 
   ##
@@ -432,119 +416,6 @@ class ChangesetsControllerTest < ActionDispatch::IntegrationTest
     assert_redirected_to :action => :feed
   end
 
-  def test_subscribe_page
-    user = create(:user)
-    other_user = create(:user)
-    changeset = create(:changeset, :user => user)
-    path = subscribe_changeset_path(changeset)
-
-    get path
-    assert_redirected_to login_path(:referer => path)
-
-    session_for(other_user)
-    get path
-    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
-    end
-  end
-
-  def test_subscribe_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 subscribe_changeset_path(changeset)
-    end
-    assert_redirected_to changeset_path(changeset)
-    assert changeset.reload.subscribed?(other_user)
-  end
-
-  def test_subscribe_fail
-    user = create(:user)
-    other_user = create(:user)
-
-    changeset = create(:changeset, :user => user)
-
-    # not signed in
-    assert_no_difference "changeset.subscribers.count" do
-      post subscribe_changeset_path(changeset)
-    end
-    assert_response :forbidden
-
-    session_for(other_user)
-
-    # bad diary id
-    post subscribe_changeset_path(999111)
-    assert_response :not_found
-
-    # trying to subscribe when already subscribed
-    post subscribe_changeset_path(changeset)
-    assert_no_difference "changeset.subscribers.count" do
-      post subscribe_changeset_path(changeset)
-    end
-  end
-
-  def test_unsubscribe_page
-    user = create(:user)
-    other_user = create(:user)
-    changeset = create(:changeset, :user => user)
-    path = unsubscribe_changeset_path(changeset)
-
-    get path
-    assert_redirected_to login_path(:referer => path)
-
-    session_for(other_user)
-    get path
-    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
-    end
-  end
-
-  def test_unsubscribe_success
-    user = create(:user)
-    other_user = create(:user)
-
-    changeset = create(:changeset, :user => user)
-    changeset.subscribers.push(other_user)
-
-    session_for(other_user)
-    assert_difference "changeset.subscribers.count", -1 do
-      post unsubscribe_changeset_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
-      post unsubscribe_changeset_path(changeset)
-    end
-    assert_response :forbidden
-
-    session_for(other_user)
-
-    # bad diary id
-    post unsubscribe_changeset_path(999111)
-    assert_response :not_found
-
-    # trying to unsubscribe when not subscribed
-    assert_no_difference "changeset.subscribers.count" do
-      post unsubscribe_changeset_path(changeset)
-    end
-  end
-
   private
 
   ##
index 3b7119ff645ae467a2f29e06ad25d44c4ec5e260..9b895c4758ef72485dd314941e3e49a6e1671e83 100644 (file)
@@ -83,7 +83,7 @@ class UserMailerTest < ActionMailer::TestCase
     body = Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body)
 
     url = Rails.application.routes.url_helpers.changeset_url(changeset, :host => Settings.server_url, :protocol => Settings.server_protocol)
-    unsubscribe_url = Rails.application.routes.url_helpers.unsubscribe_changeset_url(changeset, :host => Settings.server_url, :protocol => Settings.server_protocol)
+    unsubscribe_url = Rails.application.routes.url_helpers.changeset_subscription_url(changeset, :host => Settings.server_url, :protocol => Settings.server_protocol)
     assert_select body, "a[href^='#{url}']"
     assert_select body, "a[href='#{unsubscribe_url}']", :count => 1
   end