fix validation for status-message when the author is missing

closes #5986
This commit is contained in:
Benjamin Neff 2015-05-24 03:56:16 +02:00 committed by Jonne Haß
parent 8531b160a6
commit 986ad0df14
4 changed files with 13 additions and 2 deletions

View file

@ -14,6 +14,7 @@
* Remove two unused methods [#5970](https://github.com/diaspora/diaspora/pull/5970) * 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) * 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) * 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 ## Bug fixes
* Disable auto follow back on aspect deletion [#5846](https://github.com/diaspora/diaspora/pull/5846) * Disable auto follow back on aspect deletion [#5846](https://github.com/diaspora/diaspora/pull/5846)

View file

@ -28,6 +28,8 @@ class Post < ActiveRecord::Base
validates_uniqueness_of :id validates_uniqueness_of :id
validates :author, presence: true
after_create do after_create do
self.touch(:interacted_at) self.touch(:interacted_at)
end end

View file

@ -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)} 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 # 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_name :status_message
xml_attr :raw_message xml_attr :raw_message

View file

@ -443,4 +443,12 @@ STR
end end
end 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 end