2013-12-28 23:45:13 +01:00
|
|
|
require 'test_helper'
|
|
|
|
|
2014-08-06 14:47:47 +02:00
|
|
|
# Test events, which are the application central part
|
2013-12-28 23:45:13 +01:00
|
|
|
class EventTest < ActiveSupport::TestCase
|
2014-09-02 01:02:51 +02:00
|
|
|
setup do
|
2015-10-22 21:14:36 +02:00
|
|
|
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
|
|
|
|
|
2014-09-02 01:02:51 +02:00
|
|
|
@event = events :one
|
|
|
|
end
|
|
|
|
|
2014-06-29 14:09:02 +02:00
|
|
|
test 'basic event' do
|
2014-05-25 23:59:03 +02:00
|
|
|
@event = Event.new(
|
|
|
|
title: 'hello world',
|
2015-04-18 17:24:15 +02:00
|
|
|
start_time: Time.zone.now,
|
|
|
|
end_time: Time.zone.now + 1.hour,
|
2014-05-25 23:59:03 +02:00
|
|
|
description: 'et hop!',
|
2014-08-06 14:47:47 +02:00
|
|
|
city: City.first,
|
2015-02-15 15:50:47 +01:00
|
|
|
region: Region.first,
|
2014-05-26 01:06:43 +02:00
|
|
|
url: 'http://example.com',
|
2014-05-31 23:13:43 +02:00
|
|
|
contact: 'contact@example.com',
|
2014-12-14 13:29:52 +01:00
|
|
|
submitter: 'submitter@example.com',
|
2016-12-17 16:59:11 +01:00
|
|
|
tag_list: 'hello world'
|
2014-05-25 23:59:03 +02:00
|
|
|
)
|
2016-09-11 17:40:49 +02:00
|
|
|
assert_difference 'Event.count' do
|
|
|
|
assert @event.save, @event.errors.messages
|
|
|
|
end
|
2014-05-25 23:59:03 +02:00
|
|
|
|
2014-08-06 14:47:47 +02:00
|
|
|
assert_equal 32, @event.secret.size
|
|
|
|
assert_equal 32, @event.moderator_mail_id.size
|
|
|
|
assert_equal 32, @event.submitter_mail_id.size
|
2014-05-31 23:13:43 +02:00
|
|
|
end
|
|
|
|
|
2014-06-29 14:09:02 +02:00
|
|
|
test 'validations' do
|
2014-05-31 23:13:43 +02:00
|
|
|
@event = Event.new(
|
|
|
|
title: 'hello world',
|
2015-04-18 17:24:15 +02:00
|
|
|
start_time: Time.zone.now,
|
|
|
|
end_time: Time.zone.now + 1.hour,
|
2014-05-31 23:13:43 +02:00
|
|
|
description: 'et hop!',
|
2014-08-06 14:47:47 +02:00
|
|
|
city: City.first,
|
2015-02-15 15:50:47 +01:00
|
|
|
region: Region.first,
|
2014-05-31 23:13:43 +02:00
|
|
|
url: 'http://example.com',
|
2014-12-14 13:29:52 +01:00
|
|
|
contact: 'contact@example.com',
|
2016-12-17 16:59:11 +01:00
|
|
|
tag_list: 'hello world'
|
2014-05-31 23:13:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
assert @event.valid?, @event.errors.messages
|
|
|
|
assert_equal @event.contact, @event.submitter
|
|
|
|
|
|
|
|
@event.contact = 'hop@@@'
|
|
|
|
assert !@event.valid?, @event.errors.messages
|
|
|
|
|
|
|
|
@event.contact = 'contact@example.com'
|
|
|
|
assert @event.valid?, @event.errors.messages
|
2014-05-26 01:06:43 +02:00
|
|
|
|
|
|
|
# Check invalid url
|
|
|
|
@event.url = 'htt://truc.com'
|
2014-05-31 23:13:43 +02:00
|
|
|
assert !@event.valid?, @event.errors.messages
|
2014-05-26 01:06:43 +02:00
|
|
|
|
|
|
|
@event.url = 'http:/truc.com'
|
2014-05-31 23:13:43 +02:00
|
|
|
assert !@event.valid?, @event.errors.messages
|
2014-05-25 23:59:03 +02:00
|
|
|
end
|
2014-07-28 16:16:27 +02:00
|
|
|
|
|
|
|
test 'moderation' do
|
|
|
|
@event = Event.new(
|
|
|
|
title: 'hello world',
|
2015-04-18 17:24:15 +02:00
|
|
|
start_time: Time.zone.now,
|
|
|
|
end_time: Time.zone.now + 1.hour,
|
2014-07-28 16:16:27 +02:00
|
|
|
description: 'et hop!',
|
2014-08-06 14:47:47 +02:00
|
|
|
city: City.first,
|
2015-02-15 15:50:47 +01:00
|
|
|
region: Region.first,
|
2014-07-28 16:16:27 +02:00
|
|
|
url: 'http://example.com',
|
2014-12-14 13:29:52 +01:00
|
|
|
contact: 'contact@example.com',
|
2016-12-17 16:59:11 +01:00
|
|
|
tag_list: 'hello world'
|
2014-07-28 16:16:27 +02:00
|
|
|
)
|
|
|
|
|
2014-08-06 14:47:47 +02:00
|
|
|
assert @event.save, @event.errors.messages
|
2014-07-28 16:16:27 +02:00
|
|
|
assert !@event.moderated?
|
|
|
|
|
2014-09-02 01:02:51 +02:00
|
|
|
@event.update moderated: 1
|
2014-07-28 16:16:27 +02:00
|
|
|
|
|
|
|
assert @event.moderated?, @event.errors.messages
|
|
|
|
end
|
2014-09-02 01:02:51 +02:00
|
|
|
|
2014-11-05 21:25:18 +01:00
|
|
|
test 'named scope future.daylimit' do
|
2014-09-05 22:15:38 +02:00
|
|
|
assert Event.respond_to? :future
|
2014-11-05 21:25:18 +01:00
|
|
|
assert Event.respond_to? :daylimit
|
|
|
|
assert_match(/<= end_time/, Event.future.daylimit(nil).where_values[0])
|
|
|
|
assert_match(/end_time <=/, Event.future.daylimit(nil).where_values[1])
|
2014-09-02 01:02:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'named scope year' do
|
|
|
|
assert Event.respond_to? :year
|
|
|
|
assert_match(/<= end_time/, Event.year(2014).where_values[0])
|
|
|
|
assert_match(/start_time <=/, Event.year(2014).where_values[0])
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'geo data reset' do
|
|
|
|
# Setup geo data
|
|
|
|
@event.latitude = 3
|
|
|
|
@event.longitude = 3
|
|
|
|
|
|
|
|
# Change address to ensure geo data is reset
|
|
|
|
@event.address = 'hello world'
|
|
|
|
|
2014-09-25 19:14:16 +02:00
|
|
|
assert @event.valid?, @event.errors.messages
|
2014-09-02 01:02:51 +02:00
|
|
|
assert @event.save
|
2014-10-16 23:31:02 +02:00
|
|
|
assert_equal 40.7143528, @event.latitude
|
|
|
|
assert_equal(-74.0059731, @event.longitude)
|
2014-09-02 01:02:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'json transform' do
|
2014-09-03 02:14:21 +02:00
|
|
|
assert_not_nil @event.as_json
|
2014-09-02 01:02:51 +02:00
|
|
|
|
2014-09-03 02:14:21 +02:00
|
|
|
assert_equal 'Feature', @event.as_json[:type]
|
|
|
|
assert_equal 'Point', @event.as_json[:geometry][:type]
|
2014-09-02 01:02:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'full address' do
|
|
|
|
@event.address = 'hello'
|
|
|
|
@event.city = 'world'
|
2016-01-30 19:09:20 +01:00
|
|
|
# Region is no longer used for geocoding..;
|
|
|
|
# @event.region.name = 'all'
|
2017-07-02 12:25:43 +02:00
|
|
|
# assert_equal 'hello, world', @event.full_address
|
|
|
|
assert_equal 'hello, world, Alsace', @event.full_address
|
2014-09-02 01:02:51 +02:00
|
|
|
end
|
2013-12-28 23:45:13 +01:00
|
|
|
end
|