Skip to content
Extraits de code Groupes Projets
Valider ae65b7fc rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Merge branch 'master' of github.com:diaspora/diaspora

parents 16e45595 ebce9675
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
# the COPYRIGHT file. # the COPYRIGHT file.
require File.join(File.dirname(__FILE__), "..", "..", "config", "environment") require File.join(File.dirname(__FILE__), "..", "..", "config", "environment")
require File.join(File.dirname(__FILE__), "..", "..", "spec", "helper_methods")
def set_app_config username def set_app_config username
current_config = YAML.load(File.read(Rails.root.join('config', 'app_config.yml.example'))) current_config = YAML.load(File.read(Rails.root.join('config', 'app_config.yml.example')))
...@@ -18,7 +20,7 @@ username = "tom" ...@@ -18,7 +20,7 @@ username = "tom"
set_app_config username unless File.exists?(Rails.root.join('config', 'app_config.yml')) set_app_config username unless File.exists?(Rails.root.join('config', 'app_config.yml'))
require Rails.root.join('config', "initializers", "_load_app_config.rb") require Rails.root.join('config', "initializers", "_load_app_config.rb")
include HelperMethods
# Create seed user # Create seed user
user = User.build( :email => "tom@tom.joindiaspora.com", user = User.build( :email => "tom@tom.joindiaspora.com",
:username => "tom", :username => "tom",
...@@ -44,7 +46,8 @@ user2.save ...@@ -44,7 +46,8 @@ user2.save
user2.person.save! user2.person.save!
user2.seed_aspects user2.seed_aspects
# friending users # friending users
aspect = user.aspect(:name => "other dudes") aspect = user.aspect(:name => "other dudes")
request = user.send_friend_request_to(user2, aspect) aspect2 = user2.aspect(:name => "presidents")
reversed_request = user2.accept_friend_request( request.id, user2.aspect(:name => "presidents").id )
user.receive reversed_request.to_diaspora_xml, user2.person friend_users(user, aspect, user2, aspect2)
user.aspect(:name => "Presidents")
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# the COPYRIGHT file. # the COPYRIGHT file.
require File.join(File.dirname(__FILE__), "..", "..", "config", "environment") require File.join(File.dirname(__FILE__), "..", "..", "config", "environment")
require File.join(File.dirname(__FILE__), "..", "..", "spec", "helper_methods")
def set_app_config username def set_app_config username
current_config = YAML.load(File.read(Rails.root.join('config', 'app_config.yml.example'))) current_config = YAML.load(File.read(Rails.root.join('config', 'app_config.yml.example')))
...@@ -17,6 +18,7 @@ end ...@@ -17,6 +18,7 @@ end
set_app_config "tom" unless File.exists?(Rails.root.join('config', 'app_config.yml')) set_app_config "tom" unless File.exists?(Rails.root.join('config', 'app_config.yml'))
require 'config/initializers/_load_app_config.rb' require 'config/initializers/_load_app_config.rb'
include HelperMethods
# Create seed user # Create seed user
user = User.build( :email => "tom@tom.joindiaspora.com", user = User.build( :email => "tom@tom.joindiaspora.com",
...@@ -40,9 +42,8 @@ user2.save! ...@@ -40,9 +42,8 @@ user2.save!
user2.seed_aspects user2.seed_aspects
user2.person.save! user2.person.save!
# friending users # friending users
aspect = user.aspect(:name => "other dudes") aspect = user.aspect(:name => "other dudes")
request = user.send_friend_request_to(user2, aspect) aspect2 = user2.aspect(:name => "presidents")
reversed_request = user2.accept_friend_request( request.id, user2.aspect(:name => "presidents").id )
user.receive reversed_request.to_diaspora_xml, user2.person
user.aspect(:name => "Presidents")
friend_users(user, aspect, user2, aspect2)
user.aspect(:name => "Presidents")
...@@ -54,7 +54,8 @@ describe AspectsController do ...@@ -54,7 +54,8 @@ describe AspectsController do
describe "#move_friend" do describe "#move_friend" do
let(:opts) { {:friend_id => "person_id", :from => "from_aspect_id", :to => {:to => "to_aspect_id"}}} let(:opts) { {:friend_id => "person_id", :from => "from_aspect_id", :to => {:to => "to_aspect_id"}}}
it 'calls the move_friend_method' do it 'calls the move_friend_method' do
pending "need to figure out how to stub current_user to return our test @user" pending "need to figure out what is the deal with remote requests"
@controller.stub!(:current_user).and_return(@user)
@user.should_receive(:move_friend).with( :friend_id => "person_id", :from => "from_aspect_id", :to => "to_aspect_id") @user.should_receive(:move_friend).with( :friend_id => "person_id", :from => "from_aspect_id", :to => "to_aspect_id")
post :move_friend, opts post :move_friend, opts
end end
......
module HelperMethods
def stub_sockets
Diaspora::WebSocket.stub!(:queue_to_user).and_return(true)
Diaspora::WebSocket.stub!(:subscribe).and_return(true)
Diaspora::WebSocket.stub!(:unsubscribe).and_return(true)
end
def unstub_sockets
Diaspora::WebSocket.unstub!(:queue_to_user)
Diaspora::WebSocket.unstub!(:subscribe)
Diaspora::WebSocket.unstub!(:unsubscribe)
end
def stub_comment_signature_verification
Comment.any_instance.stubs(:verify_signature).returns(true)
end
def unstub_mocha_stubs
Mocha::Mockery.instance.stubba.unstub_all
end
def get_models
models = []
Dir.glob( File.dirname(__FILE__) + '/../app/models/*' ).each do |f|
models << File.basename( f ).gsub( /^(.+).rb/, '\1')
end
models
end
def message_queue
User::QUEUE
end
def friend_users(user1, aspect1, user2, aspect2)
request = user1.send_friend_request_to(user2.person, aspect1)
user2.receive_friend_request(request)
reversed_request = user2.accept_friend_request( request.id, aspect2.id)
user1.reload
user1.receive reversed_request.to_diaspora_xml, user2.person
user1.reload
aspect1.reload
user2.reload
aspect2.reload
end
def stub_success(address = 'abc@example.com', opts = {})
host = address.split('@')[1]
stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
if opts[:diaspora] || host.include?("diaspora")
stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd)
stub_request(:get, "http://#{host}/hcard/users/4c8eccce34b7da59ff000002").to_return(:status => 200, :body => hcard_response)
else
stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => nonseed_finger_xrd)
stub_request(:get, 'http://evan.status.net/hcard').to_return(:status => 200, :body => evan_hcard)
end
end
def stub_failure(address = 'abc@example.com')
host = address.split('@')[1]
stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 500)
end
def host_xrd
File.open(File.dirname(__FILE__) + '/fixtures/host_xrd').read
end
def finger_xrd
File.open(File.dirname(__FILE__) + '/fixtures/finger_xrd').read
end
def hcard_response
File.open(File.dirname(__FILE__) + '/fixtures/hcard_response').read
end
def nonseed_finger_xrd
File.open(File.dirname(__FILE__) + '/fixtures/nonseed_finger_xrd').read
end
def evan_hcard
File.open(File.dirname(__FILE__) + '/fixtures/evan_hcard').read
end
end
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
ENV["RAILS_ENV"] ||= 'test' ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails) require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails)
require 'helper_methods'
require 'rspec/rails' require 'rspec/rails'
require 'database_cleaner' require 'database_cleaner'
require 'webmock/rspec' require 'webmock/rspec'
include Devise::TestHelpers include Devise::TestHelpers
include WebMock::API include WebMock::API
include HelperMethods
# Requires supporting files with custom matchers and macros, etc, # Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories. # in ./support/ and its subdirectories.
...@@ -33,86 +35,3 @@ end ...@@ -33,86 +35,3 @@ end
ImageUploader.enable_processing = false ImageUploader.enable_processing = false
def stub_sockets
Diaspora::WebSocket.stub!(:queue_to_user).and_return(true)
Diaspora::WebSocket.stub!(:subscribe).and_return(true)
Diaspora::WebSocket.stub!(:unsubscribe).and_return(true)
end
def unstub_sockets
Diaspora::WebSocket.unstub!(:queue_to_user)
Diaspora::WebSocket.unstub!(:subscribe)
Diaspora::WebSocket.unstub!(:unsubscribe)
end
def stub_comment_signature_verification
Comment.any_instance.stubs(:verify_signature).returns(true)
end
def unstub_mocha_stubs
Mocha::Mockery.instance.stubba.unstub_all
end
def get_models
models = []
Dir.glob( File.dirname(__FILE__) + '/../app/models/*' ).each do |f|
models << File.basename( f ).gsub( /^(.+).rb/, '\1')
end
models
end
def message_queue
User::QUEUE
end
def friend_users(user1, aspect1, user2, aspect2)
request = user1.send_friend_request_to(user2.person, aspect1)
user2.receive_friend_request(request)
reversed_request = user2.accept_friend_request( request.id, aspect2.id)
user1.reload
user1.receive reversed_request.to_diaspora_xml, user2.person
user1.reload
aspect1.reload
user2.reload
aspect2.reload
end
def stub_success(address = 'abc@example.com', opts = {})
host = address.split('@')[1]
stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
if opts[:diaspora] || host.include?("diaspora")
stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => finger_xrd)
stub_request(:get, "http://#{host}/hcard/users/4c8eccce34b7da59ff000002").to_return(:status => 200, :body => hcard_response)
else
stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 200, :body => nonseed_finger_xrd)
stub_request(:get, 'http://evan.status.net/hcard').to_return(:status => 200, :body => evan_hcard)
end
end
def stub_failure(address = 'abc@example.com')
host = address.split('@')[1]
stub_request(:get, "https://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
stub_request(:get, "http://#{host}/.well-known/host-meta").to_return(:status => 200, :body => host_xrd)
stub_request(:get, /webfinger\/\?q=#{address}/).to_return(:status => 500)
end
def host_xrd
File.open(File.dirname(__FILE__) + '/fixtures/host_xrd').read
end
def finger_xrd
File.open(File.dirname(__FILE__) + '/fixtures/finger_xrd').read
end
def hcard_response
File.open(File.dirname(__FILE__) + '/fixtures/hcard_response').read
end
def nonseed_finger_xrd
File.open(File.dirname(__FILE__) + '/fixtures/nonseed_finger_xrd').read
end
def evan_hcard
File.open(File.dirname(__FILE__) + '/fixtures/evan_hcard').read
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter