From f2da6ac6f656fbb559840538f02ae74957aeef3d Mon Sep 17 00:00:00 2001 From: Cyril Mougel Date: Thu, 30 May 2013 12:25:16 +0200 Subject: [PATCH] Fix ical generation The ical generation failed in some case like report on #343. Now the ical generation work. fix #343 --- app/helpers/application_helper.rb | 4 ++-- app/models/notice.rb | 10 ++++++++++ spec/helpers/application_helper_spec.rb | 9 +++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cd44503a6..f100e82dc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -8,11 +8,11 @@ def generate_problem_ical(notices) notices.each_with_index do |notice,idx| cal.event do |event| event.summary = "#{idx+1} #{notice.message.to_s}" - event.description = notice.request['url'] + event.description = notice.url if notice.url event.dtstart = notice.created_at.utc event.dtend = notice.created_at.utc + 60.minutes event.organizer = notice.server_environment && notice.server_environment["hostname"] - event.location = notice.server_environment && notice.server_environment["project-root"] + event.location = notice.project_root event.url = app_problem_url(:app_id => notice.problem.app.id, :id => notice.problem) end end diff --git a/app/models/notice.rb b/app/models/notice.rb index f428af602..b1f433ac7 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -114,6 +114,15 @@ def should_notify? app.notification_service.notify_at_notices.include?(0) || app.notification_service.notify_at_notices.include?(similar_count) end + ## + # TODO: Move on decorator maybe + # + def project_root + if server_environment + server_environment['project-root'] || '' + end + end + protected def decrease_counter_cache @@ -138,6 +147,7 @@ def sanitize end end + def sanitize_hash(h) h.recurse do |h| h.inject({}) do |h,(k,v)| diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 028facc9b..25c1666da 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -10,3 +10,12 @@ # end # end # end + +describe ApplicationHelper do + let(:notice) { Fabricate(:notice) } + describe "#generate_problem_ical" do + it 'return the ical format' do + helper.generate_problem_ical([notice]) + end + end +end