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

refactor hash indentation and add double quotes

this is the suggested styling according to hound/pronto/rubocop
(#6192)
parent c5a2334f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -6,6 +6,7 @@
* Add link to pod statistics in right navigation [#6117](https://github.com/diaspora/diaspora/pull/6117)
* Refactor person related URL generation [#6168](https://github.com/diaspora/diaspora/pull/6168)
* Move webfinger and HCard generation out of the core and embed the `diaspora_federation-rails` gem [#6151](https://github.com/diaspora/diaspora/pull/6151/)
* Refactor rspec tests to to use `let` instead of before blocks [#6199](https://github.com/diaspora/diaspora/pull/6199)
## Bug fixes
* Precompile facebox images [#6105](https://github.com/diaspora/diaspora/pull/6105)
......
......@@ -2,59 +2,59 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
require "spec_helper"
describe AccountDeletion, :type => :model do
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
it "assigns the diaspora_handle from the person object" do
expect(account_deletion_new.diaspora_handle).to eq(alice.person.diaspora_handle)
end
it 'fires a job after creation'do
it "fires a job after creation"do
expect(Workers::DeleteAccount).to receive(:perform_async).with(anything)
account_deletion_create
end
describe "#perform!" do
it 'creates a deleter' do
it "creates a deleter" do
expect(AccountDeleter).to receive(:new).with(alice.person.diaspora_handle).and_return(double(perform!: true))
account_deletion_new.perform!
end
it 'dispatches the account deletion if the user exists' do
it "dispatches the account deletion if the user exists" do
expect(account_deletion_new).to receive(:dispatch)
account_deletion_new.perform!
end
it 'does not dispatch an account deletion for non-local people' do
it "does not dispatch an account deletion for non-local people" do
deletion = AccountDeletion.new(person: remote_raphael)
expect(deletion).not_to receive(:dispatch)
deletion.perform!
end
it 'marks an AccountDeletion as completed when successful' do
it "marks an AccountDeletion as completed when successful" do
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
describe "#dispatch" do
it "creates a public postzord" do
expect(Postzord::Dispatcher::Public).to receive(:new).and_return(double.as_null_object)
account_deletion_new.dispatch
end
end
describe "#subscribers" do
it 'includes all remote contacts' do
it "includes all remote contacts" do
alice.share_with(remote_raphael, alice.aspects.first)
expect(account_deletion_new.subscribers(alice)).to eq([remote_raphael])
end
it 'includes remote resharers' do
it "includes remote resharers" do
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)
......@@ -63,14 +63,14 @@ describe AccountDeletion, :type => :model do
end
end
describe 'serialization' do
describe "serialization" do
let(:xml) { account_deletion_new.to_xml.to_s }
it 'should have a diaspora_handle' do
it "should have a diaspora_handle" do
expect(xml.include?(alice.person.diaspora_handle)).to eq(true)
end
it 'marshals the xml' do
it "marshals the xml" do
expect(AccountDeletion.from_xml(xml)).to be_valid
end
end
......
require 'spec_helper'
require "spec_helper"
describe ActsAsTaggableOn::Tag, :type => :model do
subject(:tag) { ActsAsTaggableOn::Tag }
describe '.autocomplete' do
describe ".autocomplete" do
let!(:tag_cats) { tag.create(name: "cats") }
it 'downcases the tag name' do
it "downcases the tag name" do
expect(tag.autocomplete("CATS")).to eq([tag_cats])
end
it 'does an end where on tags' do
it "does an end where on tags" do
expect(tag.autocomplete("CAT")).to eq([tag_cats])
end
end
......@@ -37,7 +37,7 @@ describe ActsAsTaggableOn::Tag, :type => :model do
end
end
it 'allows for love' do
it "allows for love" do
expect(tag.normalize("<3")).to eq("<3")
expect(tag.normalize("#<3")).to eq("<3")
end
......
......@@ -2,10 +2,10 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#
require 'spec_helper'
require "spec_helper"
describe AspectMembership, :type => :model do
describe '#before_destroy' do
describe "#before_destroy" do
let(:aspect) { alice.aspects.create(name: "two") }
let(:contact) { alice.contact_for(bob.person) }
let(:aspect_membership) { alice.aspects.where(name: "generic").first.aspect_memberships.first }
......@@ -14,13 +14,13 @@ describe AspectMembership, :type => :model do
allow(aspect_membership).to receive(:user).and_return(alice)
end
it 'calls disconnect if its the last aspect for the contact' do
it "calls disconnect if its the last aspect for the contact" do
expect(alice).to receive(:disconnect).with(contact)
aspect_membership.destroy
end
it 'does not call disconnect if its not the last aspect for the contact' do
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)
......
......@@ -2,26 +2,26 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
require "spec_helper"
describe Aspect, :type => :model do
describe 'creation' do
describe "creation" do
let(:name) { alice.aspects.first.name }
it 'does not allow duplicate names' do
it "does not allow duplicate names" do
expect { alice.aspects.create(name: name) }.not_to change(Aspect, :count)
end
it 'validates case insensitiveness on names' do
it "validates case insensitiveness on names" do
expect { alice.aspects.create(name: name.titleize) }.not_to change(Aspect, :count)
end
it 'has a 20 character limit on names' do
it "has a 20 character limit on names" do
aspect = Aspect.new(name: "this name is really too too too too too long")
expect(aspect.valid?).to eq(false)
end
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")
Contact.create(user: alice, person: eve.person, aspects: [aspect])
......@@ -30,7 +30,7 @@ describe Aspect, :type => :model do
expect(aspect.contacts.size).to eq(1)
end
it 'has a contacts_visible? method' do
it "has a contacts_visible? method" do
expect(alice.aspects.first.contacts_visible?).to be true
end
......@@ -42,8 +42,8 @@ describe Aspect, :type => :model do
end
end
describe 'validation' do
it 'has no uniqueness of name between users' do
describe "validation" do
it "has no uniqueness of name between users" do
aspect = alice.aspects.create(name: "New Aspect")
aspect2 = eve.aspects.create(name: aspect.name)
expect(aspect2).to be_valid
......
require 'spec_helper'
require "spec_helper"
describe Block, :type => :model do
describe 'validations' do
it 'doesnt allow you to block yourself' do
describe "validations" do
it "doesnt allow you to block yourself" do
block = alice.blocks.create(person: alice.person)
expect(block.errors[:person_id].size).to eq(1)
end
......
......@@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
require "spec_helper"
require Rails.root.join("spec", "shared_behaviors", "relayable")
describe Comment, :type => :model do
......@@ -20,7 +20,7 @@ describe Comment, :type => :model do
expect(comment_alice.notification_type(eve, alice.person)).to eq(Notifications::AlsoCommented)
end
it 'returns false if the comment is not on a post you own and no one "also_commented"' do
it "returns false if the comment is not on a post you own and no one 'also_commented'" do
expect(comment_alice.notification_type(eve, alice.person)).to be false
end
......@@ -31,7 +31,7 @@ describe Comment, :type => :model do
comment_alice
end
it 'does not return also commented if the user commented' do
it "does not return also commented if the user commented" do
expect(comment_eve.notification_type(eve, alice.person)).to eq(false)
end
......@@ -41,7 +41,7 @@ describe Comment, :type => :model do
end
end
describe 'User#comment' do
describe "User#comment" do
it "should be able to comment on one's own status" do
bob.comment!(status_bob, "sup dog")
expect(status_bob.reload.comments.first.text).to eq("sup dog")
......@@ -52,15 +52,15 @@ describe Comment, :type => :model do
expect(status_bob.reload.comments.first.text).to eq("why so formal?")
end
it 'does not multi-post a comment' do
it "does not multi-post a comment" do
expect {
comment_alice
}.to change { Comment.count }.by(1)
end
end
describe 'counter cache' do
it 'increments the counter cache on its post' do
describe "counter cache" do
it "increments the counter cache on its post" do
expect {
comment_alice
}.to change{
......@@ -69,7 +69,7 @@ describe Comment, :type => :model do
end
end
describe 'xml' do
describe "xml" do
let(:commenter) { create(:user) }
let(:commenter_aspect) { commenter.aspects.create(name: "bruisers") }
let(:post) { alice.post :status_message, text: "hello", to: alices_aspect.id }
......@@ -80,26 +80,26 @@ describe Comment, :type => :model do
connect_users(alice, alices_aspect, commenter, commenter_aspect)
end
it 'serializes the sender handle' do
it "serializes the sender handle" do
expect(xml.include?(commenter.diaspora_handle)).to be true
end
it 'serializes the post_guid' do
it "serializes the post_guid" do
expect(xml).to include(post.guid)
end
describe 'marshalling' do
describe "marshalling" do
let(:marshalled_comment) { Comment.from_xml(xml) }
it 'marshals the author' do
it "marshals the author" do
expect(marshalled_comment.author).to eq(commenter.person)
end
it 'marshals the post' do
it "marshals the post" do
expect(marshalled_comment.post).to eq(post)
end
it 'tries to fetch a missing parent' do
it "tries to fetch a missing parent" do
guid = post.guid
marshalled_comment
post.destroy
......@@ -109,7 +109,7 @@ describe Comment, :type => :model do
end
end
describe 'it is relayable' do
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!") }
......@@ -119,7 +119,7 @@ describe Comment, :type => :model do
before do
# shared_behaviors/relayable.rb is still using instance variables, so we need to define them here.
# Suggestion: refactor all specs using shared_behaviors/relayable.rb to use 'let'
# Suggestion: refactor all specs using shared_behaviors/relayable.rb to use "let"
@object_by_parent_author = object_by_parent_author
@object_by_recipient = object_by_recipient
@dup_object_by_parent_author = dup_object_by_parent_author
......@@ -127,17 +127,17 @@ describe Comment, :type => :model do
end
let(:build_object) { alice.build_comment(post: status_bob, text: "why so formal?") }
it_should_behave_like 'it is relayable'
it_should_behave_like "it is relayable"
end
describe 'tags' do
describe "tags" do
let(:object) { build(:comment) }
before do
# shared_behaviors/taggable.rb is still using instance variables, so we need to define them here.
# Suggestion: refactor all specs using shared_behaviors/taggable.rb to use 'let'
# Suggestion: refactor all specs using shared_behaviors/taggable.rb to use "let"
@object = object
end
it_should_behave_like 'it is taggable'
it_should_behave_like "it is taggable"
end
end
......@@ -2,31 +2,31 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
require "spec_helper"
describe Contact, :type => :model do
describe 'aspect_memberships' do
it 'deletes dependent aspect memberships' do
describe "aspect_memberships" do
it "deletes dependent aspect memberships" do
expect {
alice.contact_for(bob.person).destroy
}.to change(AspectMembership, :count).by(-1)
end
end
context 'validations' do
context "validations" do
let(:contact) { Contact.new }
it 'requires a user' do
it "requires a user" do
contact.valid?
expect(contact.errors.full_messages).to include "User can't be blank"
end
it 'requires a person' do
it "requires a person" do
contact.valid?
expect(contact.errors.full_messages).to include "Person can't be blank"
end
it 'ensures user is not making a contact for himself' do
it "ensures user is not making a contact for himself" do
contact.person = alice.person
contact.user = alice
......@@ -34,7 +34,7 @@ describe Contact, :type => :model do
expect(contact.errors.full_messages).to include "Cannot create self-contact"
end
it 'validates uniqueness' do
it "validates uniqueness" do
person = FactoryGirl.create(:person)
contact2 = alice.contacts.create(person: person)
......@@ -54,9 +54,9 @@ describe Contact, :type => :model do
end
end
context 'scope' do
describe 'sharing' do
it 'returns contacts with sharing true' do
context "scope" do
describe "sharing" do
it "returns contacts with sharing true" do
expect {
alice.contacts.create!(sharing: true, person: FactoryGirl.create(:person))
alice.contacts.create!(sharing: false, person: FactoryGirl.create(:person))
......@@ -66,8 +66,8 @@ describe Contact, :type => :model do
end
end
describe 'receiving' do
it 'returns contacts with sharing true' do
describe "receiving" do
it "returns contacts with sharing true" do
expect {
alice.contacts.create!(receiving: true, person: FactoryGirl.build(:person))
alice.contacts.create!(receiving: false, person: FactoryGirl.build(:person))
......@@ -77,8 +77,8 @@ describe Contact, :type => :model do
end
end
describe 'only_sharing' do
it 'returns contacts with sharing true and receiving false' do
describe "only_sharing" do
it "returns contacts with sharing true and receiving false" do
expect {
alice.contacts.create!(receiving: true, sharing: true, person: FactoryGirl.build(:person))
alice.contacts.create!(receiving: false, sharing: true, person: FactoryGirl.build(:person))
......@@ -91,7 +91,7 @@ describe Contact, :type => :model do
end
describe "all_contacts_of_person" do
it 'returns all contacts where the person is the passed in person' do
it "returns all contacts where the person is the passed in person" do
person = FactoryGirl.create(:person)
contact1 = FactoryGirl.create(:contact, person: person)
contact2 = FactoryGirl.create(:contact)
......@@ -101,7 +101,7 @@ describe Contact, :type => :model do
end
end
describe '#contacts' do
describe "#contacts" do
before do
bob.aspects.create(name: "next")
bob.aspects(true)
......@@ -125,7 +125,7 @@ describe Contact, :type => :model do
#eve <-> bob <-> alice
end
context 'on a contact for a local user' do
context "on a contact for a local user" do
before do
alice.reload
alice.aspects.reload
......@@ -136,35 +136,35 @@ describe Contact, :type => :model do
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
it "returns nothing if contacts_visible is false in that aspect" do
@original_aspect.contacts_visible = false
@original_aspect.save
expect(@contact.contacts).to eq([])
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) }
contact_ids = @contact.contacts.map(&:id)
expect(contact_ids.uniq).to eq(contact_ids)
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 }
it 'returns an empty array' do
it "returns an empty array" do
expect(contact.contacts).to eq([])
end
end
end
context 'requesting' do
context "requesting" do
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
describe "#generate_request" do
it "makes a request" do
allow(contact).to receive(:user).and_return(user)
request = contact.generate_request
......@@ -173,8 +173,8 @@ describe Contact, :type => :model do
end
end
describe '#dispatch_request' do
it 'pushes to people' do
describe "#dispatch_request" do
it "pushes to people" do
allow(contact).to receive(:user).and_return(user)
m = double()
expect(m).to receive(:post)
......
......@@ -2,26 +2,32 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
require "spec_helper"
describe Conversation, :type => :model do
let(:user1) { alice }
let(:user2) { bob }
let(:participant_ids) { [user1.contacts.first.person.id, user1.person.id] }
let(:create_hash) {{author: user1.person, participant_ids: participant_ids,
subject: "cool stuff", messages_attributes: [{author: user1.person, text: "hey"}]}}
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
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)
end
describe '#last_author' do
it 'returns the last author to a conversation' do
describe "#last_author" do
it "returns the last author to a conversation" do
message_last
expect(conversation.reload.last_author.id).to eq(user2.person.id)
end
......@@ -35,36 +41,36 @@ describe Conversation, :type => :model do
end
end
describe '#first_unread_message' do
describe "#first_unread_message" do
before do
message_last.increase_unread(user1)
end
it 'returns the first unread message if there are unread messages in a conversation' do
it "returns the first unread message if there are unread messages in a conversation" do
conversation.first_unread_message(user1) == message_last
end
it 'returns nil if there are no unread messages in a conversation' do
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
expect(conversation.first_unread_message(user1)).to be_nil
end
end
describe '#set_read' do
describe "#set_read" do
before do
conversation
message_first.increase_unread(user1)
message_last.increase_unread(user1)
end
it 'sets the unread counter to 0' do
it "sets the unread counter to 0" do
expect(conversation.conversation_visibilities.where(person_id: user1.person.id).first.unread).to eq(2)
conversation.set_read(user1)
expect(conversation.conversation_visibilities.where(person_id: user1.person.id).first.unread).to eq(0)
end
end
context 'transport' do
context "transport" do
let(:conversation_message) { conversation.messages.first }
let(:xml) { conversation.to_diaspora_xml }
......@@ -72,53 +78,53 @@ describe Conversation, :type => :model do
conversation
end
describe 'serialization' do
it 'serializes the message' do
describe "serialization" do
it "serializes the message" do
expect(xml.gsub(/\s/, "")).to include(conversation_message.to_xml.to_s.gsub(/\s/, ""))
end
it 'serializes the participants' do
it "serializes the participants" do
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
it "serializes the created_at time" do
expect(xml).to include(conversation_message.created_at.to_s)
end
end
describe '#subscribers' do
it 'returns the recipients for the post owner' do
describe "#subscribers" do
it "returns the recipients for the post owner" do
expect(conversation.subscribers(user1)).to eq(user1.contacts.map(&:person))
end
end
describe '#receive' do
describe "#receive" do
before do
Message.destroy_all
Conversation.destroy_all
end
it 'creates a message' do
it "creates a message" do
expect {
Diaspora::Parser.from_xml(xml).receive(user1, user2.person)
}.to change(Message, :count).by(1)
end
it 'creates a conversation' do
it "creates a conversation" do
expect {
Diaspora::Parser.from_xml(xml).receive(user1, user2.person)
}.to change(Conversation, :count).by(1)
end
it 'creates appropriate visibilities' do
it "creates appropriate visibilities" do
expect {
Diaspora::Parser.from_xml(xml).receive(user1, user2.person)
}.to change(ConversationVisibility, :count).by(participant_ids.size)
end
it 'does not save before receive' do
it "does not save before receive" do
expect(Diaspora::Parser.from_xml(xml).persisted?).to be false
end
it 'notifies for the message' do
it "notifies for the message" do
expect(Notification).to receive(:notify).once
Diaspora::Parser.from_xml(xml).receive(user1, user2.person)
end
......@@ -127,8 +133,10 @@ describe Conversation, :type => :model do
describe "#invalid parameters" do
context "local author" do
let(:invalid_hash) {{author: peter.person, participant_ids: [peter.person.id, user1.person.id],
subject: "cool stuff", messages_attributes: [{author: peter.person, text: "hey"}]}}
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)
......@@ -140,8 +148,10 @@ describe Conversation, :type => :model do
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"}]}}
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)
......
......@@ -2,16 +2,18 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
require "spec_helper"
describe ConversationVisibility, type: :model do
let(:user1) { alice }
let(:participant_ids) { [user1.contacts.first.person.id, user1.person.id] }
let(:create_hash) {{author: user1.person, participant_ids: participant_ids, subject: "cool stuff",
messages_attributes: [{author: user1.person, text: "hey"}]}}
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
it "destroy conversation when no participant" do
conversation.conversation_visibilities.each(&:destroy)
expect(Conversation).not_to exist(conversation.id)
......
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