pusher-client gem throwing 2 for 1 error with Presence-Channels - ruby

The pusher-client rubygem works fine when subscribing to Public Channels, but it's throwing "ArgumentError: wrong number of arguments (2 for 1)" when I try to subscribe to a Presence or Private Channel. Does this happen for anyone else?
module PusherClientTest
require 'pusher-client'
PusherClient.logger = Logger.new(STDOUT)
options = { :secret => '12345' }
socket = PusherClient::Socket.new("54321", options)
USER_ID = 1
socket.subscribe('presence-TestChannel', USER_ID)
socket.bind('remark') do |data|
puts data
end
socket.connect
end
Results in:
ree-1.8.7-2010.02 > PusherClientTest
ArgumentError: wrong number of arguments (2 for 1)
from /Users/Dev/Sites/test_app/app/models/pusher_client_test.rb:16:in `subscribe'
from /Users/Dev/Sites/test_app/app/models/pusher_client_test.rb:16
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:406:in `load_without_new_constant_marking'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:406:in `load_file'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:547:in `new_constants_in'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:405:in `load_file'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:285:in `require_or_load'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:451:in `load_missing_constant'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:106:in `const_missing_not_from_s3_library'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
from /Users/Dev/.rvm/gems/ree-1.8.7-2010.02#test_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:118:in `const_missing'
from (irb):1

The git URL to the pusher-client repo needs to be specified in order to subscribe to presence & private Channels. It appears as though the published pusher-client gem hasn't been updated with the latest commits to the repo.
gem 'pusher-client', :git => "git://github.com/logankoester/pusher-client.git"
Further to this, specifying a fork of the main repo will enable :user_info options to be passed across in the subscription:
gem 'pusher-client', :git => "git://github.com/agileanimal/pusher-client.git"

Related

Unable to send exception data to Raygun through the rails app and rake test task. Works through Rails Console

