Skip to content
Extraits de code Groupes Projets
Valider 8823bb01 rédigé par realtin's avatar realtin Validation de Dennis Schubert
Parcourir les fichiers

refactor test to use let and better indentation

(#6192)
parent 56e0d3d5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -8,7 +8,6 @@ describe ActsAsTaggableOn::Tag, :type => :model do ...@@ -8,7 +8,6 @@ describe ActsAsTaggableOn::Tag, :type => :model do
it 'downcases the tag name' do it 'downcases the tag name' do
expect(tag.autocomplete("CATS")).to eq([tag_cats]) expect(tag.autocomplete("CATS")).to eq([tag_cats])
end end
it 'does an end where on tags' do it 'does an end where on tags' do
...@@ -23,16 +22,16 @@ describe ActsAsTaggableOn::Tag, :type => :model do ...@@ -23,16 +22,16 @@ describe ActsAsTaggableOn::Tag, :type => :model do
it "removes punctuation and whitespace" do it "removes punctuation and whitespace" do
{ {
'node.js' => 'nodejs', 'node.js' => 'nodejs',
'.dotatstart' => 'dotatstart', '.dotatstart' => 'dotatstart',
'you,inside' => 'youinside', 'you,inside' => 'youinside',
'iam(parenthetical)' => 'iamparenthetical', 'iam(parenthetical)' => 'iamparenthetical',
'imeanit?maybe' => 'imeanitmaybe', 'imeanit?maybe' => 'imeanitmaybe',
'imeanit!' => 'imeanit', 'imeanit!' => 'imeanit',
'how about spaces' => 'howaboutspaces', 'how about spaces' => 'howaboutspaces',
"other\twhitespace\n" => 'otherwhitespace', "other\twhitespace\n" => 'otherwhitespace',
'hash#inside' => 'hashinside', 'hash#inside' => 'hashinside',
'f!u@n#k$y%-<c>^h&a*r(a)c{t}e[r]s' => 'funky-characters' 'f!u@n#k$y%-<c>^h&a*r(a)c{t}e[r]s' => 'funky-characters'
}.each do |invalid, normalized| }.each do |invalid, normalized|
expect(tag.normalize(invalid)).to eq(normalized) expect(tag.normalize(invalid)).to eq(normalized)
end end
......
...@@ -23,8 +23,8 @@ describe Aspect, :type => :model do ...@@ -23,8 +23,8 @@ describe Aspect, :type => :model do
it 'is able to have other users as contacts' do 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]) Contact.create(user: alice, person: eve.person, aspects: [aspect])
expect(aspect.contacts.where(person_id: alice.person.id)).to be_empty expect(aspect.contacts.where(person_id: alice.person.id)).to be_empty
expect(aspect.contacts.where(person_id: eve.person.id)).not_to be_empty expect(aspect.contacts.where(person_id: eve.person.id)).not_to be_empty
expect(aspect.contacts.size).to eq(1) expect(aspect.contacts.size).to eq(1)
......
...@@ -47,7 +47,6 @@ describe Contact, :type => :model do ...@@ -47,7 +47,6 @@ describe Contact, :type => :model do
it "validates that the person's account is not closed" do it "validates that the person's account is not closed" do
person = FactoryGirl.create(:person, :closed_account => true) person = FactoryGirl.create(:person, :closed_account => true)
contact = alice.contacts.new(person: person) contact = alice.contacts.new(person: person)
expect(contact).not_to be_valid expect(contact).not_to be_valid
...@@ -104,26 +103,23 @@ describe Contact, :type => :model do ...@@ -104,26 +103,23 @@ describe Contact, :type => :model do
describe '#contacts' do describe '#contacts' do
before do before do
@alice = alice bob.aspects.create(name: 'next')
@bob = bob bob.aspects(true)
@eve = eve
@bob.aspects.create(name: 'next')
@bob.aspects(true)
@original_aspect = @bob.aspects.where(name: "generic").first @original_aspect = bob.aspects.where(name: "generic").first
@new_aspect = @bob.aspects.where(name: "next").first @new_aspect = bob.aspects.where(name: "next").first
@people1 = [] @people1 = []
@people2 = [] @people2 = []
1.upto(5) do 1.upto(5) do
person = FactoryGirl.build(:person) person = FactoryGirl.build(:person)
@bob.contacts.create(person: person, aspects: [@original_aspect]) bob.contacts.create(person: person, aspects: [@original_aspect])
@people1 << person @people1 << person
end end
1.upto(5) do 1.upto(5) do
person = FactoryGirl.build(:person) person = FactoryGirl.build(:person)
@bob.contacts.create(person: person, aspects: [@new_aspect]) bob.contacts.create(person: person, aspects: [@new_aspect])
@people2 << person @people2 << person
end end
#eve <-> bob <-> alice #eve <-> bob <-> alice
...@@ -131,13 +127,13 @@ describe Contact, :type => :model do ...@@ -131,13 +127,13 @@ describe Contact, :type => :model do
context 'on a contact for a local user' do context 'on a contact for a local user' do
before do before do
@alice.reload alice.reload
@alice.aspects.reload alice.aspects.reload
@contact = @alice.contact_for(@bob.person) @contact = alice.contact_for(bob.person)
end end
it "returns the target local user's contacts that are in the same aspect" do 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{|p| p.id}).to match_array([eve.person].concat(@people1).map{|p| p.id})
end end
it 'returns nothing if contacts_visible is false in that aspect' do it 'returns nothing if contacts_visible is false in that aspect' do
...@@ -147,14 +143,14 @@ describe Contact, :type => :model do ...@@ -147,14 +143,14 @@ describe Contact, :type => :model do
end end
it 'returns no duplicate contacts' do it 'returns no duplicate contacts' do
[@alice, @eve].each {|c| @bob.add_contact_to_aspect(@bob.contact_for(c.person), @bob.aspects.last)} [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} contact_ids = @contact.contacts.map{|p| p.id}
expect(contact_ids.uniq).to eq(contact_ids) expect(contact_ids.uniq).to eq(contact_ids)
end end
end end
context 'on a contact for a remote user' do context 'on a contact for a remote user' do
let(:contact) { @bob.contact_for @people1.first } let(:contact) { bob.contact_for @people1.first }
it 'returns an empty array' do it 'returns an empty array' do
expect(contact.contacts).to eq([]) expect(contact.contacts).to eq([])
...@@ -164,8 +160,8 @@ describe Contact, :type => :model do ...@@ -164,8 +160,8 @@ describe Contact, :type => :model do
context 'requesting' do context 'requesting' do
let(:contact) { Contact.new } let(:contact) { Contact.new }
let(:user) { build(:user) } let(:user) { build(:user) }
let(:person) { build(:person) } let(:person) { build(:person) }
before do before do
contact.user = user contact.user = user
...@@ -203,7 +199,7 @@ describe Contact, :type => :model do ...@@ -203,7 +199,7 @@ describe Contact, :type => :model do
it "adds to errors if potential contact is blocked by user" do it "adds to errors if potential contact is blocked by user" do
person = eve.person person = eve.person
block = alice.blocks.create(person: person) alice.blocks.create(person: person)
bad_contact = alice.contacts.create(person: person) bad_contact = alice.contacts.create(person: person)
expect(bad_contact.send(:not_blocked_user)).to be false expect(bad_contact.send(:not_blocked_user)).to be false
......
...@@ -5,14 +5,20 @@ ...@@ -5,14 +5,20 @@
require 'spec_helper' require 'spec_helper'
describe Conversation, :type => :model do describe Conversation, :type => :model do
let(:user1) { alice } let(:user1) { alice }
let(:user2) { bob } let(:user2) { bob }
let(:participant_ids) { [user1.contacts.first.person.id, user1.person.id] } let(:participant_ids) { [user1.contacts.first.person.id, user1.person.id] }
let(:create_hash) { {author: user1.person, participant_ids: participant_ids, subject: "cool stuff", let(:create_hash) do
messages_attributes: [ {author: user1.person, text: "hey"} ]} } {
let(:conversation) { Conversation.create(create_hash) } author: user1.person,
let(:message_last) { Message.create(author: user2.person, created_at: Time.now + 100, text: "last", conversation_id: conversation.id) } participant_ids: participant_ids,
let(:message_first) { Message.create(author: user2.person, created_at: Time.now + 100, text: "first", conversation_id: conversation.id) } 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) }
it 'creates a message on create' do it 'creates a message on create' do
expect{ conversation }.to change(Message, :count).by(1) expect{ conversation }.to change(Message, :count).by(1)
...@@ -65,7 +71,7 @@ describe Conversation, :type => :model do ...@@ -65,7 +71,7 @@ describe Conversation, :type => :model do
context 'transport' do context 'transport' do
let(:conversation_message) { conversation.messages.first } let(:conversation_message) { conversation.messages.first }
let(:xml) { conversation.to_diaspora_xml } let(:xml) { conversation.to_diaspora_xml }
before do before do
conversation conversation
...@@ -77,7 +83,7 @@ describe Conversation, :type => :model do ...@@ -77,7 +83,7 @@ describe Conversation, :type => :model do
end end
it 'serializes the participants' do it 'serializes the participants' do
create_hash[:participant_ids].each{|id| create_hash[:participant_ids].each{ |id|
expect(xml).to include(Person.find(id).diaspora_handle) expect(xml).to include(Person.find(id).diaspora_handle)
} }
end end
...@@ -126,9 +132,13 @@ describe Conversation, :type => :model do ...@@ -126,9 +132,13 @@ describe Conversation, :type => :model do
describe "#invalid parameters" do describe "#invalid parameters" do
context "local author" do context "local author" do
let(:invalid_hash) { {author: peter.person, participant_ids: [peter.person.id, user1.person.id], let(:invalid_hash) do
subject: "cool stuff", messages_attributes: [{author: peter.person, text: "hey"}]} } {
author: peter.person,
participant_ids: [peter.person.id, user1.person.id],
subject: "cool stuff", messages_attributes: [{author: peter.person, text: "hey"}]
}
end
it "is invalid with invalid recipient" do it "is invalid with invalid recipient" do
invalid_conversation = Conversation.create(invalid_hash) invalid_conversation = Conversation.create(invalid_hash)
expect(invalid_conversation).to be_invalid expect(invalid_conversation).to be_invalid
...@@ -136,12 +146,16 @@ describe Conversation, :type => :model do ...@@ -136,12 +146,16 @@ describe Conversation, :type => :model do
end end
context "remote author" do context "remote author" do
let(:remote_person) { remote_raphael } let(:remote_person) { remote_raphael }
let(:local_user) { alice } let(:local_user) { alice }
let(:participant_ids) { [remote_person.id, local_user.person.id] } let(:participant_ids) { [remote_person.id, local_user.person.id] }
let(:invalid_hash_remote) { {author: remote_person, participant_ids: participant_ids, let(:invalid_hash_remote) do
subject: "cool stuff", messages_attributes: [{author: remote_person, text: "hey"}]} } {
author: remote_person,
participant_ids: participant_ids,
subject: "cool stuff", messages_attributes: [{author: remote_person, text: "hey"}]
}
end
it "is invalid with invalid recipient" do it "is invalid with invalid recipient" do
invalid_conversation_remote = Conversation.create(invalid_hash_remote) invalid_conversation_remote = Conversation.create(invalid_hash_remote)
expect(invalid_conversation_remote).to be_invalid expect(invalid_conversation_remote).to be_invalid
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
require 'spec_helper' require 'spec_helper'
describe ConversationVisibility, type: :model do describe ConversationVisibility, type: :model do
let(:user1) { alice } let(:user1) { alice }
let(:participant_ids) { [user1.contacts.first.person.id, user1.person.id] } let(:participant_ids) { [user1.contacts.first.person.id, user1.person.id] }
let(:create_hash) do let(:create_hash) do
{ {
...@@ -15,11 +15,11 @@ describe ConversationVisibility, type: :model do ...@@ -15,11 +15,11 @@ describe ConversationVisibility, type: :model do
messages_attributes: [{ author: user1.person, text: 'hey' }] messages_attributes: [{ author: user1.person, text: 'hey' }]
} }
end end
let(:conversation) { Conversation.create(create_hash) } let(:conversation) { Conversation.create(create_hash) }
it 'destroy conversation when no participant' do it 'destroy conversation when no participant' do
conversation.conversation_visibilities.each(&:destroy) conversation.conversation_visibilities.each(&:destroy)
expect(Conversation).not_to exist(conversation.id) expect(Conversation).not_to exist(conversation.id)
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