Do not add participation for comment if comment validation failed The same fix is also done for the other social actions

closes #6552
This commit is contained in:
Manuel Vögele 2015-11-18 01:45:32 +01:00 committed by Jonne Haß
parent acb9547978
commit 0925a26506
3 changed files with 24 additions and 11 deletions

View file

@ -7,6 +7,7 @@
* Correctly skip setting sidekiq logfile on Heroku [#6500](https://github.com/diaspora/diaspora/pull/6500) * Correctly skip setting sidekiq logfile on Heroku [#6500](https://github.com/diaspora/diaspora/pull/6500)
* Fix notifications for interactions by non-contacts [#6498](https://github.com/diaspora/diaspora/pull/6498) * Fix notifications for interactions by non-contacts [#6498](https://github.com/diaspora/diaspora/pull/6498)
* Fix issue where the publisher was broken on profile pages [#6503](https://github.com/diaspora/diaspora/pull/6503) * Fix issue where the publisher was broken on profile pages [#6503](https://github.com/diaspora/diaspora/pull/6503)
* Prevent participations being created for invalid interactions [#6552](https://github.com/diaspora/diaspora/pull/6552)
## Features ## Features

View file

@ -1,7 +1,8 @@
module User::SocialActions module User::SocialActions
def comment!(target, text, opts={}) def comment!(target, text, opts={})
find_or_create_participation!(target) Comment::Generator.new(self, target, text).create!(opts).tap do
Comment::Generator.new(self, target, text).create!(opts) find_or_create_participation!(target)
end
end end
def participate!(target, opts={}) def participate!(target, opts={})
@ -9,21 +10,23 @@ module User::SocialActions
end end
def like!(target, opts={}) def like!(target, opts={})
find_or_create_participation!(target) Like::Generator.new(self, target).create!(opts).tap do
Like::Generator.new(self, target).create!(opts) find_or_create_participation!(target)
end
end end
def participate_in_poll!(target, answer, opts={}) def participate_in_poll!(target, answer, opts={})
find_or_create_participation!(target) PollParticipation::Generator.new(self, target, answer).create!(opts).tap do
PollParticipation::Generator.new(self, target, answer).create!(opts) find_or_create_participation!(target)
end
end end
def reshare!(target, opts={}) def reshare!(target, opts={})
find_or_create_participation!(target) build_post(:reshare, :root_guid => target.guid).tap do |reshare|
reshare = build_post(:reshare, :root_guid => target.guid) reshare.save!
reshare.save! find_or_create_participation!(target)
Postzord::Dispatcher.defer_build_and_post(self, reshare) Postzord::Dispatcher.defer_build_and_post(self, reshare)
reshare end
end end
def build_comment(options={}) def build_comment(options={})

View file

@ -57,6 +57,15 @@ describe Comment, :type => :model do
comment_alice comment_alice
}.to change { Comment.count }.by(1) }.to change { Comment.count }.by(1)
end end
it "does not create a participation if comment validation failed" do
begin
alice.comment!(status_bob, " ")
rescue ActiveRecord::RecordInvalid
end
participations = Participation.where(target_id: status_bob, author_id: alice.person.id)
expect(participations.count).to eq(0)
end
end end
describe "counter cache" do describe "counter cache" do