Skip to content
Extraits de code Groupes Projets
Valider ab2118ff rédigé par Benjamin Neff's avatar Benjamin Neff
Parcourir les fichiers

don't participate own posts

parent 2f2fe71c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -48,6 +48,7 @@ module User::SocialActions ...@@ -48,6 +48,7 @@ module User::SocialActions
end end
def update_or_create_participation!(target) def update_or_create_participation!(target)
return if target.author == person
participation = participations.where(target_id: target).first participation = participations.where(target_id: target).first
if participation.present? if participation.present?
participation.update!(count: participation.count.next) participation.update!(count: participation.count.next)
......
require "spec_helper" require "spec_helper"
describe User::SocialActions, :type => :model do describe User::SocialActions, type: :model do
before do let(:status) { FactoryGirl.create(:status_message, public: true, author: bob.person) }
@bobs_aspect = bob.aspects.where(:name => "generic").first
@status = bob.post(:status_message, :text => "hello", :to => @bobs_aspect.id)
end
describe 'User#comment!' do describe "User#comment!" do
it "sets the comment text" do it "sets the comment text" do
expect(alice.comment!(@status, "unicorn_mountain").text).to eq("unicorn_mountain") expect(alice.comment!(status, "unicorn_mountain").text).to eq("unicorn_mountain")
end end
it "creates a participation" do it "creates a participation" do
expect{ alice.comment!(@status, "bro") }.to change(Participation, :count).by(1) expect { alice.comment!(status, "bro") }.to change(Participation, :count).by(1)
expect(alice.participations.last.target).to eq(@status) expect(alice.participations.last.target).to eq(status)
expect(alice.participations.last.count).to eq(1) expect(alice.participations.last.count).to eq(1)
end end
it "creates the comment" do it "does not create a participation for the post author" do
expect{ alice.comment!(@status, "bro") }.to change(Comment, :count).by(1) expect { bob.comment!(status, "bro") }.not_to change(Participation, :count)
end
it "federates" do
allow_any_instance_of(Participation::Generator).to receive(:create!)
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
alice.comment!(@status, "omg")
end
end
describe 'User#like!' do
it "creates a participation" do
expect{ alice.like!(@status) }.to change(Participation, :count).by(1)
expect(alice.participations.last.target).to eq(@status)
end end
it "creates the like" do it "creates the comment" do
expect{ alice.like!(@status) }.to change(Like, :count).by(1) expect { alice.comment!(status, "bro") }.to change(Comment, :count).by(1)
end end
it "federates" do it "federates" do
#participation and like
allow_any_instance_of(Participation::Generator).to receive(:create!) allow_any_instance_of(Participation::Generator).to receive(:create!)
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch) expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
alice.like!(@status) alice.comment!(status, "omg")
end end
end end
describe 'User#like!' do describe "User#like!" do
before do it "creates a participation" do
@bobs_aspect = bob.aspects.where(:name => "generic").first expect { alice.like!(status) }.to change(Participation, :count).by(1)
@status = bob.post(:status_message, :text => "hello", :to => @bobs_aspect.id) expect(alice.participations.last.target).to eq(status)
end end
it "creates a participation" do it "does not create a participation for the post author" do
expect{ alice.like!(@status) }.to change(Participation, :count).by(1) expect { bob.like!(status) }.not_to change(Participation, :count)
end end
it "creates the like" do it "creates the like" do
expect{ alice.like!(@status) }.to change(Like, :count).by(1) expect { alice.like!(status) }.to change(Like, :count).by(1)
end end
it "federates" do it "federates" do
#participation and like allow_any_instance_of(Participation::Generator).to receive(:create!)
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).twice expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
alice.like!(@status) alice.like!(status)
end end
it "should be able to like on one's own status" do it "should be able to like on one's own status" do
like = alice.like!(@status) like = bob.like!(status)
expect(@status.reload.likes.first).to eq(like) expect(status.reload.likes.first).to eq(like)
end end
it "should be able to like on a contact's status" do it "should be able to like on a contact's status" do
like = bob.like!(@status) like = alice.like!(status)
expect(@status.reload.likes.first).to eq(like) expect(status.reload.likes.first).to eq(like)
end end
it "does not allow multiple likes" do it "does not allow multiple likes" do
alice.like!(@status) alice.like!(status)
likes = @status.likes likes = status.likes
expect { alice.like!(@status) }.to raise_error ActiveRecord::RecordInvalid expect { alice.like!(status) }.to raise_error ActiveRecord::RecordInvalid
expect(@status.reload.likes).to eq(likes) expect(status.reload.likes).to eq(likes)
end end
end end
describe 'User#participate_in_poll!' do describe "User#participate_in_poll!" do
before do let(:poll) { FactoryGirl.create(:poll, status_message: status) }
@bobs_aspect = bob.aspects.where(:name => "generic").first let(:answer) { poll.poll_answers.first }
@status = bob.post(:status_message, :text => "hello", :to => @bobs_aspect.id)
@poll = FactoryGirl.create(:poll, :status_message => @status)
@answer = @poll.poll_answers.first
end
it "federates" do it "federates" do
allow_any_instance_of(Participation::Generator).to receive(:create!) allow_any_instance_of(Participation::Generator).to receive(:create!)
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch) expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
alice.participate_in_poll!(@status, @answer) alice.participate_in_poll!(status, answer)
end
it "creates a participation" do
expect { alice.participate_in_poll!(status, answer) }.to change(Participation, :count).by(1)
end end
it "creates a partcipation" do it "does not create a participation for the post author" do
expect{ alice.participate_in_poll!(@status, @answer) }.to change(Participation, :count).by(1) expect { bob.participate_in_poll!(status, answer) }.not_to change(Participation, :count)
end end
it "creates the poll participation" do it "creates the poll participation" do
expect{ alice.participate_in_poll!(@status, @answer) }.to change(PollParticipation, :count).by(1) expect { alice.participate_in_poll!(status, answer) }.to change(PollParticipation, :count).by(1)
end end
it "sets the poll answer id" do it "sets the poll answer id" do
expect(alice.participate_in_poll!(@status, @answer).poll_answer).to eq(@answer) expect(alice.participate_in_poll!(status, answer).poll_answer).to eq(answer)
end end
end end
describe "many actions" do describe "many actions" do
it "two coments" do it "two comments" do
alice.comment!(@status, "bro...") alice.comment!(status, "bro...")
alice.comment!(@status, "...ther") alice.comment!(status, "...ther")
expect(alice.participations.last.count).to eq(2) expect(alice.participations.last.count).to eq(2)
end end
it "like and comment" do it "like and comment" do
alice.comment!(@status, "bro...") alice.comment!(status, "bro...")
alice.like!(@status) alice.like!(status)
expect(alice.participations.last.count).to eq(2) expect(alice.participations.last.count).to eq(2)
end end
end end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter