forked from openstreetmap/openstreetmap-website
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/pull/4889'
- Loading branch information
Showing
9 changed files
with
120 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class DiaryCommentsController < ApplicationController | ||
include UserMethods | ||
include PaginationMethods | ||
|
||
layout "site" | ||
|
||
before_action :authorize_web | ||
before_action :set_locale | ||
before_action :check_database_readable | ||
|
||
authorize_resource | ||
|
||
before_action :lookup_user, :only => :index | ||
|
||
allow_thirdparty_images :only => :index | ||
|
||
def index | ||
@title = t ".title", :user => @user.display_name | ||
|
||
comments = DiaryComment.where(:user => @user) | ||
comments = comments.visible unless can? :unhidecomment, DiaryEntry | ||
|
||
@params = params.permit(:display_name, :before, :after) | ||
|
||
@comments, @newer_comments_id, @older_comments_id = get_page_items(comments, :includes => [:user]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require "test_helper" | ||
|
||
class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest | ||
def setup | ||
super | ||
# Create the default language for diary entries | ||
create(:language, :code => "en") | ||
end | ||
|
||
def test_routes | ||
assert_routing( | ||
{ :path => "/user/username/diary/comments", :method => :get }, | ||
{ :controller => "diary_comments", :action => "index", :display_name => "username" } | ||
) | ||
|
||
get "/user/username/diary/comments/1" | ||
assert_redirected_to "/user/username/diary/comments" | ||
end | ||
|
||
def test_index | ||
user = create(:user) | ||
other_user = create(:user) | ||
suspended_user = create(:user, :suspended) | ||
deleted_user = create(:user, :deleted) | ||
|
||
# Test a user with no comments | ||
get diary_comments_path(:display_name => user.display_name) | ||
assert_response :success | ||
assert_template :index | ||
assert_select "h4", :html => "No diary comments" | ||
|
||
# Test a user with a comment | ||
create(:diary_comment, :user => other_user) | ||
|
||
get diary_comments_path(:display_name => other_user.display_name) | ||
assert_response :success | ||
assert_template :index | ||
assert_dom "a[href='#{user_path(other_user)}']", :text => other_user.display_name | ||
assert_select "table.table-striped tbody" do | ||
assert_select "tr", :count => 1 | ||
end | ||
|
||
# Test a suspended user | ||
get diary_comments_path(:display_name => suspended_user.display_name) | ||
assert_response :not_found | ||
|
||
# Test a deleted user | ||
get diary_comments_path(:display_name => deleted_user.display_name) | ||
assert_response :not_found | ||
end | ||
|
||
def test_index_invalid_paged | ||
user = create(:user) | ||
|
||
%w[-1 0 fred].each do |id| | ||
get diary_comments_path(:display_name => user.display_name, :before => id) | ||
assert_redirected_to :controller => :errors, :action => :bad_request | ||
|
||
get diary_comments_path(:display_name => user.display_name, :after => id) | ||
assert_redirected_to :controller => :errors, :action => :bad_request | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters