Commit 201a3ec1 authored by Dennis Schubert's avatar Dennis Schubert

Merge branch 'stable' into develop

parents 13845a96 d0b290ea
......@@ -58,6 +58,7 @@ With the port to Bootstrap 3, app/views/terms/default.haml has a new structure.
* Update to Rails 4.2.3 [#6140](https://github.com/diaspora/diaspora/pull/6140)
* 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,91 +2,76 @@
# 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
it 'assigns the diaspora_handle from the person object' do
a = AccountDeletion.new(:person => alice.person)
expect(a.diaspora_handle).to eq(alice.person.diaspora_handle)
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(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)
AccountDeletion.create(:person => alice.person)
account_deletion_create
end
describe "#perform!" do
before do
@ad = AccountDeletion.new(:person => alice.person)
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 'creates a deleter' do
expect(AccountDeleter).to receive(:new).with(alice.person.diaspora_handle).and_return(double(:perform! => true))
@ad.perform!
end
it 'dispatches the account deletion if the user exists' do
expect(@ad).to receive(:dispatch)
@ad.perform!
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
deletion = AccountDeletion.new(:person => remote_raphael)
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
ad = AccountDeletion.create(:person => alice.person)
ad.perform!
expect(ad.reload.completed_at).not_to be_nil
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 "sends the account deletion xml" do
@ad = AccountDeletion.new(:person => alice.person)
@ad.send(:dispatch)
end
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)
@ad = AccountDeletion.new(:person => alice.person)
@ad.send(:dispatch)
account_deletion_new.dispatch
end
end
describe "#subscribers" do
it 'includes all remote contacts' do
@ad = AccountDeletion.new(:person => alice.person)
it "includes all remote contacts" do
alice.share_with(remote_raphael, alice.aspects.first)
expect(@ad.subscribers(alice)).to eq([remote_raphael])
expect(account_deletion_new.subscribers(alice)).to eq([remote_raphael])
end
it 'includes remote resharers' do
@ad = AccountDeletion.new(:person => alice.person)
sm = FactoryGirl.create( :status_message, :public => true, :author => alice.person)
r1 = FactoryGirl.create( :reshare, :author => remote_raphael, :root => sm)
r2 = FactoryGirl.create( :reshare, :author => local_luke.person, :root => sm)
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)
expect(@ad.subscribers(alice)).to eq([remote_raphael])
expect(account_deletion_new.subscribers(alice)).to eq([remote_raphael])
end
end
describe 'serialization' do
before do
account_deletion = AccountDeletion.new(:person => alice.person)
@xml = account_deletion.to_xml.to_s
end
describe "serialization" do
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)
it "should have a diaspora_handle" do
expect(xml.include?(alice.person.diaspora_handle)).to eq(true)
end
it 'marshals the xml' do
expect(AccountDeletion.from_xml(@xml)).to be_valid
it "marshals the xml" do
expect(AccountDeletion.from_xml(xml)).to be_valid
end
end
end
require 'spec_helper'
require "spec_helper"
describe ActsAsTaggableOn::Tag, :type => :model do
describe '.autocomplete' do
before do
@tag = ActsAsTaggableOn::Tag.create(:name => "cats")
end
it 'downcases the tag name' do
expect(ActsAsTaggableOn::Tag.autocomplete("CATS")).to eq([@tag])
subject(:tag) { ActsAsTaggableOn::Tag }
describe ".autocomplete" do
let!(:tag_cats) { tag.create(name: "cats") }
it "downcases the tag name" do
expect(tag.autocomplete("CATS")).to eq([tag_cats])
end
it 'does an end where on tags' do
expect(ActsAsTaggableOn::Tag.autocomplete("CAT")).to eq([@tag])
it "does an end where on tags" do
expect(tag.autocomplete("CAT")).to eq([tag_cats])
end
end
describe ".normalize" do
it "removes leading hash symbols" do
expect(ActsAsTaggableOn::Tag.normalize("#mytag")).to eq("mytag")
expect(tag.normalize("#mytag")).to eq("mytag")
end
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(ActsAsTaggableOn::Tag.normalize(invalid)).to eq(normalized)
expect(tag.normalize(invalid)).to eq(normalized)
end
end
it 'allows for love' do
expect(ActsAsTaggableOn::Tag.normalize("<3")).to eq("<3")
expect(ActsAsTaggableOn::Tag.normalize("#<3")).to eq("<3")
it "allows for love" do
expect(tag.normalize("<3")).to eq("<3")
expect(tag.normalize("#<3")).to eq("<3")
end
end
end
......@@ -2,31 +2,29 @@
# 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
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 }
describe '#before_destroy' do
before do
@aspect = alice.aspects.create(:name => "two")
@contact = alice.contact_for(bob.person)
@am = alice.aspects.where(:name => "generic").first.aspect_memberships.first
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)
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
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
alice.add_contact_to_aspect(contact, aspect)
aspect_membership.destroy
end
end
end
......@@ -2,41 +2,35 @@
# 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
before do
@name = alice.aspects.first.name
end
describe "creation" do
let(:name) { alice.aspects.first.name }
it 'does not allow duplicate names' do
expect {
invalid_aspect = alice.aspects.create(:name => @name)
}.not_to change(Aspect, :count)
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
expect {
invalid_aspect = alice.aspects.create(:name => @name.titleize)
}.not_to change(Aspect, :count)
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
aspect = Aspect.new(:name => "this name is really too too too too too long")
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
aspect = alice.aspects.create(:name => 'losers')
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])
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 => eve.person.id)).not_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.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
......@@ -48,10 +42,10 @@ describe Aspect, :type => :model do
end
end
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)
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
end
end
......
require 'spec_helper'
require "spec_helper"
describe Block, :type => :model do
describe 'validations' do
it 'doesnt allow you to block yourself' do
block = alice.blocks.create(:person => alice.person)
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
end
end
\ No newline at end of file
end
......@@ -2,161 +2,162 @@
# 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
before do
@alices_aspect = alice.aspects.first
@status = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id)
end
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 "#destroy" do
before do
@comment = alice.comment!(@status, "why so formal?")
end
it "should delete a participation" do
expect { @comment.destroy }.to change { Participation.count }.by(-1)
comment_alice
expect { comment_alice.destroy }.to change { Participation.count }.by(-1)
end
it "should decrease count participation" do
alice.comment!(@status, "Are you there?")
@comment.destroy
participations = Participation.where(target_id: @comment.commentable_id, author_id: @comment.author_id)
alice.comment!(status_bob, "Are you there?")
comment_alice.destroy
participations = Participation.where(target_id: comment_alice.commentable_id, author_id: comment_alice.author_id)
expect(participations.first.count).to eq(1)
end
end
describe 'comment#notification_type' do
let (:comment) { alice.comment!(@status, "why so formal?") }
describe "comment#notification_type" do
it "returns 'comment_on_post' if the comment is on a post you own" do
expect(comment.notification_type(bob, alice.person)).to eq(Notifications::CommentOnPost)
expect(comment_alice.notification_type(bob, alice.person)).to eq(Notifications::CommentOnPost)
end
it "returns 'also_commented' if the comment is on a post you participate to" do
eve.participate! @status
expect(comment.notification_type(eve, alice.person)).to eq(Notifications::AlsoCommented)
eve.participate! status_bob
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
comment = alice.comment!(@status, "I simply felt like issuing a greeting. Do step off.")
expect(comment.notification_type(eve, alice.person)).to be false
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
context "also commented" do
let(:comment_eve) { eve.comment!(status_bob, "I also commented on the first user's post") }
before do
alice.comment!(@status, "a-commenta commenta")
@comment = eve.comment!(@status, "I also commented on the first user's post")
comment_alice
end
it 'does not return also commented if the user commented' do
expect(@comment.notification_type(eve, alice.person)).to eq(false)
it "does not return also commented if the user commented" do
expect(comment_eve.notification_type(eve, alice.person)).to eq(false)
end
it "returns 'also_commented' if another person commented on a post you commented on" do
expect(@comment.notification_type(alice, alice.person)).to eq(Notifications::AlsoCommented)
expect(comment_eve.notification_type(alice, alice.person)).to eq(Notifications::AlsoCommented)
end
end
end
describe 'User#comment' do
describe "User#comment" do
it "should be able to comment on one's own status" do
alice.comment!(@status, "Yeah, it was great")
expect(@status.reload.comments.first.text).to eq("Yeah, it was great")
bob.comment!(status_bob, "sup dog")
expect(status_bob.reload.comments.first.text).to eq("sup dog")
end
it "should be able to comment on a contact's status" do
bob.comment!(@status, "sup dog")
expect(@status.reload.comments.first.text).to eq("sup dog")
comment_alice
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 {
alice.comment!(@status, 'hello')
comment_alice
}.to change { Comment.count }.by(1)
end
it "should create a participation" do
comment = bob.comment!(@status, "sup dog")
participations = Participation.where(target_id: comment.commentable_id, author_id: comment.author_id)
comment_alice
participations = Participation.where(target_id: comment_alice.commentable_id, author_id: comment_alice.author_id)
expect(participations.count).to eq(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 {
alice.comment!(@status, "oh yeah")
comment_alice
}.to change{
@status.reload.comments_count
status_bob.reload.comments_count
}.by(1)
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 }
let(:comment) { commenter.comment!(post, "Fool!") }
let(:xml) { comment.to_xml.to_s }
before do
@commenter = FactoryGirl.create(:user)
@commenter_aspect = @commenter.aspects.create(:name => "bruisers")
connect_users(alice, @alices_aspect, @commenter, @commenter_aspect)
@post = alice.post :status_message, :text => "hello", :to => @alices_aspect.id
@comment = @commenter.comment!(@post, "Fool!")
@xml = @comment.to_xml.to_s
connect_users(alice, alices_aspect, commenter, commenter_aspect)
end
it 'serializes the sender handle' do
expect(@xml.include?(@commenter.diaspora_handle)).to be true
it "serializes the sender handle" do
expect(xml.include?(commenter.diaspora_handle)).to be true
end
it 'serializes the post_guid' do
expect(@xml).to include(@post.guid)
it "serializes the post_guid" do
expect(xml).to include(post.guid)
end
describe 'marshalling' do
before do
@marshalled_comment = Comment.from_xml(@xml)
end
describe "marshalling" do
let(:marshalled_comment) { Comment.from_xml(xml) }
it 'marshals the author' do
expect(@marshalled_comment.author).to eq(@commenter.person)
it "marshals the author" do
expect(marshalled_comment.author).to eq(commenter.person)
end
it 'marshals the post' do
expect(@marshalled_comment.post).to eq(@post)
it "marshals the post" do
expect(marshalled_comment.post).to eq(post)
end
it 'tries to fetch a missing parent' do
guid = @post.guid
@post.destroy
it "tries to fetch a missing parent" do
guid = post.guid
marshalled_comment
post.destroy
expect_any_instance_of(Comment).to receive(:fetch_parent).with(guid).and_return(nil)
Comment.from_xml(@xml)
Comment.from_xml(xml)
end
end
end
describe 'it is relayable' do
before do
@local_luke, @local_leia, @remote_raphael = set_up_friends
@remote_parent = FactoryGirl.build(:status_message, :author => @remote_raphael)
@local_parent = @local_luke.post :status_message, :text => "hi", :to => @local_luke.aspects.first
@object_by_parent_author = @local_luke.comment!(@local_parent, "yo")
@object_by_recipient = @local_leia.build_comment(:text => "yo", :post => @local_parent)
@dup_object_by_parent_author = @object_by_parent_author.dup
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(:dup_object_by_parent_author) { object_by_parent_author.dup }
let(:object_on_remote_parent) { local_luke.comment!(remote_parent, "Yeah, it was great") }
@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.
# 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
@object_on_remote_parent = object_on_remote_parent
end
let(:build_object) { alice.build_comment(:post => @status, :text => "why so formal?") }
it_should_behave_like 'it is relayable'
let(:build_object) { alice.build_comment(post: status_bob, text: "why so formal?") }
it_should_behave_like "it is relayable"
end
describe 'tags' do
describe "tags" do
let(:object) { build(:comment) }
before do
@object = FactoryGirl.build(:comment)
# 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"
@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
expect{
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
let(:contact){Contact.new}
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