refactor tests to use let
instead of before blocks creating instance variables pronto checked #6192
This commit is contained in:
parent
8823bb01a2
commit
c5a2334fbe
8 changed files with 84 additions and 111 deletions
|
|
@ -5,27 +5,27 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe AccountDeletion, :type => :model do
|
||||
let(:ad_new) { AccountDeletion.new(person: alice.person) }
|
||||
let(:ad_create) { AccountDeletion.create(person: alice.person) }
|
||||
let(:account_deletion_new) { AccountDeletion.new(person: alice.person) }
|
||||
let(:account_deletion_create) { AccountDeletion.create(person: alice.person) }
|
||||
|
||||
it 'assigns the diaspora_handle from the person object' do
|
||||
expect(ad_new.diaspora_handle).to eq(alice.person.diaspora_handle)
|
||||
expect(account_deletion_new.diaspora_handle).to eq(alice.person.diaspora_handle)
|
||||
end
|
||||
|
||||
it 'fires a job after creation'do
|
||||
expect(Workers::DeleteAccount).to receive(:perform_async).with(anything)
|
||||
ad_create
|
||||
account_deletion_create
|
||||
end
|
||||
|
||||
describe "#perform!" do
|
||||
it 'creates a deleter' do
|
||||
expect(AccountDeleter).to receive(:new).with(alice.person.diaspora_handle).and_return(double(perform!: true))
|
||||
ad_new.perform!
|
||||
account_deletion_new.perform!
|
||||
end
|
||||
|
||||
it 'dispatches the account deletion if the user exists' do
|
||||
expect(ad_new).to receive(:dispatch)
|
||||
ad_new.perform!
|
||||
expect(account_deletion_new).to receive(:dispatch)
|
||||
account_deletion_new.perform!
|
||||
end
|
||||
|
||||
it 'does not dispatch an account deletion for non-local people' do
|
||||
|
|
@ -35,15 +35,15 @@ describe AccountDeletion, :type => :model do
|
|||
end
|
||||
|
||||
it 'marks an AccountDeletion as completed when successful' do
|
||||
ad_create.perform!
|
||||
expect(ad_create.reload.completed_at).not_to be_nil
|
||||
account_deletion_create.perform!
|
||||
expect(account_deletion_create.reload.completed_at).not_to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dispatch' do
|
||||
it 'creates a public postzord' do
|
||||
expect(Postzord::Dispatcher::Public).to receive(:new).and_return(double.as_null_object)
|
||||
ad_new.dispatch
|
||||
account_deletion_new.dispatch
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -51,20 +51,20 @@ describe AccountDeletion, :type => :model do
|
|||
it 'includes all remote contacts' do
|
||||
alice.share_with(remote_raphael, alice.aspects.first)
|
||||
|
||||
expect(ad_new.subscribers(alice)).to eq([remote_raphael])
|
||||
expect(account_deletion_new.subscribers(alice)).to eq([remote_raphael])
|
||||
end
|
||||
|
||||
it 'includes remote resharers' do
|
||||
sm = FactoryGirl.create( :status_message, public: true, author: alice.person)
|
||||
FactoryGirl.create( :reshare, author: remote_raphael, root: sm)
|
||||
FactoryGirl.create( :reshare, author: local_luke.person, root: sm)
|
||||
status_message = FactoryGirl.create(:status_message, public: true, author: alice.person)
|
||||
FactoryGirl.create(:reshare, author: remote_raphael, root: status_message)
|
||||
FactoryGirl.create(:reshare, author: local_luke.person, root: status_message)
|
||||
|
||||
expect(ad_new.subscribers(alice)).to eq([remote_raphael])
|
||||
expect(account_deletion_new.subscribers(alice)).to eq([remote_raphael])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'serialization' do
|
||||
let(:xml) { ad_new.to_xml.to_s }
|
||||
let(:xml) { account_deletion_new.to_xml.to_s }
|
||||
|
||||
it 'should have a diaspora_handle' do
|
||||
expect(xml.include?(alice.person.diaspora_handle)).to eq(true)
|
||||
|
|
|
|||
|
|
@ -22,16 +22,16 @@ describe ActsAsTaggableOn::Tag, :type => :model do
|
|||
|
||||
it "removes punctuation and whitespace" do
|
||||
{
|
||||
'node.js' => 'nodejs',
|
||||
'.dotatstart' => 'dotatstart',
|
||||
'you,inside' => 'youinside',
|
||||
'iam(parenthetical)' => 'iamparenthetical',
|
||||
'imeanit?maybe' => 'imeanitmaybe',
|
||||
'imeanit!' => 'imeanit',
|
||||
'how about spaces' => 'howaboutspaces',
|
||||
"other\twhitespace\n" => 'otherwhitespace',
|
||||
'hash#inside' => 'hashinside',
|
||||
'f!u@n#k$y%-<c>^h&a*r(a)c{t}e[r]s' => 'funky-characters'
|
||||
"node.js" => "nodejs",
|
||||
".dotatstart" => "dotatstart",
|
||||
"you,inside" => "youinside",
|
||||
"iam(parenthetical)" => "iamparenthetical",
|
||||
"imeanit?maybe" => "imeanitmaybe",
|
||||
"imeanit!" => "imeanit",
|
||||
"how about spaces" => "howaboutspaces",
|
||||
"other\twhitespace\n" => "otherwhitespace",
|
||||
"hash#inside" => "hashinside",
|
||||
"f!u@n#k$y%-<c>^h&a*r(a)c{t}e[r]s" => "funky-characters"
|
||||
}.each do |invalid, normalized|
|
||||
expect(tag.normalize(invalid)).to eq(normalized)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,28 +5,26 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe AspectMembership, :type => :model do
|
||||
|
||||
describe '#before_destroy' do
|
||||
let(:aspect) { alice.aspects.create(name: "two") }
|
||||
let(:aspect) { alice.aspects.create(name: "two") }
|
||||
let(:contact) { alice.contact_for(bob.person) }
|
||||
let(:am) { alice.aspects.where(name: "generic").first.aspect_memberships.first }
|
||||
let(:aspect_membership) { alice.aspects.where(name: "generic").first.aspect_memberships.first }
|
||||
|
||||
before do
|
||||
allow(am).to receive(:user).and_return(alice)
|
||||
allow(aspect_membership).to receive(:user).and_return(alice)
|
||||
end
|
||||
|
||||
it 'calls disconnect if its the last aspect for the contact' do
|
||||
expect(alice).to receive(:disconnect).with(contact)
|
||||
|
||||
am.destroy
|
||||
aspect_membership.destroy
|
||||
end
|
||||
|
||||
it 'does not call disconnect if its not the last aspect for the contact' do
|
||||
expect(alice).not_to receive(:disconnect)
|
||||
|
||||
alice.add_contact_to_aspect(contact, aspect)
|
||||
am.destroy
|
||||
aspect_membership.destroy
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ describe Aspect, :type => :model do
|
|||
end
|
||||
|
||||
it 'is able to have other users as contacts' do
|
||||
aspect = alice.aspects.create(name: 'losers')
|
||||
aspect = alice.aspects.create(name: "losers")
|
||||
Contact.create(user: alice, person: eve.person, aspects: [aspect])
|
||||
|
||||
expect(aspect.contacts.where(person_id: alice.person.id)).to be_empty
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ require 'spec_helper'
|
|||
require Rails.root.join("spec", "shared_behaviors", "relayable")
|
||||
|
||||
describe Comment, :type => :model do
|
||||
let(:alices_aspect) { alice.aspects.first }
|
||||
let(:status_bob) { bob.post(:status_message, text: "hello", to: bob.aspects.first.id) }
|
||||
let(:comment_alice) { alice.comment!(status_bob, "why so formal?") }
|
||||
let(:alices_aspect) { alice.aspects.first }
|
||||
let(:status_bob) { bob.post(:status_message, text: "hello", to: bob.aspects.first.id) }
|
||||
let(:comment_alice) { alice.comment!(status_bob, "why so formal?") }
|
||||
|
||||
describe 'comment#notification_type' do
|
||||
it "returns 'comment_on_post' if the comment is on a post you own" do
|
||||
|
|
@ -70,11 +70,11 @@ describe Comment, :type => :model do
|
|||
end
|
||||
|
||||
describe 'xml' do
|
||||
let(:commenter) { create(:user) }
|
||||
let(:commenter) { create(:user) }
|
||||
let(:commenter_aspect) { commenter.aspects.create(name: "bruisers") }
|
||||
let(:post) { alice.post :status_message, text: "hello", to: alices_aspect.id }
|
||||
let(:comment) { commenter.comment!(post, "Fool!") }
|
||||
let(:xml) { comment.to_xml.to_s }
|
||||
let(:post) { alice.post :status_message, text: "hello", to: alices_aspect.id }
|
||||
let(:comment) { commenter.comment!(post, "Fool!") }
|
||||
let(:xml) { comment.to_xml.to_s }
|
||||
|
||||
before do
|
||||
connect_users(alice, alices_aspect, commenter, commenter_aspect)
|
||||
|
|
@ -110,12 +110,12 @@ describe Comment, :type => :model do
|
|||
end
|
||||
|
||||
describe 'it is relayable' do
|
||||
let(:remote_parent) { build(:status_message, author: remote_raphael) }
|
||||
let(:local_parent) { local_luke.post :status_message, text: "hi", to: local_luke.aspects.first }
|
||||
let(:object_by_parent_author) { local_luke.comment!(local_parent, "yo!") }
|
||||
let(:object_by_recipient) { local_leia.build_comment(text: "yo", post: local_parent) }
|
||||
let(:remote_parent) { build(:status_message, author: remote_raphael) }
|
||||
let(:local_parent) { local_luke.post :status_message, text: "hi", to: local_luke.aspects.first }
|
||||
let(:object_by_parent_author) { local_luke.comment!(local_parent, "yo!") }
|
||||
let(:object_by_recipient) { local_leia.build_comment(text: "yo", post: local_parent) }
|
||||
let(:dup_object_by_parent_author) { object_by_parent_author.dup }
|
||||
let(:object_on_remote_parent) { local_luke.comment!(remote_parent, "Yeah, it was great") }
|
||||
let(:object_on_remote_parent) { local_luke.comment!(remote_parent, "Yeah, it was great") }
|
||||
|
||||
before do
|
||||
# shared_behaviors/relayable.rb is still using instance variables, so we need to define them here.
|
||||
|
|
@ -140,5 +140,4 @@ describe Comment, :type => :model do
|
|||
end
|
||||
it_should_behave_like 'it is taggable'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ require 'spec_helper'
|
|||
describe Contact, :type => :model do
|
||||
describe 'aspect_memberships' do
|
||||
it 'deletes dependent aspect memberships' do
|
||||
expect{
|
||||
expect {
|
||||
alice.contact_for(bob.person).destroy
|
||||
}.to change(AspectMembership, :count).by(-1)
|
||||
end
|
||||
|
|
@ -103,7 +103,7 @@ describe Contact, :type => :model do
|
|||
|
||||
describe '#contacts' do
|
||||
before do
|
||||
bob.aspects.create(name: 'next')
|
||||
bob.aspects.create(name: "next")
|
||||
bob.aspects(true)
|
||||
|
||||
@original_aspect = bob.aspects.where(name: "generic").first
|
||||
|
|
@ -133,7 +133,7 @@ describe Contact, :type => :model do
|
|||
end
|
||||
|
||||
it "returns the target local user's contacts that are in the same aspect" do
|
||||
expect(@contact.contacts.map{|p| p.id}).to match_array([eve.person].concat(@people1).map{|p| p.id})
|
||||
expect(@contact.contacts.map(&:id)).to match_array([eve.person].concat(@people1).map(&:id))
|
||||
end
|
||||
|
||||
it 'returns nothing if contacts_visible is false in that aspect' do
|
||||
|
|
@ -143,8 +143,8 @@ describe Contact, :type => :model do
|
|||
end
|
||||
|
||||
it 'returns no duplicate contacts' do
|
||||
[alice, eve].each {|c| bob.add_contact_to_aspect(bob.contact_for(c.person), bob.aspects.last)}
|
||||
contact_ids = @contact.contacts.map{|p| p.id}
|
||||
[alice, eve].each {|c| bob.add_contact_to_aspect(bob.contact_for(c.person), bob.aspects.last) }
|
||||
contact_ids = @contact.contacts.map(&:id)
|
||||
expect(contact_ids.uniq).to eq(contact_ids)
|
||||
end
|
||||
end
|
||||
|
|
@ -159,14 +159,9 @@ describe Contact, :type => :model do
|
|||
end
|
||||
|
||||
context 'requesting' do
|
||||
let(:contact) { Contact.new }
|
||||
let(:user) { build(:user) }
|
||||
let(:person) { build(:person) }
|
||||
|
||||
before do
|
||||
contact.user = user
|
||||
contact.person = person
|
||||
end
|
||||
let(:contact) { Contact.new user: user, person: person }
|
||||
let(:user) { build(:user) }
|
||||
let(:person) { build(:person) }
|
||||
|
||||
describe '#generate_request' do
|
||||
it 'makes a request' do
|
||||
|
|
|
|||
|
|
@ -5,23 +5,19 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Conversation, :type => :model do
|
||||
let(:user1) { alice }
|
||||
let(:user2) { bob }
|
||||
let(:user1) { alice }
|
||||
let(:user2) { bob }
|
||||
let(:participant_ids) { [user1.contacts.first.person.id, user1.person.id] }
|
||||
let(:create_hash) do
|
||||
{
|
||||
author: user1.person,
|
||||
participant_ids: participant_ids,
|
||||
subject: "cool stuff",
|
||||
messages_attributes: [ {author: user1.person, text: "hey"} ]
|
||||
}
|
||||
end
|
||||
let(:conversation) { Conversation.create(create_hash) }
|
||||
let(:message_last) { Message.create(author: user2.person, created_at: Time.now + 100, text: "last", conversation_id: conversation.id) }
|
||||
let(:message_first) { Message.create(author: user2.person, created_at: Time.now + 100, text: "first", conversation_id: conversation.id) }
|
||||
let(:create_hash) {{author: user1.person, participant_ids: participant_ids,
|
||||
subject: "cool stuff", messages_attributes: [{author: user1.person, text: "hey"}]}}
|
||||
let(:conversation) { Conversation.create(create_hash) }
|
||||
let(:message_last) { Message.create(author: user2.person, created_at: Time.now + 100,
|
||||
text: "last", conversation_id: conversation.id) }
|
||||
let(:message_first) { Message.create(author: user2.person, created_at: Time.now + 100,
|
||||
text: "first", conversation_id: conversation.id) }
|
||||
|
||||
it 'creates a message on create' do
|
||||
expect{ conversation }.to change(Message, :count).by(1)
|
||||
expect { conversation }.to change(Message, :count).by(1)
|
||||
end
|
||||
|
||||
describe '#last_author' do
|
||||
|
|
@ -49,13 +45,12 @@ describe Conversation, :type => :model do
|
|||
end
|
||||
|
||||
it 'returns nil if there are no unread messages in a conversation' do
|
||||
conversation.conversation_visibilities.where(person_id: user1.person.id).first.tap { |cv| cv.unread = 0 }.save
|
||||
conversation.conversation_visibilities.where(person_id: user1.person.id).first.tap {|cv| cv.unread = 0 }.save
|
||||
expect(conversation.first_unread_message(user1)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#set_read' do
|
||||
|
||||
before do
|
||||
conversation
|
||||
message_first.increase_unread(user1)
|
||||
|
|
@ -71,7 +66,7 @@ describe Conversation, :type => :model do
|
|||
|
||||
context 'transport' do
|
||||
let(:conversation_message) { conversation.messages.first }
|
||||
let(:xml) { conversation.to_diaspora_xml }
|
||||
let(:xml) { conversation.to_diaspora_xml }
|
||||
|
||||
before do
|
||||
conversation
|
||||
|
|
@ -79,13 +74,13 @@ describe Conversation, :type => :model do
|
|||
|
||||
describe 'serialization' do
|
||||
it 'serializes the message' do
|
||||
expect(xml.gsub(/\s/, '')).to include(conversation_message.to_xml.to_s.gsub(/\s/, ''))
|
||||
expect(xml.gsub(/\s/, "")).to include(conversation_message.to_xml.to_s.gsub(/\s/, ""))
|
||||
end
|
||||
|
||||
it 'serializes the participants' do
|
||||
create_hash[:participant_ids].each{ |id|
|
||||
create_hash[:participant_ids].each do |id|
|
||||
expect(xml).to include(Person.find(id).diaspora_handle)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
it 'serializes the created_at time' do
|
||||
|
|
@ -95,7 +90,7 @@ describe Conversation, :type => :model do
|
|||
|
||||
describe '#subscribers' do
|
||||
it 'returns the recipients for the post owner' do
|
||||
expect(conversation.subscribers(user1)).to eq(user1.contacts.map{|c| c.person})
|
||||
expect(conversation.subscribers(user1)).to eq(user1.contacts.map(&:person))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -106,17 +101,17 @@ describe Conversation, :type => :model do
|
|||
end
|
||||
|
||||
it 'creates a message' do
|
||||
expect{
|
||||
expect {
|
||||
Diaspora::Parser.from_xml(xml).receive(user1, user2.person)
|
||||
}.to change(Message, :count).by(1)
|
||||
end
|
||||
it 'creates a conversation' do
|
||||
expect{
|
||||
expect {
|
||||
Diaspora::Parser.from_xml(xml).receive(user1, user2.person)
|
||||
}.to change(Conversation, :count).by(1)
|
||||
end
|
||||
it 'creates appropriate visibilities' do
|
||||
expect{
|
||||
expect {
|
||||
Diaspora::Parser.from_xml(xml).receive(user1, user2.person)
|
||||
}.to change(ConversationVisibility, :count).by(participant_ids.size)
|
||||
end
|
||||
|
|
@ -132,13 +127,9 @@ describe Conversation, :type => :model do
|
|||
|
||||
describe "#invalid parameters" do
|
||||
context "local author" do
|
||||
let(:invalid_hash) do
|
||||
{
|
||||
author: peter.person,
|
||||
participant_ids: [peter.person.id, user1.person.id],
|
||||
subject: "cool stuff", messages_attributes: [{author: peter.person, text: "hey"}]
|
||||
}
|
||||
end
|
||||
let(:invalid_hash) {{author: peter.person, participant_ids: [peter.person.id, user1.person.id],
|
||||
subject: "cool stuff", messages_attributes: [{author: peter.person, text: "hey"}]}}
|
||||
|
||||
it "is invalid with invalid recipient" do
|
||||
invalid_conversation = Conversation.create(invalid_hash)
|
||||
expect(invalid_conversation).to be_invalid
|
||||
|
|
@ -146,16 +137,12 @@ describe Conversation, :type => :model do
|
|||
end
|
||||
|
||||
context "remote author" do
|
||||
let(:remote_person) { remote_raphael }
|
||||
let(:local_user) { alice }
|
||||
let(:participant_ids) { [remote_person.id, local_user.person.id] }
|
||||
let(:invalid_hash_remote) do
|
||||
{
|
||||
author: remote_person,
|
||||
participant_ids: participant_ids,
|
||||
subject: "cool stuff", messages_attributes: [{author: remote_person, text: "hey"}]
|
||||
}
|
||||
end
|
||||
let(:remote_person) { remote_raphael }
|
||||
let(:local_user) { alice }
|
||||
let(:participant_ids) { [remote_person.id, local_user.person.id] }
|
||||
let(:invalid_hash_remote) {{author: remote_person, participant_ids: participant_ids,
|
||||
subject: "cool stuff", messages_attributes: [{author: remote_person, text: "hey"}]}}
|
||||
|
||||
it "is invalid with invalid recipient" do
|
||||
invalid_conversation_remote = Conversation.create(invalid_hash_remote)
|
||||
expect(invalid_conversation_remote).to be_invalid
|
||||
|
|
|
|||
|
|
@ -5,17 +5,11 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ConversationVisibility, type: :model do
|
||||
let(:user1) { alice }
|
||||
let(:user1) { alice }
|
||||
let(:participant_ids) { [user1.contacts.first.person.id, user1.person.id] }
|
||||
let(:create_hash) do
|
||||
{
|
||||
author: user1.person,
|
||||
participant_ids: participant_ids,
|
||||
subject: 'cool stuff',
|
||||
messages_attributes: [{ author: user1.person, text: 'hey' }]
|
||||
}
|
||||
end
|
||||
let(:conversation) { Conversation.create(create_hash) }
|
||||
let(:create_hash) {{author: user1.person, participant_ids: participant_ids, subject: "cool stuff",
|
||||
messages_attributes: [{author: user1.person, text: "hey"}]}}
|
||||
let(:conversation) { Conversation.create(create_hash) }
|
||||
|
||||
it 'destroy conversation when no participant' do
|
||||
conversation.conversation_visibilities.each(&:destroy)
|
||||
|
|
|
|||
Loading…
Reference in a new issue