Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Raise and log on unknown server paths.

  • Loading branch information...
commit 9df7d56ed60eecb278a2f3afe1cef02cf533e781 1 parent d4ab700
@tristandunn authored
View
1  CHANGELOG.markdown
@@ -2,6 +2,7 @@
## Unreleased
+* Raise and log on unknown server paths. (Tristan Dunn)
* Update dependencies. (Tristan Dunn)
## 0.6.0 — January 23, 2013
View
11 lib/pusher-fake/server/application.rb
@@ -24,6 +24,8 @@ def self.call(environment)
channel($1, request)
when %r{\A/apps/#{id}/channels/([^/]+)/users\Z}
users($1)
+ else
+ unknown_path(request.path)
end
Rack::Response.new(MultiJson.dump(response)).finish
@@ -111,6 +113,15 @@ def self.users(name)
{ users: users || [] }
end
+
+ def self.unknown_path(path)
+ message = "Unknown path: #{path}"
+
+ logger = Logger.new(STDOUT)
+ logger.error(message)
+
+ raise message
+ end
end
end
end
View
79 spec/lib/pusher-fake/server/application_spec.rb
@@ -74,6 +74,49 @@
end
end
+describe PusherFake::Server::Application, ".call, with unknown path" do
+ let(:path) { "/apps/fake/events" }
+ let(:request) { stub(path: path) }
+ let(:message) { "Unknown path: #{path}" }
+ let(:response) { mock }
+ let(:environment) { mock }
+
+ before do
+ subject.stubs(:unknown_path).raises(message)
+
+ response.stubs(finish: response)
+
+ Rack::Request.stubs(new: request)
+ Rack::Response.stubs(new: response)
+ end
+
+ subject { PusherFake::Server::Application }
+
+ it "creates a request" do
+ subject.call(environment)
+ Rack::Request.should have_received(:new).with(environment)
+ end
+
+ it "calls unknown_path with the path" do
+ subject.call(environment)
+ subject.should have_received(:unknown_path).with(request.path)
+ end
+
+ it "creates a Rack response with the error message" do
+ subject.call(environment)
+ Rack::Response.should have_received(:new).with(message, 400)
+ end
+
+ it "finishes the response" do
+ subject.call(environment)
+ response.should have_received(:finish).with()
+ end
+
+ it "returns the response" do
+ subject.call(environment).should == response
+ end
+end
+
describe PusherFake::Server::Application, ".call, raising an error" do
let(:id) { PusherFake.configuration.app_id }
let(:path) { "/apps/#{id}/channels" }
@@ -229,9 +272,9 @@
subject { PusherFake::Server::Application }
it "raises an error" do
- lambda {
+ expect {
subject.channels(request)
- }.should raise_error(subject::CHANNEL_FILTER_ERROR)
+ }.to raise_error(subject::CHANNEL_FILTER_ERROR)
end
end
@@ -309,9 +352,9 @@
subject { PusherFake::Server::Application }
it "raises an error" do
- lambda {
+ expect {
subject.channel("public-1", request)
- }.should raise_error(subject::CHANNEL_USER_COUNT_ERROR)
+ }.to raise_error(subject::CHANNEL_USER_COUNT_ERROR)
end
end
@@ -365,3 +408,31 @@
subject.users("fake").should == { users: [] }
end
end
+
+describe PusherFake::Server::Application, ".unknown_path" do
+ let(:path) { "/apps/fake/events" }
+ let(:logger) { stub(error: true) }
+ let(:message) { "Unknown path: #{path}" }
+
+ before do
+ Logger.stubs(new: logger)
+ end
+
+ subject { PusherFake::Server::Application }
+
+ it "creates a logger" do
+ expect { subject.unknown_path(path) }.to raise_error
+ Logger.should have_received(:new).with(STDOUT)
+ end
+
+ it "logs the error message" do
+ expect { subject.unknown_path(path) }.to raise_error
+ logger.should have_received(:error).with(message)
+ end
+
+ it "raises an error" do
+ expect {
+ subject.unknown_path(path)
+ }.to raise_error(message)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.