diff --git a/spec/integration/attack_vectors_spec.rb b/spec/integration/attack_vectors_spec.rb index 398297428..7e7f9f126 100644 --- a/spec/integration/attack_vectors_spec.rb +++ b/spec/integration/attack_vectors_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' -def receive(post, opts) +def receive_post(post, opts) sender = opts.fetch(:from) receiver = opts.fetch(:by) salmon_xml = sender.salmon(post).xml_for(receiver.person) @@ -36,7 +36,7 @@ def temporary_post(user, &block) end def expect_error(partial_message, &block)# DOES NOT REQUIRE ERROR!! - begin + begin yield rescue => e e.message.should match partial_message @@ -58,7 +58,7 @@ end #returns the message def legit_post_from_user1_to_user2(user1, user2) original_message = user1.post(:status_message, :text => 'store this!', :to => user1.aspects.find_by_name("generic").id) - receive(original_message, :from => user1, :by => user2) + receive_post(original_message, :from => user1, :by => user2) original_message end @@ -126,9 +126,9 @@ describe "attack vectors" do expect { expect { - receive(profile, :from => alice, :by => bob) + receive_post(profile, :from => alice, :by => bob) }.to raise_error Diaspora::AuthorXMLAuthorMismatch - }.to_not change(eve.profile, :first_name) + }.to_not change(eve.profile, :first_name) end end @@ -153,7 +153,7 @@ describe "attack vectors" do malicious_message = FactoryGirl.build(:status_message, :id => original_message.id, :guid => original_message.guid, :author => alice.person) expect{ - receive(malicious_message, :from => alice, :by => bob) + receive_post(malicious_message, :from => alice, :by => bob) }.to_not change(original_message, :author_id) end @@ -166,7 +166,7 @@ describe "attack vectors" do malicious_message = FactoryGirl.build( :status_message, :id => original_message.id, :text => 'BAD!!!', :author => eve.person) expect { - receive(malicious_message, :from => eve, :by => bob) + receive_post(malicious_message, :from => eve, :by => bob) }.to_not change(original_message, :text) end end @@ -175,14 +175,14 @@ describe "attack vectors" do it "ignores retractions on a post not owned by the retraction's sender" do original_message = legit_post_from_user1_to_user2(eve, bob) - ret = bogus_retraction do |retraction| + ret = bogus_retraction do |retraction| retraction.post_guid = original_message.guid retraction.diaspora_handle = alice.person.diaspora_handle retraction.type = original_message.class.to_s end expect { - receive(ret, :from => alice, :by => bob) + receive_post(ret, :from => alice, :by => bob) }.to_not change(StatusMessage, :count) end @@ -195,7 +195,7 @@ describe "attack vectors" do end end expect{ - receive(bogus_retraction, :from => alice, :by => bob) + receive_post(bogus_retraction, :from => alice, :by => bob) }.to_not raise_error end @@ -210,7 +210,7 @@ describe "attack vectors" do expect { expect { - receive(retraction, :from => alice, :by => bob) + receive_post(retraction, :from => alice, :by => bob) }.to raise_error Diaspora::AuthorXMLAuthorMismatch }.to_not change(bob.visible_shareables(Post), :count) @@ -227,7 +227,7 @@ describe "attack vectors" do end expect{ - receive(retraction, :from => alice, :by => bob) + receive_post(retraction, :from => alice, :by => bob) }.to_not change{bob.reload.contacts.count} end @@ -240,14 +240,14 @@ describe "attack vectors" do expect{ expect { - receive(retraction, :from => alice, :by => bob) + receive_post(retraction, :from => alice, :by => bob) }.to raise_error Diaspora::AuthorXMLAuthorMismatch }.to_not change(bob.contacts, :count) end it 'does not let another user update other persons post' do original_message = eve.post(:photo, :user_file => uploaded_photo, :text => "store this!", :to => eves_aspect.id) - receive(original_message, :from => eve, :by => bob) + receive_post(original_message, :from => eve, :by => bob) #is this testing two things? new_message = original_message.dup @@ -255,7 +255,7 @@ describe "attack vectors" do new_message.text = "bad bad bad" expect{ - receive(new_message, :from => alice, :by => bob) + receive_post(new_message, :from => alice, :by => bob) }.to_not change(original_message, :text) end end diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index aedb365d5..20a50682a 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -23,26 +23,27 @@ describe Reshare do end describe "#receive" do - let(:receive) {@reshare.receive(@root.author.owner, @reshare.author)} + let(:receive_reshare) { @reshare.receive(@root.author.owner, @reshare.author) } + before do @reshare = FactoryGirl.create(:reshare, :root => FactoryGirl.build(:status_message, :author => bob.person, :public => true)) @root = @reshare.root end it 'increments the reshare count' do - receive + receive_reshare @root.resharers.count.should == 1 end it 'adds the resharer to the re-sharers of the post' do - receive + receive_reshare @root.resharers.should include(@reshare.author) end it 'does not error if the root author has a contact for the resharer' do bob.share_with @reshare.author, bob.aspects.first proc { Timeout.timeout(5) do - receive #This doesn't ever terminate on my machine before it was fixed. + receive_reshare #This doesn't ever terminate on my machine before it was fixed. end }.should_not raise_error end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ceef36105..2f375e9e4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,8 +2,6 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -require 'rubygems' - prefork = proc do # Loading more in this block will cause your tests to run faster. However, # if you change any configuration or code from libraries loaded here, you'll @@ -13,7 +11,7 @@ prefork = proc do #Spork.trap_method(Rails::Application::RoutesReloader, :reload!) ENV["RAILS_ENV"] ||= 'test' - require File.join(File.dirname(__FILE__), '..', 'config', 'environment') unless defined?(Rails) + require File.join(File.dirname(__FILE__), '..', 'config', 'environment') require Rails.root.join('spec', 'helper_methods') require Rails.root.join('spec', 'spec-doc') require 'rspec/rails' @@ -112,6 +110,6 @@ RSpec.configure do |config| DeferredGarbageCollection.start end config.after(:all) do - DeferredGarbageCollection.reconsider + DeferredGarbageCollection.reconsider end end