The rejection reason is better managed

filter
echarp 6 years ago
parent 93bdb05a01
commit cb474960f0
  1. 11
      app/controllers/moderations_controller.rb
  2. 2
      app/models/event.rb
  3. 2
      app/views/moderations/refuse.html.haml
  4. 6
      test/controllers/moderations_controller_test.rb

@ -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]

@ -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

@ -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')

@ -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

Loading…
Cancel
Save