The rejection reason is better managed

This commit is contained in:
echarp 2016-09-11 19:13:10 +02:00
parent 93bdb05a01
commit cb474960f0
4 changed files with 15 additions and 6 deletions

View File

@ -44,8 +44,7 @@ class ModerationsController < ApplicationController
# DELETE /events/1
# DELETE /events/1.json
def destroy
@moderation.reason = params[:event][:reason] ||
t("moderations.refuse.reason_#{params[:reason]}_long")
@moderation.reason = generate_destroy_reason(params)
@moderation.destroy!
respond_to do |format|
format.html { redirect_to :moderations, notice: t('.ok') }
@ -55,6 +54,14 @@ class ModerationsController < ApplicationController
private
def generate_destroy_reason(params)
if params[:reason] == 'r_4'
params[:event][:reason]
else
t "moderations.refuse.reason_#{params[:reason]}_long"
end
end
# Use callbacks to share common setup or constraints between actions.
def set_moderation
@event = Event.find params[:id]

View File

@ -15,7 +15,7 @@ class Event < ActiveRecord::Base
validates :title, presence: true
validate :end_after_start
RULES = %w(daily weekly monthly).freeze
validates :rule, inclusion: RULES
validates :rule, allow_nil: true, inclusion: RULES
validates :description, presence: true
validates :city, presence: true
validates :region, presence: true

View File

@ -16,7 +16,7 @@
= radio_button_tag :reason, :r_3, params[:event] == 'reason_r_3'
= label_tag :reason_r_3, t('.reason_r_3')
.field.opener{ title: t('.reason_r_4_long') }
.field.opener
= radio_button_tag :reason, :r_4,
params[:event] == 'reason_r_4' || !params[:event]
= label_tag :reason_r_4, t('.reason_r_4')

View File

@ -92,9 +92,10 @@ class ModerationsControllerTest < ActionController::TestCase
test 'should reject event' do
assert_difference 'Event.count', -1 do
delete :destroy, id: @moderation, event: {}
delete :destroy, id: @moderation, reason: 'r_1', event: { reason: '' }
end
assert_not_empty assigns(:moderation).reason
assert_empty assigns(:moderation).errors
assert_redirected_to :moderations
@ -102,9 +103,10 @@ class ModerationsControllerTest < ActionController::TestCase
test 'should reject event with a reason' do
assert_difference 'Event.count', -1 do
delete :destroy, id: @moderation, reason: 'r_4', event: {}
delete :destroy, id: @moderation, reason: 'r_4', event: { reason: 'bye' }
end
assert_not_empty assigns(:moderation).reason
assert_empty assigns(:moderation).errors
assert_redirected_to :moderations