Commit 438a8144 authored by Mario Manno's avatar Mario Manno

tune rake jobs output for tests

parent 074b57e5
class ConferenceScrubber
include RakeLogger
DUMMY_MAIL = "root@localhost.localdomain"
VERBOSE = true
def initialize(conference,dry_run=false)
@conference = conference
......@@ -12,7 +12,7 @@ class ConferenceScrubber
def scrub!
if @dry_run
puts "dry run, won't change anything!"
log "dry run, won't change anything!"
end
ActiveRecord::Base.transaction do
scrub_people
......@@ -25,7 +25,7 @@ class ConferenceScrubber
def scrub_people
Person.involved_in(@conference).each { |person|
unless still_active(person)
puts "scrubbing #{person.public_name} <#{person.email}>" if VERBOSE
log "scrubbing #{person.public_name} <#{person.email}>"
scrub_person(person)
end
}
......@@ -54,7 +54,7 @@ class ConferenceScrubber
person.note = nil
unless person.active_in_any_conference?
puts "scrubbing description of #{person.public_name}" if VERBOSE
log "scrubbing description of #{person.public_name}"
person.abstract = nil
person.description = nil
person.avatar.destroy unless @dry_run
......@@ -65,7 +65,7 @@ class ConferenceScrubber
def scrub_event_ratings
return if @dry_run
puts "scrubbing conference ratings of #{@conference.acronym}" if VERBOSE
log "scrubbing conference ratings of #{@conference.acronym}"
# keeps events average rating for performance reasons
EventRating.skip_callback(:save, :after, :update_average)
EventRating.joins(:event).where(Event.arel_table[:conference_id].eq(@conference.id)).destroy_all
......
module RakeLogger
def error(msg)
STDERR.puts(msg)
end
def warning(msg)
STDERR.puts(msg) unless Rails.env.test?
end
def log(msg)
STDOUT.puts(msg) unless ENV['QUIET']
end
end
class StaticProgramExport
include RakeLogger
EXPORT_PATH = Rails.root.join("tmp", "static_export").to_s
......@@ -56,7 +57,7 @@ class StaticProgramExport
base_url = URI.parse(@conference.program_export_base_url).path
base_url += '/' unless base_url.end_with?('/')
base_url
else
else
"/"
end
end
......@@ -87,7 +88,7 @@ class StaticProgramExport
FileUtils.mkdir_p(File.dirname(new_path))
FileUtils.cp(original_path, new_path)
else
STDERR.puts '?? We might be missing "%s"' % original_path
warning('?? We might be missing "%s"' % original_path)
end
end
end
......@@ -133,8 +134,8 @@ class StaticProgramExport
def save_response(source, filename)
status_code = @session.get(source)
unless status_code == 200
STDERR.puts '!! Failed to fetch "%s" as "%s" with error code %d' % [ source, filename, status_code ]
return
error('!! Failed to fetch "%s" as "%s" with error code %d' % [ source, filename, status_code ])
return
end
file_path = File.join(@base_directory, URI.decode(filename))
......@@ -142,18 +143,18 @@ class StaticProgramExport
if filename =~ /\.html$/
document = modify_response_html(filename)
File.open(file_path, "w") do |f|
File.open(file_path, "w") do |f|
# FIXME corrupts events and speakers?
#document.write_html_to(f, encoding: "UTF-8")
f.puts(document.to_html)
end
elsif filename =~ /\.pdf$/
File.open(file_path, "wb") do |f|
File.open(file_path, "wb") do |f|
f.write(@session.response.body)
end
else
# CSS,...
File.open(file_path, "w:utf-8") do |f|
File.open(file_path, "w:utf-8") do |f|
f.write(@session.response.body.encode("UTF-8", invalid: :replace, undef: :replace, replace: "?"))
end
end
......@@ -161,7 +162,7 @@ class StaticProgramExport
def modify_response_html(filename)
document = Nokogiri::HTML(@session.response.body, nil, "UTF-8")
# <link>
document.css("link").each do |link|
href_attr = link.attributes["href"]
......@@ -176,15 +177,15 @@ class StaticProgramExport
document.css("script").each do |script|
strip_asset_path(script, "src") if script.attributes["src"]
end
# <img>
document.css("img").each do |image|
strip_asset_path(image, "src")
end
# <a>
document.css("a").each do |link|
href = link.attributes["href"]
href = link.attributes["href"]
if href and href.value.start_with?("/")
if href.value =~ /\?\d+$/
strip_asset_path(link, "href")
......
FactoryGirl.define do
sequence :email do |n|
"test#{n}@example.com"
end
......@@ -59,17 +59,17 @@ FactoryGirl.define do
trait :with_events do
after :create do |conference|
conference.events << create(:event, conference: conference,
room: conference.rooms.first,
room: conference.rooms.first,
state: 'confirmed',
public: true,
start_time: Date.today.since(1.days).since(11.hours))
conference.events << create(:event, conference: conference,
room: conference.rooms.first,
room: conference.rooms.first,
state: 'confirmed',
public: true,
start_time: Date.today.since(1.days).since(15.hours))
start_time: Date.today.since(2.days).since(15.hours))
conference.events << create(:event, conference: conference,
room: conference.rooms.first,
room: conference.rooms.first,
state: 'confirmed',
public: true,
start_time: Date.today.since(3.days).since(11.hours))
......@@ -162,7 +162,7 @@ FactoryGirl.define do
factory :language do
code "EN"
factory :english_language do
end
factory :german_language do
......@@ -180,7 +180,7 @@ FactoryGirl.define do
factory :event_person do
person
event
event
event_role "speaker"
end
......
......@@ -3,13 +3,13 @@ require 'test_helper'
class StaticProgramExportTask < ActionDispatch::IntegrationTest
setup do
@conference = create(:three_day_conference)
@conference = create(:three_day_conference_with_events)
@target_dir = File.join(Rails.root, 'tmp', 'static_export')
end
test "can run program export task" do
locale = 'en'
load File.join(Rails.root, 'lib', 'tasks', 'static_program_export.rake')
Rake::Task.define_task(:environment)
ENV['CONFERENCE'] = @conference.acronym
......
......@@ -9,17 +9,18 @@ class ConferenceScrubberTest < ActiveSupport::TestCase
@conference = FactoryGirl.create(:conference)
add_day(@conference, 2.years)
@event_person = add_event_with_speaker(@conference)
ENV['QUIET'] = '1'
end
def add_day(conference, time)
conference.days << FactoryGirl.create(:day,
conference.days << FactoryGirl.create(:day,
start_date: Date.today.ago(time).since(11.hours),
end_date: Date.today.ago(time).since(23.hours))
end
def add_event_with_speaker(conference)
event = FactoryGirl.create(:event, conference: conference, state: "confirmed")
event_person = FactoryGirl.create(:event_person, event: event)
FactoryGirl.create(:event_person, event: event)
end
test "should find last years conferences" do
......
......@@ -3,7 +3,7 @@ require 'test_helper'
class StaticProgramExportTest < ActiveSupport::TestCase
setup do
@conference = create(:three_day_conference)
@conference = create(:three_day_conference_with_events)
@locale = 'en'
@target_dir = File.join(Rails.root, 'tmp', 'static_export')
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment