diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 216172657..e6648f712 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 = {} diff --git a/app/controllers/judgements_controller.rb b/app/controllers/judgements_controller.rb index 1cb837247..2f5e0e54f 100644 --- a/app/controllers/judgements_controller.rb +++ b/app/controllers/judgements_controller.rb @@ -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 !@judgement.valid? && (@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 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 09abb63a2..4c477acd8 100755 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,7 +5,6 @@ <%= favicon_link_tag asset_path "favicon.ico" %> - <% if flash[:unfurl] %> @@ -33,7 +32,6 @@ " /> <% end %> <% else %> - Quepid -- Relevant Search Solved @@ -60,7 +58,7 @@ <%= csrf_meta_tags %> <%= javascript_include_tag 'application' %> - + diff --git a/test/controllers/judgements_controller_test.rb b/test/controllers/judgements_controller_test.rb new file mode 100644 index 000000000..f6831aecc --- /dev/null +++ b/test/controllers/judgements_controller_test.rb @@ -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 diff --git a/test/controllers/judgements_controller_test.txt b/test/controllers/judgements_controller_test.txt deleted file mode 100644 index 663715983..000000000 --- a/test/controllers/judgements_controller_test.txt +++ /dev/null @@ -1,54 +0,0 @@ -# frozen_string_literal: true - -require 'test_helper' - -class JudgementsControllerTest < ActionDispatch::IntegrationTest - setup do - @judgement = judgements(:one) - end - - test 'should get index' do - get judgements_url - 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 -end