From: Tom Hughes Date: Wed, 1 Feb 2023 19:10:22 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/3911' X-Git-Tag: live~829 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/52591c55610b656cca3ef37269a8eef713368fc6?hp=9b39577f4646f3624cf24aaa04b06b6f053c3270 Merge remote-tracking branch 'upstream/pull/3911' --- diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index fd548c5f3..5d196fa98 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -5,7 +5,8 @@ class Ability def initialize(user) can [:relation, :relation_history, :way, :way_history, :node, :node_history, - :changeset, :note, :new_note, :query], :browse + :changeset, :query], :browse + can [:show, :new], Note can :search, :direction can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site can [:finish, :embed], :export diff --git a/app/assets/javascripts/index/note.js b/app/assets/javascripts/index/note.js index e5eb3a041..e7790c904 100644 --- a/app/assets/javascripts/index/note.js +++ b/app/assets/javascripts/index/note.js @@ -60,10 +60,10 @@ OSM.Note = function (map) { var form = e.target.form; if ($(e.target).val() === "") { - $(form.close).val(I18n.t("javascripts.notes.show.resolve")); + $(form.close).val($(form.close).data("defaultActionText")); $(form.comment).prop("disabled", true); } else { - $(form.close).val(I18n.t("javascripts.notes.show.comment_and_resolve")); + $(form.close).val($(form.close).data("commentActionText")); $(form.comment).prop("disabled", false); } }); diff --git a/app/controllers/browse_controller.rb b/app/controllers/browse_controller.rb index 6c5336908..88871a9e1 100644 --- a/app/controllers/browse_controller.rb +++ b/app/controllers/browse_controller.rb @@ -76,19 +76,5 @@ class BrowseController < ApplicationController render :action => "not_found", :status => :not_found end - def note - @type = "note" - - if current_user&.moderator? - @note = Note.find(params[:id]) - @note_comments = @note.comments.unscope(:where => :visible) - else - @note = Note.visible.find(params[:id]) - @note_comments = @note.comments - end - rescue ActiveRecord::RecordNotFound - render :action => "not_found", :status => :not_found - end - def query; end end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 7d6163f48..440a620e8 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -1,8 +1,9 @@ class NotesController < ApplicationController - layout "site" + layout :map_layout before_action :check_api_readable before_action :authorize_web + before_action :require_oauth authorize_resource @@ -21,12 +22,30 @@ class NotesController < ApplicationController @notes = @user.notes @notes = @notes.visible unless current_user&.moderator? @notes = @notes.order("updated_at DESC, id").distinct.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author) + + render :layout => "site" else @title = t "users.no_such_user.title" @not_found_user = params[:display_name] - render :template => "users/no_such_user", :status => :not_found + render :template => "users/no_such_user", :status => :not_found, :layout => "site" end end end + + def show + @type = "note" + + if current_user&.moderator? + @note = Note.find(params[:id]) + @note_comments = @note.comments.unscope(:where => :visible) + else + @note = Note.visible.find(params[:id]) + @note_comments = @note.comments + end + rescue ActiveRecord::RecordNotFound + render :template => "browse/not_found", :status => :not_found + end + + def new; end end diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index 9d9cf0f39..a05fe376b 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -140,7 +140,7 @@ class SiteController < ApplicationController elsif params[:relation] redirect_to relation_path(params[:relation]) elsif params[:note] - redirect_to browse_note_path(params[:note]) + redirect_to note_path(params[:note]) elsif params[:query] redirect_to search_path(:query => params[:query]) end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index e6c1adb16..dcec4990b 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -8,7 +8,7 @@ module IssuesHelper when DiaryComment diary_entry_url(reportable.diary_entry.user, reportable.diary_entry, :anchor => "comment#{reportable.id}") when Note - url_for(:controller => :browse, :action => :note, :id => reportable.id) + note_url(reportable) end end diff --git a/app/helpers/note_helper.rb b/app/helpers/note_helper.rb index 809480a04..86e5c40f8 100644 --- a/app/helpers/note_helper.rb +++ b/app/helpers/note_helper.rb @@ -3,11 +3,11 @@ module NoteHelper def note_event(event, at, by) if by.nil? - t("browse.note.#{event}_by_anonymous_html", + t("notes.show.#{event}_by_anonymous_html", :when => friendly_date_ago(at), :exact_time => l(at)) else - t("browse.note.#{event}_by_html", + t("notes.show.#{event}_by_html", :when => friendly_date_ago(at), :exact_time => l(at), :user => note_author(by)) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 33fcc7465..c5c0118e6 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -123,7 +123,7 @@ class UserMailer < ApplicationMailer def note_comment_notification(comment, recipient) with_recipient_locale recipient do - @noteurl = browse_note_url(comment.note) + @noteurl = note_url(comment.note) @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, I18n.locale) @comment = comment.body @owner = recipient == comment.note.author diff --git a/app/views/api/notes/_note.gpx.builder b/app/views/api/notes/_note.gpx.builder index c79ed6a6e..bb5cac1c9 100644 --- a/app/views/api/notes/_note.gpx.builder +++ b/app/views/api/notes/_note.gpx.builder @@ -1,22 +1,22 @@ xml.wpt("lon" => note.lon, "lat" => note.lat) do xml.time note.created_at.to_fs(:iso8601) - xml.name t("browse.note.title", :id => note.id) + xml.name t("notes.show.title", :id => note.id) xml.desc do xml.cdata! render(:partial => "description", :object => note, :formats => [:html]) end - xml.link("href" => browse_note_url(note, :only_path => false)) + xml.link("href" => note_url(note, :only_path => false)) xml.extensions do xml.id note.id - xml.url note_url(note, :format => params[:format]) + xml.url api_note_url(note, :format => params[:format]) if note.closed? - xml.reopen_url reopen_note_url(note, :format => params[:format]) + xml.reopen_url reopen_api_note_url(note, :format => params[:format]) else - xml.comment_url comment_note_url(note, :format => params[:format]) - xml.close_url close_note_url(note, :format => params[:format]) + xml.comment_url comment_api_note_url(note, :format => params[:format]) + xml.close_url close_api_note_url(note, :format => params[:format]) end xml.date_created note.created_at diff --git a/app/views/api/notes/_note.json.jbuilder b/app/views/api/notes/_note.json.jbuilder index 34f796880..0884c4426 100644 --- a/app/views/api/notes/_note.json.jbuilder +++ b/app/views/api/notes/_note.json.jbuilder @@ -7,13 +7,13 @@ end json.properties do json.id note.id - json.url note_url(note, :format => params[:format]) + json.url api_note_url(note, :format => params[:format]) if note.closed? - json.reopen_url reopen_note_url(note, :format => params[:format]) + json.reopen_url reopen_api_note_url(note, :format => params[:format]) else - json.comment_url comment_note_url(note, :format => params[:format]) - json.close_url close_note_url(note, :format => params[:format]) + json.comment_url comment_api_note_url(note, :format => params[:format]) + json.close_url close_api_note_url(note, :format => params[:format]) end json.date_created note.created_at.to_s diff --git a/app/views/api/notes/_note.rss.builder b/app/views/api/notes/_note.rss.builder index 968b4dc67..fa70536f7 100644 --- a/app/views/api/notes/_note.rss.builder +++ b/app/views/api/notes/_note.rss.builder @@ -9,8 +9,8 @@ xml.item do xml.title t("api.notes.rss.opened", :place => location) end - xml.link browse_note_url(note) - xml.guid note_url(note) + xml.link note_url(note) + xml.guid api_note_url(note) xml.description render(:partial => "description", :object => note, :formats => [:html]) xml.dc :creator, note.author.display_name if note.author diff --git a/app/views/api/notes/_note.xml.builder b/app/views/api/notes/_note.xml.builder index adb4e6a52..0e5ad0007 100644 --- a/app/views/api/notes/_note.xml.builder +++ b/app/views/api/notes/_note.xml.builder @@ -1,12 +1,12 @@ xml.note("lon" => note.lon, "lat" => note.lat) do xml.id note.id - xml.url note_url(note, :format => params[:format]) + xml.url api_note_url(note, :format => params[:format]) if note.closed? - xml.reopen_url reopen_note_url(note, :format => params[:format]) + xml.reopen_url reopen_api_note_url(note, :format => params[:format]) else - xml.comment_url comment_note_url(note, :format => params[:format]) - xml.close_url close_note_url(note, :format => params[:format]) + xml.comment_url comment_api_note_url(note, :format => params[:format]) + xml.close_url close_api_note_url(note, :format => params[:format]) end xml.date_created note.created_at diff --git a/app/views/api/notes/feed.rss.builder b/app/views/api/notes/feed.rss.builder index 89f888f5b..cf380be31 100644 --- a/app/views/api/notes/feed.rss.builder +++ b/app/views/api/notes/feed.rss.builder @@ -15,8 +15,8 @@ xml.rss("version" => "2.0", xml.item do xml.title t("api.notes.rss.#{comment.event}", :place => location) - xml.link url_for(:controller => "/browse", :action => "note", :id => comment.note.id, :anchor => "c#{comment.id}", :only_path => false) - xml.guid url_for(:controller => "/browse", :action => "note", :id => comment.note.id, :anchor => "c#{comment.id}", :only_path => false) + xml.link url_for(:controller => "/notes", :action => "show", :id => comment.note.id, :anchor => "c#{comment.id}", :only_path => false) + xml.guid url_for(:controller => "/notes", :action => "show", :id => comment.note.id, :anchor => "c#{comment.id}", :only_path => false) xml.description do xml.cdata! render(:partial => "entry", :object => comment, :formats => [:html]) diff --git a/app/views/browse/new_note.html.erb b/app/views/browse/new_note.html.erb deleted file mode 100644 index c8f658f53..000000000 --- a/app/views/browse/new_note.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -<% set_title(t("browse.note.new_note")) %> - -<%= render "sidebar_header", :title => t("browse.note.new_note") %> - -
-

