diff --git a/test/factories/forum_topic.rb b/test/factories/forum_topic.rb index 144ef1941..689679509 100644 --- a/test/factories/forum_topic.rb +++ b/test/factories/forum_topic.rb @@ -4,5 +4,9 @@ FactoryGirl.define do is_sticky false is_locked false category_id 0 + + factory(:mod_up_forum_topic) do + min_level User::Levels::MODERATOR + end end end diff --git a/test/functional/forum_posts_controller_test.rb b/test/functional/forum_posts_controller_test.rb index bbf4b6623..82c8416c8 100644 --- a/test/functional/forum_posts_controller_test.rb +++ b/test/functional/forum_posts_controller_test.rb @@ -36,6 +36,31 @@ class ForumPostsControllerTest < ActionController::TestCase assert_equal(0, assigns(:forum_posts).size) end end + + context "with private topics" do + setup do + @mod_topic = FactoryGirl.create(:mod_up_forum_topic) + @mod_posts = 2.times.map do + FactoryGirl.create(:forum_post, :topic_id => @mod_topic.id) + end + @mod_post_ids = ([@forum_post] + @mod_posts).map(&:id).reverse + end + + should "list only permitted posts for members" do + get :index, {}, { :user_id => @user.id } + + assert_response :success + assert_equal([@forum_post.id], assigns(:forum_posts).map(&:id)) + end + + should "list only permitted posts for mods" do + CurrentUser.user = @mod + get :index, {}, { :user_id => @mod.id } + + assert_response :success + assert_equal(@mod_post_ids, assigns(:forum_posts).map(&:id)) + end + end end context "edit action" do