]> git.openstreetmap.org Git - rails.git/commitdiff
Move element history actions to old element controllers
authorAnton Khorev <tony29@yandex.ru>
Thu, 14 Mar 2024 15:10:18 +0000 (18:10 +0300)
committerAnton Khorev <tony29@yandex.ru>
Thu, 14 Mar 2024 15:10:18 +0000 (18:10 +0300)
13 files changed:
app/abilities/ability.rb
app/controllers/browse_controller.rb
app/controllers/old_nodes_controller.rb
app/controllers/old_relations_controller.rb
app/controllers/old_ways_controller.rb
app/views/browse/_version_actions.erb
app/views/browse/feature.html.erb
app/views/browse/history.html.erb
config/routes.rb
test/controllers/browse_controller_test.rb
test/controllers/old_nodes_controller_test.rb
test/controllers/old_relations_controller_test.rb
test/controllers/old_ways_controller_test.rb

index ef4c0a778dc487dcadf7a5b014340599869d2c7d..3802fb8261b2dcab357ee362fb2ec595c2af680d 100644 (file)
@@ -4,10 +4,8 @@ class Ability
   include CanCan::Ability
 
   def initialize(user)
-    can [:relation, :relation_history, :way, :way_history, :node, :node_history, :query], :browse
-    can [:show], OldNode
-    can [:show], OldWay
-    can [:show], OldRelation
+    can [:relation, :way, :node, :query], :browse
+    can [:index, :show], [OldNode, OldWay, OldRelation]
     can [:show, :new], Note
     can :search, :direction
     can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site
index db291f6eb89a8fc5900cd8c4da953f987473c55e..f69acc158e7ab5ae350ff4e69da442c8c9d29e08 100644 (file)
@@ -6,7 +6,6 @@ class BrowseController < ApplicationController
   before_action -> { check_database_readable(:need_api => true) }
   before_action :require_oauth
   before_action :update_totp, :only => [:query]
-  before_action :require_moderator_for_unredacted_history, :only => [:relation_history, :way_history, :node_history]
   around_action :web_timeout
   authorize_resource :class => false
 
@@ -18,14 +17,6 @@ class BrowseController < ApplicationController
     render :action => "not_found", :status => :not_found
   end
 
-  def relation_history
-    @type = "relation"
-    @feature = Relation.preload(:relation_tags, :old_relations => [:old_tags, { :changeset => [:changeset_tags, :user], :old_members => :member }]).find(params[:id])
-    render "history"
-  rescue ActiveRecord::RecordNotFound
-    render :action => "not_found", :status => :not_found
-  end
-
   def way
     @type = "way"
     @feature = Way.preload(:way_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :nodes => [:node_tags, { :ways => :way_tags }]).find(params[:id])
@@ -34,14 +25,6 @@ class BrowseController < ApplicationController
     render :action => "not_found", :status => :not_found
   end
 
-  def way_history
-    @type = "way"
-    @feature = Way.preload(:way_tags, :old_ways => [:old_tags, { :changeset => [:changeset_tags, :user], :old_nodes => { :node => [:node_tags, :ways] } }]).find(params[:id])
-    render "history"
-  rescue ActiveRecord::RecordNotFound
-    render :action => "not_found", :status => :not_found
-  end
-
   def node
     @type = "node"
     @feature = Node.preload(:node_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :ways => :way_tags).find(params[:id])
@@ -50,19 +33,5 @@ class BrowseController < ApplicationController
     render :action => "not_found", :status => :not_found
   end
 
-  def node_history
-    @type = "node"
-    @feature = Node.preload(:node_tags, :old_nodes => [:old_tags, { :changeset => [:changeset_tags, :user] }]).find(params[:id])
-    render "history"
-  rescue ActiveRecord::RecordNotFound
-    render :action => "not_found", :status => :not_found
-  end
-
   def query; end
-
-  private
-
-  def require_moderator_for_unredacted_history
-    deny_access(nil) if params[:show_redactions] && !current_user&.moderator?
-  end
 end