<%= t("javascripts.notes.new.intro") %>

-
- - -
- -
-
- " disabled="1" class="btn btn-primary"> -
-
-
diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index a627e1c54..2eb99b812 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -29,7 +29,7 @@ <%= image_tag("open_note_marker.png", :alt => "open", :size => "25x40") %> <% end %> - <%= link_to note.id, browse_note_path(note) %> + <%= link_to note.id, note %> <%= note_author(note.author) %> <%= note.comments.first.body.to_html %> <%= friendly_date_ago(note.created_at) %> diff --git a/app/views/notes/new.html.erb b/app/views/notes/new.html.erb new file mode 100644 index 000000000..ee9837056 --- /dev/null +++ b/app/views/notes/new.html.erb @@ -0,0 +1,17 @@ +<% set_title(t(".title")) %> + +<%= render "sidebar_header", :title => t(".title") %> + +
+

<%= t(".intro") %>

+
+ + +
+ +
+
+ " disabled="1" class="btn btn-primary"> +
+
+
diff --git a/app/views/browse/note.html.erb b/app/views/notes/show.html.erb similarity index 61% rename from app/views/browse/note.html.erb rename to app/views/notes/show.html.erb index a814d8c8b..2378d8c2e 100644 --- a/app/views/browse/note.html.erb +++ b/app/views/notes/show.html.erb @@ -25,7 +25,7 @@ <% if @note_comments.find { |comment| comment.author.nil? } -%> -

<%= t "javascripts.notes.show.anonymous_warning" %>

+

<%= t ".anonymous_warning" %>

<% end -%> <% if @note_comments.length > 1 %> @@ -49,10 +49,18 @@
<% if current_user.moderator? -%> - " class="btn btn-light" data-method="DELETE" data-url="<%= note_url(@note, "json") %>"> + <%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-light", + :data => { :method => "DELETE", + :url => api_note_url(@note, "json") } %> <% end -%> - " class="btn btn-primary" data-method="POST" data-url="<%= close_note_url(@note, "json") %>"> - " class="btn btn-primary" data-method="POST" data-url="<%= comment_note_url(@note, "json") %>" disabled="1"> + <%= submit_tag t(".resolve"), :name => "close", :class => "btn btn-primary", + :data => { :method => "POST", + :url => close_api_note_url(@note, "json"), + :default_action_text => t(".resolve"), + :comment_action_text => t(".comment_and_resolve") } %> + <%= submit_tag t(".comment"), :name => "comment", :class => "btn btn-primary", :disabled => true, + :data => { :method => "POST", + :url => comment_api_note_url(@note, "json") } %>
<% end -%> @@ -61,10 +69,10 @@
<% if @note.status != "hidden" and current_user and current_user.moderator? -%> - " class="btn btn-light" data-method="DELETE" data-url="<%= note_url(@note, "json") %>"> + " class="btn btn-light" data-method="DELETE" data-url="<%= api_note_url(@note, "json") %>"> <% end -%> <% if current_user -%> - " class="btn btn-primary" data-method="POST" data-url="<%= reopen_note_url(@note, "json") %>"> + " class="btn btn-primary" data-method="POST" data-url="<%= reopen_api_note_url(@note, "json") %>"> <% end -%>
@@ -73,11 +81,11 @@ <% if current_user && current_user != @note.author %>

- <%= t "javascripts.notes.show.report_link_html", :link => report_link(t(".report"), @note) %> + <%= t ".report_link_html", :link => report_link(t(".report"), @note) %> <% if @note.status == "open" %> - <%= t "javascripts.notes.show.other_problems_resolve", :link => report_link(t(".report"), @note) %> + <%= t ".other_problems_resolve", :link => report_link(t(".report"), @note) %> <% elsif @note.status == "closed" %> - <%= t "javascripts.notes.show.other_problems_resolved" %> + <%= t ".other_problems_resolved" %> <% end %>

