Skip to content

Commit

Permalink
lets be able to debug ratings.
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Sep 6, 2023
1 parent 4a78eb0 commit ffde2be
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/assets/templates/views/devQueryParams.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ <h4>Tuning Knobs</h4>
<div class="settings-tab" ng-show="qp.curTab == 'history'">
<div class="container">
<p>
<a ng-href="analytics/tries_visualization/{{ caseNo }}" target="_self">Visualize your tries</a> | <a ng-href="analytics/cases/{{ caseNo }}/duplicate_scores" target="_self">Check Scores</a>
<a ng-href="analytics/tries_visualization/{{ caseNo }}" target="_self">Visualize your tries</a> |
<a ng-href="analytics/cases/{{ caseNo }}/duplicate_scores" target="_self">Check Scores</a> |
<a ng-href="cases/{{ caseNo }}/ratings" target="_self">Check Ratings</a>
</p>
<p>
To switch back to a previous try, click on the try listing.<br />
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/ratings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class RatingsController < ApplicationController
before_action :find_case

# GET /ratings or /ratings.json
def index
@ratings = @case.ratings.includes([ :query, :user ])
end
end
7 changes: 7 additions & 0 deletions app/views/ratings/_rating.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

json.rating_id rating.id
json.query_text rating.query.query_text
json.doc_id rating.doc_id
json.rating rating.rating
json.user_name rating&.user&.fullname
41 changes: 41 additions & 0 deletions app/views/ratings/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Ratings for Case <%= @case.case_name %></h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group me-2">
<%= link_to "Back to Case #{@case.case_name}", case_path(@case), class: "btn btn-sm btn-outline-secondary" %>
</div>
</div>
</div>

<table class="table table-hover table-sm">
<thead>
<tr>
<th>Rating ID</th>
<th>Query</th>
<th>Doc ID</th>
<th>Rating</th>
<th>User</th>
<th>Created At</th>
<th>Updated At</th>

</tr>
</thead>

<tbody>
<% @ratings.each do |rating| %>
<tr>
<td><%= rating.id %></td>
<td><%= rating.query.query_text %></td>
<td><%= rating.doc_id %></td>
<td><%= rating.rating %></td>
<td><%= rating&.user&.fullname %></td>
<td>
<%= rating.created_at %>
</td>
<td>
<%= rating.updated_at %>
</td>
</tr>
<% end %>
</tbody>
</table>
3 changes: 3 additions & 0 deletions app/views/ratings/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

json.array! @ratings, partial: 'ratings/rating', as: :rating
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

# rubocop:disable Metrics/BlockLength
Rails.application.routes.draw do
# get 'home/show'
root 'home#show'
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

Expand All @@ -31,6 +30,7 @@

resources :cases, only: [] do
resource :book
resources :ratings, only: [ :index ]
end

resources :books do
Expand Down
34 changes: 34 additions & 0 deletions test/controllers/ratings_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require 'test_helper'

class RatingsControllerTest < ActionDispatch::IntegrationTest
let(:user) { users(:random) }
setup do
@case = cases(:import_ratings_case)
end

test 'should get index' do
# get the login page

get case_ratings_url(@case)
assert_equal 302, status
follow_redirect!

login_user
get case_ratings_url(@case)
assert_response :success
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

0 comments on commit ffde2be

Please sign in to comment.