I am unable to send exception data to Raygun through the Rails App and the Rake Test task on our staging environment. The sending of exception data works through the Rails Console though.
Raygun.rb
Raygun.setup do |config|
config.api_key = [Key]
config.filterparameters = Rails.application.config.filterparameters
config.enable_reporting = !Rails.env.development?
end
Gemfile.lock raygun entry
raygun4ruby (1.1.9)
httparty (~> 0.11)
json
rack
The error that I get when I try the rake test
$ RAILS_ENV=production rake raygun:test
Oh-oh, something went wrong - double check your API key
API Key - [FIltered])
rake aborted!
TypeError: no implicit conversion of HTTParty::Response into String
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/raygun/testable.rb:17:in `rescue in tracktestexception'
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/raygun/testable.rb:8:in `tracktestexception'
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/tasks/raygun.tasks:5:in `block (2 levels) in
Raygun::ItWorksException: Woohoo! Your Raygun<->Ruby connection is set up correctly
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/raygun/testable.rb:9:in `tracktestexception'
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/tasks/raygun.tasks:5:in `block (2 levels) in
Tasks: TOP => raygun:test
(See full trace by running task with --trace)
We are using AWS for our staging environment. It is surprising to me that Rails C works while through the app and rake test it does not.
When done through the Rails Console
irb(main):003:0> class ItWorksException < StandardError; end
=> nil
irb(main):004:0> e = ItWorksException.new("Woohoo! Your Raygun<->Ruby connection is set up correctly")
=> #
irb(main):005:0> response = Raygun.track_exception(e)
[Raygun] Tracking Exception...
=> #
irb(main):006:0> response.success?
=> true
This may seem a bit odd, but can you try running it in a slightly different order like:
rake RAILS_ENV=production raygun:test

rspec-puppet tests fail undefined method

I'm trying to write my first rspec test for a simple puppet class. Here's the class, rspec test and results. I'm new to rspec and would like to know what I'm doing wrong here. I follow the directions here http://rspec-puppet.com/setup/ to configure rspec-puppet for these tests. Thanks.
Class example for cron module init.pp
class cron {
service { 'crond' :
ensure => running,
enable => true
}
}
Rspec Test
require '/etc/puppetlabs/puppet/modules/cron/spec/spec_helper'
describe 'cron', :type => :module do
it { should contain_class('cron') }
it do should contain_service('crond').with(
'ensure' => 'running',
'enable' => 'true'
) end
end
Results
FF
Failures:
1) cron
Failure/Error: it { should contain_class('cron') }
NoMethodError:
undefined method `contain_class' for #<RSpec::Core::ExampleGroup::Nested_1:0x00000001c66d70>
# ./cron_spec.rb:5:in `block (2 levels) in <top (required)>'
2) cron
Failure/Error: it do should contain_service('crond').with(
NoMethodError:
undefined method `contain_service' for #<RSpec::Core::ExampleGroup::Nested_1:0x00000001c867b0>
# ./cron_spec.rb:6:in `block (2 levels) in <top (required)>'
Finished in 0.00237 seconds
2 examples, 2 failures
Failed examples:
rspec ./cron_spec.rb:5 # cron
rspec ./cron_spec.rb:6 # cron
Where did you pick up the
describe 'cron', :type => :module
syntax? That may be obsolete.
With current versions of rspec-puppet, you describe
classes
defined types
functions
hosts
You basically just want to put your spec right into spec/classes/cron_spec.rb, that should do half your work for you, e.g.
# spec/classes/cron.rb
require "#{File.join(File.dirname(__FILE__),'..','spec_helper.rb')}"
describe 'cron' do
it { should contain_service('crond').with('ensure' => 'running') }
it { should contain_service('crond').with('enable' => 'true') }
end
It is good practice to have distinct tests for each attribute value, so that possible future regressions can be identified more accurately.
Do see the README.
For a nice example of a well structured module test-suite see example42's modules.

Error while upgrading from Rails 3.1 to Rails 3.2

Upgrade steps were performed as mentioned in http://guides.rubyonrails.org/3_2_release_notes.html
Right now I'm on Ruby 1.8.7 and Rails 3.1.x (using system ruby). I installed RVM with ruby 1.8.7 and added to rails 3.2 and then I get the following error:
[app]$ rails console
Faraday: you may want to install system_timer for reliable timeouts
$HOME/src/qbol/tapp/config/environment.rb:16:in `add': undefined method `>' for nil:NilClass (NoMethodError)
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/tagged_logging.rb:55:in `add'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/tagged_logging.rb:61:in `info'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-3.2.17/lib/active_record/railtie.rb:86
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/lazy_load_hooks.rb:25:in `each'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/lazy_load_hooks.rb:25:in `on_load'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-3.2.17/lib/active_record/railtie.rb:80
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `instance_exec'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `run'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/initializable.rb:55:in `run_initializers'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `each'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `run_initializers'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/application.rb:136:in `initialize!'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/railtie/configurable.rb:30:in `send'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/railtie/configurable.rb:30:in `method_missing'
from $HOME/src/app/config/environment.rb:48
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/application.rb:103:in `require_environment!'
from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/commands.rb:40
from script/rails:6:in `require'
from script/rails:6
This is on my development box. Any idea why this is happening?
EDIT: Below is the environment.rb. The error is happening on the last line App::Application.initialize!
# Load the rails application
require File.expand_path('../application', __FILE__)
module ActiveSupport
class BufferedLogger
def self.current_user
Thread.current[:user]
end
def self.current_user=(user)
Thread.current[:user] = user
end
def add(severity, message = nil, progname = nil, &block)
return if #level > severity
message = (message || (block && block.call) || progname).to_s
level = {
0 => "DEBUG",
1 => "INFO ",
2 => "WARN ",
3 => "ERROR",
4 => "FATAL"
}[severity] || "UNKNOWN"
user=BufferedLogger.current_user
if(!user.nil?)
idstr = "uid:#{user.id}"
if !user.current_app_user.nil?
idstr.concat(", acid: #{user.current_app_user.account_id}")
end
else
idstr=""
end
message = "[%s: %s #{idstr}] %s" %
["#{level} pid: #{$$}", Time.now.strftime("%y-%m-%d %H:%M:%S"), message]
message = "#{message}\n" unless message[-1] == ?\n
buffer << message
auto_flush
message
end
end
end
# Initialize the rails application
App::Application.initialize!
The error is happening inside ActiveSupport::BufferedLogger#add method call and you appear to be monkey-patching this class. The internals of ActiveSupport::BufferedLogger have likely changing between the versions of Rails you're using.
Try removing all of the ActiveSupport::BufferedLogger code from your environment.rb to work past this error and get your app running. Then, if you still need the monkeypatch (don't know why), you'd have to rewrite it on top of the newer version of the class.

rake spec failed, it cannot load or find constant or global variable

I create standalone rspec test script to testing existing api framework. It works pretty well, but I found problem where in the Rakefile I need to assign some value from YAML file (uri link, email) either CONSTANT or $global_var the code in the Rakefile looks like this:
require 'rubygems'
require 'bundler/setup'
require 'yaml'
require 'rspec/core/rake_task'
task :default => :spec
desc 'Running rspec test'
task :spec, :option do |t, opt|
choice = opt[:choice]
if choice == "production"
puts 'Test running on production'
VAR = YAML::load(File.read(File.expand_path("../config/prod_variable.yml", __FILE__)))
elsif choice == "development"
puts 'Test running on development'
VAR = YAML::load(File.read(File.expand_path("../config/dev_variable.yml", __FILE__)))
end
puts VAR['URI'] #=> print out the value correctly
RSpec::Core::RakeTask.new do |task|
test = Rake.application.original_dir
task.fail_on_error = false
task.rspec_opts = '--format documentation --color'
end
end
When I run the rake command on the terminal, the rspec failed find the VAR constant value. Here is the error message from rspec
Failures:
1) ApiTest Testing API platform for GET request
Failure/Error: #var = ApiTest.new(VAR['URI'] ,
NameError:
uninitialized constant VAR
# ./rspec_test/api_test/api_test_get_spec.rb:8:in `block (2 levels) in <top (required)>'
2) ApiTest Testing API platform for POST request
Failure/Error: #zat = ApiTest.new(VAR['URI'] ,
NameError:
uninitialized constant VAR
# ./rspec_test/api_test/api_test_post_spec.rb:7:in `block (2 levels) in <top (required)>'
Is there any idea how to get this works? I need to get value from VAR constant or global variable, but seems ruby failed to assign the value.
If opt[:choice] is neither "production" nor "development", VAR is undefined in your code.

