Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/doc_methods_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
15 changes: 15 additions & 0 deletions test/functional/doc_methods_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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