Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pluralize controllers #2052

Merged
merged 3 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Style/FrozenStringLiteralComment:
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Exclude:
- 'app/controllers/way_controller.rb'
- 'app/controllers/ways_controller.rb'

# Offense count: 70
# Cop supports --auto-correct.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DiaryEntryController < ApplicationController
class DiaryEntriesController < ApplicationController
layout "site", :except => :rss

before_action :authorize_web
Expand All @@ -12,7 +12,7 @@ class DiaryEntryController < ApplicationController
before_action :allow_thirdparty_images, :only => [:new, :edit, :index, :show, :comments]

def new
@title = t "diary_entry.new.title"
@title = t "diary_entries.new.title"

if request.post?
@diary_entry = DiaryEntry.new(entry_params)
Expand Down Expand Up @@ -44,7 +44,7 @@ def new
end

def edit
@title = t "diary_entry.edit.title"
@title = t "diary_entries.edit.title"
@diary_entry = DiaryEntry.find(params[:id])

if current_user != @diary_entry.user
Expand Down Expand Up @@ -105,23 +105,23 @@ def index
@user = User.active.find_by(:display_name => params[:display_name])

if @user
@title = t "diary_entry.index.user_title", :user => @user.display_name
@title = t "diary_entries.index.user_title", :user => @user.display_name
@entries = @user.diary_entries
else
render_unknown_user params[:display_name]
return
end
elsif params[:friends]
if current_user
@title = t "diary_entry.index.title_friends"
@title = t "diary_entries.index.title_friends"
@entries = DiaryEntry.where(:user_id => current_user.friend_users)
else
require_user
return
end
elsif params[:nearby]
if current_user
@title = t "diary_entry.index.title_nearby"
@title = t "diary_entries.index.title_nearby"
@entries = DiaryEntry.where(:user_id => current_user.nearby)
else
require_user
Expand All @@ -131,10 +131,10 @@ def index
@entries = DiaryEntry.joins(:user).where(:users => { :status => %w[active confirmed] })

if params[:language]
@title = t "diary_entry.index.in_language_title", :language => Language.find(params[:language]).english_name
@title = t "diary_entries.index.in_language_title", :language => Language.find(params[:language]).english_name
@entries = @entries.where(:language_code => params[:language])
else
@title = t "diary_entry.index.title"
@title = t "diary_entries.index.title"
end
end

Expand All @@ -156,9 +156,9 @@ def rss

if user
@entries = user.diary_entries
@title = t("diary_entry.feed.user.title", :user => user.display_name)
@description = t("diary_entry.feed.user.description", :user => user.display_name)
@link = url_for :controller => "diary_entry", :action => "index", :display_name => user.display_name, :host => SERVER_URL, :protocol => SERVER_PROTOCOL
@title = t("diary_entries.feed.user.title", :user => user.display_name)
@description = t("diary_entries.feed.user.description", :user => user.display_name)
@link = url_for :action => "index", :display_name => user.display_name, :host => SERVER_URL, :protocol => SERVER_PROTOCOL
else
head :not_found
return
Expand All @@ -168,13 +168,13 @@ def rss

if params[:language]
@entries = @entries.where(:language_code => params[:language])
@title = t("diary_entry.feed.language.title", :language_name => Language.find(params[:language]).english_name)
@description = t("diary_entry.feed.language.description", :language_name => Language.find(params[:language]).english_name)
@link = url_for :controller => "diary_entry", :action => "index", :language => params[:language], :host => SERVER_URL, :protocol => SERVER_PROTOCOL
@title = t("diary_entries.feed.language.title", :language_name => Language.find(params[:language]).english_name)
@description = t("diary_entries.feed.language.description", :language_name => Language.find(params[:language]).english_name)
@link = url_for :action => "index", :language => params[:language], :host => SERVER_URL, :protocol => SERVER_PROTOCOL
else
@title = t("diary_entry.feed.all.title")
@description = t("diary_entry.feed.all.description")
@link = url_for :controller => "diary_entry", :action => "index", :host => SERVER_URL, :protocol => SERVER_PROTOCOL
@title = t("diary_entries.feed.all.title")
@description = t("diary_entries.feed.all.description")
@link = url_for :action => "index", :host => SERVER_URL, :protocol => SERVER_PROTOCOL
end
end