@@ -85,7 +93,7 @@ <% if @note.freshly_closed? %> - <%= t "javascripts.notes.show.disappear_date_html", :disappear_in => disappear_in(@note) %> + <%= t ".disappear_date_html", :disappear_in => disappear_in(@note) %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index b1752834b..40eb533a2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -407,24 +407,6 @@ en: telephone_link: "Call %{phone_number}" colour_preview: "Colour %{colour_value} preview" email_link: "Email %{email}" - note: - title: "Note: %{id}" - new_note: "New Note" - description: "Description" - open_title: "Unresolved note #%{note_name}" - closed_title: "Resolved note #%{note_name}" - hidden_title: "Hidden note #%{note_name}" - opened_by_html: "Created by %{user} %{when}" - opened_by_anonymous_html: "Created by anonymous %{when}" - commented_by_html: "Comment from %{user} %{when}" - commented_by_anonymous_html: "Comment from anonymous %{when}" - closed_by_html: "Resolved by %{user} %{when}" - closed_by_anonymous_html: "Resolved by anonymous %{when}" - reopened_by_html: "Reactivated by %{user} %{when}" - reopened_by_anonymous_html: "Reactivated by anonymous %{when}" - hidden_by_html: "Hidden by %{user} %{when}" - report: report this note - coordinates_html: "%{latitude}, %{longitude}" query: title: "Query Features" introduction: "Click on the map to find nearby features." @@ -2837,6 +2819,38 @@ en: description: "Description" created_at: "Created at" last_changed: "Last changed" + show: + title: "Note: %{id}" + description: "Description" + open_title: "Unresolved note #%{note_name}" + closed_title: "Resolved note #%{note_name}" + hidden_title: "Hidden note #%{note_name}" + opened_by_html: "Created by %{user} %{when}" + opened_by_anonymous_html: "Created by anonymous %{when}" + commented_by_html: "Comment from %{user} %{when}" + commented_by_anonymous_html: "Comment from anonymous %{when}" + closed_by_html: "Resolved by %{user} %{when}" + closed_by_anonymous_html: "Resolved by anonymous %{when}" + reopened_by_html: "Reactivated by %{user} %{when}" + reopened_by_anonymous_html: "Reactivated by anonymous %{when}" + hidden_by_html: "Hidden by %{user} %{when}" + report: report this note + coordinates_html: "%{latitude}, %{longitude}" + anonymous_warning: This note includes comments from anonymous users which should be independently verified. + hide: Hide + resolve: Resolve + reactivate: Reactivate + comment_and_resolve: Comment & Resolve + comment: Comment + report_link_html: "If this note contains sensitive information that needs to be removed, you can %{link}." + other_problems_resolve: "For all other problems with the note, please resolve it yourself with a comment." + other_problems_resolved: "For all other problems, resolving is sufficient." + disappear_date_html: "This resolved note will disappear from the map in %{disappear_in}." + new: + title: "New Note" + intro: "Spotted a mistake or something missing? Let other mappers know so we can fix it. Move the marker to the correct position and type a note to explain the problem." + advice: "Your note is public and may be used to update the map, so don't enter personal information, or information from copyrighted maps or directory listings." + add: Add Note javascripts: close: Close share: @@ -2914,22 +2928,6 @@ en: unsubscribe: "Unsubscribe" hide_comment: "hide" unhide_comment: "unhide" - notes: - new: - intro: "Spotted a mistake or something missing? Let other mappers know so we can fix it. Move the marker to the correct position and type a note to explain the problem." - advice: "Your note is public and may be used to update the map, so don't enter personal information, or information from copyrighted maps or directory listings." - add: Add Note - show: - anonymous_warning: This note includes comments from anonymous users which should be independently verified. - hide: Hide - resolve: Resolve - reactivate: Reactivate - comment_and_resolve: Comment & Resolve - comment: Comment - report_link_html: "If this note contains sensitive information that needs to be removed, you can %{link}." - other_problems_resolve: "For all other problems with the note, please resolve it yourself with a comment." - other_problems_resolved: "For all other problems, resolving is sufficient." - disappear_date_html: "This resolved note will disappear from the map in %{disappear_in}." edit_help: Move the map and zoom in on a location you want to edit, then click here. directions: ascend: "Ascend" diff --git a/config/routes.rb b/config/routes.rb index 8fd11c091..c0fbf2020 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -84,7 +84,7 @@ OpenStreetMap::Application.routes.draw do get "gpx/:id/data" => "api/traces#data", :as => :api_trace_data # Map notes API - resources :notes, :except => [:new, :edit, :update], :constraints => { :id => /\d+/ }, :controller => "api/notes" do + resources :notes, :except => [:new, :edit, :update], :constraints => { :id => /\d+/ }, :controller => "api/notes", :as => :api_notes do collection do get "search" get "feed", :defaults => { :format => "rss" } @@ -113,8 +113,8 @@ OpenStreetMap::Application.routes.draw do get "/relation/:id/history" => "browse#relation_history", :id => /\d+/, :as => :relation_history get "/changeset/:id" => "browse#changeset", :as => :changeset, :id => /\d+/ get "/changeset/:id/comments/feed" => "changeset_comments#index", :as => :changeset_comments_feed, :id => /\d*/, :defaults => { :format => "rss" } - get "/note/:id" => "browse#note", :id => /\d+/, :as => "browse_note" - get "/note/new" => "browse#new_note" + resources :notes, :path => "note", :only => [:show, :new] + get "/user/:display_name/history" => "changesets#index" get "/user/:display_name/history/feed" => "changesets#feed", :defaults => { :format => :atom } get "/user/:display_name/notes" => "notes#index", :as => :user_notes diff --git a/test/controllers/api/notes_controller_test.rb b/test/controllers/api/notes_controller_test.rb index 31c55b3a8..da2478169 100644 --- a/test/controllers/api/notes_controller_test.rb +++ b/test/controllers/api/notes_controller_test.rb @@ -125,7 +125,7 @@ module Api def test_create_success assert_difference "Note.count", 1 do assert_difference "NoteComment.count", 1 do - post notes_path(:lat => -1.0, :lon => -1.0, :text => "This is a comment", :format => "json") + post api_notes_path(:lat => -1.0, :lon => -1.0, :text => "This is a comment", :format => "json") end end assert_response :success @@ -141,7 +141,7 @@ module Api assert_nil js["properties"]["comments"].last["user"] id = js["properties"]["id"] - get note_path(:id => id, :format => "json") + get api_note_path(:id => id, :format => "json") assert_response :success js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -159,63 +159,63 @@ module Api def test_create_fail assert_no_difference "Note.count" do assert_no_difference "NoteComment.count" do - post notes_path(:lon => -1.0, :text => "This is a comment") + post api_notes_path(:lon => -1.0, :text => "This is a comment") end end assert_response :bad_request assert_no_difference "Note.count" do assert_no_difference "NoteComment.count" do - post notes_path(:lat => -1.0, :text => "This is a comment") + post api_notes_path(:lat => -1.0, :text => "This is a comment") end end assert_response :bad_request assert_no_difference "Note.count" do assert_no_difference "NoteComment.count" do - post notes_path(:lat => -1.0, :lon => -1.0) + post api_notes_path(:lat => -1.0, :lon => -1.0) end end assert_response :bad_request assert_no_difference "Note.count" do assert_no_difference "NoteComment.count" do - post notes_path(:lat => -1.0, :lon => -1.0, :text => "") + post api_notes_path(:lat => -1.0, :lon => -1.0, :text => "") end end assert_response :bad_request assert_no_difference "Note.count" do assert_no_difference "NoteComment.count" do - post notes_path(:lat => -100.0, :lon => -1.0, :text => "This is a comment") + post api_notes_path(:lat => -100.0, :lon => -1.0, :text => "This is a comment") end end assert_response :bad_request assert_no_difference "Note.count" do assert_no_difference "NoteComment.count" do - post notes_path(:lat => -1.0, :lon => -200.0, :text => "This is a comment") + post api_notes_path(:lat => -1.0, :lon => -200.0, :text => "This is a comment") end end assert_response :bad_request assert_no_difference "Note.count" do assert_no_difference "NoteComment.count" do - post notes_path(:lat => "abc", :lon => -1.0, :text => "This is a comment") + post api_notes_path(:lat => "abc", :lon => -1.0, :text => "This is a comment") end end assert_response :bad_request assert_no_difference "Note.count" do assert_no_difference "NoteComment.count" do - post notes_path(:lat => -1.0, :lon => "abc", :text => "This is a comment") + post api_notes_path(:lat => -1.0, :lon => "abc", :text => "This is a comment") end end assert_response :bad_request assert_no_difference "Note.count" do assert_no_difference "NoteComment.count" do - post notes_path(:lat => -1.0, :lon => -1.0, :text => "x\u0000y") + post api_notes_path(:lat => -1.0, :lon => -1.0, :text => "x\u0000y") end end assert_response :bad_request @@ -228,7 +228,7 @@ module Api assert_difference "NoteComment.count", 1 do assert_no_difference "ActionMailer::Base.deliveries.size" do perform_enqueued_jobs do - post comment_note_path(:id => open_note_with_comment, :text => "This is an additional comment", :format => "json"), :headers => auth_header + post comment_api_note_path(:id => open_note_with_comment, :text => "This is an additional comment", :format => "json"), :headers => auth_header end end end @@ -243,7 +243,7 @@ module Api assert_equal "This is an additional comment", js["properties"]["comments"].last["text"] assert_equal user.display_name, js["properties"]["comments"].last["user"] - get note_path(:id => open_note_with_comment, :format => "json") + get api_note_path(:id => open_note_with_comment, :format => "json") assert_response :success js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -270,7 +270,7 @@ module Api assert_difference "NoteComment.count", 1 do assert_difference "ActionMailer::Base.deliveries.size", 2 do perform_enqueued_jobs do - post comment_note_path(:id => note_with_comments_by_users, :text => "This is an additional comment", :format => "json"), :headers => auth_header + post comment_api_note_path(:id => note_with_comments_by_users, :text => "This is an additional comment", :format => "json"), :headers => auth_header end end end @@ -296,7 +296,7 @@ module Api assert_equal 1, email.to.length assert_equal "[OpenStreetMap] #{third_user.display_name} has commented on a note you are interested in", email.subject - get note_path(:id => note_with_comments_by_users, :format => "json") + get api_note_path(:id => note_with_comments_by_users, :format => "json") assert_response :success js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -317,43 +317,43 @@ module Api user = create(:user) assert_no_difference "NoteComment.count" do - post comment_note_path(:id => open_note_with_comment) + post comment_api_note_path(:id => open_note_with_comment) assert_response :unauthorized end auth_header = basic_authorization_header user.email, "test" assert_no_difference "NoteComment.count" do - post comment_note_path(:id => open_note_with_comment), :headers => auth_header + post comment_api_note_path(:id => open_note_with_comment), :headers => auth_header end assert_response :bad_request assert_no_difference "NoteComment.count" do - post comment_note_path(:id => open_note_with_comment, :text => ""), :headers => auth_header + post comment_api_note_path(:id => open_note_with_comment, :text => ""), :headers => auth_header end assert_response :bad_request assert_no_difference "NoteComment.count" do - post comment_note_path(:id => 12345, :text => "This is an additional comment"), :headers => auth_header + post comment_api_note_path(:id => 12345, :text => "This is an additional comment"), :headers => auth_header end assert_response :not_found hidden_note_with_comment = create(:note_with_comments, :status => "hidden") assert_no_difference "NoteComment.count" do - post comment_note_path(:id => hidden_note_with_comment, :text => "This is an additional comment"), :headers => auth_header + post comment_api_note_path(:id => hidden_note_with_comment, :text => "This is an additional comment"), :headers => auth_header end assert_response :gone closed_note_with_comment = create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc) assert_no_difference "NoteComment.count" do - post comment_note_path(:id => closed_note_with_comment, :text => "This is an additional comment"), :headers => auth_header + post comment_api_note_path(:id => closed_note_with_comment, :text => "This is an additional comment"), :headers => auth_header end assert_response :conflict assert_no_difference "NoteComment.count" do - post comment_note_path(:id => open_note_with_comment, :text => "x\u0000y"), :headers => auth_header + post comment_api_note_path(:id => open_note_with_comment, :text => "x\u0000y"), :headers => auth_header end assert_response :bad_request end @@ -362,12 +362,12 @@ module Api open_note_with_comment = create(:note_with_comments) user = create(:user) - post close_note_path(:id => open_note_with_comment, :text => "This is a close comment", :format => "json") + post close_api_note_path(:id => open_note_with_comment, :text => "This is a close comment", :format => "json") assert_response :unauthorized auth_header = basic_authorization_header user.email, "test" - post close_note_path(:id => open_note_with_comment, :text => "This is a close comment", :format => "json"), :headers => auth_header + post close_api_note_path(:id => open_note_with_comment, :text => "This is a close comment", :format => "json"), :headers => auth_header assert_response :success js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -379,7 +379,7 @@ module Api assert_equal "This is a close comment", js["properties"]["comments"].last["text"] assert_equal user.display_name, js["properties"]["comments"].last["user"] - get note_path(:id => open_note_with_comment.id, :format => "json") + get api_note_path(:id => open_note_with_comment.id, :format => "json") assert_response :success js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -393,22 +393,22 @@ module Api end def test_close_fail - post close_note_path(:id => 12345) + post close_api_note_path(:id => 12345) assert_response :unauthorized auth_header = basic_authorization_header create(:user).email, "test" - post close_note_path(:id => 12345), :headers => auth_header + post close_api_note_path(:id => 12345), :headers => auth_header assert_response :not_found hidden_note_with_comment = create(:note_with_comments, :status => "hidden") - post close_note_path(:id => hidden_note_with_comment), :headers => auth_header + post close_api_note_path(:id => hidden_note_with_comment), :headers => auth_header assert_response :gone closed_note_with_comment = create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc) - post close_note_path(:id => closed_note_with_comment), :headers => auth_header + post close_api_note_path(:id => closed_note_with_comment), :headers => auth_header assert_response :conflict end @@ -416,12 +416,12 @@ module Api closed_note_with_comment = create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc) user = create(:user) - post reopen_note_path(:id => closed_note_with_comment, :text => "This is a reopen comment", :format => "json") + post reopen_api_note_path(:id => closed_note_with_comment, :text => "This is a reopen comment", :format => "json") assert_response :unauthorized auth_header = basic_authorization_header user.email, "test" - post reopen_note_path(:id => closed_note_with_comment, :text => "This is a reopen comment", :format => "json"), :headers => auth_header + post reopen_api_note_path(:id => closed_note_with_comment, :text => "This is a reopen comment", :format => "json"), :headers => auth_header assert_response :success js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -433,7 +433,7 @@ module Api assert_equal "This is a reopen comment", js["properties"]["comments"].last["text"] assert_equal user.display_name, js["properties"]["comments"].last["user"] - get note_path(:id => closed_note_with_comment, :format => "json") + get api_note_path(:id => closed_note_with_comment, :format => "json") assert_response :success js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -449,35 +449,35 @@ module Api def test_reopen_fail hidden_note_with_comment = create(:note_with_comments, :status => "hidden") - post reopen_note_path(:id => hidden_note_with_comment) + post reopen_api_note_path(:id => hidden_note_with_comment) assert_response :unauthorized auth_header = basic_authorization_header create(:user).email, "test" - post reopen_note_path(:id => 12345), :headers => auth_header + post reopen_api_note_path(:id => 12345), :headers => auth_header assert_response :not_found - post reopen_note_path(:id => hidden_note_with_comment), :headers => auth_header + post reopen_api_note_path(:id => hidden_note_with_comment), :headers => auth_header assert_response :gone open_note_with_comment = create(:note_with_comments) - post reopen_note_path(:id => open_note_with_comment), :headers => auth_header + post reopen_api_note_path(:id => open_note_with_comment), :headers => auth_header assert_response :conflict end def test_show_success open_note = create(:note_with_comments) - get note_path(:id => open_note, :format => "xml") + get api_note_path(:id => open_note, :format => "xml") assert_response :success assert_equal "application/xml", @response.media_type assert_select "osm", :count => 1 do assert_select "note[lat='#{open_note.lat}'][lon='#{open_note.lon}']", :count => 1 do assert_select "id", open_note.id.to_s - assert_select "url", note_url(open_note, :format => "xml") - assert_select "comment_url", comment_note_url(open_note, :format => "xml") - assert_select "close_url", close_note_url(open_note, :format => "xml") + assert_select "url", api_note_url(open_note, :format => "xml") + assert_select "comment_url", comment_api_note_url(open_note, :format => "xml") + assert_select "close_url", close_api_note_url(open_note, :format => "xml") assert_select "date_created", open_note.created_at.to_s assert_select "status", open_note.status assert_select "comments", :count => 1 do @@ -486,14 +486,14 @@ module Api end end - get note_path(:id => open_note, :format => "rss") + get api_note_path(:id => open_note, :format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do assert_select "channel", :count => 1 do assert_select "item", :count => 1 do - assert_select "link", browse_note_url(open_note) - assert_select "guid", note_url(open_note) + assert_select "link", note_url(open_note) + assert_select "guid", api_note_url(open_note) assert_select "pubDate", open_note.created_at.to_fs(:rfc822) assert_select "geo|lat", open_note.lat.to_s assert_select "geo|long", open_note.lon.to_s @@ -502,7 +502,7 @@ module Api end end - get note_path(:id => open_note, :format => "json") + get api_note_path(:id => open_note, :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -512,13 +512,13 @@ module Api assert_equal open_note.lat, js["geometry"]["coordinates"][0] assert_equal open_note.lon, js["geometry"]["coordinates"][1] assert_equal open_note.id, js["properties"]["id"] - assert_equal note_url(open_note, :format => "json"), js["properties"]["url"] - assert_equal comment_note_url(open_note, :format => "json"), js["properties"]["comment_url"] - assert_equal close_note_url(open_note, :format => "json"), js["properties"]["close_url"] + assert_equal api_note_url(open_note, :format => "json"), js["properties"]["url"] + assert_equal comment_api_note_url(open_note, :format => "json"), js["properties"]["comment_url"] + assert_equal close_api_note_url(open_note, :format => "json"), js["properties"]["close_url"] assert_equal open_note.created_at.to_s, js["properties"]["date_created"] assert_equal open_note.status, js["properties"]["status"] - get note_path(:id => open_note, :format => "gpx") + get api_note_path(:id => open_note, :format => "gpx") assert_response :success assert_equal "application/gpx+xml", @response.media_type assert_select "gpx", :count => 1 do @@ -529,9 +529,9 @@ module Api assert_select "link[href='http://www.example.com/note/#{open_note.id}']", :count => 1 assert_select "extensions", :count => 1 do assert_select "id", open_note.id.to_s - assert_select "url", note_url(open_note, :format => "gpx") - assert_select "comment_url", comment_note_url(open_note, :format => "gpx") - assert_select "close_url", close_note_url(open_note, :format => "gpx") + assert_select "url", api_note_url(open_note, :format => "gpx") + assert_select "comment_url", comment_api_note_url(open_note, :format => "gpx") + assert_select "close_url", close_api_note_url(open_note, :format => "gpx") end end end @@ -544,7 +544,7 @@ module Api create(:note_comment, :note => note, :body => "Another valid comment for hidden note") end - get note_path(:id => note_with_hidden_comment, :format => "json") + get api_note_path(:id => note_with_hidden_comment, :format => "json") assert_response :success js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -556,10 +556,10 @@ module Api end def test_show_fail - get note_path(:id => 12345) + get api_note_path(:id => 12345) assert_response :not_found - get note_path(:id => create(:note, :status => "hidden")) + get api_note_path(:id => create(:note, :status => "hidden")) assert_response :gone end @@ -568,17 +568,17 @@ module Api user = create(:user) moderator_user = create(:moderator_user) - delete note_path(:id => open_note_with_comment, :text => "This is a hide comment", :format => "json") + delete api_note_path(:id => open_note_with_comment, :text => "This is a hide comment", :format => "json") assert_response :unauthorized auth_header = basic_authorization_header user.email, "test" - delete note_path(:id => open_note_with_comment, :text => "This is a hide comment", :format => "json"), :headers => auth_header + delete api_note_path(:id => open_note_with_comment, :text => "This is a hide comment", :format => "json"), :headers => auth_header assert_response :forbidden auth_header = basic_authorization_header moderator_user.email, "test" - delete note_path(:id => open_note_with_comment, :text => "This is a hide comment", :format => "json"), :headers => auth_header + delete api_note_path(:id => open_note_with_comment, :text => "This is a hide comment", :format => "json"), :headers => auth_header assert_response :success js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -590,12 +590,12 @@ module Api assert_equal "This is a hide comment", js["properties"]["comments"].last["text"] assert_equal moderator_user.display_name, js["properties"]["comments"].last["user"] - get note_path(:id => open_note_with_comment, :format => "json"), :headers => auth_header + get api_note_path(:id => open_note_with_comment, :format => "json"), :headers => auth_header assert_response :success auth_header = basic_authorization_header user.email, "test" - get note_path(:id => open_note_with_comment, :format => "json"), :headers => auth_header + get api_note_path(:id => open_note_with_comment, :format => "json"), :headers => auth_header assert_response :gone end @@ -603,22 +603,22 @@ module Api user = create(:user) moderator_user = create(:moderator_user) - delete note_path(:id => 12345, :format => "json") + delete api_note_path(:id => 12345, :format => "json") assert_response :unauthorized auth_header = basic_authorization_header user.email, "test" - delete note_path(:id => 12345, :format => "json"), :headers => auth_header + delete api_note_path(:id => 12345, :format => "json"), :headers => auth_header assert_response :forbidden auth_header = basic_authorization_header moderator_user.email, "test" - delete note_path(:id => 12345, :format => "json"), :headers => auth_header + delete api_note_path(:id => 12345, :format => "json"), :headers => auth_header assert_response :not_found hidden_note_with_comment = create(:note_with_comments, :status => "hidden") - delete note_path(:id => hidden_note_with_comment, :format => "json"), :headers => auth_header + delete api_note_path(:id => hidden_note_with_comment, :format => "json"), :headers => auth_header assert_response :gone end @@ -627,7 +627,7 @@ module Api create(:note_with_comments, :latitude => position, :longitude => position) create(:note_with_comments, :latitude => position, :longitude => position) - get notes_path(:bbox => "1,1,1.2,1.2", :format => "rss") + get api_notes_path(:bbox => "1,1,1.2,1.2", :format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -637,7 +637,7 @@ module Api end end - get notes_path(:bbox => "1,1,1.2,1.2", :format => "json") + get api_notes_path(:bbox => "1,1,1.2,1.2", :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -645,14 +645,14 @@ module Api assert_equal "FeatureCollection", js["type"] assert_equal 2, js["features"].count - get notes_path(:bbox => "1,1,1.2,1.2", :format => "xml") + get api_notes_path(:bbox => "1,1,1.2,1.2", :format => "xml") assert_response :success assert_equal "application/xml", @response.media_type assert_select "osm", :count => 1 do assert_select "note", :count => 2 end - get notes_path(:bbox => "1,1,1.2,1.2", :format => "gpx") + get api_notes_path(:bbox => "1,1,1.2,1.2", :format => "gpx") assert_response :success assert_equal "application/gpx+xml", @response.media_type assert_select "gpx", :count => 1 do @@ -665,7 +665,7 @@ module Api create(:note_with_comments, :latitude => position, :longitude => position) create(:note_with_comments, :latitude => position, :longitude => position) - get notes_path(:bbox => "1,1,1.2,1.2", :limit => 1, :format => "rss") + get api_notes_path(:bbox => "1,1,1.2,1.2", :limit => 1, :format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -674,7 +674,7 @@ module Api end end - get notes_path(:bbox => "1,1,1.2,1.2", :limit => 1, :format => "json") + get api_notes_path(:bbox => "1,1,1.2,1.2", :limit => 1, :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -682,14 +682,14 @@ module Api assert_equal "FeatureCollection", js["type"] assert_equal 1, js["features"].count - get notes_path(:bbox => "1,1,1.2,1.2", :limit => 1, :format => "xml") + get api_notes_path(:bbox => "1,1,1.2,1.2", :limit => 1, :format => "xml") assert_response :success assert_equal "application/xml", @response.media_type assert_select "osm", :count => 1 do assert_select "note", :count => 1 end - get notes_path(:bbox => "1,1,1.2,1.2", :limit => 1, :format => "gpx") + get api_notes_path(:bbox => "1,1,1.2,1.2", :limit => 1, :format => "gpx") assert_response :success assert_equal "application/gpx+xml", @response.media_type assert_select "gpx", :count => 1 do @@ -698,7 +698,7 @@ module Api end def test_index_empty_area - get notes_path(:bbox => "5,5,5.1,5.1", :format => "rss") + get api_notes_path(:bbox => "5,5,5.1,5.1", :format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -707,7 +707,7 @@ module Api end end - get notes_path(:bbox => "5,5,5.1,5.1", :format => "json") + get api_notes_path(:bbox => "5,5,5.1,5.1", :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -715,14 +715,14 @@ module Api assert_equal "FeatureCollection", js["type"] assert_equal 0, js["features"].count - get notes_path(:bbox => "5,5,5.1,5.1", :format => "xml") + get api_notes_path(:bbox => "5,5,5.1,5.1", :format => "xml") assert_response :success assert_equal "application/xml", @response.media_type assert_select "osm", :count => 1 do assert_select "note", :count => 0 end - get notes_path(:bbox => "5,5,5.1,5.1", :format => "gpx") + get api_notes_path(:bbox => "5,5,5.1,5.1", :format => "gpx") assert_response :success assert_equal "application/gpx+xml", @response.media_type assert_select "gpx", :count => 1 do @@ -731,19 +731,19 @@ module Api end def test_index_large_area - get notes_path(:bbox => "-2.5,-2.5,2.5,2.5", :format => :json) + get api_notes_path(:bbox => "-2.5,-2.5,2.5,2.5", :format => :json) assert_response :success assert_equal "application/json", @response.media_type - get notes_path(:l => "-2.5", :b => "-2.5", :r => "2.5", :t => "2.5", :format => :json) + get api_notes_path(:l => "-2.5", :b => "-2.5", :r => "2.5", :t => "2.5", :format => :json) assert_response :success assert_equal "application/json", @response.media_type - get notes_path(:bbox => "-10,-10,12,12", :format => :json) + get api_notes_path(:bbox => "-10,-10,12,12", :format => :json) assert_response :bad_request assert_equal "text/plain", @response.media_type - get notes_path(:l => "-10", :b => "-10", :r => "12", :t => "12", :format => :json) + get api_notes_path(:l => "-10", :b => "-10", :r => "12", :t => "12", :format => :json) assert_response :bad_request assert_equal "text/plain", @response.media_type end @@ -755,7 +755,7 @@ module Api create(:note_with_comments) # Open notes + closed in last 7 days - get notes_path(:bbox => "1,1,1.7,1.7", :closed => "7", :format => "json") + get api_notes_path(:bbox => "1,1,1.7,1.7", :closed => "7", :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -764,7 +764,7 @@ module Api assert_equal 2, js["features"].count # Only open notes - get notes_path(:bbox => "1,1,1.7,1.7", :closed => "0", :format => "json") + get api_notes_path(:bbox => "1,1,1.7,1.7", :closed => "0", :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -773,7 +773,7 @@ module Api assert_equal 1, js["features"].count # Open notes + all closed notes - get notes_path(:bbox => "1,1,1.7,1.7", :closed => "-1", :format => "json") + get api_notes_path(:bbox => "1,1,1.7,1.7", :closed => "-1", :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -783,42 +783,42 @@ module Api end def test_index_bad_params - get notes_path(:bbox => "-2.5,-2.5,2.5") + get api_notes_path(:bbox => "-2.5,-2.5,2.5") assert_response :bad_request - get notes_path(:bbox => "-2.5,-2.5,2.5,2.5,2.5") + get api_notes_path(:bbox => "-2.5,-2.5,2.5,2.5,2.5") assert_response :bad_request - get notes_path(:b => "-2.5", :r => "2.5", :t => "2.5") + get api_notes_path(:b => "-2.5", :r => "2.5", :t => "2.5") assert_response :bad_request - get notes_path(:l => "-2.5", :r => "2.5", :t => "2.5") + get api_notes_path(:l => "-2.5", :r => "2.5", :t => "2.5") assert_response :bad_request - get notes_path(:l => "-2.5", :b => "-2.5", :t => "2.5") + get api_notes_path(:l => "-2.5", :b => "-2.5", :t => "2.5") assert_response :bad_request - get notes_path(:l => "-2.5", :b => "-2.5", :r => "2.5") + get api_notes_path(:l => "-2.5", :b => "-2.5", :r => "2.5") assert_response :bad_request - get notes_path(:bbox => "1,1,1.7,1.7", :limit => "0", :format => "json") + get api_notes_path(:bbox => "1,1,1.7,1.7", :limit => "0", :format => "json") assert_response :bad_request - get notes_path(:bbox => "1,1,1.7,1.7", :limit => "10001", :format => "json") + get api_notes_path(:bbox => "1,1,1.7,1.7", :limit => "10001", :format => "json") assert_response :bad_request end def test_search_success create(:note_with_comments) - get search_notes_path(:q => "note comment", :format => "xml") + get search_api_notes_path(:q => "note comment", :format => "xml") assert_response :success assert_equal "application/xml", @response.media_type assert_select "osm", :count => 1 do assert_select "note", :count => 1 end - get search_notes_path(:q => "note comment", :format => "json") + get search_api_notes_path(:q => "note comment", :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -826,7 +826,7 @@ module Api assert_equal "FeatureCollection", js["type"] assert_equal 1, js["features"].count - get search_notes_path(:q => "note comment", :format => "rss") + get search_api_notes_path(:q => "note comment", :format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -835,7 +835,7 @@ module Api end end - get search_notes_path(:q => "note comment", :format => "gpx") + get search_api_notes_path(:q => "note comment", :format => "gpx") assert_response :success assert_equal "application/gpx+xml", @response.media_type assert_select "gpx", :count => 1 do @@ -850,14 +850,14 @@ module Api create(:note_comment, :note => note, :author => user) end - get search_notes_path(:display_name => user.display_name, :format => "xml") + get search_api_notes_path(:display_name => user.display_name, :format => "xml") assert_response :success assert_equal "application/xml", @response.media_type assert_select "osm", :count => 1 do assert_select "note", :count => 1 end - get search_notes_path(:display_name => user.display_name, :format => "json") + get search_api_notes_path(:display_name => user.display_name, :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -865,7 +865,7 @@ module Api assert_equal "FeatureCollection", js["type"] assert_equal 1, js["features"].count - get search_notes_path(:display_name => user.display_name, :format => "rss") + get search_api_notes_path(:display_name => user.display_name, :format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -874,7 +874,7 @@ module Api end end - get search_notes_path(:display_name => user.display_name, :format => "gpx") + get search_api_notes_path(:display_name => user.display_name, :format => "gpx") assert_response :success assert_equal "application/gpx+xml", @response.media_type assert_select "gpx", :count => 1 do @@ -889,14 +889,14 @@ module Api create(:note_comment, :note => note, :author => user) end - get search_notes_path(:user => user.id, :format => "xml") + get search_api_notes_path(:user => user.id, :format => "xml") assert_response :success assert_equal "application/xml", @response.media_type assert_select "osm", :count => 1 do assert_select "note", :count => 1 end - get search_notes_path(:user => user.id, :format => "json") + get search_api_notes_path(:user => user.id, :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -904,7 +904,7 @@ module Api assert_equal "FeatureCollection", js["type"] assert_equal 1, js["features"].count - get search_notes_path(:user => user.id, :format => "rss") + get search_api_notes_path(:user => user.id, :format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -913,7 +913,7 @@ module Api end end - get search_notes_path(:user => user.id, :format => "gpx") + get search_api_notes_path(:user => user.id, :format => "gpx") assert_response :success assert_equal "application/gpx+xml", @response.media_type assert_select "gpx", :count => 1 do @@ -924,14 +924,14 @@ module Api def test_search_no_match create(:note_with_comments) - get search_notes_path(:q => "no match", :format => "xml") + get search_api_notes_path(:q => "no match", :format => "xml") assert_response :success assert_equal "application/xml", @response.media_type assert_select "osm", :count => 1 do assert_select "note", :count => 0 end - get search_notes_path(:q => "no match", :format => "json") + get search_api_notes_path(:q => "no match", :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -939,7 +939,7 @@ module Api assert_equal "FeatureCollection", js["type"] assert_equal 0, js["features"].count - get search_notes_path(:q => "no match", :format => "rss") + get search_api_notes_path(:q => "no match", :format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -948,7 +948,7 @@ module Api end end - get search_notes_path(:q => "no match", :format => "gpx") + get search_api_notes_path(:q => "no match", :format => "gpx") assert_response :success assert_equal "application/gpx+xml", @response.media_type assert_select "gpx", :count => 1 do @@ -959,14 +959,14 @@ module Api def test_search_by_time_no_match create(:note_with_comments) - get search_notes_path(:from => "01.01.2010", :to => "01.10.2010", :format => "xml") + get search_api_notes_path(:from => "01.01.2010", :to => "01.10.2010", :format => "xml") assert_response :success assert_equal "application/xml", @response.media_type assert_select "osm", :count => 1 do assert_select "note", :count => 0 end - get search_notes_path(:from => "01.01.2010", :to => "01.10.2010", :format => "json") + get search_api_notes_path(:from => "01.01.2010", :to => "01.10.2010", :format => "json") assert_response :success assert_equal "application/json", @response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -974,7 +974,7 @@ module Api assert_equal "FeatureCollection", js["type"] assert_equal 0, js["features"].count - get search_notes_path(:from => "01.01.2010", :to => "01.10.2010", :format => "rss") + get search_api_notes_path(:from => "01.01.2010", :to => "01.10.2010", :format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -983,7 +983,7 @@ module Api end end - get search_notes_path(:from => "01.01.2010", :to => "01.10.2010", :format => "gpx") + get search_api_notes_path(:from => "01.01.2010", :to => "01.10.2010", :format => "gpx") assert_response :success assert_equal "application/gpx+xml", @response.media_type assert_select "gpx", :count => 1 do @@ -992,22 +992,22 @@ module Api end def test_search_bad_params - get search_notes_path(:q => "no match", :limit => "0", :format => "json") + get search_api_notes_path(:q => "no match", :limit => "0", :format => "json") assert_response :bad_request - get search_notes_path(:q => "no match", :limit => "10001", :format => "json") + get search_api_notes_path(:q => "no match", :limit => "10001", :format => "json") assert_response :bad_request - get search_notes_path(:display_name => "non-existent") + get search_api_notes_path(:display_name => "non-existent") assert_response :bad_request - get search_notes_path(:user => "-1") + get search_api_notes_path(:user => "-1") assert_response :bad_request - get search_notes_path(:from => "wrong-date", :to => "wrong-date") + get search_api_notes_path(:from => "wrong-date", :to => "wrong-date") assert_response :bad_request - get search_notes_path(:from => "01.01.2010", :to => "2010.01.2010") + get search_api_notes_path(:from => "01.01.2010", :to => "2010.01.2010") assert_response :bad_request end @@ -1019,7 +1019,7 @@ module Api create(:note_with_comments, :latitude => position, :longitude => position) create(:note_with_comments, :latitude => position, :longitude => position) - get feed_notes_path(:format => "rss") + get feed_api_notes_path(:format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -1028,7 +1028,7 @@ module Api end end - get feed_notes_path(:bbox => "1,1,1.2,1.2", :format => "rss") + get feed_api_notes_path(:bbox => "1,1,1.2,1.2", :format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -1040,16 +1040,16 @@ module Api end def test_feed_fail - get feed_notes_path(:bbox => "1,1,1.2", :format => "rss") + get feed_api_notes_path(:bbox => "1,1,1.2", :format => "rss") assert_response :bad_request - get feed_notes_path(:bbox => "1,1,1.2,1.2,1.2", :format => "rss") + get feed_api_notes_path(:bbox => "1,1,1.2,1.2,1.2", :format => "rss") assert_response :bad_request - get feed_notes_path(:bbox => "1,1,1.2,1.2", :limit => "0", :format => "rss") + get feed_api_notes_path(:bbox => "1,1,1.2,1.2", :limit => "0", :format => "rss") assert_response :bad_request - get feed_notes_path(:bbox => "1,1,1.2,1.2", :limit => "10001", :format => "rss") + get feed_api_notes_path(:bbox => "1,1,1.2,1.2", :limit => "10001", :format => "rss") assert_response :bad_request end end diff --git a/test/controllers/browse_controller_test.rb b/test/controllers/browse_controller_test.rb index cde9403d0..578e78fa2 100644 --- a/test/controllers/browse_controller_test.rb +++ b/test/controllers/browse_controller_test.rb @@ -32,14 +32,6 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest { :path => "/changeset/1", :method => :get }, { :controller => "browse", :action => "changeset", :id => "1" } ) - assert_routing( - { :path => "/note/1", :method => :get }, - { :controller => "browse", :action => "note", :id => "1" } - ) - assert_routing( - { :path => "/note/new", :method => :get }, - { :controller => "browse", :action => "new_note" } - ) assert_routing( { :path => "/query", :method => :get }, { :controller => "browse", :action => "query" } @@ -106,78 +98,6 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest assert_select "div.changeset-comments ul li", :count => 4 end - def test_read_note - open_note = create(:note_with_comments) - - browse_check :browse_note_path, open_note.id, "browse/note" - end - - def test_read_hidden_note - hidden_note_with_comment = create(:note_with_comments, :status => "hidden") - - get browse_note_path(:id => hidden_note_with_comment) - assert_response :not_found - assert_template "browse/not_found" - assert_template :layout => "map" - - get browse_note_path(:id => hidden_note_with_comment), :xhr => true - assert_response :not_found - assert_template "browse/not_found" - assert_template :layout => "xhr" - - session_for(create(:moderator_user)) - - browse_check :browse_note_path, hidden_note_with_comment.id, "browse/note" - end - - def test_read_note_hidden_comments - note_with_hidden_comment = create(:note_with_comments, :comments_count => 2) do |note| - create(:note_comment, :note => note, :visible => false) - end - - browse_check :browse_note_path, note_with_hidden_comment.id, "browse/note" - assert_select "div.note-comments ul li", :count => 1 - - session_for(create(:moderator_user)) - - browse_check :browse_note_path, note_with_hidden_comment.id, "browse/note" - assert_select "div.note-comments ul li", :count => 2 - end - - def test_read_note_hidden_user_comment - hidden_user = create(:user, :deleted) - note_with_hidden_user_comment = create(:note_with_comments, :comments_count => 2) do |note| - create(:note_comment, :note => note, :author => hidden_user) - end - - browse_check :browse_note_path, note_with_hidden_user_comment.id, "browse/note" - assert_select "div.note-comments ul li", :count => 1 - - session_for(create(:moderator_user)) - - browse_check :browse_note_path, note_with_hidden_user_comment.id, "browse/note" - assert_select "div.note-comments ul li", :count => 1 - end - - def test_read_closed_note - user = create(:user) - closed_note = create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc, :comments_count => 2) do |note| - create(:note_comment, :event => "closed", :note => note, :author => user) - end - - browse_check :browse_note_path, closed_note.id, "browse/note" - assert_select "div.note-comments ul li", :count => 2 - assert_select "div.details", /Resolved by #{user.display_name}/ - - user.soft_destroy! - - reset! - - browse_check :browse_note_path, closed_note.id, "browse/note" - assert_select "div.note-comments ul li", :count => 1 - assert_select "div.details", /Resolved by deleted/ - end - ## # Methods to check redaction. # @@ -256,12 +176,6 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest assert_select ".browse-section.browse-relation", 2 end - def test_new_note - get note_new_path - assert_response :success - assert_template "browse/new_note" - end - def test_query get query_path assert_response :success diff --git a/test/controllers/notes_controller_test.rb b/test/controllers/notes_controller_test.rb index 50e7ae833..5cffbd702 100644 --- a/test/controllers/notes_controller_test.rb +++ b/test/controllers/notes_controller_test.rb @@ -15,6 +15,14 @@ class NotesControllerTest < ActionDispatch::IntegrationTest { :path => "/user/username/notes", :method => :get }, { :controller => "notes", :action => "index", :display_name => "username" } ) + assert_routing( + { :path => "/note/1", :method => :get }, + { :controller => "notes", :action => "show", :id => "1" } + ) + assert_routing( + { :path => "/note/new", :method => :get }, + { :controller => "notes", :action => "new" } + ) end def test_index_success @@ -80,4 +88,120 @@ class NotesControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_select "h4", :html => "No notes" end + + def test_read_note + open_note = create(:note_with_comments) + + browse_check :note_path, open_note.id, "notes/show" + end + + def test_read_hidden_note + hidden_note_with_comment = create(:note_with_comments, :status => "hidden") + + get note_path(:id => hidden_note_with_comment) + assert_response :not_found + assert_template "browse/not_found" + assert_template :layout => "map" + + get note_path(:id => hidden_note_with_comment), :xhr => true + assert_response :not_found + assert_template "browse/not_found" + assert_template :layout => "xhr" + + session_for(create(:moderator_user)) + + browse_check :note_path, hidden_note_with_comment.id, "notes/show" + end + + def test_read_note_hidden_comments + note_with_hidden_comment = create(:note_with_comments, :comments_count => 2) do |note| + create(:note_comment, :note => note, :visible => false) + end + + browse_check :note_path, note_with_hidden_comment.id, "notes/show" + assert_select "div.note-comments ul li", :count => 1 + + session_for(create(:moderator_user)) + + browse_check :note_path, note_with_hidden_comment.id, "notes/show" + assert_select "div.note-comments ul li", :count => 2 + end + + def test_read_note_hidden_user_comment + hidden_user = create(:user, :deleted) + note_with_hidden_user_comment = create(:note_with_comments, :comments_count => 2) do |note| + create(:note_comment, :note => note, :author => hidden_user) + end + + browse_check :note_path, note_with_hidden_user_comment.id, "notes/show" + assert_select "div.note-comments ul li", :count => 1 + + session_for(create(:moderator_user)) + + browse_check :note_path, note_with_hidden_user_comment.id, "notes/show" + assert_select "div.note-comments ul li", :count => 1 + end + + def test_read_closed_note + user = create(:user) + closed_note = create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc, :comments_count => 2) do |note| + create(:note_comment, :event => "closed", :note => note, :author => user) + end + + browse_check :note_path, closed_note.id, "notes/show" + assert_select "div.note-comments ul li", :count => 2 + assert_select "div.details", /Resolved by #{user.display_name}/ + + user.soft_destroy! + + reset! + + browse_check :note_path, closed_note.id, "notes/show" + assert_select "div.note-comments ul li", :count => 1 + assert_select "div.details", /Resolved by deleted/ + end + + def test_new_note + get new_note_path + assert_response :success + assert_template "notes/new" + end + + private + + # This is a convenience method for most of the above checks + # First we check that when we don't have an id, it will correctly return a 404 + # then we check that we get the correct 404 when a non-existant id is passed + # then we check that it will get a successful response, when we do pass an id + def browse_check(path, id, template) + path_method = method(path) + + assert_raise ActionController::UrlGenerationError do + get path_method.call + end + + # assert_raise ActionController::UrlGenerationError do + # get path_method.call(:id => -10) # we won't have an id that's negative + # end + + get path_method.call(:id => 0) + assert_response :not_found + assert_template "browse/not_found" + assert_template :layout => "map" + + get path_method.call(:id => 0), :xhr => true + assert_response :not_found + assert_template "browse/not_found" + assert_template :layout => "xhr" + + get path_method.call(:id => id) + assert_response :success + assert_template template + assert_template :layout => "map" + + get path_method.call(:id => id), :xhr => true + assert_response :success + assert_template template + assert_template :layout => "xhr" + end end diff --git a/test/controllers/site_controller_test.rb b/test/controllers/site_controller_test.rb index ccd8ba254..8a38da5c0 100644 --- a/test/controllers/site_controller_test.rb +++ b/test/controllers/site_controller_test.rb @@ -98,7 +98,7 @@ class SiteControllerTest < ActionDispatch::IntegrationTest assert_redirected_to :controller => :browse, :action => :relation, :id => 123 get root_path(:note => 123) - assert_redirected_to :controller => :browse, :action => :note, :id => 123 + assert_redirected_to :controller => :notes, :action => :show, :id => 123 get root_path(:query => "test") assert_redirected_to :controller => :geocoder, :action => :search, :query => "test" diff --git a/test/system/index_test.rb b/test/system/index_test.rb index 1167797c5..1de18c9ed 100644 --- a/test/system/index_test.rb +++ b/test/system/index_test.rb @@ -12,7 +12,7 @@ class IndexTest < ApplicationSystemTestCase test "note included in edit link" do note = create(:note_with_comments) - visit browse_note_path(note) + visit note_path(note) assert_selector "#editanchor[href*='?note=#{note.id}#']" find("#sidebar .btn-close").click @@ -27,8 +27,8 @@ class IndexTest < ApplicationSystemTestCase visible_note = create(:note, :latitude => position, :longitude => position) create(:note_comment, :note => visible_note, :body => "this-is-a-visible-note") - visit root_path(:anchor => "map=15/1/1") # view place of hidden note in case it is not rendered during browse_note_path(hidden_note) - visit browse_note_path(hidden_note) + visit root_path(:anchor => "map=15/1/1") # view place of hidden note in case it is not rendered during note_path(hidden_note) + visit note_path(hidden_note) find(".leaflet-control.control-layers .control-button").click find("#map-ui .overlay-layers .form-check-label", :text => "Map Notes").click visible_note_marker = find(".leaflet-marker-icon[title=this-is-a-visible-note]") diff --git a/test/system/note_comments_test.rb b/test/system/note_comments_test.rb new file mode 100644 index 000000000..23f3fc98e --- /dev/null +++ b/test/system/note_comments_test.rb @@ -0,0 +1,17 @@ +require "application_system_test_case" + +class NoteCommentsTest < ApplicationSystemTestCase + def test_action_text + note = create(:note_with_comments) + sign_in_as(create(:user)) + visit note_path(note) + + assert_button "Resolve" + assert_button "Comment", :disabled => true + + fill_in "text", :with => "Some text" + + assert_button "Comment & Resolve" + assert_button "Comment" + end +end diff --git a/test/system/report_note_test.rb b/test/system/report_note_test.rb index 2f407ca60..79894eb89 100644 --- a/test/system/report_note_test.rb +++ b/test/system/report_note_test.rb @@ -3,18 +3,18 @@ require "application_system_test_case" class ReportNoteTest < ApplicationSystemTestCase def test_no_link_when_not_logged_in note = create(:note_with_comments) - visit browse_note_path(note) + visit note_path(note) assert_content note.comments.first.body - assert_no_content I18n.t("browse.note.report") + assert_no_content I18n.t("notes.show.report") end def test_can_report_anonymous_notes note = create(:note_with_comments) sign_in_as(create(:user)) - visit browse_note_path(note) + visit note_path(note) - click_on I18n.t("browse.note.report") + click_on I18n.t("notes.show.report") assert_content "Report" assert_content I18n.t("reports.new.disclaimer.intro") @@ -33,9 +33,9 @@ class ReportNoteTest < ApplicationSystemTestCase def test_can_report_notes_with_author note = create(:note_comment, :author => create(:user)).note sign_in_as(create(:user)) - visit browse_note_path(note) + visit note_path(note) - click_on I18n.t("browse.note.report") + click_on I18n.t("notes.show.report") assert_content "Report" assert_content I18n.t("reports.new.disclaimer.intro") diff --git a/test/system/report_user_test.rb b/test/system/report_user_test.rb index 879558ab5..7a9e800c8 100644 --- a/test/system/report_user_test.rb +++ b/test/system/report_user_test.rb @@ -3,7 +3,7 @@ require "application_system_test_case" class ReportUserTest < ApplicationSystemTestCase def test_no_link_when_not_logged_in note = create(:note_with_comments) - visit browse_note_path(note) + visit note_path(note) assert_content note.comments.first.body assert_no_content I18n.t("users.show.report")