diaspora/spec/shared_behaviors/mentions_container.rb
2016-11-28 15:56:56 +02:00

44 lines
1.3 KiB
Ruby

shared_examples_for "it is mentions container" do
let(:people) { [alice, bob, eve].map(&:person) }
let(:test_string) {
"@{Raphael; #{people[0].diaspora_handle}} can mention people like @{Ilya; #{people[1].diaspora_handle}}"\
"can mention people like @{Daniel; #{people[2].diaspora_handle}}"
}
let(:target) { FactoryGirl.build(described_class.to_s.underscore.to_sym, text: test_string, author: alice.person) }
let(:target_persisted) {
target.save!
target
}
describe ".after_create" do
it "calls create_mentions" do
expect(target).to receive(:create_mentions).and_call_original
target.save
end
end
describe "#create_mentions" do
it "creates a mention for everyone mentioned in the message" do
people.each do |person|
expect(target.mentions).to receive(:find_or_create_by).with(person_id: person.id)
end
target.create_mentions
end
it "does not barf if it gets called twice" do
expect {
target_persisted.create_mentions
}.to_not raise_error
end
end
describe "#mentioned_people" do
it "returns the mentioned people if non-persisted" do
expect(target.mentioned_people).to match_array(people)
end
it "returns the mentioned people if persisted" do
expect(target_persisted.mentioned_people).to match_array(people)
end
end
end