Skip to content

Instantly share code, notes, and snippets.

@m4tm4t
Created January 10, 2013 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4tm4t/4503217 to your computer and use it in GitHub Desktop.
Save m4tm4t/4503217 to your computer and use it in GitHub Desktop.
class Users::SessionsController < Devise::SessionsController
respond_to :xml
before_filter :init_faye_client, if: "TEST_JABBER_INTEGRATION == true"
after_filter :close_faye_client, if: "TEST_JABBER_INTEGRATION == true"
def init_faye_client
@client = Faye::Client.new('http://localhost:9292/faye')
end
def close_faye_client
@client.disconnect
end
def new
add_breadcrumb "Compte", false
add_breadcrumb "Connexion"
super
end
def create
super
@client.publish('/xmpp/auth', 'result' => resource) if: TEST_JABBER_INTEGRATION == true
end
end
require 'rubygems'
require 'thin'
require 'faye'
require 'xmpp4r'
Thread.new do
$bayeux = Faye::RackAdapter.new(mount: '/faye', timeout: 10)
$bayeux.listen(9292)
end
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.after(:suite) do
$bayeux.stop
end
end
require "spec_helper"
describe "XMPP" do
def subscribe(namespace)
@client.subscribe(namespace) do |message|
@message = message
end
sleep 1
end
before(:each) do
@client = Faye::Client.new('http://localhost:9292/faye')
end
after(:each) do
@client.disconnect
@message = nil
end
describe "Faye pub/sub" do
it "Faye should work" do
subscribe "/foo"
@client.publish('/foo', 'text' => 'Hello world')
sleep 0.1 until !@message.nil? # Wait a message from Faye
expect(@message).to eq({'text' => 'Hello world'})
end
end
describe "Ejabberd" do
it "Should authenticate" do
subscribe "/xmpp/auth"
jid = Jabber::JID.new('foohey@localhost')
client = Jabber::Client.new(jid)
client.connect('127.0.0.1')
client.auth '123456'
sleep 0.1 until !@message.nil? # Wait a message from Faye
expect(@message['result']).to_not be_empty
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment