* no longer using 'pg' gem for ActiveRecord, because it's not tested for jruby; also making all tests pass

This commit is contained in:
Seth Call 2012-08-21 22:08:01 -05:00
parent 568929e25a
commit 11e403deb3
9 changed files with 57 additions and 33 deletions

2
.rvmrc
View File

@ -1,2 +1,2 @@
rvm use jruby-1.7.0.preview1@websockets --create
rvm use jruby-head@websockets --create
#rvm use ruby-1.9.3@websockets --create

View File

@ -11,17 +11,19 @@ gem 'pg_migrate', '0.1.4'
gem 'jam_db', :path => '~/workspace/jam-db/target/ruby_package'
gem 'jam_ruby', :path => '~/workspace/jam-ruby'
gem 'jampb', :path => '~/workspace/jam-pb/target/ruby/jampb'
gem 'em-websocket', :path=> '~/workspace/em-websocket'
gem 'em-websocket' # :path=> '~/workspace/em-websocket'
gem 'hot_bunnies', '1.3.8'
gem 'activerecord', '3.2.7'
gem 'logging'
#gem 'em-http-request'
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcpostgresql-adapter'
group :test do
gem 'cucumber'
gem 'rspec'
gem 'factory_girl'
gem 'spork', '0.9.0'
#gem 'spork', '0.9.0'
gem 'database_cleaner', '0.7.0'
gem 'guard', '>= 0.10.0'
gem 'guard-rspec', '>= 0.7.3'

View File

@ -1,8 +1,10 @@
test:
adapter: postgresql
adapter: jdbcpostgresql
database: jam_websockets_test
host: localhost
port: 5432
pool: 3
username: postgres
password: postgres
timeout: 2000
encoding: unicode
encoding: unicode

View File

@ -1,10 +1,10 @@
module JamWebsockets
class ClientContext
attr_accessor :user_id, :user_queue, :session_topic, :subscription
attr_accessor :user, :user_queue, :session_topic, :subscription
def initialize(user_id, user_queue, subscription)
@user_id = user_id
def initialize(user, user_queue, subscription)
@user = user
@user_queue = user_queue
@subscription = subscription
@session_topic = nil

View File

@ -98,7 +98,7 @@ module JamWebsockets
begin
self.route(pb_msg, client)
rescue => e
@log.debug "ending client session due to error: #{e.to_s}"
@log.debug "ending client session due to error: #{e.to_s} #{e.backtrace}"
begin
# wrap the message up and send it down
@ -162,7 +162,7 @@ module JamWebsockets
elsif @message_factory.session_directed? client_msg
session = client_msg.target[MessageFactory::SESSION_PREFIX_TARGET.length..-1]
session = client_msg.target[MessageFactory::SESSION_TARGET_PREFIX.length..-1]
handle_session_directed(session, client_msg, client)
elsif @message_factory.user_directed? client_msg
@ -268,7 +268,7 @@ module JamWebsockets
context.session_topic = subscription
# respond with LOGIN_JAM_SESSION_ACK to let client know it was successful
client.send(@message_factory.login_jam_session_ack(false, nil)
client.send(@message_factory.login_jam_session_ack(false, nil))
# send 'new client' message
@ -276,7 +276,7 @@ module JamWebsockets
end
def handle_leave_jam_session(leae_jam_session, client)
def handle_leave_jam_session(leave_jam_session, client)
context = @clients[client]
@ -324,7 +324,7 @@ module JamWebsockets
raise 'not allowed to join the specified session'
end
return jam_sesson
return jam_session
end
def handle_session_directed(session, client_msg, client)
@ -346,5 +346,3 @@ module JamWebsockets
end
end
end

View File

@ -17,4 +17,4 @@ FactoryGirl.define do
factory :jam_session_member, :class => JamRuby::JamSessionMember do
end
end
end

View File

@ -86,7 +86,7 @@ describe Router do
TestClient = Class.new do
attr_accessor :onmsgblock, :onopenblock
attr_accessor :onmsgblock, :onopenblock, :oncloseblock
def initiaize()
@ -100,6 +100,9 @@ describe Router do
@onmsgblock = block
end
def close(&block)
@oncloseblock = block
end
end
client = TestClient.new
@ -153,6 +156,10 @@ describe Router do
def onmessage(&block)
@onmsgblock = block
end
def close(&block)
@oncloseblock = block
end
end
client = TestClient.new
@ -169,7 +176,7 @@ describe Router do
client.onopenblock.call
# create a login message, and pass it into the router via onmsgblock.call
login = message_factory.login_with_user_pass("baduser@example.com", "foobar")
login = message_factory.login_with_user_pass(user1.email, "foobar")
# first log in
client.onmsgblock.call login.to_s
@ -180,7 +187,5 @@ describe Router do
end
end
end

View File

@ -2,7 +2,22 @@ class SpecDb
TEST_DB_NAME="jam_websockets_test"
def self.recreate_database
def self.recreate_database(db_config)
recreate_database_jdbc(db_config)
end
def self.recreate_database_jdbc(db_config)
original = db_config["database"]
db_config["database"] = "postgres"
ActiveRecord::Base.establish_connection(db_config)
ActiveRecord::Base.connection.execute("DROP DATABASE IF EXISTS #{TEST_DB_NAME}")
ActiveRecord::Base.connection.execute("CREATE DATABASE #{TEST_DB_NAME}")
JamDb::Migrator.new.migrate(:dbname => TEST_DB_NAME)
db_config["database"] = original
end
def self.recreate_database_pg
conn = PG::Connection.open("dbname=postgres")
conn.exec("DROP DATABASE IF EXISTS #{TEST_DB_NAME}")
conn.exec("CREATE DATABASE #{TEST_DB_NAME}")

View File

@ -21,15 +21,16 @@ end
Logging.logger.root.appenders = Logging.appenders.stdout
# recreate test database and migrate it
SpecDb::recreate_database
# initialize ActiveRecord's db connection
ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))["test"])
db_config = YAML::load(File.open('config/database.yml'))["test"]
SpecDb::recreate_database(db_config)
# initialize ActiveRecord's db connection
ActiveRecord::Base.establish_connection(db_config)
require 'jam_ruby'
require 'jampb'
require 'rubygems'
require 'spork'
#require 'spork'
require 'database_cleaner'
require 'factory_girl'
require 'factories'
@ -43,7 +44,7 @@ include Jampb
#require 'spork/ext/ruby-debug'
Spork.prefork do
#Spork.prefork 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
# need to restart spork for it take effect.
@ -64,16 +65,17 @@ Spork.prefork do
config.filter_run :focus
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
# DatabaseCleaner.strategy = :transaction
# DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.start
# DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
ActiveRecord::Base.connection.execute('select truncate_tables()')
# DatabaseCleaner.clean
end
# If you're not using ActiveRecord, or you'd prefer not to run each of your
@ -87,10 +89,10 @@ Spork.prefork do
# --seed 1234
config.order = 'random'
end
end
#end
Spork.each_run do
#Spork.each_run do
# This code will be run each time you run your specs.
end
#end