do not overwrite rspec methods (receive)

This commit is contained in:
Jonne Haß 2014-01-06 18:18:10 +01:00
parent df0bff6537
commit 01ecd9d054
3 changed files with 22 additions and 23 deletions

View file

@ -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)
@ -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,7 +126,7 @@ 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)
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
@ -182,7 +182,7 @@ describe "attack vectors" do
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

View file

@ -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

View file

@ -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'