diff --git a/Changelog.md b/Changelog.md index 736e38950..2de7a30f1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,6 +14,7 @@ * Remove two unused methods [#5970](https://github.com/diaspora/diaspora/pull/5970) * Refactored the Logger to add basic logrotating and more useful timestamps [#5975](https://github.com/diaspora/diaspora/pull/5975) * Gracefully handle mailer failures if a like is already deleted again [#5983](https://github.com/diaspora/diaspora/pull/5983) +* Ensure posts have an author [#5986](https://github.com/diaspora/diaspora/pull/5986) ## Bug fixes * Disable auto follow back on aspect deletion [#5846](https://github.com/diaspora/diaspora/pull/5846) diff --git a/app/models/post.rb b/app/models/post.rb index 3a5636922..ea317f5b1 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -28,6 +28,8 @@ class Post < ActiveRecord::Base validates_uniqueness_of :id + validates :author, presence: true + after_create do self.touch(:interacted_at) end diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 5d857c640..b9024cb3f 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -13,7 +13,7 @@ class StatusMessage < Post validates_length_of :text, :maximum => 65535, :message => proc {|p, v| I18n.t('status_messages.too_long', :count => 65535, :current_length => v[:value].length)} # don't allow creation of empty status messages - validate :presence_of_content, on: :create, if: proc { |sm| sm.author.local? } + validate :presence_of_content, on: :create, if: proc {|sm| sm.author && sm.author.local? } xml_name :status_message xml_attr :raw_message diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 605b6ede0..0f37390a4 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -70,7 +70,7 @@ describe StatusMessage, :type => :model do expect(guids).to eq([sm1.guid]) end end - + describe '.before_validation' do it 'calls build_tags' do status = FactoryGirl.build(:status_message) @@ -443,4 +443,12 @@ STR end end end + + describe "validation" do + it "should not be valid if the author is missing" do + sm = FactoryGirl.build(:status_message, text: @message_text) + sm.author = nil + expect(sm).not_to be_valid + end + end end