multiple_man 0.5.19 → 0.5.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/multiple_man.rb +4 -2
- data/lib/multiple_man/attribute_extractor.rb +20 -6
- data/lib/multiple_man/{listener.rb → listeners/listener.rb} +7 -6
- data/lib/multiple_man/{seeder_listener.rb → listeners/seeder_listener.rb} +1 -1
- data/lib/multiple_man/mixins/publisher.rb +8 -6
- data/lib/multiple_man/model_populator.rb +3 -1
- data/lib/multiple_man/model_publisher.rb +5 -33
- data/lib/multiple_man/payload_generator.rb +42 -0
- data/lib/multiple_man/tasks/worker.rake +2 -2
- data/lib/multiple_man/version.rb +1 -1
- data/multiple_man.gemspec +2 -0
- data/spec/attribute_extractor_spec.rb +9 -2
- data/spec/integration/ephermal_model_spec.rb +38 -0
- data/spec/{listener_spec.rb → listeners/listener_spec.rb} +18 -7
- data/spec/{seeder_listener_spec.rb → listeners/seeder_listener_spec.rb} +1 -1
- data/spec/model_populator_spec.rb +17 -0
- data/spec/model_publisher_spec.rb +2 -2
- data/spec/payload_generator_spec.rb +53 -0
- data/spec/spec_helper.rb +4 -0
- metadata +41 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0591b04188fa134c346891d8797b182f08a42f0d
|
4
|
+
data.tar.gz: 1a077b8c73e84f51203c4c7d2b6da4346278cc07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81995d16cc55a54ebffdde454fc01ae64fd02bc353a2acdaf9124e110253ffac287b8b47d7008903e5b28363e4e92622b73239b2d9b44e8eb126b8144cd6b7c0
|
7
|
+
data.tar.gz: 99602120d126845c63a7e8aee2d25c117abdd754e8f0837d0d3f56cffbdc1db779624a9721588cfd1644584bf792ff9ec0d6a54b12ef29188b5b10ad027321db
|
data/lib/multiple_man.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "multiple_man/version"
|
2
|
+
require 'active_support'
|
2
3
|
|
3
4
|
module MultipleMan
|
4
5
|
require 'multiple_man/railtie' if defined?(Rails)
|
@@ -11,10 +12,11 @@ module MultipleMan
|
|
11
12
|
require 'multiple_man/configuration'
|
12
13
|
require 'multiple_man/model_publisher'
|
13
14
|
require 'multiple_man/attribute_extractor'
|
15
|
+
require 'multiple_man/payload_generator'
|
14
16
|
require 'multiple_man/connection'
|
15
17
|
require 'multiple_man/routing_key'
|
16
|
-
require 'multiple_man/listener'
|
17
|
-
require 'multiple_man/seeder_listener'
|
18
|
+
require 'multiple_man/listeners/listener'
|
19
|
+
require 'multiple_man/listeners/seeder_listener'
|
18
20
|
require 'multiple_man/model_populator'
|
19
21
|
require 'multiple_man/identity'
|
20
22
|
require 'multiple_man/publish'
|
@@ -3,26 +3,40 @@ require 'json'
|
|
3
3
|
module MultipleMan
|
4
4
|
class AttributeExtractor
|
5
5
|
|
6
|
-
def initialize(record, fields)
|
6
|
+
def initialize(record, fields, include_previous = false)
|
7
7
|
raise "Fields must be specified" unless fields
|
8
8
|
|
9
|
+
self.include_previous = include_previous
|
9
10
|
self.record = record
|
10
11
|
self.fields = fields
|
11
12
|
end
|
12
13
|
|
14
|
+
def as_json
|
15
|
+
if include_previous
|
16
|
+
data.merge(previous_data)
|
17
|
+
else
|
18
|
+
data
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
13
24
|
def data
|
14
25
|
Hash[fields.map do |field|
|
15
|
-
[field, record.send(field)]
|
26
|
+
[field, record.send(field)]
|
16
27
|
end]
|
17
28
|
end
|
18
29
|
|
19
|
-
def
|
20
|
-
|
30
|
+
def previous_data
|
31
|
+
{ previous: Hash[fields.map do |field|
|
32
|
+
previous_data_method = "#{field}_was"
|
33
|
+
[field, record.send(previous_data_method)] if record.respond_to? previous_data_method
|
34
|
+
end.reject(&:nil?)]
|
35
|
+
}
|
21
36
|
end
|
22
37
|
|
23
|
-
private
|
24
38
|
|
25
|
-
attr_accessor :record, :fields, :identifier
|
39
|
+
attr_accessor :record, :fields, :identifier, :include_previous
|
26
40
|
|
27
41
|
end
|
28
42
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'active_support/core_ext/hash'
|
3
3
|
|
4
|
-
module MultipleMan
|
4
|
+
module MultipleMan::Listeners
|
5
5
|
class Listener
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def start
|
9
9
|
MultipleMan.logger.debug "Starting listeners."
|
10
|
-
MultipleMan.logger.debug Subscribers::Registry.subscriptions.to_json
|
10
|
+
MultipleMan.logger.debug MultipleMan::Subscribers::Registry.subscriptions.to_json
|
11
11
|
|
12
|
-
Subscribers::Registry.subscriptions.each do |subscription|
|
12
|
+
MultipleMan::Subscribers::Registry.subscriptions.each do |subscription|
|
13
13
|
new(subscription).listen
|
14
14
|
end
|
15
15
|
end
|
@@ -43,7 +43,8 @@ module MultipleMan
|
|
43
43
|
def process_message(delivery_info, payload)
|
44
44
|
MultipleMan.logger.info "Processing message for #{delivery_info.routing_key}."
|
45
45
|
begin
|
46
|
-
|
46
|
+
payload = JSON.parse(payload).with_indifferent_access
|
47
|
+
subscription.send(operation(delivery_info, payload), payload)
|
47
48
|
rescue Exception => ex
|
48
49
|
handle_error(ex, delivery_info)
|
49
50
|
else
|
@@ -60,8 +61,8 @@ module MultipleMan
|
|
60
61
|
queue.channel.nack(delivery_info.delivery_tag)
|
61
62
|
end
|
62
63
|
|
63
|
-
def operation(delivery_info)
|
64
|
-
delivery_info.routing_key.split(".").last
|
64
|
+
def operation(delivery_info, payload)
|
65
|
+
payload['operation'] || delivery_info.routing_key.split(".").last
|
65
66
|
end
|
66
67
|
|
67
68
|
def queue
|
@@ -4,21 +4,23 @@ module MultipleMan
|
|
4
4
|
module Publisher
|
5
5
|
def Publisher.included(base)
|
6
6
|
base.extend(ClassMethods)
|
7
|
-
base.
|
8
|
-
|
9
|
-
|
7
|
+
if base.respond_to?(:after_commit)
|
8
|
+
base.after_commit(on: :create) { |r| r.multiple_man_publish(:create) }
|
9
|
+
base.after_commit(on: :update) { |r| r.multiple_man_publish(:update) }
|
10
|
+
base.after_commit(on: :destroy) { |r| r.multiple_man_publish(:destroy) }
|
11
|
+
end
|
10
12
|
|
11
13
|
base.class_attribute :multiple_man_publisher
|
12
14
|
end
|
13
15
|
|
14
16
|
def multiple_man_publish(operation=:create)
|
15
|
-
self.class.multiple_man_publisher.publish(self, operation)
|
17
|
+
self.class.multiple_man_publisher.publish(self, operation)
|
16
18
|
end
|
17
19
|
|
18
20
|
module ClassMethods
|
19
|
-
|
21
|
+
|
20
22
|
def multiple_man_publish(operation=:create)
|
21
|
-
multiple_man_publisher.publish(self, operation)
|
23
|
+
multiple_man_publisher.publish(self, operation)
|
22
24
|
end
|
23
25
|
|
24
26
|
def publish(options = {})
|
@@ -24,7 +24,9 @@ module MultipleMan
|
|
24
24
|
|
25
25
|
def populate_field(field, value)
|
26
26
|
# Attempt to populate source id if id is specified
|
27
|
-
|
27
|
+
if field.to_s == 'id' && record.respond_to?('source_id')
|
28
|
+
field = 'source_id'
|
29
|
+
end
|
28
30
|
|
29
31
|
setter = "#{field}="
|
30
32
|
if record.respond_to?(setter)
|
@@ -22,10 +22,12 @@ module MultipleMan
|
|
22
22
|
attr_accessor :options
|
23
23
|
|
24
24
|
def push_record(connection, record, operation)
|
25
|
-
data =
|
26
|
-
routing_key = RoutingKey.new(
|
25
|
+
data = PayloadGenerator.new(record, operation, options)
|
26
|
+
routing_key = RoutingKey.new(data.type, operation).to_s
|
27
|
+
|
27
28
|
MultipleMan.logger.debug(" Record Data: #{data} | Routing Key: #{routing_key}")
|
28
|
-
|
29
|
+
|
30
|
+
connection.topic.publish(data.payload, routing_key: routing_key)
|
29
31
|
rescue Exception => ex
|
30
32
|
MultipleMan.error(ex)
|
31
33
|
end
|
@@ -40,35 +42,5 @@ module MultipleMan
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
|
-
|
44
|
-
def record_type(record)
|
45
|
-
options[:as] || record.class.name
|
46
|
-
end
|
47
|
-
|
48
|
-
def record_data(record)
|
49
|
-
{
|
50
|
-
id: Identity.build(record, options).value,
|
51
|
-
data: serializer(record).as_json
|
52
|
-
}.to_json
|
53
|
-
end
|
54
|
-
|
55
|
-
# Todo - can we unify the constructor for serializers
|
56
|
-
# and attribute extractors and simplify this?
|
57
|
-
def serializer(record)
|
58
|
-
if options[:with]
|
59
|
-
options[:with].new(record)
|
60
|
-
else
|
61
|
-
AttributeExtractor.new(record, fields)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def fields
|
66
|
-
options[:fields]
|
67
|
-
end
|
68
|
-
|
69
|
-
def identifier
|
70
|
-
options[:identifier]
|
71
|
-
end
|
72
|
-
|
73
45
|
end
|
74
46
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module MultipleMan
|
2
|
+
class PayloadGenerator
|
3
|
+
def initialize(record, operation = :create, options = {})
|
4
|
+
self.record = record
|
5
|
+
self.operation = operation.to_s
|
6
|
+
self.options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def payload
|
10
|
+
{
|
11
|
+
type: type,
|
12
|
+
operation: operation,
|
13
|
+
id: id,
|
14
|
+
data: data
|
15
|
+
}.to_json
|
16
|
+
end
|
17
|
+
|
18
|
+
def type
|
19
|
+
options[:as] || record.class.name
|
20
|
+
end
|
21
|
+
|
22
|
+
def id
|
23
|
+
Identity.build(record, options).value
|
24
|
+
end
|
25
|
+
|
26
|
+
def data
|
27
|
+
if options[:with]
|
28
|
+
options[:with].new(record).as_json
|
29
|
+
else
|
30
|
+
AttributeExtractor.new(record, options[:fields]).as_json
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_reader :operation
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_accessor :record, :options
|
39
|
+
attr_writer :operation
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
namespace :multiple_man do
|
2
2
|
desc "Run multiple man listeners"
|
3
3
|
task :worker => :environment do
|
4
|
-
run_listener(MultipleMan::Listener)
|
4
|
+
run_listener(MultipleMan::Listeners::Listener)
|
5
5
|
end
|
6
6
|
|
7
7
|
desc 'Run a seeding listener'
|
8
8
|
task seed: :environment do
|
9
|
-
run_listener(MultipleMan::SeederListener)
|
9
|
+
run_listener(MultipleMan::Listeners::SeederListener)
|
10
10
|
end
|
11
11
|
|
12
12
|
def run_listener(listener)
|
data/lib/multiple_man/version.rb
CHANGED
data/multiple_man.gemspec
CHANGED
@@ -19,8 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "pry"
|
22
23
|
spec.add_development_dependency "rake", '~> 10.1.0'
|
23
24
|
spec.add_development_dependency "rspec", '~> 2.14.1'
|
25
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
24
26
|
spec.add_runtime_dependency "bunny", '>= 1.2'
|
25
27
|
spec.add_runtime_dependency "activesupport", '>= 3.0'
|
26
28
|
spec.add_runtime_dependency "connection_pool", ">= 1.2"
|
@@ -4,8 +4,9 @@ describe MultipleMan::AttributeExtractor do
|
|
4
4
|
|
5
5
|
MockClass = Struct.new(:a, :b, :c, :id)
|
6
6
|
let(:object) { MockClass.new(1,2,3,10) }
|
7
|
-
subject { described_class.new(object, fields) }
|
7
|
+
subject { described_class.new(object, fields, include_previous) }
|
8
8
|
let(:fields) { nil }
|
9
|
+
let(:include_previous) { false }
|
9
10
|
|
10
11
|
context "without fields" do
|
11
12
|
it "should not be allowed" do
|
@@ -15,11 +16,17 @@ describe MultipleMan::AttributeExtractor do
|
|
15
16
|
|
16
17
|
context "with fields" do
|
17
18
|
let(:fields) { [:a, :c] }
|
18
|
-
its(:data) { should == {a: 1, c: 3}}
|
19
19
|
its(:as_json) { should == {
|
20
20
|
a: 1,
|
21
21
|
c: 3
|
22
22
|
} }
|
23
23
|
end
|
24
|
+
|
25
|
+
context "including old fields" do
|
26
|
+
let(:object) { Struct.new(:a,:b,:a_was,:b_was).new("new_a", "new_b", "old_a", "old_b") }
|
27
|
+
let(:fields) { [:a, :b] }
|
28
|
+
let(:include_previous) { true }
|
29
|
+
its(:as_json) { should == {a: 'new_a', b: 'new_b', previous: { a: 'old_a', b: 'old_b' }}}
|
30
|
+
end
|
24
31
|
|
25
32
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Publishing of ephermal models" do
|
4
|
+
let(:ephermal_class) do
|
5
|
+
Class.new do
|
6
|
+
def self.name
|
7
|
+
'Ephermal'
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :foo, :bar, :baz, :id
|
11
|
+
def initialize(params)
|
12
|
+
self.id = params[:id]
|
13
|
+
self.foo = params[:foo]
|
14
|
+
self.bar = params[:bar]
|
15
|
+
self.baz = params[:baz]
|
16
|
+
end
|
17
|
+
|
18
|
+
include MultipleMan::Publisher
|
19
|
+
publish fields: [:foo, :bar, :baz]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should publish properly" do
|
24
|
+
obj = ephermal_class.new(id: 5, foo: 'foo', bar: 'bar', baz: 'baz')
|
25
|
+
|
26
|
+
payload = {
|
27
|
+
type: 'Ephermal',
|
28
|
+
operation: 'create',
|
29
|
+
id: { id: 5 },
|
30
|
+
data: { foo: 'foo', bar: 'bar', baz: 'baz'}
|
31
|
+
}.to_json
|
32
|
+
expect_any_instance_of(Bunny::Exchange).to receive(:publish)
|
33
|
+
.with(payload, routing_key: 'multiple_man.Ephermal.create')
|
34
|
+
|
35
|
+
obj.multiple_man_publish(:create)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe MultipleMan::Listener do
|
3
|
+
describe MultipleMan::Listeners::Listener do
|
4
4
|
class MockClass1; end
|
5
5
|
class MockClass2; end
|
6
6
|
|
@@ -13,14 +13,14 @@ describe MultipleMan::Listener do
|
|
13
13
|
mock2 = double(MultipleMan::Subscribers::ModelSubscriber, klass: MockClass2)
|
14
14
|
])
|
15
15
|
|
16
|
-
mock_listener = double(
|
17
|
-
|
16
|
+
mock_listener = double(described_class)
|
17
|
+
described_class.should_receive(:new).twice.and_return(mock_listener)
|
18
18
|
|
19
19
|
# Would actually be two seperate objects in reality, this is for
|
20
20
|
# ease of stubbing.
|
21
21
|
mock_listener.should_receive(:listen).twice
|
22
22
|
|
23
|
-
|
23
|
+
described_class.start
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -32,7 +32,7 @@ describe MultipleMan::Listener do
|
|
32
32
|
before { MultipleMan::Connection.stub(:new).and_return(connection_stub) }
|
33
33
|
|
34
34
|
it "should listen to the right topic, and for all updates to a model" do
|
35
|
-
listener =
|
35
|
+
listener = described_class.new(double(MultipleMan::Subscribers::ModelSubscriber, klass: MockClass1, routing_key: "MockClass1.#", queue_name: "MockClass1"))
|
36
36
|
queue_stub.should_receive(:bind).with('app', routing_key: "MockClass1.#")
|
37
37
|
listener.listen
|
38
38
|
end
|
@@ -42,18 +42,29 @@ describe MultipleMan::Listener do
|
|
42
42
|
connection_stub = double(MultipleMan::Connection).as_null_object
|
43
43
|
MultipleMan::Connection.stub(:new).and_return(connection_stub)
|
44
44
|
subscriber = double(MultipleMan::Subscribers::ModelSubscriber, klass: MockClass1, routing_key: "MockClass1.#").as_null_object
|
45
|
-
listener =
|
45
|
+
listener = described_class.new(subscriber)
|
46
46
|
|
47
47
|
connection_stub.should_receive(:acknowledge)
|
48
48
|
subscriber.should_receive(:create).with({"a" => 1, "b" => 2})
|
49
49
|
listener.process_message(OpenStruct.new(routing_key: "app.MockClass1.create"), '{"a":1,"b":2}')
|
50
50
|
end
|
51
51
|
|
52
|
+
specify "process_message should use the payload to determine the operation if it's available" do
|
53
|
+
connection_stub = double(MultipleMan::Connection).as_null_object
|
54
|
+
MultipleMan::Connection.stub(:new).and_return(connection_stub)
|
55
|
+
subscriber = double(MultipleMan::Subscribers::ModelSubscriber, klass: MockClass1, routing_key: "MockClass1.#").as_null_object
|
56
|
+
listener = described_class.new(subscriber)
|
57
|
+
|
58
|
+
connection_stub.should_receive(:acknowledge)
|
59
|
+
subscriber.should_receive(:create)
|
60
|
+
listener.process_message(OpenStruct.new(routing_key: "some random routing key"), '{"operation":"create","data":{"a":1,"b":2}}')
|
61
|
+
end
|
62
|
+
|
52
63
|
it "should nack on failure" do
|
53
64
|
connection_stub = double(MultipleMan::Connection).as_null_object
|
54
65
|
MultipleMan::Connection.stub(:new).and_return(connection_stub)
|
55
66
|
subscriber = double(MultipleMan::Subscribers::ModelSubscriber, klass: MockClass1, routing_key: "MockClass1.#").as_null_object
|
56
|
-
listener =
|
67
|
+
listener = described_class.new(subscriber)
|
57
68
|
|
58
69
|
connection_stub.should_receive(:nack)
|
59
70
|
MultipleMan.should_receive(:error)
|
@@ -27,6 +27,23 @@ describe MultipleMan::ModelPopulator do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
|
+
context "record has source id" do
|
31
|
+
let(:model) { Class.new do
|
32
|
+
attr_accessor :source_id, :id
|
33
|
+
end.new }
|
34
|
+
let(:data) { { id: 1 }}
|
35
|
+
|
36
|
+
its(:source_id) { should == 1 }
|
37
|
+
its(:id) { should be_nil }
|
38
|
+
end
|
39
|
+
context "record does not have source id" do
|
40
|
+
let(:model) { Class.new do
|
41
|
+
attr_accessor :id
|
42
|
+
end.new }
|
43
|
+
let(:data) { { id: 1 }}
|
44
|
+
|
45
|
+
its(:id) { should == 1 }
|
46
|
+
end
|
30
47
|
context "without fields defined" do
|
31
48
|
let(:fields) { nil }
|
32
49
|
|
@@ -30,7 +30,7 @@ describe MultipleMan::ModelPublisher do
|
|
30
30
|
describe "publish" do
|
31
31
|
it "should send the jsonified version of the model to the correct routing key" do
|
32
32
|
MultipleMan::AttributeExtractor.any_instance.should_receive(:as_json).and_return({foo: "bar"})
|
33
|
-
topic_stub.should_receive(:publish).with('{"id":{"id":10},"data":{"foo":"bar"}}', routing_key: "app.MockObject.create")
|
33
|
+
topic_stub.should_receive(:publish).with('{"type":"MockObject","operation":"create","id":{"id":10},"data":{"foo":"bar"}}', routing_key: "app.MockObject.create")
|
34
34
|
described_class.new(fields: [:foo]).publish(MockObject.new)
|
35
35
|
end
|
36
36
|
|
@@ -55,7 +55,7 @@ describe MultipleMan::ModelPublisher do
|
|
55
55
|
|
56
56
|
it "should get its data from the serializer" do
|
57
57
|
obj = MockObject.new
|
58
|
-
topic_stub.should_receive(:publish).with('{"id":{"id":10},"data":{"a":"yes"}}', routing_key: "app.MockObject.create")
|
58
|
+
topic_stub.should_receive(:publish).with('{"type":"MockObject","operation":"create","id":{"id":10},"data":{"a":"yes"}}', routing_key: "app.MockObject.create")
|
59
59
|
subject.publish(obj)
|
60
60
|
end
|
61
61
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MultipleMan::PayloadGenerator do
|
4
|
+
class PayloadMockClass < Struct.new(:foo, :bar)
|
5
|
+
end
|
6
|
+
|
7
|
+
let(:mock_object) { PayloadMockClass.new(1,2) }
|
8
|
+
|
9
|
+
describe "operation" do
|
10
|
+
it "should be whatever was passed in" do
|
11
|
+
expect(described_class.new(mock_object, :update).operation).to eq('update')
|
12
|
+
end
|
13
|
+
it "should be create by default" do
|
14
|
+
expect(described_class.new(mock_object).operation).to eq('create')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "data" do
|
19
|
+
context "with a serializer" do
|
20
|
+
it "should return stuff from the serializer" do
|
21
|
+
serializer = Struct.new(:record) do
|
22
|
+
def as_json
|
23
|
+
{a: 1, b: 2}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
described_class.new(mock_object, :create, {with: serializer}).data.should == {a: 1, b: 2}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
context "without a serializer" do
|
31
|
+
it "should call the attribute extractor" do
|
32
|
+
MultipleMan::AttributeExtractor.any_instance.stub(:as_json).and_return({c: 3, d: 4})
|
33
|
+
described_class.new(mock_object, :create, { fields: [:c, :d] }).data.should == {c: 3, d: 4}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "id" do
|
39
|
+
it "should defer to identity" do
|
40
|
+
MultipleMan::Identity::MultipleField.any_instance.stub(:value).and_return("foo_1")
|
41
|
+
described_class.new(mock_object).id.should == "foo_1"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "record_type" do
|
46
|
+
it "should use the as option if available" do
|
47
|
+
expect(described_class.new(mock_object).type).to eq("PayloadMockClass")
|
48
|
+
end
|
49
|
+
it "should use the class otherwise" do
|
50
|
+
expect(described_class.new(mock_object, :create, { as: 'FooClass'}).type).to eq("FooClass")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multiple_man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Brunner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: 2.14.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: codeclimate-test-reporter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: bunny
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,15 +140,16 @@ files:
|
|
112
140
|
- lib/multiple_man/configuration.rb
|
113
141
|
- lib/multiple_man/connection.rb
|
114
142
|
- lib/multiple_man/identity.rb
|
115
|
-
- lib/multiple_man/listener.rb
|
143
|
+
- lib/multiple_man/listeners/listener.rb
|
144
|
+
- lib/multiple_man/listeners/seeder_listener.rb
|
116
145
|
- lib/multiple_man/mixins/publisher.rb
|
117
146
|
- lib/multiple_man/mixins/subscriber.rb
|
118
147
|
- lib/multiple_man/model_populator.rb
|
119
148
|
- lib/multiple_man/model_publisher.rb
|
149
|
+
- lib/multiple_man/payload_generator.rb
|
120
150
|
- lib/multiple_man/publish.rb
|
121
151
|
- lib/multiple_man/railtie.rb
|
122
152
|
- lib/multiple_man/routing_key.rb
|
123
|
-
- lib/multiple_man/seeder_listener.rb
|
124
153
|
- lib/multiple_man/subscribers/base.rb
|
125
154
|
- lib/multiple_man/subscribers/model_subscriber.rb
|
126
155
|
- lib/multiple_man/subscribers/registry.rb
|
@@ -130,13 +159,15 @@ files:
|
|
130
159
|
- spec/attribute_extractor_spec.rb
|
131
160
|
- spec/connection_spec.rb
|
132
161
|
- spec/identity_spec.rb
|
133
|
-
- spec/
|
162
|
+
- spec/integration/ephermal_model_spec.rb
|
163
|
+
- spec/listeners/listener_spec.rb
|
164
|
+
- spec/listeners/seeder_listener_spec.rb
|
134
165
|
- spec/logger_spec.rb
|
135
166
|
- spec/model_populator_spec.rb
|
136
167
|
- spec/model_publisher_spec.rb
|
168
|
+
- spec/payload_generator_spec.rb
|
137
169
|
- spec/publisher_spec.rb
|
138
170
|
- spec/routing_key_spec.rb
|
139
|
-
- spec/seeder_listener_spec.rb
|
140
171
|
- spec/spec_helper.rb
|
141
172
|
- spec/subscriber_spec.rb
|
142
173
|
- spec/subscribers/base_spec.rb
|
@@ -170,13 +201,15 @@ test_files:
|
|
170
201
|
- spec/attribute_extractor_spec.rb
|
171
202
|
- spec/connection_spec.rb
|
172
203
|
- spec/identity_spec.rb
|
173
|
-
- spec/
|
204
|
+
- spec/integration/ephermal_model_spec.rb
|
205
|
+
- spec/listeners/listener_spec.rb
|
206
|
+
- spec/listeners/seeder_listener_spec.rb
|
174
207
|
- spec/logger_spec.rb
|
175
208
|
- spec/model_populator_spec.rb
|
176
209
|
- spec/model_publisher_spec.rb
|
210
|
+
- spec/payload_generator_spec.rb
|
177
211
|
- spec/publisher_spec.rb
|
178
212
|
- spec/routing_key_spec.rb
|
179
|
-
- spec/seeder_listener_spec.rb
|
180
213
|
- spec/spec_helper.rb
|
181
214
|
- spec/subscriber_spec.rb
|
182
215
|
- spec/subscribers/base_spec.rb
|