Expand All @@ -184,9 +184,9 @@ def rss
def show
@entry = @user.diary_entries.visible.where(:id => params[:id]).first
if @entry
@title = t "diary_entry.show.title", :user => params[:display_name], :title => @entry.title
@title = t "diary_entries.show.title", :user => params[:display_name], :title => @entry.title
else
@title = t "diary_entry.no_such_entry.title", :id => params[:id]
@title = t "diary_entries.no_such_entry.title", :id => params[:id]
render :action => "no_such_entry", :status => :not_found
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The NodeController is the RESTful interface to Node objects

class NodeController < ApplicationController
class NodesController < ApplicationController
require "xml/libxml"

skip_before_action :verify_authenticity_token
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class OldNodeController < OldController
class OldNodesController < OldController
private

def lookup_old_element
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class OldRelationController < OldController
class OldRelationsController < OldController
private

def lookup_old_element
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class OldWayController < OldController
class OldWaysController < OldController
private

def lookup_old_element
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class RelationController < ApplicationController
class RelationsController < ApplicationController
require "xml/libxml"

skip_before_action :verify_authenticity_token
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class WayController < ApplicationController
class WaysController < ApplicationController
require "xml/libxml"

skip_before_action :verify_authenticity_token
Expand Down
2 changes: 1 addition & 1 deletion app/views/browse/feature.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<%= render :partial => @type, :object => @feature %>

<div class='secondary-actions'>
<%= link_to(t('browse.download_xml'), :controller => @type, :action => "read") %>
<%= link_to(t('browse.download_xml'), :controller => @type.pluralize, :action => "read") %>
&middot;
<%= link_to(t('browse.view_history'), :action => "#{@type}_history") %>
</div>
2 changes: 1 addition & 1 deletion app/views/browse/history.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<%= render :partial => @type, :collection => @feature.send("old_#{@type}s").reverse %>

<div class='secondary-actions'>
<%= link_to(t('browse.download_xml'), :controller => "old_#{@type}", :action => "history") %>
<%= link_to(t('browse.download_xml'), :controller => "old_#{@type.pluralize}", :action => "history") %>
&middot;
<%= link_to(t('browse.view_details'), :action => @type) %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h2><%= link_to h(diary_entry.title), diary_entry_path(diary_entry.user, diary_entry) %></h2>

<small class='deemphasize'>
<%= raw(t '.posted_by', :link_user => (link_to h(diary_entry.user.display_name), user_path(diary_entry.user)), :created => l(diary_entry.created_at, :format => :blog), :language_link => (link_to h(diary_entry.language.name), :controller => 'diary_entry', :action => 'index', :display_name => nil, :language => diary_entry.language_code)) %>
<%= raw(t '.posted_by', :link_user => (link_to h(diary_entry.user.display_name), user_path(diary_entry.user)), :created => l(diary_entry.created_at, :format => :blog), :language_link => (link_to h(diary_entry.language.name), :controller => 'diary_entries', :action => 'index', :display_name => nil, :language => diary_entry.language_code)) %>
</small>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</fieldset>

