Actually implement validation error case in Photo#ownserhip_of_status_message

closes #8214
closes #8048

Co-authored-by: Thorsten Claus <thorstenclaus@web.de>
This commit is contained in:
gabrielrumiranda 2019-09-23 00:00:20 -03:00 committed by Jonne Haß
parent ef9e764f7a
commit 394eafccc5
5 changed files with 8 additions and 9 deletions

View file

@ -12,6 +12,7 @@
* Removed support for defunct Uni Heidelberg OSM tile server, Mapbox is now required if you want to show maps [#8215](https://github.com/diaspora/diaspora/pull/8215) * Removed support for defunct Uni Heidelberg OSM tile server, Mapbox is now required if you want to show maps [#8215](https://github.com/diaspora/diaspora/pull/8215)
* Render only two fractional digits in the posts per user/day admin statistics [#8227](https://github.com/diaspora/diaspora/pull/8227) * Render only two fractional digits in the posts per user/day admin statistics [#8227](https://github.com/diaspora/diaspora/pull/8227)
* Make aspect dropdowns scrollable [#8213](https://github.com/diaspora/diaspora/pull/8213) * Make aspect dropdowns scrollable [#8213](https://github.com/diaspora/diaspora/pull/8213)
* Fix `Photo#ownserhip_of_status_message` validation [#8214](https://github.com/diaspora/diaspora/pull/8214)
## Features ## Features
* Support and recommend TOML as configuration format [#8132](https://github.com/diaspora/diaspora/pull/8132) * Support and recommend TOML as configuration format [#8132](https://github.com/diaspora/diaspora/pull/8132)

View file

@ -68,11 +68,9 @@ class Photo < ApplicationRecord
def ownership_of_status_message def ownership_of_status_message
message = StatusMessage.find_by_guid(self.status_message_guid) message = StatusMessage.find_by_guid(self.status_message_guid)
if self.status_message_guid && message return unless status_message_guid && message && diaspora_handle != message.diaspora_handle
self.diaspora_handle == message.diaspora_handle
else errors.add(:base, "Photo must have the same owner as status message")
true
end
end end
def self.diaspora_initialize(params={}) def self.diaspora_initialize(params={})

View file

@ -32,7 +32,7 @@ end
Given /^"([^"]*)" has a public post with text "([^"]*)" and a picture/ do |email, text| Given /^"([^"]*)" has a public post with text "([^"]*)" and a picture/ do |email, text|
user = User.find_by(email: email) user = User.find_by(email: email)
post = user.post(:status_message, text: text, public: true, to: user.aspect_ids) post = user.post(:status_message, text: text, public: true, to: user.aspect_ids)
FactoryGirl.create(:photo, status_message: post) FactoryGirl.create(:photo, status_message: post, author: user.person)
end end
Given /^there are (\d+) public posts from "([^"]*)"$/ do |n_posts, email| Given /^there are (\d+) public posts from "([^"]*)"$/ do |n_posts, email|

View file

@ -216,7 +216,7 @@ describe Notifier, type: :mailer do
end end
it "can handle status_messages without text" do it "can handle status_messages without text" do
photo = FactoryGirl.create(:photo, public: true) photo = FactoryGirl.create(:photo, public: true, author: alice.person)
status = FactoryGirl.create(:status_message, author: alice.person, text: nil, photos: [photo], public: true) status = FactoryGirl.create(:status_message, author: alice.person, text: nil, photos: [photo], public: true)
like = status.likes.create!(author: bob.person) like = status.likes.create!(author: bob.person)
mail = Notifier.send_notification("liked", alice.id, like.author.id, like.id) mail = Notifier.send_notification("liked", alice.id, like.author.id, like.id)

View file

@ -306,7 +306,7 @@ describe StatusMessage, type: :model do
let(:post) { FactoryGirl.create(:status_message, author: alice.person) } let(:post) { FactoryGirl.create(:status_message, author: alice.person) }
it "receives attached photos" do it "receives attached photos" do
photo = FactoryGirl.create(:photo, status_message: post) photo = FactoryGirl.create(:photo, status_message: post, author: alice.person)
post.receive([bob.id]) post.receive([bob.id])
@ -321,7 +321,7 @@ describe StatusMessage, type: :model do
end end
it "works with already received attached photos" do it "works with already received attached photos" do
photo = FactoryGirl.create(:photo, status_message: post) photo = FactoryGirl.create(:photo, status_message: post, author: alice.person)
photo.receive([bob.id]) photo.receive([bob.id])
post.receive([bob.id]) post.receive([bob.id])