diff --git a/Changelog.md b/Changelog.md index 70b0a9bea..06deff067 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,7 @@ # Head ## Refactor +Move non-model federation stuff into lib/ [#4363](https://github.com/diaspora/diaspora/pull/4363) ## Bug fixes Highlight down arrow at the user menu on hover [#4441](https://github.com/diaspora/diaspora/pull/4441) diff --git a/app/models/account_deleter.rb b/lib/account_deleter.rb similarity index 100% rename from app/models/account_deleter.rb rename to lib/account_deleter.rb diff --git a/lib/diaspora.rb b/lib/diaspora.rb index d8e2e3100..db63f94c8 100644 --- a/lib/diaspora.rb +++ b/lib/diaspora.rb @@ -9,4 +9,5 @@ module Diaspora require 'diaspora/markdownify' require 'diaspora/mentionable' require 'diaspora/exporter' + require 'diaspora/federated' end diff --git a/lib/diaspora/federated.rb b/lib/diaspora/federated.rb new file mode 100644 index 000000000..b554d2b71 --- /dev/null +++ b/lib/diaspora/federated.rb @@ -0,0 +1,12 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +module Diaspora + module Federated + require 'diaspora/federated/request' + require 'diaspora/federated/retraction' + require 'diaspora/federated/signed_retraction' + require 'diaspora/federated/relayable_retraction' + end +end \ No newline at end of file diff --git a/app/models/relayable_retraction.rb b/lib/diaspora/federated/relayable_retraction.rb similarity index 99% rename from app/models/relayable_retraction.rb rename to lib/diaspora/federated/relayable_retraction.rb index 4dacde55c..ab7be6528 100644 --- a/app/models/relayable_retraction.rb +++ b/lib/diaspora/federated/relayable_retraction.rb @@ -1,7 +1,6 @@ # Copyright (c) 2010-2011, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. - class RelayableRetraction < SignedRetraction xml_name :relayable_retraction xml_attr :parent_author_signature diff --git a/app/models/request.rb b/lib/diaspora/federated/request.rb similarity index 100% rename from app/models/request.rb rename to lib/diaspora/federated/request.rb diff --git a/app/models/retraction.rb b/lib/diaspora/federated/retraction.rb similarity index 99% rename from app/models/retraction.rb rename to lib/diaspora/federated/retraction.rb index 3a35c28f2..e1798ed94 100644 --- a/app/models/retraction.rb +++ b/lib/diaspora/federated/retraction.rb @@ -1,7 +1,6 @@ # Copyright (c) 2010-2011, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. - class Retraction include Diaspora::Federated::Base @@ -61,4 +60,4 @@ class Retraction end self end -end +end \ No newline at end of file diff --git a/app/models/signed_retraction.rb b/lib/diaspora/federated/signed_retraction.rb similarity index 100% rename from app/models/signed_retraction.rb rename to lib/diaspora/federated/signed_retraction.rb diff --git a/spec/models/account_deleter_spec.rb b/spec/lib/account_deleter_spec.rb similarity index 100% rename from spec/models/account_deleter_spec.rb rename to spec/lib/account_deleter_spec.rb diff --git a/spec/models/relayable_retraction_spec.rb b/spec/lib/diaspora/federated/relayable_retraction_spec.rb similarity index 96% rename from spec/models/relayable_retraction_spec.rb rename to spec/lib/diaspora/federated/relayable_retraction_spec.rb index d76fa60a4..d7b42159c 100644 --- a/spec/models/relayable_retraction_spec.rb +++ b/spec/lib/diaspora/federated/relayable_retraction_spec.rb @@ -82,7 +82,7 @@ describe RelayableRetraction do context 'from the upstream owner' do before do @comment = @local_luke.comment!(@remote_parent, "Yeah, it was great") - @retraction = RelayableRetraction.allocate + @retraction = described_class.allocate @retraction.sender = @remote_raphael @retraction.target = @comment @retraction.stub!(:parent_author_signature_valid?).and_return(true) @@ -104,7 +104,7 @@ describe RelayableRetraction do describe 'xml' do before do @comment = @local_leia.comment!(@local_parent, "yo") - @retraction = RelayableRetraction.build(@local_leia, @comment) + @retraction = described_class.build(@local_leia, @comment) @retraction.parent_author_signature = 'PARENTSIGNATURE' @retraction.target_author_signature = 'TARGETSIGNATURE' @xml = @retraction.to_xml.to_s @@ -131,7 +131,7 @@ describe RelayableRetraction do describe '.from_xml' do before do - @marshalled = RelayableRetraction.from_xml(@xml) + @marshalled = described_class.from_xml(@xml) end it 'marshals the target' do diff --git a/spec/models/request_spec.rb b/spec/lib/diaspora/federated/request_spec.rb similarity index 74% rename from spec/models/request_spec.rb rename to spec/lib/diaspora/federated/request_spec.rb index 733dc3de0..a0d77a237 100644 --- a/spec/models/request_spec.rb +++ b/spec/lib/diaspora/federated/request_spec.rb @@ -11,7 +11,7 @@ describe Request do describe 'validations' do before do - @request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) + @request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) end it 'is valid' do @@ -42,7 +42,7 @@ describe Request do end it 'is not to yourself' do - @request = Request.diaspora_initialize(:from => alice.person, :to => alice.person, :into => @aspect) + @request = described_class.diaspora_initialize(:from => alice.person, :to => alice.person, :into => @aspect) @request.should_not be_valid end end @@ -51,7 +51,7 @@ describe Request do it 'returns request_accepted' do person = FactoryGirl.build:person - request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) + request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) alice.contacts.create(:person_id => person.id) request.notification_type(alice, person).should == Notifications::StartedSharing @@ -60,14 +60,14 @@ describe Request do describe '#subscribers' do it 'returns an array with to field on a request' do - request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) + request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) request.subscribers(alice).should =~ [eve.person] end end describe '#receive' do it 'creates a contact' do - request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) + request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) lambda{ request.receive(eve, alice.person) }.should change{ @@ -79,7 +79,7 @@ describe Request do alice.share_with(eve.person, alice.aspects.first) lambda { - Request.diaspora_initialize(:from => eve.person, :to => alice.person, + described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) }.should change { alice.contacts.find_by_person_id(eve.person.id).mutual? @@ -88,7 +88,7 @@ describe Request do end it 'sets sharing' do - Request.diaspora_initialize(:from => eve.person, :to => alice.person, + described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) alice.contact_for(eve.person).should be_sharing end @@ -98,10 +98,10 @@ describe Request do alice.auto_follow_back_aspect = alice.aspects.first alice.save - Request.diaspora_initialize(:from => eve.person, :to => alice.person, - :into => eve.aspects.first).receive(alice, eve.person) + described_class.diaspora_initialize(:from => eve.person, :to => alice.person, + :into => eve.aspects.first).receive(alice, eve.person) - eve.contact_for(alice.person).should be_sharing + eve.contact_for( alice.person ).should be_sharing end it 'shares not back if auto_following is not enabled' do @@ -109,7 +109,7 @@ describe Request do alice.auto_follow_back_aspect = alice.aspects.first alice.save - Request.diaspora_initialize(:from => eve.person, :to => alice.person, + described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) eve.contact_for(alice.person).should be_nil @@ -126,14 +126,14 @@ describe Request do alice.should_not_receive(:share_with) - Request.diaspora_initialize(:from => eve.person, :to => alice.person, + described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) end end context 'xml' do before do - @request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) + @request = described_class.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect) @xml = @request.to_xml.to_s end @@ -148,7 +148,7 @@ describe Request do context 'marshalling' do it 'produces a request object' do - marshalled = Request.from_xml @xml + marshalled = described_class.from_xml @xml marshalled.sender.should == alice.person marshalled.recipient.should == eve.person diff --git a/spec/models/retraction_spec.rb b/spec/lib/diaspora/federated/retraction_spec.rb similarity index 90% rename from spec/models/retraction_spec.rb rename to spec/lib/diaspora/federated/retraction_spec.rb index 3b8d3092c..8f556d47e 100644 --- a/spec/models/retraction_spec.rb +++ b/spec/lib/diaspora/federated/retraction_spec.rb @@ -13,7 +13,7 @@ describe Retraction do describe 'serialization' do it 'should have a post id after serialization' do - retraction = Retraction.for(@post) + retraction = described_class.for(@post) xml = retraction.to_xml.to_s xml.include?(@post.guid.to_s).should == true end @@ -22,7 +22,7 @@ describe Retraction do describe '#subscribers' do context 'posts' do before do - @retraction = Retraction.for(@post) + @retraction = described_class.for(@post) @obj = @retraction.instance_variable_get(:@object) @wanted_subscribers = @obj.subscribers(alice) end @@ -42,7 +42,7 @@ describe Retraction do context 'setting subscribers' do it 'barfs if the type is a person, and subscribers instance varabile is not set' do - retraction = Retraction.for(alice) + retraction = described_class.for(alice) obj = retraction.instance_variable_get(:@object) lambda { @@ -51,7 +51,7 @@ describe Retraction do end it 'returns manually set subscribers' do - retraction = Retraction.for(alice) + retraction = described_class.for(alice) retraction.subscribers = "fooey" retraction.subscribers(alice).should == 'fooey' end diff --git a/spec/models/signed_retraction_spec.rb b/spec/lib/diaspora/federated/signed_retraction_spec.rb similarity index 93% rename from spec/models/signed_retraction_spec.rb rename to spec/lib/diaspora/federated/signed_retraction_spec.rb index d76eb5be3..64bd0e230 100644 --- a/spec/models/signed_retraction_spec.rb +++ b/spec/lib/diaspora/federated/signed_retraction_spec.rb @@ -9,7 +9,7 @@ describe SignedRetraction do end describe '#perform' do it "dispatches the retraction onward to recipients of the recipient's reshare" do - retraction = SignedRetraction.build(bob, @post) + retraction = described_class.build(bob, @post) onward_retraction = retraction.dup retraction.should_receive(:dup).and_return(onward_retraction) @@ -24,7 +24,7 @@ describe SignedRetraction do bob.post(:reshare, :root_guid => remote_post.guid) alice.post(:reshare, :root_guid => remote_post.guid) - remote_retraction = SignedRetraction.new.tap{|r| + remote_retraction = described_class.new.tap{|r| r.target_type = remote_post.type r.target_guid = remote_post.guid r.sender = remote_post.author