index 9ef2ef881671550281858e5d8d967760646eb456..596b579673649c4bcd806c628dd8a8218a8344ed 100644 (file)
@@ -11,6 +11,14 @@ class OldNodesController < ApplicationController
   before_action :require_moderator_for_unredacted_history
   around_action :web_timeout
 
+  def index
+    @type = "node"
+    @feature = Node.preload(:node_tags, :old_nodes => [:old_tags, { :changeset => [:changeset_tags, :user] }]).find(params[:id])
+    render "browse/history"
+  rescue ActiveRecord::RecordNotFound
+    render "browse/not_found", :status => :not_found
+  end
+
   def show
     @type = "node"
     @feature = OldNode.preload(:old_tags, :changeset => [:changeset_tags, :user]).find([params[:id], params[:version]])
index b9e151a4fd8b9cc702bf753bc700efcb60528afc..d57cf25fe070dc3d3a278650ede0c2d049c67e89 100644 (file)
@@ -11,6 +11,14 @@ class OldRelationsController < ApplicationController
   before_action :require_moderator_for_unredacted_history
   around_action :web_timeout
 
+  def index
+    @type = "relation"
+    @feature = Relation.preload(:relation_tags, :old_relations => [:old_tags, { :changeset => [:changeset_tags, :user], :old_members => :member }]).find(params[:id])
+    render "browse/history"
+  rescue ActiveRecord::RecordNotFound
+    render "browse/not_found", :status => :not_found
+  end
+
   def show
     @type = "relation"
     @feature = OldRelation.preload(:old_tags, :changeset => [:changeset_tags, :user], :old_members => :member).find([params[:id], params[:version]])
index dd3c3279fd41fa54928bbe13362da0e7468e2055..de60de317fde2ed5c89e5e6d675b51e545d69ebe 100644 (file)
@@ -11,6 +11,14 @@ class OldWaysController < ApplicationController
   before_action :require_moderator_for_unredacted_history
   around_action :web_timeout
 
+  def index
+    @type = "way"
+    @feature = Way.preload(:way_tags, :old_ways => [:old_tags, { :changeset => [:changeset_tags, :user], :old_nodes => { :node => [:node_tags, :ways] } }]).find(params[:id])
+    render "browse/history"
+  rescue ActiveRecord::RecordNotFound
+    render "browse/not_found", :status => :not_found
+  end
+
   def show
     @type = "way"
     @feature = OldWay.preload(:old_tags, :changeset => [:changeset_tags, :user], :old_nodes => { :node => [:node_tags, :ways] }).find([params[:id], params[:version]])
index 3d4e4be13ea8acf3d8de8577828ce8b463af1f43..63cadeb3fab9e82a8dd7bb8dc67484d47af95d0d 100644 (file)
@@ -21,7 +21,7 @@
     <% end %>
     &middot;
   <% end %>
-  <%= link_to t("browse.view_history"), :controller => :browse, :action => "#{@type}_history" %>
+  <%= link_to t("browse.view_history"), :action => :index %>
   <% unless @feature.latest_version? %>
     &middot;
     <%= link_to({ :version => @feature.version + 1 }, { :class => "icon-link" }) do %>
index 9ee9f807fb1899f395b2bd0fd9529209bd6ee050..7f96b74b9873f6561db7011c0a1f13c76cca4b68 100644 (file)
     <% end %>
     &middot;
   <% end %>
-    <%= link_to t("browse.view_history"), :action => "#{@type}_history" %>
+    <%= link_to t("browse.view_history"), :controller => "old_#{@type.pluralize}" %>
   <% if current_user&.moderator? %>
     &middot;
-    <%= link_to(t("browse.view_unredacted_history"), :action => "#{@type}_history", :params => { :show_redactions => true }) %>
+    <%= link_to(t("browse.view_unredacted_history"), :controller => "old_#{@type.pluralize}", :params => { :show_redactions => true }) %>
   <% end %>
   <% if @feature.version > 1 %>
     &middot;
