tristandunn / pusher-fake

A fake Pusher server for development and testing.
https://rubygems.org/gems/pusher-fake
MIT License
173 stars 32 forks source link

Using Pusher.trigger([channel], event, message), fails in client js response #7

Closed ashramsey closed 11 years ago

ashramsey commented 11 years ago

Hi,

I'm using the latest version of this gem and the pusher gem, and calling Pusher.trigger([channel], event, message), as using the Pusher[channel].trigger(event, message) returns a 202 from Pusher.com and is deprecated api, where as pusher-fake returns a 200 but an empty string, raising an exception. This approach works as expected with Pusher.com.

So I updated the PusherFake::Server::Application.channel to match the correct path

%r{/apps/#{PusherFake.configuration.app_id}/events}i

and my application server receives the empty json response correctly, but my cucumber assertions for the client side receiving the message fails.

A little lost, I started the pusher-fake server manually (in a rake task) and ran the scenario, and all steps pass. I guess I wanted to try debugging the server code.

Hoping you might have some clues as to how to debug the fake server code? Or where I'm going wrong.

I'm using the pusher_fake.rb file in features/support/ as per your example. I also ran the pusher-fake example app and that runs correctly.

Cheers

tristandunn commented 11 years ago

Thanks for reporting the issue.

After investigating the recent pusher-gem and client library changes, I believe I have it all working again. I still need to clean up the tests and test against a live server to be 100% though.

In addition to updating all the dependencies and using the new trigger format, the channels now come from the JSON data in the body as well. Here is what Pusher::Server::Application looks like now:

module PusherFake
  module Server
    class Application
      # Process an API request by emitting the event with data to the
      # requested channels.
      #
      # @param [Hash] environment The request environment.
      # @return [Rack::Response] A successful response.
      def self.call(environment)
        request = Rack::Request.new(environment)
        event   = Yajl::Parser.parse(request.body.read)

        event["channels"].each do |channel|
          Channel.factory(channel).emit(event["name"], event["data"])
        end

        Rack::Response.new("{}").finish
      end
    end
  end
end

I'll release a new version with the updates and fixes soon.

tristandunn commented 11 years ago

Changes pushed to master and 0.1.5 pushed to Rubygems.