<% if action_name == 'new' %>
<%= submit_tag t('diary_entry.new.publish_button') %>
<%= submit_tag t('diary_entries.new.publish_button') %>
<% else %>
<%= submit_tag t('.save_button') %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
<% if @user %>
<% if @user == current_user %>
<div>
<li><%= link_to image_tag("new.png", :class => "small_icon", :border=>0) + t('.new'), {:controller => 'diary_entry', :action => 'new'}, {:title => t('.new_title')} %></li>
<li><%= link_to image_tag("new.png", :class => "small_icon", :border=>0) + t('.new'), diary_new_path, {:title => t('.new_title')} %></li>
</div>
<% end %>
<% else %>
<% if current_user %>
<div>
<li><%= link_to image_tag("new.png", :class => "small_icon", :border=>0) + t('.new'), {:controller => 'diary_entry', :action => 'new'}, {:title => t('.new_title')} %></li>
<li><%= link_to image_tag("new.png", :class => "small_icon", :border=>0) + t('.new'), diary_new_path, {:title => t('.new_title')} %></li>
</div>
<% end %>
<% end %>
Expand Down
8 changes: 4 additions & 4 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
<span class='count-number'><%= number_with_delimiter(current_user.traces.size) %></span>
</li>
<li>
<%= link_to t('.my diary'), :controller => 'diary_entry', :action => 'index', :display_name => current_user.display_name %>
<%= link_to t('.my diary'), :controller => 'diary_entries', :action => 'index', :display_name => current_user.display_name %>
<span class='count-number'><%= number_with_delimiter(current_user.diary_entries.size) %></span>
</li>
<li>
<%= link_to t('.my comments' ), :controller => 'diary_entry', :action => 'comments', :display_name => current_user.display_name %>
<%= link_to t('.my comments' ), :controller => 'diary_entries', :action => 'comments', :display_name => current_user.display_name %>
</li>
<li>
<%= link_to t('.my settings'), :controller => 'users', :action => 'account', :display_name => current_user.display_name %>
Expand Down Expand Up @@ -66,11 +66,11 @@
<%= link_to t('.send message'), new_message_path(@user) %>
</li>
<li>
<%= link_to t('.diary'), :controller => 'diary_entry', :action => 'index', :display_name => @user.display_name %>
<%= link_to t('.diary'), :controller => 'diary_entries', :action => 'index', :display_name => @user.display_name %>
<span class='count-number'><%= number_with_delimiter(@user.diary_entries.size) %></span>
</li>
<li>
<%= link_to t('.comments'), :controller => 'diary_entry', :action => 'comments', :display_name => @user.display_name %>
<%= link_to t('.comments'), :controller => 'diary_entries', :action => 'comments', :display_name => @user.display_name %>
</li>
<li>
<% if current_user and current_user.is_friends_with?(@user) %>
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ en:
commented_at_html: "Updated %{when} ago"
commented_at_by_html: "Updated %{when} ago by %{user}"
full: Full discussion
diary_entry:
diary_entries:
new:
title: New Diary Entry
publish_button: "Publish"
Expand Down
100 changes: 50 additions & 50 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,38 @@
post "changeset/comment/:id/hide" => "changeset#hide_comment", :as => :changeset_comment_hide, :id => /\d+/
post "changeset/comment/:id/unhide" => "changeset#unhide_comment", :as => :changeset_comment_unhide, :id => /\d+/

put "node/create" => "node#create"
get "node/:id/ways" => "way#ways_for_node", :id => /\d+/
get "node/:id/relations" => "relation#relations_for_node", :id => /\d+/
get "node/:id/history" => "old_node#history", :id => /\d+/
post "node/:id/:version/redact" => "old_node#redact", :version => /\d+/, :id => /\d+/
get "node/:id/:version" => "old_node#version", :id => /\d+/, :version => /\d+/
get "node/:id" => "node#read", :id => /\d+/
put "node/:id" => "node#update", :id => /\d+/
delete "node/:id" => "node#delete", :id => /\d+/
get "nodes" => "node#nodes"

put "way/create" => "way#create"
get "way/:id/history" => "old_way#history", :id => /\d+/
get "way/:id/full" => "way#full", :id => /\d+/
get "way/:id/relations" => "relation#relations_for_way", :id => /\d+/
post "way/:id/:version/redact" => "old_way#redact", :version => /\d+/, :id => /\d+/
get "way/:id/:version" => "old_way#version", :id => /\d+/, :version => /\d+/
get "way/:id" => "way#read", :id => /\d+/
put "way/:id" => "way#update", :id => /\d+/
delete "way/:id" => "way#delete", :id => /\d+/
get "ways" => "way#ways"

