-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' for release 5.7.2
- Loading branch information
Showing
11 changed files
with
167 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
module Events; end | ||
|
||
class Events::RecurrenceUpdateTest < ActionDispatch::IntegrationTest | ||
def setup | ||
@admin = User.find_by(username: 'admin') | ||
login_as(@admin, scope: :user) | ||
end | ||
|
||
test 'update a recurrent event' do | ||
# first create a recurrent event | ||
name = 'Fablab party' | ||
post '/api/events', | ||
params: { | ||
event: { | ||
title: name, | ||
event_image_attributes: { | ||
attachment: fixture_file_upload('/files/event/Party.jpg') | ||
}, | ||
description: 'Come party tonight at the fablab...', | ||
start_date: 2.weeks.from_now, | ||
end_date: 2.weeks.from_now, | ||
all_day: false, | ||
start_time: '18:00', | ||
end_time: '23:29', | ||
amount: 20, | ||
category_id: 2, | ||
recurrence: 'month', | ||
recurrence_end_at: 2.weeks.from_now + 3.months | ||
} | ||
}, | ||
headers: upload_headers | ||
|
||
# Check response format & status | ||
assert_equal 201, response.status, response.body | ||
assert_equal Mime[:json], response.content_type | ||
|
||
# Check the events were correctly created | ||
db_events = Event.where(title: name) | ||
assert_equal 4, db_events.count | ||
|
||
# Update all the events | ||
event = db_events.first | ||
new_title = 'Skateboard party' | ||
new_descr = 'Come make a skateboard tonight at the Fablab' | ||
new_image = '/files/event/Skateboard.jpg' | ||
put "/api/events/#{event&.id}", params: { | ||
event: { | ||
title: new_title, | ||
event_image_attributes: { | ||
attachment: fixture_file_upload(new_image) | ||
}, | ||
description: new_descr, | ||
category_id: 1, | ||
event_theme_ids: [1], | ||
age_range_id: 1, | ||
start_date: event&.availability&.start_at, | ||
end_date: event&.availability&.end_at, | ||
all_day: false, | ||
start_time: '18:00', | ||
end_time: '23:29', | ||
amount: 20 | ||
}, | ||
edit_mode: 'all' | ||
}, headers: upload_headers | ||
|
||
# Check response format & status | ||
assert_response :success, response.body | ||
assert_equal Mime[:json], response.content_type | ||
|
||
# Check the events were correctly updated | ||
res = json_response(response.body) | ||
assert_equal 'update', res[:action] | ||
assert_equal 4, res[:total] | ||
assert_equal 4, res[:updated] | ||
res[:details][:events].each do |res_event| | ||
assert res_event[:status] | ||
db_event = Event.find(res_event[:event][:id]) | ||
assert_equal new_title, db_event.title | ||
assert_equal new_descr, db_event.description | ||
assert_equal 1, db_event.category_id | ||
assert_includes db_event.event_theme_ids, 1 | ||
assert_equal 1, db_event.age_range_id | ||
assert FileUtils.compare_file( | ||
File.join(ActionDispatch::IntegrationTest.fixture_path, new_image), | ||
db_event.event_image.attachment.file.path | ||
) | ||
end | ||
|
||
# Update again but only the next events | ||
event = Event.includes(:availability).where(title: new_title).order('availabilities.start_at').limit(2)[1] | ||
put "/api/events/#{event&.id}", params: { | ||
event: { | ||
title: event.title, | ||
description: event.description, | ||
event_image_attributes: { | ||
id: event.event_image.id | ||
}, | ||
category_id: 2, | ||
event_theme_ids: [1], | ||
age_range_id: 1, | ||
start_date: event.availability.start_at, | ||
end_date: event.availability.end_at, | ||
all_day: false, | ||
start_time: '18:00', | ||
end_time: '23:29', | ||
amount: 20 | ||
}, | ||
edit_mode: 'next' | ||
}.to_json, headers: default_headers | ||
|
||
# Check response format & status | ||
assert_response :success, response.body | ||
assert_equal Mime[:json], response.content_type | ||
|
||
# Check the events were correctly updated | ||
res = json_response(response.body) | ||
assert_equal 'update', res[:action] | ||
assert_equal 3, res[:total] | ||
assert_equal 3, res[:updated] | ||
res[:details][:events].each do |res_event| | ||
assert res_event[:status] | ||
db_event = Event.find(res_event[:event][:id]) | ||
assert_equal 2, db_event.category_id | ||
assert FileUtils.compare_file( | ||
File.join(ActionDispatch::IntegrationTest.fixture_path, new_image), | ||
db_event.event_image.attachment.file.path | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters