Move diary comments index action to comments controller
This commit is contained in:
parent
63a323dbe3
commit
6624beff11
9 changed files with 120 additions and 79 deletions
|
@ -17,10 +17,14 @@ class GuestAbilityTest < AbilityTest
|
|||
|
||||
test "diary permissions for a guest" do
|
||||
ability = Ability.new nil
|
||||
[:index, :rss, :show, :comments].each do |action|
|
||||
[:index, :rss, :show].each do |action|
|
||||
assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
|
||||
end
|
||||
|
||||
[:index].each do |action|
|
||||
assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComments"
|
||||
end
|
||||
|
||||
[:create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
|
||||
assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
|
||||
end
|
||||
|
@ -47,10 +51,14 @@ class UserAbilityTest < AbilityTest
|
|||
test "Diary permissions" do
|
||||
ability = Ability.new create(:user)
|
||||
|
||||
[:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action|
|
||||
[:index, :rss, :show, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action|
|
||||
assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
|
||||
end
|
||||
|
||||
[:index].each do |action|
|
||||
assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComments"
|
||||
end
|
||||
|
||||
[:hide, :hidecomment].each do |action|
|
||||
assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
|
||||
end
|
||||
|
@ -86,9 +94,13 @@ end
|
|||
class AdministratorAbilityTest < AbilityTest
|
||||
test "Diary for an administrator" do
|
||||
ability = Ability.new create(:administrator_user)
|
||||
[:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
|
||||
[:index, :rss, :show, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
|
||||
assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
|
||||
end
|
||||
|
||||
[:index].each do |action|
|
||||
assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComments"
|
||||
end
|
||||
end
|
||||
|
||||
test "User Roles permissions for an administrator" do
|
||||
|
|
63
test/controllers/diary_comments_controller_test.rb
Normal file
63
test/controllers/diary_comments_controller_test.rb
Normal file
|
@ -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
|
|
@ -49,11 +49,6 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
|
|||
{ :controller => "diary_entries", :action => "rss", :display_name => "username", :format => :rss }
|
||||
)
|
||||
|
||||
assert_routing(
|
||||
{ :path => "/user/username/diary/comments", :method => :get },
|
||||
{ :controller => "diary_entries", :action => "comments", :display_name => "username" }
|
||||
)
|
||||
|
||||
assert_routing(
|
||||
{ :path => "/diary/new", :method => :get },
|
||||
{ :controller => "diary_entries", :action => "new" }
|
||||
|
@ -110,9 +105,6 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
|
|||
{ :path => "/user/username/diary/1/unsubscribe", :method => :post },
|
||||
{ :controller => "diary_entries", :action => "unsubscribe", :display_name => "username", :id => "1" }
|
||||
)
|
||||
|
||||
get "/user/username/diary/comments/1"
|
||||
assert_redirected_to "/user/username/diary/comments"
|
||||
end
|
||||
|
||||
def test_new_no_login
|
||||
|
@ -900,50 +892,6 @@ class DiaryEntriesControllerTest < ActionDispatch::IntegrationTest
|
|||
assert DiaryComment.find(diary_comment.id).visible
|
||||
end
|
||||
|
||||
def test_comments
|
||||
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 :comments
|
||||
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 :comments
|
||||
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_comments_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
|
||||
|
||||
def test_subscribe_page
|
||||
user = create(:user)
|
||||
other_user = create(:user)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue