Create diary_comments resources for users
This commit is contained in:
parent
6f71b372fb
commit
08292292f0
8 changed files with 115 additions and 84 deletions
|
@ -1,7 +1,4 @@
|
||||||
class DiaryCommentsController < ApplicationController
|
class DiaryCommentsController < ApplicationController
|
||||||
include UserMethods
|
|
||||||
include PaginationMethods
|
|
||||||
|
|
||||||
layout "site"
|
layout "site"
|
||||||
|
|
||||||
before_action :authorize_web
|
before_action :authorize_web
|
||||||
|
@ -10,23 +7,9 @@ class DiaryCommentsController < ApplicationController
|
||||||
|
|
||||||
authorize_resource
|
authorize_resource
|
||||||
|
|
||||||
before_action :lookup_user, :only => :index
|
before_action :check_database_writable
|
||||||
before_action :check_database_writable, :only => [:create, :hide, :unhide]
|
|
||||||
|
|
||||||
allow_thirdparty_images :only => [:index, :create]
|
allow_thirdparty_images :only => :create
|
||||||
|
|
||||||
def index
|
|
||||||
@title = t ".title", :user => @user.display_name
|
|
||||||
|
|
||||||
comments = DiaryComment.where(:user => @user)
|
|
||||||
comments = comments.visible unless can? :unhide, DiaryComment
|
|
||||||
|
|
||||||
@params = params.permit(:display_name, :before, :after)
|
|
||||||
|
|
||||||
@comments, @newer_comments_id, @older_comments_id = get_page_items(comments, :includes => [:user])
|
|
||||||
|
|
||||||
render :partial => "page" if turbo_frame_request_id == "pagination"
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@entry = DiaryEntry.find(params[:id])
|
@entry = DiaryEntry.find(params[:id])
|
||||||
|
|
31
app/controllers/users/diary_comments_controller.rb
Normal file
31
app/controllers/users/diary_comments_controller.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
module Users
|
||||||
|
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
|
||||||
|
|
||||||
|
allow_thirdparty_images
|
||||||
|
|
||||||
|
def index
|
||||||
|
@title = t ".title", :user => @user.display_name
|
||||||
|
|
||||||
|
comments = DiaryComment.where(:user => @user)
|
||||||
|
comments = comments.visible unless can? :unhide, DiaryComment
|
||||||
|
|
||||||
|
@params = params.permit(:display_name, :before, :after)
|
||||||
|
|
||||||
|
@comments, @newer_comments_id, @older_comments_id = get_page_items(comments, :includes => [:user])
|
||||||
|
|
||||||
|
render :partial => "page" if turbo_frame_request_id == "pagination"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -622,15 +622,6 @@ en:
|
||||||
heading: Unsubscribe from the following diary entry discussion?
|
heading: Unsubscribe from the following diary entry discussion?
|
||||||
button: Unsubscribe from discussion
|
button: Unsubscribe from discussion
|
||||||
diary_comments:
|
diary_comments:
|
||||||
index:
|
|
||||||
title: "Diary Comments added by %{user}"
|
|
||||||
heading: "%{user}'s Diary Comments"
|
|
||||||
subheading_html: "Diary Comments added by %{user}"
|
|
||||||
no_comments: "No diary comments"
|
|
||||||
page:
|
|
||||||
post: Post
|
|
||||||
when: When
|
|
||||||
comment: Comment
|
|
||||||
new:
|
new:
|
||||||
heading: Add a comment to the following diary entry discussion?
|
heading: Add a comment to the following diary entry discussion?
|
||||||
doorkeeper:
|
doorkeeper:
|
||||||
|
@ -2881,6 +2872,16 @@ en:
|
||||||
user:
|
user:
|
||||||
summary_html: "%{name} created from %{ip_address} on %{date}"
|
summary_html: "%{name} created from %{ip_address} on %{date}"
|
||||||
summary_no_ip_html: "%{name} created on %{date}"
|
summary_no_ip_html: "%{name} created on %{date}"
|
||||||
|
diary_comments:
|
||||||
|
index:
|
||||||
|
title: "Diary Comments added by %{user}"
|
||||||
|
heading: "%{user}'s Diary Comments"
|
||||||
|
subheading_html: "Diary Comments added by %{user}"
|
||||||
|
no_comments: "No diary comments"
|
||||||
|
page:
|
||||||
|
post: Post
|
||||||
|
when: When
|
||||||
|
comment: Comment
|
||||||
suspended:
|
suspended:
|
||||||
title: Account Suspended
|
title: Account Suspended
|
||||||
heading: Account Suspended
|
heading: Account Suspended
|
||||||
|
|
|
@ -246,8 +246,6 @@ OpenStreetMap::Application.routes.draw do
|
||||||
get "/user/:display_name/diary/rss" => "diary_entries#rss", :defaults => { :format => :rss }
|
get "/user/:display_name/diary/rss" => "diary_entries#rss", :defaults => { :format => :rss }
|
||||||
get "/diary/:language/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 "/diary/rss" => "diary_entries#rss", :defaults => { :format => :rss }
|
||||||
get "/user/:display_name/diary/comments(/:page)", :page => /[1-9][0-9]*/, :to => redirect(:path => "/user/%{display_name}/diary_comments")
|
|
||||||
get "/user/:display_name/diary_comments" => "diary_comments#index", :as => :user_diary_comments
|
|
||||||
get "/user/:display_name/diary" => "diary_entries#index"
|
get "/user/:display_name/diary" => "diary_entries#index"
|
||||||
get "/diary/:language" => "diary_entries#index"
|
get "/diary/:language" => "diary_entries#index"
|
||||||
scope "/user/:display_name" do
|
scope "/user/:display_name" do
|
||||||
|
@ -269,12 +267,14 @@ OpenStreetMap::Application.routes.draw do
|
||||||
resources :users, :path => "user", :param => :display_name, :only => [:new, :create, :show] do
|
resources :users, :path => "user", :param => :display_name, :only => [:new, :create, :show] do
|
||||||
resource :role, :controller => "user_roles", :path => "roles/:role", :only => [:create, :destroy]
|
resource :role, :controller => "user_roles", :path => "roles/:role", :only => [:create, :destroy]
|
||||||
scope :module => :users do
|
scope :module => :users do
|
||||||
|
resources :diary_comments, :only => :index
|
||||||
resource :issued_blocks, :path => "blocks_by", :only => :show
|
resource :issued_blocks, :path => "blocks_by", :only => :show
|
||||||
resource :received_blocks, :path => "blocks", :only => [:show, :edit, :destroy]
|
resource :received_blocks, :path => "blocks", :only => [:show, :edit, :destroy]
|
||||||
resource :status, :only => :update
|
resource :status, :only => :update
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
get "/user/:display_name/account", :to => redirect(:path => "/account/edit")
|
get "/user/:display_name/account", :to => redirect(:path => "/account/edit")
|
||||||
|
get "/user/:display_name/diary/comments(/:page)", :page => /[1-9][0-9]*/, :to => redirect(:path => "/user/%{display_name}/diary_comments")
|
||||||
|
|
||||||
resource :account, :only => [:edit, :update, :destroy] do
|
resource :account, :only => [:edit, :update, :destroy] do
|
||||||
scope :module => :accounts do
|
scope :module => :accounts do
|
||||||
|
|
|
@ -8,10 +8,6 @@ class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_routes
|
def test_routes
|
||||||
assert_routing(
|
|
||||||
{ :path => "/user/username/diary_comments", :method => :get },
|
|
||||||
{ :controller => "diary_comments", :action => "index", :display_name => "username" }
|
|
||||||
)
|
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :path => "/user/username/diary/1/comments", :method => :post },
|
{ :path => "/user/username/diary/1/comments", :method => :post },
|
||||||
{ :controller => "diary_comments", :action => "create", :display_name => "username", :id => "1" }
|
{ :controller => "diary_comments", :action => "create", :display_name => "username", :id => "1" }
|
||||||
|
@ -24,56 +20,6 @@ class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest
|
||||||
{ :path => "/diary_comments/2/unhide", :method => :post },
|
{ :path => "/diary_comments/2/unhide", :method => :post },
|
||||||
{ :controller => "diary_comments", :action => "unhide", :comment => "2" }
|
{ :controller => "diary_comments", :action => "unhide", :comment => "2" }
|
||||||
)
|
)
|
||||||
|
|
||||||
get "/user/username/diary/comments/1"
|
|
||||||
assert_redirected_to "/user/username/diary_comments"
|
|
||||||
|
|
||||||
get "/user/username/diary/comments"
|
|
||||||
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 user_diary_comments_path(user)
|
|
||||||
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 user_diary_comments_path(other_user)
|
|
||||||
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 user_diary_comments_path(suspended_user)
|
|
||||||
assert_response :not_found
|
|
||||||
|
|
||||||
# Test a deleted user
|
|
||||||
get user_diary_comments_path(deleted_user)
|
|
||||||
assert_response :not_found
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_index_invalid_paged
|
|
||||||
user = create(:user)
|
|
||||||
|
|
||||||
%w[-1 0 fred].each do |id|
|
|
||||||
get user_diary_comments_path(user, :before => id)
|
|
||||||
assert_redirected_to :controller => :errors, :action => :bad_request
|
|
||||||
|
|
||||||
get user_diary_comments_path(user, :after => id)
|
|
||||||
assert_redirected_to :controller => :errors, :action => :bad_request
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create
|
def test_create
|
||||||
|
|
70
test/controllers/users/diary_comments_controller_test.rb
Normal file
70
test/controllers/users/diary_comments_controller_test.rb
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
module Users
|
||||||
|
class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
# Create the default language for diary entries
|
||||||
|
create(:language, :code => "en")
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# test all routes which lead to this controller
|
||||||
|
def test_routes
|
||||||
|
assert_routing(
|
||||||
|
{ :path => "/user/username/diary_comments", :method => :get },
|
||||||
|
{ :controller => "users/diary_comments", :action => "index", :user_display_name => "username" }
|
||||||
|
)
|
||||||
|
|
||||||
|
get "/user/username/diary/comments/1"
|
||||||
|
assert_redirected_to "/user/username/diary_comments"
|
||||||
|
|
||||||
|
get "/user/username/diary/comments"
|
||||||
|
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 user_diary_comments_path(user)
|
||||||
|
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 user_diary_comments_path(other_user)
|
||||||
|
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 user_diary_comments_path(suspended_user)
|
||||||
|
assert_response :not_found
|
||||||
|
|
||||||
|
# Test a deleted user
|
||||||
|
get user_diary_comments_path(deleted_user)
|
||||||
|
assert_response :not_found
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_index_invalid_paged
|
||||||
|
user = create(:user)
|
||||||
|
|
||||||
|
%w[-1 0 fred].each do |id|
|
||||||
|
get user_diary_comments_path(user, :before => id)
|
||||||
|
assert_redirected_to :controller => "/errors", :action => :bad_request
|
||||||
|
|
||||||
|
get user_diary_comments_path(user, :after => id)
|
||||||
|
assert_redirected_to :controller => "/errors", :action => :bad_request
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue