From 6a9b68022a5aef83deece9a4b0829de4c1feb59f Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 31 Oct 2016 17:08:28 -0500 Subject: [PATCH 1/2] Test /forum_posts?search[creator_id]=1. --- test/functional/forum_posts_controller_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/functional/forum_posts_controller_test.rb b/test/functional/forum_posts_controller_test.rb index 82c8416c8..5a22bdff8 100644 --- a/test/functional/forum_posts_controller_test.rb +++ b/test/functional/forum_posts_controller_test.rb @@ -35,6 +35,12 @@ class ForumPostsControllerTest < ActionController::TestCase assert_response :success assert_equal(0, assigns(:forum_posts).size) end + + should "list by creator id" do + get :index, {:search => {:creator_id => @user.id}} + assert_response :success + assert_equal(1, assigns(:forum_posts).size) + end end context "with private topics" do From f46d055218af9dc1de16484810b69061fc65a405 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 31 Oct 2016 17:05:57 -0500 Subject: [PATCH 2/2] Fix AmbiguousColumn exception in /forum_posts?search[creator_id]=1 --- app/models/forum_post.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index e0a1e65df..4a334b600 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -55,7 +55,7 @@ class ForumPost < ActiveRecord::Base end def permitted - joins(:topic).where("min_level <= ?", CurrentUser.level) + joins(:topic).where("forum_topics.min_level <= ?", CurrentUser.level) end def search(params) @@ -63,11 +63,11 @@ class ForumPost < ActiveRecord::Base return q if params.blank? if params[:creator_id].present? - q = q.where("creator_id = ?", params[:creator_id].to_i) + q = q.where("forum_posts.creator_id = ?", params[:creator_id].to_i) end if params[:topic_id].present? - q = q.where("topic_id = ?", params[:topic_id].to_i) + q = q.where("forum_posts.topic_id = ?", params[:topic_id].to_i) end if params[:topic_title_matches].present?