spec/mandrill/web_hook/processor_spec.rb in mandrill-rails-1.0.2 vs spec/mandrill/web_hook/processor_spec.rb in mandrill-rails-1.1.0
- old
+ new
@@ -18,24 +18,73 @@
processor.should_receive(:handle_inbound).twice
processor.run!
end
end
context "with callback host" do
- let(:callback_host) do
- host = double()
- host.stub(:handle_inbound)
- host
+ shared_examples_for 'pass event payload to the handler' do
+
end
+
+ let(:callback_host) { callback_host_class.new }
let(:processor) { processor_class.new(params,callback_host) }
let(:event1) { { "event" => "inbound" } }
let(:event2) { { "event" => "inbound" } }
let(:params) { { "mandrill_events" => [event1,event2].to_json } }
- it "should pass event payload to the handler" do
- callback_host.should_receive(:handle_inbound).twice
- processor.run!
+
+ context "with handler method as public" do
+ let(:callback_host_class) do
+ Class.new do
+ public
+
+ def handle_inbound; end
+ end
+ end
+
+ it "should pass event payload to the handler" do
+ callback_host.should_receive(:handle_inbound).twice
+ processor.run!
+ end
end
+ context "with handler method as protected" do
+ let(:callback_host_class) do
+ Class.new do
+ protected
+
+ def handle_inbound; end
+ end
+ end
+
+ it "should pass event payload to the handler" do
+ callback_host.should_receive(:handle_inbound).twice
+ processor.run!
+ end
+ end
+ context "with handler method as private" do
+ let(:callback_host_class) do
+ Class.new do
+ private
+
+ def handle_inbound; end
+ end
+ end
+
+ it "should pass event payload to the handler" do
+ callback_host.should_receive(:handle_inbound).twice
+ processor.run!
+ end
+ end
end
+ context "without handler method" do
+ let(:event1) { { "event" => "inbound" } }
+ let(:event2) { { "event" => "inbound" } }
+ let(:params) { { "mandrill_events" => [event1,event2].to_json } }
+
+ it "raises error on run!" do
+ expect { processor.run! }
+ .to raise_error(Mandrill::Rails::Errors::MissingEventHandler)
+ end
+ end
end
describe "#wrap_payload" do
let(:raw_payload) { {} }
subject { processor.wrap_payload(raw_payload) }
@@ -77,6 +126,6 @@
let(:params) { example_payload['raw_params'] }
subject { processor_class.generate_signature(webhook_key, original_url, params) }
it { should eql(expected_signature) }
end
-end
\ No newline at end of file
+end