Sinatra, Mongoid, Heroku, MongoHQ: connecting to Mongodb

Trying to get Mongoid up and running with Sinatra on Heroku (MongoHQ). Previous experience with Rails but first time with the stack and Sinatra.
Started with one of the simple examples on the web (app.rb):
require 'rubygems'
require 'sinatra'
require 'mongo'
require 'mongoid'
configure do
Mongoid.load!('mongoid.yml')
Mongoid.configure do |config|
if ENV['MONGOHQ_URL']
conn = Mongo::Connection.from_uri(ENV['MONGOHQ_URL'])
uri = URI.parse(ENV['MONGOHQ_URL'])
# problem happens here
config.master = conn.db(uri.path.gsub(/^\//, ''))
else
config.master = Mongo::Connection.from_uri("mongodb://localhost:27017").db('test')
end
end
end
# Models
class Counter
include Mongoid::Document
field :count, :type => Integer
def self.increment
c = first || new({:count => 0})
c.inc(:count, 1)
c.save
c.count
end
end
# Controllers
get '/' do
"Hello visitor n" + Counter.increment.to_s
end
For reference, mongoid.yml looks like:
development:
sessions:
default:
database: localhost
production:
sessions:
default:
uri: <%= ENV['MONGOHQ_URL'] %>
As per app.rb (# problem happens here), my logs say:
/app/app.rb:15:in `block (2 levels) in <top (required)>': undefined method `master=' for Mongoid::Config:Module (NoMethodError)
from /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.3/lib/mongoid.rb:112:in `configure'
from /app/app.rb:11:in `block in <top (required)>'
from /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1273:in `configure'
from /app/app.rb:8:in `<top (required)>'
I have also tried variants, including:
config.master = Mongo::Connection.from_uri(ENV['MONGOHQ_URL']).db('appXXXXX')
Mongoid.database = Mongo::Connection.from_uri(ENV['MONGOHQ_URL']).db('appXXXXXXX')
But get the same error:
undefined method `master` for Mongoid::Config:Module (NoMethodError)
or:
undefined method `database=` for Mongoid::Config:Module (NoMethodError)
What am I missing?
Shouldn't be
configure do
Mongoid.load!('mongoid.yml')
end
enough?
That's what the mongid docs are saying. The MONGOHQ_URL environment variable already contains every information to initialize the connection to the db.
So was using Mongoid 3.x ... which:
Doesn't use 10gen driver: uses Moped
Doesn't use config.master
The canonical sample code above which is all over the web works out of the box with Mongoid 2.x so have dropped back to that for the time being.
Thanks!

Resources