put "relation/create" => "relation#create"
get "relation/:id/relations" => "relation#relations_for_relation", :id => /\d+/
get "relation/:id/history" => "old_relation#history", :id => /\d+/
get "relation/:id/full" => "relation#full", :id => /\d+/
post "relation/:id/:version/redact" => "old_relation#redact", :version => /\d+/, :id => /\d+/
get "relation/:id/:version" => "old_relation#version", :id => /\d+/, :version => /\d+/
get "relation/:id" => "relation#read", :id => /\d+/
put "relation/:id" => "relation#update", :id => /\d+/
delete "relation/:id" => "relation#delete", :id => /\d+/
get "relations" => "relation#relations"
put "node/create" => "nodes#create"
get "node/:id/ways" => "ways#ways_for_node", :id => /\d+/
get "node/:id/relations" => "relations#relations_for_node", :id => /\d+/
get "node/:id/history" => "old_nodes#history", :id => /\d+/
post "node/:id/:version/redact" => "old_nodes#redact", :version => /\d+/, :id => /\d+/
get "node/:id/:version" => "old_nodes#version", :id => /\d+/, :version => /\d+/
get "node/:id" => "nodes#read", :id => /\d+/
put "node/:id" => "nodes#update", :id => /\d+/
delete "node/:id" => "nodes#delete", :id => /\d+/
get "nodes" => "nodes#nodes"

put "way/create" => "ways#create"
get "way/:id/history" => "old_ways#history", :id => /\d+/
get "way/:id/full" => "ways#full", :id => /\d+/
get "way/:id/relations" => "relations#relations_for_way", :id => /\d+/
post "way/:id/:version/redact" => "old_ways#redact", :version => /\d+/, :id => /\d+/
get "way/:id/:version" => "old_ways#version", :id => /\d+/, :version => /\d+/
get "way/:id" => "ways#read", :id => /\d+/
put "way/:id" => "ways#update", :id => /\d+/
delete "way/:id" => "ways#delete", :id => /\d+/
get "ways" => "ways#ways"

put "relation/create" => "relations#create"
get "relation/:id/relations" => "relations#relations_for_relation", :id => /\d+/
get "relation/:id/history" => "old_relations#history", :id => /\d+/
get "relation/:id/full" => "relations#full", :id => /\d+/
post "relation/:id/:version/redact" => "old_relations#redact", :version => /\d+/, :id => /\d+/
get "relation/:id/:version" => "old_relations#version", :id => /\d+/, :version => /\d+/
get "relation/:id" => "relations#read", :id => /\d+/
put "relation/:id" => "relations#update", :id => /\d+/
delete "relation/:id" => "relations#delete", :id => /\d+/
get "relations" => "relations#relations"

get "map" => "api#map"

Expand Down Expand Up @@ -214,24 +214,24 @@
post "/trace/:id/delete" => "traces#delete", :id => /\d+/

