Skip to content
Extraits de code Groupes Projets
spec_helper.rb 2,54 ko
Newer Older
#    Copyright 2010 Diaspora Inc.
#
#    This file is part of Diaspora.
#
#    Diaspora is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Diaspora is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with Diaspora.  If not, see <http://www.gnu.org/licenses/>.
#



Raphael Sofaer's avatar
Raphael Sofaer a validé
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
Raphael Sofaer's avatar
Raphael Sofaer a validé
ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails)
require 'rspec/rails'
include Devise::TestHelpers
Raphael Sofaer's avatar
Raphael Sofaer a validé

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

RSpec.configure do |config|
Raphael Sofaer's avatar
Raphael Sofaer a validé
  config.mock_with :rspec

  DatabaseCleaner.strategy = :truncation
maxwell's avatar
maxwell a validé
  DatabaseCleaner.orm = "mongo_mapper"
  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end
Raphael Sofaer's avatar
Raphael Sofaer a validé
end
  def stub_sockets
    Diaspora::WebSocket.stub!(:push_to_user).and_return(true)
    Diaspora::WebSocket.stub!(:subscribe).and_return(true)
    Diaspora::WebSocket.stub!(:unsubscribe).and_return(true)
maxwell's avatar
maxwell a validé
  end
    (get_models.map{|model| model.camelize.constantize} - [User]).each do |model|
      model.any_instance.stubs(:verify_signature).returns(true)
  end

  def unstub_mocha_stubs
    Mocha::Mockery.instance.stubba.unstub_all
  end
Raphael's avatar
Raphael a validé

  def get_models
    models = []
    Dir.glob( File.dirname(__FILE__) + '/../app/models/*' ).each do |f|
      models << File.basename( f ).gsub( /^(.+).rb/, '\1')
    end
    models
Raphael's avatar
Raphael a validé
  end
Raphael's avatar
Raphael a validé
  def friend_users(user1, aspect1, user2, aspect2)
    request = user1.send_friend_request_to(user2.person, aspect1)
    reversed_request = user2.accept_friend_request( request.id, aspect2.id) 
    user1.receive reversed_request.to_diaspora_xml
  end