Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when we can't save a judgement #809

Merged
merged 4 commits into from
Aug 31, 2023
Merged
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/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class HomeController < ApplicationController
# rubocop:disable Metrics/AbcSize
def show
# @cases = @current_user.cases.not_archived.includes([ :scores ])
@cases = @current_user.cases.not_archived.recent.uniq
@cases = @current_user.cases.not_archived

@most_recent_cases = @cases[0...4].sort_by(&:case_name)
@most_recent_cases = @current_user.cases.not_archived.recent.limit(4).sort_by(&:case_name)

@most_recent_books = []
@lookup_for_books = {}
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/judgements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,19 @@ def create
@judgement.user = current_user
@judgement.unrateable = false

# Make sure that we haven't already created the same judgement before
# This create UI can happen very quickly, and somehow we get overlapping creates..
if [email protected]? && (@judgement.errors.added? :user_id, :taken, value: @current_user.id)
@judgement = Judgement.find_by(user_id: @current_user.id, query_doc_pair_id: @judgement.query_doc_pair_id)
@judgement.update(judgement_params)
@judgement.user = current_user
@judgement.unrateable = false
end

if @judgement.save
redirect_to book_judge_path(@book)
else
@query_doc_pair = @judgement.query_doc_pair
render action: :new
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<%= favicon_link_tag asset_path "favicon.ico" %>

<!-- Probably better way of doing this -->
<% if flash[:unfurl] %>
<!-- We have unfurl -->

Expand Down Expand Up @@ -33,7 +32,6 @@
<meta name="twitter:data1" value="<%=Case.find_by_id(flash[:unfurl]["id"]).tries.latest.try_number %>" />
<% end %>
<% else %>
<!-- We DO NOT have unfurl -->

<title>Quepid -- Relevant Search Solved</title>

Expand All @@ -60,7 +58,7 @@
<%= csrf_meta_tags %>
<%= javascript_include_tag 'application' %>

</head>
</head>

<body>

Expand Down
74 changes: 74 additions & 0 deletions test/controllers/judgements_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# frozen_string_literal: true

require 'test_helper'

class JudgementsControllerTest < ActionDispatch::IntegrationTest
let(:user) { users(:random) }
let(:book) { books(:book_of_comedy_films) }

setup do
@judgement = judgements(:one)
get '/books'
assert_equal 302, status
follow_redirect!

login_user
end

test 'should get index' do
get book_judgements_url book
assert_response :success
end

# test 'should get new' do
# get new_judgement_url
# assert_response :success
# end

# test 'should create judgement' do
# assert_difference('Judgement.count') do
# post judgements_url,
# params: { judgement: { query_doc_pair_id: @judgement.query_doc_pair_id, rating: @judgement.rating,
# user_id: @judgement.user_id } }
# end

# assert_redirected_to judgement_url(Judgement.last)
# end

# test 'should show judgement' do
# get judgement_url(@judgement)
# assert_response :success
# end

# test 'should get edit' do
# get edit_judgement_url(@judgement)
# assert_response :success
# end

# test 'should update judgement' do
# patch judgement_url(@judgement),
# params: { judgement: { query_doc_pair_id: @judgement.query_doc_pair_id, rating: @judgement.rating,
# user_id: @judgement.user_id } }
# assert_redirected_to judgement_url(@judgement)
# end

# test 'should destroy judgement' do
# assert_difference('Judgement.count', -1) do
# delete judgement_url(@judgement)
# end

# assert_redirected_to judgements_url
# end

def login_user
# We don't actually want to load up scores...
Bullet.enable = false
# post the login and follow through to the home page
post '/users/login', params: { user: { email: user.email, password: 'password' } }
follow_redirect!
assert_equal 200, status
assert_equal '/', path

Bullet.enable = true
end
end
54 changes: 0 additions & 54 deletions test/controllers/judgements_controller_test.txt

This file was deleted.