1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
require "spec_helper"
describe "server publish" do
let(:engine) { double "engine" }
let(:server) { Faye::Server.new }
let(:message) { { "channel" => "/some/channel", "data" => "publish" } }
before do
Faye::Engine.stub(:get).and_return engine
end
describe "publishing a message" do
it "tells the engine to publish the message" do
engine.should_receive(:publish).with(message)
server.process(message, false) {}
end
it "returns a successful response" do
engine.stub(:publish)
server.process(message, false) do |response|
response.should == [
{ "channel" => "/some/channel",
"successful" => true
}
]
end
end
describe "with an invalid channel" do
before { message["channel"] = "channel" }
it "does not tell the engine to publish the message" do
engine.should_not_receive(:publish)
server.process(message, false) {}
end
it "returns an unsuccessful response" do
engine.stub(:publish)
server.process(message, false) do |response|
response.should == [
{ "channel" => "channel",
"successful" => false,
"error" => "405:channel:Invalid channel"
}
]
end
end
end
describe "with no data" do
before { message.delete("data") }
it "does not tell the engine to publish the message" do
engine.should_not_receive(:publish)
server.process(message, false) {}
end
it "returns an unsuccessful response" do
engine.stub(:publish)
server.process(message, false) do |response|
response.should == [
{ "channel" => "/some/channel",
"successful" => false,
"error" => "402:data:Missing required parameter"
}
]
end
end
end
describe "with an error" do
before { message["error"] = "invalid" }
it "does not tell the engine to publish the message" do
engine.should_not_receive(:publish)
server.process(message, false) {}
end
it "returns an unsuccessful response" do
engine.stub(:publish)
server.process(message, false) do |response|
response.should == [
{ "channel" => "/some/channel",
"successful" => false,
"error" => "invalid"
}
]
end
end
end
describe "to an invalid channel" do
before { message["channel"] = "/invalid/*" }
it "does not tell the engine to publish the message" do
engine.should_not_receive(:publish)
server.process(message, false) {}
end
end
end
end
|