magellan-rails 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 332b7e16cca102a6a4147f905d19e3e4a3e5e664
4
- data.tar.gz: ec9343f83483a86de1766b7548990bd5af5b8e68
3
+ metadata.gz: 8c421c287c6fa5f5c8f5b6ef25b7b3f99bfae56e
4
+ data.tar.gz: 0c895a7553fa8799cd237631a549ebd8c44206b5
5
5
  SHA512:
6
- metadata.gz: 5df36c50d2f67c599e64f36186d1db49be0d4e7480a160b8cdef4fa059362c0fdc2d5560aabb0d50a2cc2f722a0281248ec91895854df1443e5a7144cd32fb50
7
- data.tar.gz: f9c486e2431466fae90720cfcdae438d1f5ff222e02d5012077d427e5cdc00cd3d14f098911d50639a695fbfd8760df9f836a7d2a7afe46db98636bcc4d64694
6
+ metadata.gz: 36dfd7b680d8689dc06111cb67a366946fc4b0a9385a17f34d0af9dd0d5672de56bbc877c21fa1f2b4f9459585378d062bc2b23d39313b1860d00542fb380053
7
+ data.tar.gz: 1e9474777f528152bb2913dbb43eb750c65ebb7c827d3ebc058b81fc0c7bdbb4b39d8166dd5ad76d0e991b1848cc84c3da4796f9039e948c9182e9474b295cc8
@@ -1,5 +1,5 @@
1
1
  module Magellan
2
2
  module Rails
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -23,7 +23,16 @@ class Magellan::Worker::Executor
23
23
  end
24
24
 
25
25
  def execute(reply_to, correlation_id, delivery_tag, request_message)
26
- case request_message["headers"]["Method"]
26
+ version = request_message["v"] || 1
27
+ case version
28
+ when 1
29
+ request_method = request_message["headers"]["Method"]
30
+ when 2
31
+ request_method = request_message["env"]["METHOD"]
32
+ else
33
+ raise "Unsupported request format version: #{version}. Please update magellan-rails."
34
+ end
35
+ case request_method
27
36
  when /\Apublish\z/i
28
37
  subscriber_executor.execute(request_message)
29
38
  else
@@ -0,0 +1,67 @@
1
+ # coding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Magellan::Worker::Executor do
6
+
7
+ describe "#execute" do
8
+ let(:exchange) do double(:exchange) end
9
+ let(:reply_to) do double(:reply_to) end
10
+ let(:correlation_id) do double(:correlation_id) end
11
+ let(:delivery_tag) do double(:delivery_tag) end
12
+ let(:rails_executor) do double(:rails_executor) end
13
+ let(:subscriber_executor) do double(:subscriber_executor) end
14
+ let(:executor) do
15
+ Magellan::Worker::Executor.new(exchange).tap do |e|
16
+ e.instance_variable_set :@rails_executor, rails_executor
17
+ e.instance_variable_set :@subscriber_executor, subscriber_executor
18
+ end
19
+ end
20
+ before do
21
+ allow_any_instance_of(Magellan::Worker::Executor).to receive(:require)
22
+ end
23
+
24
+ context "v1" do
25
+ let(:request_obj) do { "headers" => { "Method" => @method, "Path-Info" => "topic" }, "body" => "payload" } end
26
+ context "GET" do
27
+ before do
28
+ @method = "GET"
29
+ expect(rails_executor).to receive(:execute).with(reply_to, correlation_id, delivery_tag, request_obj).and_return(:result)
30
+ end
31
+ it do
32
+ expect(executor.execute(reply_to, correlation_id, delivery_tag, request_obj)).to eql(:result)
33
+ end
34
+ end
35
+ context "PUBLISH" do
36
+ before do
37
+ @method = "PUBLISH"
38
+ expect(subscriber_executor).to receive(:execute).with(request_obj).and_return(:result)
39
+ end
40
+ it do
41
+ expect(executor.execute(reply_to, correlation_id, delivery_tag, request_obj)).to eql(:result)
42
+ end
43
+ end
44
+ end
45
+ context "v2" do
46
+ let(:request_obj) do { "v" => 2, "env" => { "METHOD" => @method, "PATH_INFO" => "topic" }, "headers" => {}, "body" => "payload" } end
47
+ context "GET" do
48
+ before do
49
+ @method = "GET"
50
+ expect(rails_executor).to receive(:execute).with(reply_to, correlation_id, delivery_tag, request_obj).and_return(:result)
51
+ end
52
+ it do
53
+ expect(executor.execute(reply_to, correlation_id, delivery_tag, request_obj)).to eql(:result)
54
+ end
55
+ end
56
+ context "PUBLISH" do
57
+ before do
58
+ @method = "PUBLISH"
59
+ expect(subscriber_executor).to receive(:execute).with(request_obj).and_return(:result)
60
+ end
61
+ it do
62
+ expect(executor.execute(reply_to, correlation_id, delivery_tag, request_obj)).to eql(:result)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magellan-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuuki Noguchi
@@ -147,6 +147,7 @@ files:
147
147
  - spec/magellan/subscriber/mapper_spec.rb
148
148
  - spec/magellan/subscriber/request_spec.rb
149
149
  - spec/magellan/worker/core_spec.rb
150
+ - spec/magellan/worker/executor_spec.rb
150
151
  - spec/spec_helper.rb
151
152
  homepage: ''
152
153
  licenses:
@@ -178,4 +179,5 @@ test_files:
178
179
  - spec/magellan/subscriber/mapper_spec.rb
179
180
  - spec/magellan/subscriber/request_spec.rb
180
181
  - spec/magellan/worker/core_spec.rb
182
+ - spec/magellan/worker/executor_spec.rb
181
183
  - spec/spec_helper.rb