Les diff dans les mails liés à une mise à jour d'evt sont correctement affichés

This commit is contained in:
echarp 2014-07-20 21:46:28 +02:00
parent 98e79698a0
commit 9c260e2dea
7 changed files with 42 additions and 15 deletions

View File

@ -90,6 +90,7 @@ class EventsController < ApplicationController
# PATCH/PUT /events/1
# PATCH/PUT /events/1.json
def update
olderEvent = Event.new @event.attributes
if params[:visu]
@event.attributes = event_params
@event.valid?
@ -100,7 +101,7 @@ class EventsController < ApplicationController
respond_to do |format|
if @event.update event_params
# Send an update mail to moderators
ModerationMailer.update(@event, nil).deliver
ModerationMailer.update(olderEvent, @event, nil).deliver
format.html { redirect_to :root, notice: t('.ok') }
format.json { head :no_content }

View File

@ -12,6 +12,7 @@ class ModerationsController < ApplicationController
# PATCH/PUT /moderations/1
# PATCH/PUT /moderations/1.json
def update
olderModeration = Event.new @event.attributes
if params[:visu]
@moderation.attributes = moderation_params
render action: 'edit'
@ -21,7 +22,7 @@ class ModerationsController < ApplicationController
respond_to do |format|
if @moderation.update(moderation_params)
# Send an update mail to moderators
ModerationMailer.update(@moderation, current_user).deliver
ModerationMailer.update(olderModeration, @moderation, current_user).deliver
format.html { redirect_to moderations_path, notice: t('.ok') }
format.json { head :no_content }

View File

@ -6,7 +6,8 @@ class ModerationMailer < ActionMailer::Base
subject: t('moderation_mailer.create.subject', subject: event.title)
end
def update(event, current_user)
def update(olderEvent, event, current_user)
@olderEvent = olderEvent
@event = event
@current_user = current_user

View File

@ -5,16 +5,7 @@
- new = render file: '/events/show'
- former = @event
- @event = Event.new(title: @event.title_was,
start_time: @event.start_time_was,
end_time: @event.end_time_was,
region: @event.region_was,
city: @event.city_was,
url: @event.url_was,
contact: @event.contact_was,
submitter: @event.submitter_was,
tags: @event.tags_was,
description: @event.description_was)
- @event = @olderEvent
- prev = render file: '/events/show'
- @event = former

View File

@ -25,6 +25,27 @@ class ModerationsControllerTest < ActionController::TestCase
assert_redirected_to moderations_path
end
test 'should update event' do
patch :update, id: @moderation, secret: 'MyString', event: {
title: @moderation.title,
start_time: @moderation.start_time,
end_time: @moderation.end_time,
description: @moderation.description,
city: @moderation.city,
region: @moderation.related_region,
locality: @moderation.locality,
url: @moderation.url,
contact: @moderation.contact,
moderated: @moderation.moderated,
secret: @moderation.secret,
submission_time: @moderation.submission_time,
submitter: @moderation.submitter,
tags: @moderation.tags }
assert_empty assigns(:moderation).errors
assert_redirected_to moderations_path
end
test 'should reject event' do
assert_difference 'Event.count', -1 do
delete :destroy, id: @moderation

View File

@ -13,10 +13,19 @@ class ModerationMailerTest < ActionMailer::TestCase
end
test 'update' do
mail = ModerationMailer.update Event.unscoped.last, User.last
event = Event.last
olderEvent = Event.new event.attributes
event.tags += ', ho'
event.start_time += 1.day
event.description = event.description + '
hello world'
mail = ModerationMailer.update olderEvent, event, User.last
assert_match(/\[Agenda du Libre\] Édition de l'événement .*/, mail.subject)
assert_equal ['moderateurs@agendadulibre.org'], mail.to
assert_equal ['moderateurs@agendadulibre.org'], mail.from
assert_match(/^{/, mail.body.to_s)
end
test 'accept' do

View File

@ -12,11 +12,14 @@ class ModerationMailerPreview < ActionMailer::Preview
def update
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
event = Event.last
olderEvent = Event.new event.attributes
event.tags += ', ho'
event.start_time += 1.day
event.description = event.description + '
hello world'
ModerationMailer.update event, nil
ModerationMailer.update olderEvent, event, nil
end
# Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/accept