# diary pages
match "/diary/new" => "diary_entry#new", :via => [:get, :post]
get "/diary/friends" => "diary_entry#index", :friends => true, :as => "friend_diaries"
get "/diary/nearby" => "diary_entry#index", :nearby => true, :as => "nearby_diaries"
get "/user/:display_name/diary/rss" => "diary_entry#rss", :defaults => { :format => :rss }
get "/diary/:language/rss" => "diary_entry#rss", :defaults => { :format => :rss }
get "/diary/rss" => "diary_entry#rss", :defaults => { :format => :rss }
get "/user/:display_name/diary/comments/:page" => "diary_entry#comments", :page => /[1-9][0-9]*/
get "/user/:display_name/diary/comments/" => "diary_entry#comments"
get "/user/:display_name/diary" => "diary_entry#index"
get "/diary/:language" => "diary_entry#index"
get "/diary" => "diary_entry#index"
get "/user/:display_name/diary/:id" => "diary_entry#show", :id => /\d+/, :as => :diary_entry
post "/user/:display_name/diary/:id/newcomment" => "diary_entry#comment", :id => /\d+/
match "/user/:display_name/diary/:id/edit" => "diary_entry#edit", :via => [:get, :post], :id => /\d+/
post "/user/:display_name/diary/:id/hide" => "diary_entry#hide", :id => /\d+/, :as => :hide_diary_entry
post "/user/:display_name/diary/:id/hidecomment/:comment" => "diary_entry#hidecomment", :id => /\d+/, :comment => /\d+/, :as => :hide_diary_comment
post "/user/:display_name/diary/:id/subscribe" => "diary_entry#subscribe", :as => :diary_entry_subscribe, :id => /\d+/
post "/user/:display_name/diary/:id/unsubscribe" => "diary_entry#unsubscribe", :as => :diary_entry_unsubscribe, :id => /\d+/
match "/diary/new" => "diary_entries#new", :via => [:get, :post]
get "/diary/friends" => "diary_entries#index", :friends => true, :as => "friend_diaries"
get "/diary/nearby" => "diary_entries#index", :nearby => true, :as => "nearby_diaries"
get "/user/:display_name/diary/rss" => "diary_entries#rss", :defaults => { :format => :rss }
get "/diary/:language/rss" => "diary_entries#rss", :defaults => { :format => :rss }
get "/diary/rss" => "diary_entries#rss", :defaults => { :format => :rss }
get "/user/:display_name/diary/comments/:page" => "diary_entries#comments", :page => /[1-9][0-9]*/
get "/user/:display_name/diary/comments/" => "diary_entries#comments"
get "/user/:display_name/diary" => "diary_entries#index"
get "/diary/:language" => "diary_entries#index"
get "/diary" => "diary_entries#index"
get "/user/:display_name/diary/:id" => "diary_entries#show", :id => /\d+/, :as => :diary_entry
post "/user/:display_name/diary/:id/newcomment" => "diary_entries#comment", :id => /\d+/
match "/user/:display_name/diary/:id/edit" => "diary_entries#edit", :via => [:get, :post], :id => /\d+/
post "/user/:display_name/diary/:id/hide" => "diary_entries#hide", :id => /\d+/, :as => :hide_diary_entry
post "/user/:display_name/diary/:id/hidecomment/:comment" => "diary_entries#hidecomment", :id => /\d+/, :comment => /\d+/, :as => :hide_diary_comment
post "/user/:display_name/diary/:id/subscribe" => "diary_entries#subscribe", :as => :diary_entry_subscribe, :id => /\d+/
post "/user/:display_name/diary/:id/unsubscribe" => "diary_entries#unsubscribe", :as => :diary_entry_unsubscribe, :id => /\d+/

# user pages
get "/user/:display_name" => "users#show", :as => "user"
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/changeset_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ def test_changeset_bbox
changeset_id = @response.body.to_i

# add a single node to it
with_controller(NodeController.new) do
with_controller(NodesController.new) do
content "<osm><node lon='1' lat='2' changeset='#{changeset_id}'/></osm>"
put :create
assert_response :success, "Couldn't create node."
Expand All @@ -1543,7 +1543,7 @@ def test_changeset_bbox
assert_select "osm>changeset[max_lat='2.0000000']", 1

# add another node to it
with_controller(NodeController.new) do
with_controller(NodesController.new) do
content "<osm><node lon='2' lat='1' changeset='#{changeset_id}'/></osm>"
put :create
assert_response :success, "Couldn't create second node."
Expand All @@ -1558,7 +1558,7 @@ def test_changeset_bbox
assert_select "osm>changeset[max_lat='2.0000000']", 1

# add (delete) a way to it, which contains a point at (3,3)
with_controller(WayController.new) do
with_controller(WaysController.new) do
content update_changeset(way.to_xml, changeset_id)
put :delete, :params => { :id => way.id }
assert_response :success, "Couldn't delete a way."
Expand Down Expand Up @@ -1838,7 +1838,7 @@ def test_changeset_limits
changeset.num_changes = Changeset::MAX_ELEMENTS - offset
changeset.save!

with_controller(NodeController.new) do
with_controller(NodesController.new) do
# create a new node
content "<osm><node changeset='#{cs_id}' lat='0.0' lon='0.0'/></osm>"
put :create
Expand Down
Loading