Skip to content
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
22 changes: 19 additions & 3 deletions app/controllers/staff/ratings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def create
@rating = Rating.find_or_initialize_by(proposal: @proposal, user: current_user)
@rating.update!(rating_params)

render partial: 'shared/proposals/rating_widget', locals: {event: @proposal.event, proposal: @proposal, rating: @rating}
# The first rating reveals the internal comments; replace the whole widget.
render_rating_widget
end

def update
Expand All @@ -21,16 +22,31 @@ def update
if rating_params[:score].blank?
@rating.destroy
@rating = current_user.ratings.build(proposal: @proposal)
render partial: 'shared/proposals/rating_widget', locals: {event: @proposal.event, proposal: @proposal, rating: @rating}
# Removing the rating re-hides the internal comments; replace the whole widget.
render_rating_widget
return
end

@rating.update!(rating_params)
render partial: 'shared/proposals/rating_widget', locals: {event: @proposal.event, proposal: @proposal, rating: @rating}
# A score change must not touch the internal comments (a draft may be in
# progress there); replace only the rating form's own frame.
render turbo_stream: turbo_stream.replace(
helpers.dom_id(@proposal, :rating_form),
partial: 'shared/proposals/rating_form_frame',
locals: {event: @proposal.event, proposal: @proposal, rating: @rating}
)
end

private

def render_rating_widget
render turbo_stream: turbo_stream.replace(
helpers.dom_id(@proposal, :rating_widget),
partial: 'shared/proposals/rating_widget',
locals: {event: @proposal.event, proposal: @proposal, rating: @rating}
)
end

def rating_params
params.require(:rating).permit(:score).merge(proposal: @proposal, user: current_user)
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/shared/proposals/_rating_form_frame.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= turbo_frame_tag dom_id(proposal, :rating_form) do
.widget-content
= render partial: 'shared/proposals/rating_form', locals: {event: event, proposal: proposal, rating: rating}
3 changes: 1 addition & 2 deletions app/views/shared/proposals/_rating_widget.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
= turbo_frame_tag dom_id(proposal, :rating_widget) do
.widget-content
= render partial: 'shared/proposals/rating_form', locals: {event: event, proposal: proposal, rating: rating}
= render partial: 'shared/proposals/rating_form_frame', locals: {event: event, proposal: proposal, rating: rating}

.internal-comments{class: !rating.persisted? ? 'hidden' : nil}
.widget-header
Expand Down
33 changes: 33 additions & 0 deletions spec/system/staff/rating_preserves_comment_draft_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'rails_helper'

feature 'Rating a proposal with an internal comment draft in progress', type: :system, js: true do
let(:event) { create(:event, state: 'open') }
let(:reviewer_user) { create(:user) }
let(:proposal) { create(:proposal_with_track, event: event) }
let!(:teammate) { create(:teammate, :reviewer, user: reviewer_user, event: event) }

before do
reviewer_user.ratings.create!(proposal: proposal, score: 3)
login_as(reviewer_user)
visit event_staff_proposal_path(event, proposal)
end

it 'changing the star rating preserves typed internal comment text' do
fill_in 'internal_comment_body', with: 'Half-typed thought'

within('#rating-form') do
find("input[value='5']", visible: false).set(true)
end
expect(page).to have_css('.avg-rating', text: '5.0')

expect(page).to have_field('internal_comment_body', with: 'Half-typed thought')
end

it 'removing the rating hides the internal comments again' do
within('#rating-form') do
find('input.star-rating-select.delete', visible: false).set(true)
end

expect(page).to_not have_content('Internal Comment')
end
end
Loading