From 09908a45fb86db74d8a8f2eb407db1c6a9f3e6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Mon, 27 Jun 2016 12:07:11 +0200 Subject: [PATCH] StatusMessage#raw_message returns empty string for NULL values Previously the federation layer has written the empty string to the database, now it writes nil/no value to it while our code still expects the empty string in some cases. Restore the old assumption by returning the empty string, the real raw value by now is available again in StatusMessage#text for those that need it, such as validations or tests. --- app/models/status_message.rb | 2 +- spec/models/status_message_spec.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/status_message.rb b/app/models/status_message.rb index b8f7e0973..28eab528d 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -53,7 +53,7 @@ class StatusMessage < Post end def raw_message - read_attribute(:text) + read_attribute(:text) || "" end def raw_message=(text) diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index dffeff841..dac72238c 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -113,6 +113,9 @@ describe StatusMessage, type: :model do post.photos << photo expect(post).to be_valid + expect(post.message.to_s).to be_empty + expect(post.raw_message).to eq "" + expect(post.nsfw).to be_falsy expect(post.errors.full_messages).to eq([]) end