diff --git a/app/controllers/doc_methods_controller.rb b/app/controllers/doc_methods_controller.rb index 883abfa1..781f9843 100644 --- a/app/controllers/doc_methods_controller.rb +++ b/app/controllers/doc_methods_controller.rb @@ -35,8 +35,8 @@ def click_method_redirect def click_source_redirect doc = DocMethod.find(params[:id]) - sub = RepoSubscription.find_by!(user_id: params[:user_id], repo: doc.repo) - assignment = DocAssignment.find_by!(doc_method_id: doc.id, repo_subscription_id: sub.id) + sub = RepoSubscription.where(user_id: params[:user_id], repo: doc.repo).first + assignment = DocAssignment.where(doc_method_id: doc.id, repo_subscription_id: sub.id).first if assignment&.user&.id.to_s == params[:user_id] assignment.user.record_click! diff --git a/test/functional/doc_methods_controller_test.rb b/test/functional/doc_methods_controller_test.rb index b6f5c694..e0ca6320 100644 --- a/test/functional/doc_methods_controller_test.rb +++ b/test/functional/doc_methods_controller_test.rb @@ -26,4 +26,19 @@ class DocMethodsControllerTest < ActionController::TestCase assert flash[:notice].eql? "Bad url, if this problem persists please open an issue github.com/codetriage/codetriage" assert_redirected_to :root end + + test "click_source_redirect with a DocAssignment redirects to the github source url" do + DocAssignment.create(doc_method_id: @triage_doc.id, repo_subscription_id: @repo_sub.id) + + get :click_source_redirect, params: {id: @triage_doc.id, user_id: @user.id} + + assert_redirected_to @triage_doc.to_github + end + + test "click_source_redirect without any DocAssignment returns to root and displays an error" do + get :click_source_redirect, params: {id: @triage_doc.id, user_id: @user.id} + + assert flash[:notice].eql? "Bad url, if this problem persists please open an issue github.com/codetriage/codetriage" + assert_redirected_to :root + end end