index b557c339b172a9eb5e1c66f5df9e0b961f3f859f..d257d25a2dc9ad896972ceb9657672eafd0ed538 100644 (file)
@@ -2,17 +2,17 @@
 
 <%= render "sidebar_header", :title => t("browse.#{@type}.history_title_html", :name => printable_element_name(@feature)) %>
 
-<%= render :partial => @type, :collection => @feature.send(:"old_#{@type}s").reverse %>
+<%= render :partial => "browse/#{@type}", :collection => @feature.send(:"old_#{@type}s").reverse %>
 
 <div class='secondary-actions'>
-  <%= link_to(t("browse.download_xml"), :controller => "api/old_#{@type.pluralize}", :action => "history") %>
+  <%= link_to t("browse.download_xml"), :controller => "api/old_#{@type.pluralize}", :action => "history" %>
   &middot;
-  <%= link_to(t("browse.view_details"), :action => @type) %>
+  <%= link_to t("browse.view_details"), :controller => "browse", :action => @type %>
   <% if params[:show_redactions] %>
     &middot;
-    <%= link_to(t("browse.view_history"), :action => "#{@type}_history") %>
+    <%= link_to t("browse.view_history") %>
   <% elsif current_user&.moderator? %>
     &middot;
-    <%= link_to(t("browse.view_unredacted_history"), :action => "#{@type}_history", :params => { :show_redactions => true }) %>
+    <%= link_to t("browse.view_unredacted_history"), :params => { :show_redactions => true } %>
   <% end %>
 </div>
index 842da82b3dc770198f2b79974e4f24018a22fed5..819baf65a910f5830b4e4e4c86ae595d6bb6a9d0 100644 (file)
@@ -110,13 +110,13 @@ OpenStreetMap::Application.routes.draw do
 
   # Data browsing
   get "/way/:id" => "browse#way", :id => /\d+/, :as => :way
-  get "/way/:id/history" => "browse#way_history", :id => /\d+/, :as => :way_history
+  get "/way/:id/history" => "old_ways#index", :id => /\d+/, :as => :way_history
   resources :old_ways, :path => "/way/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
   get "/node/:id" => "browse#node", :id => /\d+/, :as => :node
-  get "/node/:id/history" => "browse#node_history", :id => /\d+/, :as => :node_history
+  get "/node/:id/history" => "old_nodes#index", :id => /\d+/, :as => :node_history
   resources :old_nodes, :path => "/node/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
   get "/relation/:id" => "browse#relation", :id => /\d+/, :as => :relation
-  get "/relation/:id/history" => "browse#relation_history", :id => /\d+/, :as => :relation_history
+  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
   get "/changeset/:id/comments/feed" => "changeset_comments#index", :as => :changeset_comments_feed, :id => /\d*/, :defaults => { :format => "rss" }
index fcdd7c752163136e1a6f8eaa650aecb94feb80d0..4bdad7a4d0803f7e762200096270d09905799b73 100644 (file)
@@ -8,26 +8,14 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest
       { :path => "/node/1", :method => :get },
       { :controller => "browse", :action => "node", :id => "1" }
     )
-    assert_routing(
-      { :path => "/node/1/history", :method => :get },
-      { :controller => "browse", :action => "node_history", :id => "1" }
-    )
     assert_routing(
       { :path => "/way/1", :method => :get },
       { :controller => "browse", :action => "way", :id => "1" }
     )
-    assert_routing(
-      { :path => "/way/1/history", :method => :get },
-      { :controller => "browse", :action => "way_history", :id => "1" }
-    )
     assert_routing(
       { :path => "/relation/1", :method => :get },
       { :controller => "browse", :action => "relation", :id => "1" }
     )
