summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-08-17 12:15:20 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2016-08-17 12:15:20 +0200
commitfa0624fc6409d84373f3e06275e936c9e5171b79 (patch)
treee884a367f605548365c6e3745f1a7a4457afe487
parent88a0c984fc0bdbe0951b02c4e1d4b749dce88a24 (diff)
downloadgitlab-ce-fix-downtime-check-formatting.tar.gz
Better formatting for downtime check messagesfix-downtime-check-formatting
This removes excessive whitespace from the messages (e.g. leading whitespace) and ensures the message is more clearly visible.
-rw-r--r--lib/gitlab/downtime_check/message.rb15
-rw-r--r--spec/lib/gitlab/downtime_check/message_spec.rb24
2 files changed, 36 insertions, 3 deletions
diff --git a/lib/gitlab/downtime_check/message.rb b/lib/gitlab/downtime_check/message.rb
index fd85f087c03..40a4815a9a0 100644
--- a/lib/gitlab/downtime_check/message.rb
+++ b/lib/gitlab/downtime_check/message.rb
@@ -1,7 +1,7 @@
module Gitlab
class DowntimeCheck
class Message
- attr_reader :path, :offline, :reason
+ attr_reader :path, :offline
OFFLINE = "\e[31moffline\e[0m"
ONLINE = "\e[32monline\e[0m"
@@ -19,10 +19,21 @@ module Gitlab
label = offline ? OFFLINE : ONLINE
message = "[#{label}]: #{path}"
- message += ": #{reason}" if reason
+
+ if reason?
+ message += ":\n\n#{reason}\n\n"
+ end
message
end
+
+ def reason?
+ @reason.present?
+ end
+
+ def reason
+ @reason.strip.lines.map(&:strip).join("\n")
+ end
end
end
end
diff --git a/spec/lib/gitlab/downtime_check/message_spec.rb b/spec/lib/gitlab/downtime_check/message_spec.rb
index d467d2cbd18..a5a398abf78 100644
--- a/spec/lib/gitlab/downtime_check/message_spec.rb
+++ b/spec/lib/gitlab/downtime_check/message_spec.rb
@@ -5,7 +5,7 @@ describe Gitlab::DowntimeCheck::Message do
it 'returns an ANSI formatted String for an offline migration' do
message = described_class.new('foo.rb', true, 'hello')
- expect(message.to_s).to eq("[\e[31moffline\e[0m]: foo.rb: hello")
+ expect(message.to_s).to eq("[\e[31moffline\e[0m]: foo.rb:\n\nhello\n\n")
end
it 'returns an ANSI formatted String for an online migration' do
@@ -14,4 +14,26 @@ describe Gitlab::DowntimeCheck::Message do
expect(message.to_s).to eq("[\e[32monline\e[0m]: foo.rb")
end
end
+
+ describe '#reason?' do
+ it 'returns false when no reason is specified' do
+ message = described_class.new('foo.rb')
+
+ expect(message.reason?).to eq(false)
+ end
+
+ it 'returns true when a reason is specified' do
+ message = described_class.new('foo.rb', true, 'hello')
+
+ expect(message.reason?).to eq(true)
+ end
+ end
+
+ describe '#reason' do
+ it 'strips excessive whitespace from the returned String' do
+ message = described_class.new('foo.rb', true, " hello\n world\n\n foo")
+
+ expect(message.reason).to eq("hello\nworld\n\nfoo")
+ end
+ end
end