before_action :authorize_web
before_action :set_locale
before_action :require_user, :only => [:new, :edit, :comment, :hide, :hidecomment, :subscribe, :unsubscribe]
- before_action :lookup_user, :only => [:view, :comments]
+ before_action :lookup_user, :only => [:show, :comments]
before_action :check_database_readable
before_action :check_database_writable, :only => [:new, :edit, :comment, :hide, :hidecomment, :subscribe, :unsubscribe]
before_action :require_administrator, :only => [:hide, :hidecomment]
- before_action :allow_thirdparty_images, :only => [:new, :edit, :list, :view, :comments]
+ before_action :allow_thirdparty_images, :only => [:new, :edit, :list, :show, :comments]
def new
@title = t "diary_entry.new.title"
@diary_entry = DiaryEntry.find(params[:id])
if current_user != @diary_entry.user
- redirect_to :action => "view", :id => params[:id]
+ redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
elsif params[:diary_entry] && @diary_entry.update(entry_params)
- redirect_to :action => "view", :id => params[:id]
+ redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
end
set_map_location
# Add the commenter to the subscribers if necessary
@entry.subscriptions.create(:user => current_user) unless @entry.subscribers.exists?(current_user.id)
- redirect_to :action => "view", :display_name => @entry.user.display_name, :id => @entry.id
+ redirect_to diary_entry_path(@entry.user, @entry)
else
- render :action => "view"
+ render :action => "show"
end
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
diary_entry.subscriptions.create(:user => current_user) unless diary_entry.subscribers.exists?(current_user.id)
- redirect_to :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
+ redirect_to diary_entry_path(diary_entry.user, diary_entry)
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
end
diary_entry.subscriptions.where(:user => current_user).delete_all if diary_entry.subscribers.exists?(current_user.id)
- redirect_to :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
+ redirect_to diary_entry_path(diary_entry.user, diary_entry)
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
end
@entries = @entries.visible.includes(:user).order("created_at DESC").limit(20)
end
- def view
+ def show
@entry = @user.diary_entries.visible.where(:id => params[:id]).first
if @entry
- @title = t "diary_entry.view.title", :user => params[:display_name], :title => @entry.title
+ @title = t "diary_entry.show.title", :user => params[:display_name], :title => @entry.title
else
@title = t "diary_entry.no_such_entry.title", :id => params[:id]
render :action => "no_such_entry", :status => :not_found
def hidecomment
comment = DiaryComment.find(params[:comment])
comment.update(:visible => false)
- redirect_to :action => "view", :display_name => comment.diary_entry.user.display_name, :id => comment.diary_entry.id
+ redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
end
def comments
def require_administrator
unless current_user.administrator?
flash[:error] = t("user.filter.not_an_administrator")
- redirect_to :action => "view"
+ redirect_to :action => "show"
end
end
def reportable_url(reportable)
case reportable
when DiaryEntry
- url_for(:controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.user.display_name, :id => reportable.id)
+ diary_entry_url(reportable.user, reportable)
when User
url_for(:controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.display_name)
when DiaryComment
- url_for(:controller => reportable.diary_entry.class.name.underscore, :action => :view, :display_name => reportable.diary_entry.user.display_name, :id => reportable.diary_entry.id, :anchor => "comment#{reportable.id}")
+ 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)
end
@from_user = comment.user.display_name
@text = comment.body
@title = comment.diary_entry.title
- @readurl = url_for(:controller => "diary_entry",
- :action => "view",
- :display_name => comment.diary_entry.user.display_name,
- :id => comment.diary_entry.id,
- :anchor => "comment#{comment.id}")
- @commenturl = url_for(:controller => "diary_entry",
- :action => "view",
- :display_name => comment.diary_entry.user.display_name,
- :id => comment.diary_entry.id,
- :anchor => "newcomment")
+ @readurl = diary_entry_url(comment.diary_entry.user, comment.diary_entry, :anchor => "comment#{comment.id}")
+ @commenturl = diary_entry_url(comment.diary_entry.user, comment.diary_entry, :anchor => "newcomment")
@replyurl = new_message_url(comment.user, :message => { :title => "Re: #{comment.diary_entry.title}" })
@author = @from_user
<%= user_thumbnail diary_entry.user %>
<% end %>
- <h2><%= link_to h(diary_entry.title), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id %></h2>
+ <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 => 'list', :display_name => nil, :language => diary_entry.language_code)) %>
<ul class='secondary-actions clearfix'>
<% if params[:action] == 'list' %>
- <li><%= link_to t('.comment_link'), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'newcomment' %></li>
+ <li><%= link_to t('.comment_link'), diary_entry_path(diary_entry.user, diary_entry, :anchor => 'newcomment') %></li>
<li><%= link_to t('.reply_link'), new_message_path(diary_entry.user, :message => { :title => "Re: #{diary_entry.title}" }) %></li>
- <li><%= link_to t('.comment_count', :count => diary_entry.visible_comments.count), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'comments' %></li>
+ <li><%= link_to t('.comment_count', :count => diary_entry.visible_comments.count), diary_entry_path(diary_entry.user, diary_entry, :anchor => 'comments') %></li>
<% end %>
<% if current_user && current_user == diary_entry.user %>
<% @comments.each do |comment| -%>
<% cl = cycle('table0', 'table1') %>
<tr class="<%= cl %>">
- <td width="25%"><%= link_to comment.diary_entry.title, :action => :view, :display_name => comment.diary_entry.user.display_name, :id => comment.diary_entry.id %></td>
+ <td width="25%"><%= link_to comment.diary_entry.title, diary_entry_path(comment.diary_entry.user, comment.diary_entry) %></td>
<td width="25%"><span title="<%= l comment.created_at, :format => :friendly %>"><%= t '.ago', :ago => time_ago_in_words(comment.created_at) %></span></td>
<td width="50%" class="richtext"><%= comment.body.to_html %></td>
</tr>
@entries.each do |entry|
xml.item do
xml.title entry.title
- xml.link url_for(:action => "view", :id => entry.id, :display_name => entry.user.display_name, :only_path => false)
- xml.guid url_for(:action => "view", :id => entry.id, :display_name => entry.user.display_name, :only_path => false)
+ xml.link diary_entry_url(entry.user, entry, :only_path => false)
+ xml.guid diary_entry_url(entry.user, entry, :only_path => false)
xml.description entry.body.to_html
xml.dc :creator, entry.user.display_name
xml.pubDate entry.created_at.to_s(:rfc822)
- xml.comments url_for(:action => "view", :id => entry.id, :display_name => entry.user.display_name, :anchor => "comments", :only_path => false)
+ xml.comments diary_entry_url(entry.user, entry, :anchor => "comments", :only_path => false)
if entry.latitude && entry.longitude
xml.geo :lat, entry.latitude.to_s
use_map_link: "use map"
save_button: "Save"
marker_text: Diary entry location
- view:
+ show:
title: "%{user}'s diary | %{title}"
user_title: "%{user}'s diary"
leave_a_comment: "Leave a comment"
get "/user/:display_name/diary" => "diary_entry#list"
get "/diary/:language" => "diary_entry#list"
get "/diary" => "diary_entry#list"
- get "/user/:display_name/diary/:id" => "diary_entry#view", :id => /\d+/, :as => :diary_entry
+ 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
)
assert_routing(
{ :path => "/user/username/diary/1", :method => :get },
- { :controller => "diary_entry", :action => "view", :display_name => "username", :id => "1" }
+ { :controller => "diary_entry", :action => "show", :display_name => "username", :id => "1" }
)
assert_routing(
{ :path => "/user/username/diary/1/edit", :method => :get },
assert_select "h2", :text => "No entry with the id: 9999", :count => 1
end
- # Verify that you get redirected to view if you are not the user
+ # Verify that you get redirected to show if you are not the user
# that created the entry
get :edit,
:params => { :display_name => entry.user.display_name, :id => entry.id },
:session => { :user => other_user }
assert_response :redirect
- assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
+ assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
# Now pass the id, and check that you can edit it, when using the same
# user as the person who created the entry
:longitude => new_longitude, :language_code => new_language_code } },
:session => { :user => entry.user.id }
assert_response :redirect
- assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
+ assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
# Now check that the new data is rendered, when logged in
- get :view,
+ get :show,
:params => { :display_name => entry.user.display_name, :id => entry.id },
:session => { :user => entry.user }
assert_response :success
- assert_template "diary_entry/view"
+ assert_template "diary_entry/show"
assert_select "title", :text => /Users' diaries | /, :count => 1
assert_select "div.content-heading", :count => 1 do
assert_select "h2", :text => /#{entry.user.display_name}'s diary/, :count => 1
end
# and when not logged in as the user who wrote the entry
- get :view,
+ get :show,
:params => { :display_name => entry.user.display_name, :id => entry.id },
:session => { :user => create(:user) }
assert_response :success
- assert_template "diary_entry/view"
+ assert_template "diary_entry/show"
assert_select "title", :text => /Users' diaries | /, :count => 1
assert_select "div.content-heading", :count => 1 do
assert_select "h2", :text => /#{entry.user.display_name}'s diary/, :count => 1
end
end
assert_response :success
- assert_template :view
+ assert_template :show
# Now try again with the right id
assert_difference "ActionMailer::Base.deliveries.size", entry.subscribers.count do
end
end
assert_response :redirect
- assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
+ assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
email = ActionMailer::Base.deliveries.first
assert_equal [user.email], email.to
assert_equal "[OpenStreetMap] #{other_user.display_name} commented on a diary entry", email.subject
assert_equal other_user.id, comment.user_id
assert_equal "New comment", comment.body
- # Now view the diary entry, and check the new comment is present
- get :view,
+ # Now show the diary entry, and check the new comment is present
+ get :show,
:params => { :display_name => entry.user.display_name, :id => entry.id }
assert_response :success
assert_select ".diary-comment", :count => 1 do
end
end
assert_response :redirect
- assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
+ assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
email = ActionMailer::Base.deliveries.first
assert_equal [user.email], email.to
assert_equal "[OpenStreetMap] #{other_user.display_name} commented on a diary entry", email.subject
assert_response :redirect
assert_redirected_to :controller => :user, :action => :suspended
- # Now view the diary entry, and check the new comment is not present
- get :view,
+ # Now show the diary entry, and check the new comment is not present
+ get :show,
:params => { :display_name => entry.user.display_name, :id => entry.id }
assert_response :success
assert_select ".diary-comment", :count => 0
assert_match "<title><script></title>", response.body
end
- def test_view
+ def test_show
user = create(:user)
suspended_user = create(:user, :suspended)
deleted_user = create(:user, :deleted)
# Try a normal entry that should work
diary_entry = create(:diary_entry, :user => user)
- get :view, :params => { :display_name => user.display_name, :id => diary_entry.id }
+ get :show, :params => { :display_name => user.display_name, :id => diary_entry.id }
assert_response :success
- assert_template :view
+ assert_template :show
# Try a deleted entry
diary_entry_deleted = create(:diary_entry, :user => user, :visible => false)
- get :view, :params => { :display_name => user.display_name, :id => diary_entry_deleted.id }
+ get :show, :params => { :display_name => user.display_name, :id => diary_entry_deleted.id }
assert_response :not_found
# Try an entry by a suspended user
diary_entry_suspended = create(:diary_entry, :user => suspended_user)
- get :view, :params => { :display_name => suspended_user.display_name, :id => diary_entry_suspended.id }
+ get :show, :params => { :display_name => suspended_user.display_name, :id => diary_entry_suspended.id }
assert_response :not_found
# Try an entry by a deleted user
diary_entry_deleted = create(:diary_entry, :user => deleted_user)
- get :view, :params => { :display_name => deleted_user.display_name, :id => diary_entry_deleted.id }
+ get :show, :params => { :display_name => deleted_user.display_name, :id => diary_entry_deleted.id }
assert_response :not_found
end
- def test_view_hidden_comments
+ def test_show_hidden_comments
# Get a diary entry that has hidden comments
user = create(:user)
diary_entry = create(:diary_entry, :user => user)
deleted_user_comment = create(:diary_comment, :diary_entry => diary_entry, :user => create(:user, :deleted))
hidden_comment = create(:diary_comment, :diary_entry => diary_entry, :visible => false)
- get :view, :params => { :display_name => user.display_name, :id => diary_entry.id }
+ get :show, :params => { :display_name => user.display_name, :id => diary_entry.id }
assert_response :success
- assert_template :view
+ assert_template :show
assert_select "div.comments" do
assert_select "p#comment#{visible_comment.id}", :count => 1
assert_select "p#comment#{suspended_user_comment.id}", :count => 0
:params => { :display_name => user.display_name, :id => diary_entry.id },
:session => { :user => user }
assert_response :redirect
- assert_redirected_to :action => :view, :display_name => user.display_name, :id => diary_entry.id
+ assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_equal true, DiaryEntry.find(diary_entry.id).visible
# Finally try as an administrator
:params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
:session => { :user => user }
assert_response :redirect
- assert_redirected_to :action => :view, :display_name => user.display_name, :id => diary_entry.id
+ assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_equal true, DiaryComment.find(diary_comment.id).visible
# Finally try as an administrator
:params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
:session => { :user => administrator_user }
assert_response :redirect
- assert_redirected_to :action => :view, :display_name => user.display_name, :id => diary_entry.id
+ assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_equal false, DiaryComment.find(diary_comment.id).visible
end