-    assert_routing(
-      { :path => "/relation/1/history", :method => :get },
-      { :controller => "browse", :action => "relation_history", :id => "1" }
-    )
     assert_routing(
       { :path => "/query", :method => :get },
       { :controller => "browse", :action => "query" }
@@ -53,14 +41,6 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest
     assert_select ".secondary-actions a[href='#{old_relation_path relation, 2}']", :count => 1
   end
 
-  def test_read_relation_history
-    relation = create(:relation, :with_history)
-    sidebar_browse_check :relation_history_path, relation.id, "browse/history"
-    assert_select "h4", /^Version/ do
-      assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
-    end
-  end
-
   def test_read_way
     way = create(:way)
     sidebar_browse_check :way_path, way.id, "browse/feature"
@@ -80,14 +60,6 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest
     assert_select ".secondary-actions a[href='#{old_way_path way, 2}']", :count => 1
   end
 
-  def test_read_way_history
-    way = create(:way, :with_history)
-    sidebar_browse_check :way_history_path, way.id, "browse/history"
-    assert_select "h4", /^Version/ do
-      assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
-    end
-  end
-
   def test_read_node
     node = create(:node)
     sidebar_browse_check :node_path, node.id, "browse/feature"
@@ -116,14 +88,6 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest
     assert_select "a[href='#{api_node_path node}']", :count => 0
   end
 
-  def test_read_node_history
-    node = create(:node, :with_history)
-    sidebar_browse_check :node_history_path, node.id, "browse/history"
-    assert_select "h4", /^Version/ do
-      assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
-    end
-  end
-
   ##
   #  Methods to check redaction.
   #
@@ -148,109 +112,6 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest
     assert_select ".browse-section.browse-node .longitude", 0
   end
 
-  def test_redacted_node_history
-    node = create(:node, :with_history, :deleted, :version => 2)
-    node_v1 = node.old_nodes.find_by(:version => 1)
-    node_v1.redact!(create(:redaction))
-
-    get node_history_path(:id => node)
-    assert_response :success
-    assert_template "browse/history"
-
-    # there are 2 revisions of the redacted node, but only one
-    # should be showing details here.
-    assert_select ".browse-section", 2
-    assert_select ".browse-section.browse-redacted", 1
-    assert_select ".browse-section.browse-node", 1
-    assert_select ".browse-section.browse-node .latitude", 0
-    assert_select ".browse-section.browse-node .longitude", 0
-  end
-
-  def test_redacted_node_unredacted_history
-    session_for(create(:moderator_user))
-    node = create(:node, :with_history, :deleted, :version => 2)
-    node_v1 = node.old_nodes.find_by(:version => 1)
-    node_v1.redact!(create(:redaction))
-
-    get node_history_path(:id => node, :params => { :show_redactions => true })
-    assert_response :success
-    assert_template "browse/history"
-
-    assert_select ".browse-section", 2
-    assert_select ".browse-section.browse-redacted", 0
-    assert_select ".browse-section.browse-node", 2
-  end
-
-  def test_redacted_way_history
-    way = create(:way, :with_history, :version => 4)
-    way_v1 = way.old_ways.find_by(:version => 1)
-    way_v1.redact!(create(:redaction))
-    way_v3 = way.old_ways.find_by(:version => 3)
-    way_v3.redact!(create(:redaction))
-
-    get way_history_path(:id => way)
-    assert_response :success
-    assert_template "browse/history"
-
-    # there are 4 revisions of the redacted way, but only 2
-    # should be showing details here.
-    assert_select ".browse-section", 4
-    assert_select ".browse-section.browse-redacted", 2
-    assert_select ".browse-section.browse-way", 2
-  end
-
-  def test_redacted_way_unredacted_history
-    session_for(create(:moderator_user))
-    way = create(:way, :with_history, :version => 4)
-    way_v1 = way.old_ways.find_by(:version => 1)
-    way_v1.redact!(create(:redaction))
-    way_v3 = way.old_ways.find_by(:version => 3)
-    way_v3.redact!(create(:redaction))
-
-    get way_history_path(:id => way, :params => { :show_redactions => true })
-    assert_response :success
-    assert_template "browse/history"
-
-    assert_select ".browse-section", 4
-    assert_select ".browse-section.browse-redacted", 0
-    assert_select ".browse-section.browse-way", 4
-  end
-
-  def test_redacted_relation_history
-    relation = create(:relation, :with_history, :version => 4)
-    relation_v1 = relation.old_relations.find_by(:version => 1)
-    relation_v1.redact!(create(:redaction))
-    relation_v3 = relation.old_relations.find_by(:version => 3)
-    relation_v3.redact!(create(:redaction))
-
-    get relation_history_path(:id => relation)
-    assert_response :success
-    assert_template "browse/history"
-
-    # there are 4 revisions of the redacted relation, but only 2
-    # should be showing details here.
-    assert_select ".browse-section", 4
-    assert_select ".browse-section.browse-redacted", 2
-    assert_select ".browse-section.browse-relation", 2
-  end
-
-  def test_redacted_relation_unredacted_history
-    session_for(create(:moderator_user))
-    relation = create(:relation, :with_history, :version => 4)
-    relation_v1 = relation.old_relations.find_by(:version => 1)
-    relation_v1.redact!(create(:redaction))
-    relation_v3 = relation.old_relations.find_by(:version => 3)
-    relation_v3.redact!(create(:redaction))
-
-    get relation_history_path(:id => relation, :params => { :show_redactions => true })
-    assert_response :success
-    assert_template "browse/history"
-
-    assert_select ".browse-section", 4
-    assert_select ".browse-section.browse-redacted", 0
-    assert_select ".browse-section.browse-relation", 4
-  end
-
   def test_query
     get query_path
     assert_response :success
@@ -285,56 +146,4 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest
     assert_select ".secondary-actions a", :text => "View History", :count => 1
     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
   end
-
-  def test_anonymous_user_history_page_secondary_actions
-    node = create(:node, :with_history)
-    get node_history_path(:id => node)
-    assert_response :success
-    assert_select ".secondary-actions a", :text => "View Details", :count => 1
-    assert_select ".secondary-actions a", :text => "View History", :count => 0
-    assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
-  end
-
-  def test_regular_user_history_page_secondary_actions
-    session_for(create(:user))
-    node = create(:node, :with_history)
-    get node_history_path(:id => node)
-    assert_response :success
-    assert_select ".secondary-actions a", :text => "View Details", :count => 1
-    assert_select ".secondary-actions a", :text => "View History", :count => 0
-    assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
-  end
-
-  def test_moderator_user_history_page_secondary_actions
-    session_for(create(:moderator_user))
-    node = create(:node, :with_history)
-    get node_history_path(:id => node)
-    assert_response :success
-    assert_select ".secondary-actions a", :text => "View Details", :count => 1
-    assert_select ".secondary-actions a", :text => "View History", :count => 0
-    assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
-  end
-
-  def test_anonymous_user_unredacted_history_page_secondary_actions
-    node = create(:node, :with_history)
-    get node_history_path(:id => node, :params => { :show_redactions => true })
-    assert_response :redirect
-  end
-
-  def test_regular_user_unredacted_history_page_secondary_actions
-    session_for(create(:user))
-    node = create(:node, :with_history)
-    get node_history_path(:id => node, :params => { :show_redactions => true })
-    assert_response :redirect
-  end
-
-  def test_moderator_user_unredacted_history_page_secondary_actions
-    session_for(create(:moderator_user))
-    node = create(:node, :with_history)
-    get node_history_path(:id => node, :params => { :show_redactions => true })
-    assert_response :success
-    assert_select ".secondary-actions a", :text => "View Details", :count => 1
-    assert_select ".secondary-actions a", :text => "View History", :count => 1
-    assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
-  end
 end
index 81a98766abebfca4e6e22609620f78d351cc3fe1..bb4dffdc6e74636fd8c118e9bcc8207ceb7c775a 100644 (file)
@@ -2,12 +2,109 @@ require "test_helper"
 
 class OldNodesControllerTest < ActionDispatch::IntegrationTest
   def test_routes
+    assert_routing(
+      { :path => "/node/1/history", :method => :get },
+      { :controller => "old_nodes", :action => "index", :id => "1" }
+    )
     assert_routing(
       { :path => "/node/1/history/2", :method => :get },
       { :controller => "old_nodes", :action => "show", :id => "1", :version => "2" }
     )
   end
 
+  def test_history
+    node = create(:node, :with_history)
+    sidebar_browse_check :node_history_path, node.id, "browse/history"
+    assert_select "h4", /^Version/ do
+      assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
+    end
+  end
+
+  def test_history_of_redacted
+    node = create(:node, :with_history, :deleted, :version => 2)
+    node_v1 = node.old_nodes.find_by(:version => 1)
+    node_v1.redact!(create(:redaction))
+
+    get node_history_path(:id => node)
+    assert_response :success
+    assert_template "browse/history"
+
+    # there are 2 revisions of the redacted node, but only one
+    # should be showing details here.
+    assert_select ".browse-section", 2
+    assert_select ".browse-section.browse-redacted", 1
+    assert_select ".browse-section.browse-node", 1
+    assert_select ".browse-section.browse-node .latitude", 0
+    assert_select ".browse-section.browse-node .longitude", 0
+  end
+
+  def test_unredacted_history_of_redacted
+    session_for(create(:moderator_user))
+    node = create(:node, :with_history, :deleted, :version => 2)
+    node_v1 = node.old_nodes.find_by(:version => 1)
+    node_v1.redact!(create(:redaction))
+
+    get node_history_path(:id => node, :params => { :show_redactions => true })
+    assert_response :success
+    assert_template "browse/history"
+
+    assert_select ".browse-section", 2
+    assert_select ".browse-section.browse-redacted", 0
+    assert_select ".browse-section.browse-node", 2
+  end
+
+  def test_anonymous_user_history_page_secondary_actions
+    node = create(:node, :with_history)
+    get node_history_path(:id => node)
+    assert_response :success
+    assert_select ".secondary-actions a", :text => "View Details", :count => 1
+    assert_select ".secondary-actions a", :text => "View History", :count => 0
+    assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
+  end
+
+  def test_regular_user_history_page_secondary_actions
+    session_for(create(:user))
+    node = create(:node, :with_history)
+    get node_history_path(:id => node)
+    assert_response :success
+    assert_select ".secondary-actions a", :text => "View Details", :count => 1
+    assert_select ".secondary-actions a", :text => "View History", :count => 0
+    assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
+  end
+
+  def test_moderator_user_history_page_secondary_actions
+    session_for(create(:moderator_user))
+    node = create(:node, :with_history)
+    get node_history_path(:id => node)
+    assert_response :success
+    assert_select ".secondary-actions a", :text => "View Details", :count => 1
+    assert_select ".secondary-actions a", :text => "View History", :count => 0
+    assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
+  end
+
+  def test_anonymous_user_unredacted_history_page_secondary_actions
+    node = create(:node, :with_history)
+    get node_history_path(:id => node, :params => { :show_redactions => true })
+    assert_response :redirect
+  end
+
+  def test_regular_user_unredacted_history_page_secondary_actions
+    session_for(create(:user))
+    node = create(:node, :with_history)
+    get node_history_path(:id => node, :params => { :show_redactions => true })
+    assert_response :redirect
+  end
+
+  def test_moderator_user_unredacted_history_page_secondary_actions
+    session_for(create(:moderator_user))
+    node = create(:node, :with_history)
+    get node_history_path(:id => node, :params => { :show_redactions => true })
+    assert_response :success
+    assert_select ".secondary-actions a", :text => "View Details", :count => 1
+    assert_select ".secondary-actions a", :text => "View History", :count => 1
+    assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
+  end
+
   def test_visible_with_one_version
     node = create(:node, :with_history)
     get old_node_path(node, 1)
index 66a960e6f74efa87377ed668d3ec76156da6723f..a766f8b8db113178edf13a4504c8f8a622d6f646 100644 (file)
@@ -2,12 +2,59 @@ require "test_helper"
 
 class OldRelationsControllerTest < ActionDispatch::IntegrationTest
   def test_routes
+    assert_routing(
+      { :path => "/relation/1/history", :method => :get },
+      { :controller => "old_relations", :action => "index", :id => "1" }
+    )
     assert_routing(
       { :path => "/relation/1/history/2", :method => :get },
       { :controller => "old_relations", :action => "show", :id => "1", :version => "2" }
     )
   end
 
+  def test_history
+    relation = create(:relation, :with_history)
+    sidebar_browse_check :relation_history_path, relation.id, "browse/history"
+    assert_select "h4", /^Version/ do
+      assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
+    end
+  end
+
+  def test_history_of_redacted
+    relation = create(:relation, :with_history, :version => 4)
+    relation_v1 = relation.old_relations.find_by(:version => 1)
+    relation_v1.redact!(create(:redaction))
+    relation_v3 = relation.old_relations.find_by(:version => 3)
+    relation_v3.redact!(create(:redaction))
+
+    get relation_history_path(:id => relation)
+    assert_response :success
+    assert_template "browse/history"
+
+    # there are 4 revisions of the redacted relation, but only 2
+    # should be showing details here.
+    assert_select ".browse-section", 4
+    assert_select ".browse-section.browse-redacted", 2
+    assert_select ".browse-section.browse-relation", 2
+  end
+
+  def test_unredacted_history_of_redacted
+    session_for(create(:moderator_user))
+    relation = create(:relation, :with_history, :version => 4)
+    relation_v1 = relation.old_relations.find_by(:version => 1)
+    relation_v1.redact!(create(:redaction))
+    relation_v3 = relation.old_relations.find_by(:version => 3)
+    relation_v3.redact!(create(:redaction))
+
+    get relation_history_path(:id => relation, :params => { :show_redactions => true })
+    assert_response :success
+    assert_template "browse/history"
+
+    assert_select ".browse-section", 4
+    assert_select ".browse-section.browse-redacted", 0
+    assert_select ".browse-section.browse-relation", 4
+  end
+
   def test_visible_with_one_version
     relation = create(:relation, :with_history)
     get old_relation_path(relation, 1)
index 65e26ef20acf912b42b220f1da4764b0d6d57e4c..6455343cfa63af9b1e4c43cb28bab6b9bbb021a6 100644 (file)
@@ -2,12 +2,59 @@ require "test_helper"
 
 class OldWaysControllerTest < ActionDispatch::IntegrationTest
   def test_routes
+    assert_routing(
+      { :path => "/way/1/history", :method => :get },
+      { :controller => "old_ways", :action => "index", :id => "1" }
+    )
     assert_routing(
       { :path => "/way/1/history/2", :method => :get },
       { :controller => "old_ways", :action => "show", :id => "1", :version => "2" }
     )
   end
 
+  def test_history
+    way = create(:way, :with_history)
+    sidebar_browse_check :way_history_path, way.id, "browse/history"
+    assert_select "h4", /^Version/ do
+      assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
+    end
+  end
+
+  def test_history_of_redacted
+    way = create(:way, :with_history, :version => 4)
+    way_v1 = way.old_ways.find_by(:version => 1)
+    way_v1.redact!(create(:redaction))
+    way_v3 = way.old_ways.find_by(:version => 3)
+    way_v3.redact!(create(:redaction))
+
+    get way_history_path(:id => way)
+    assert_response :success
+    assert_template "browse/history"
+
+    # there are 4 revisions of the redacted way, but only 2
+    # should be showing details here.
+    assert_select ".browse-section", 4
+    assert_select ".browse-section.browse-redacted", 2
+    assert_select ".browse-section.browse-way", 2
+  end
+
+  def test_unredacted_history_of_redacted
+    session_for(create(:moderator_user))
+    way = create(:way, :with_history, :version => 4)
+    way_v1 = way.old_ways.find_by(:version => 1)
+    way_v1.redact!(create(:redaction))
+    way_v3 = way.old_ways.find_by(:version => 3)
+    way_v3.redact!(create(:redaction))
+
+    get way_history_path(:id => way, :params => { :show_redactions => true })
+    assert_response :success
+    assert_template "browse/history"
+
+    assert_select ".browse-section", 4
+    assert_select ".browse-section.browse-redacted", 0
+    assert_select ".browse-section.browse-way", 4
+  end
+
   def test_visible_with_one_version
     way = create(:way, :with_history)
     get old_way_path(way, 1)