active_pubsub 0.0.5 → 0.0.6

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: bcd064945fb467cc30fd67d30c752ef2a519dff0
4
- data.tar.gz: e96a5f3b33bc9f1479f28b2633bf9e81c40e57d1
3
+ metadata.gz: e22f01f9cf4b2f63a384b21e4aa28b9623ef20b0
4
+ data.tar.gz: 2376b5d7171510a5087cfb021c50d105f0d480f3
5
5
  SHA512:
6
- metadata.gz: bc686f2b420a0b8640bcc7a27fc49a28388541c4975bd0392aa4cbc62eb269bb303a35d4ef948b90daf467896239ec0f6fb803a2391d6520e20b195193f069ef
7
- data.tar.gz: 131fc0cb89d24fae8ee7248a72c07dad38e642c7ec2f01666a4e7fb68fd2cc19703ac188d8a2141a929bbd971ad5e08f705907c2104f36b32b28ea23a071ddf9
6
+ metadata.gz: f4fd96f0626db35b97853c803f8af0ace6746cce0910159187f18b504ddb3e6dbd1462d8f7ab9468f5d07c3090b0056aa24e61c52f8b0600a2ee3e72a0d1a7df
7
+ data.tar.gz: bb359a492946e1c60ca0d6cac8c50498c03573a3f03bc712bcfead4792915b8395fc51c0f5670a5994142439fc37bc6f258bd1c19f1b54c19688169eec541cf9
@@ -38,5 +38,6 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency 'guard-bundler', '~> 2'
39
39
  spec.add_development_dependency 'rb-fsevent'
40
40
  spec.add_development_dependency 'terminal-notifier-guard'
41
+ spec.add_development_dependency "active_model_serializers"
41
42
 
42
43
  end
@@ -2,18 +2,22 @@ module ActivePubsub
2
2
  module PublishWithSerializer
3
3
  extend ActiveSupport::Concern
4
4
 
5
- #todo: move this into separate gem
5
+ #todo: move this into separate gem?
6
6
 
7
7
  included do
8
8
  class_attribute :publish_serializer
9
9
  end
10
10
 
11
11
  def serialized_resource
12
- serialized_resource_attributes = self.class.publish_serializer.new(self).attributes
13
- serialized_resource_attributes.merge!("changes" => changes) if self.changed?
12
+ serialized_resource_attributes.merge!(:changes => previous_changes) if previous_changes
13
+
14
14
  ::Marshal.dump(serialized_resource_attributes)
15
15
  end
16
16
 
17
+ def serialized_resource_attributes
18
+ @serialized_resource_attributes ||= self.class.publish_serializer.new(self).attributes
19
+ end
20
+
17
21
  module ClassMethods
18
22
  def serialize_publish_with(klass)
19
23
  self.publish_serializer = klass
@@ -17,8 +17,11 @@ module ActivePubsub
17
17
  ::ActivePubsub::Publisher.increment_publishable_model_count!
18
18
  end
19
19
 
20
+ ### todo: investigate why specs break if && hash is omitted
20
21
  def attributes_hash
21
- attributes.merge!("changes" => changes)
22
+ hash = self.as_json
23
+ hash.merge!(:changes => previous_changes) if previous_changes && hash
24
+ hash
22
25
  end
23
26
 
24
27
  private
@@ -1,3 +1,3 @@
1
1
  module ActivePubsub
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::ActivePubsub::PublishWithSerializer do
4
+ subject { ::Fake::Blog::Author }
5
+ let(:publisher) { ::ActivePubsub.publisher }
6
+
7
+ context "ClassMethods" do
8
+ its(:publish_serializer) { should eq ::AuthorSerializer }
9
+ end
10
+
11
+ context "InstanceMethods" do
12
+ subject{ ::Fake::Blog::Author.new(:first_name => "whatever") }
13
+
14
+ its (:serialized_resource_attributes) { should have_key(:first_name) }
15
+
16
+ describe "#serialized_resource" do
17
+ it "should dump serialized resource attributes" do
18
+ Marshal.should_receive(:dump).with(subject.serialized_resource_attributes)
19
+
20
+ subject.serialized_resource
21
+ end
22
+ end
23
+ end
24
+ end
@@ -11,6 +11,24 @@ describe ::ActivePubsub::Publishable do
11
11
  end
12
12
 
13
13
  context "Instance Methods" do
14
+ describe "#attributes_hash" do
15
+ #had to do some hackyness in attributes_hash method to get this to pass
16
+ #and not sure why, but as_json was coming back nil
17
+ it "should call as json" do
18
+ instance_subject.should_receive(:as_json)
19
+
20
+ instance_subject.attributes_hash
21
+ end
22
+
23
+ context "when attributes are changed" do
24
+ let(:created_record) { ::Fake::Blog::Post.create!(:title => "Post about nothing") }
25
+
26
+ it "should merge previous changes" do
27
+ expect(created_record.attributes_hash).to have_key("title")
28
+ end
29
+ end
30
+ end
31
+
14
32
  describe "#publish_updated_event" do
15
33
  let(:created_record) { ::Fake::Blog::Post.create!(:title => "Post about nothing") }
16
34
 
@@ -18,4 +18,13 @@ ActiveRecord::Schema.define(:version => 1) do
18
18
 
19
19
  t.timestamps
20
20
  end
21
- end
21
+
22
+ create_table :authors do |t|
23
+ t.string :first_name
24
+ t.string :last_name
25
+ t.string :slug
26
+ t.integer :user_id
27
+
28
+ t.timestamps
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ require 'active_record'
2
+ require_relative '../../support/serializers/author_serializer.rb'
3
+ module Fake
4
+ module Blog
5
+ class Author < ::ActiveRecord::Base
6
+ include ::ActivePubsub::Publishable
7
+ include ::ActivePubsub::PublishWithSerializer
8
+
9
+ serialize_publish_with ::AuthorSerializer
10
+
11
+ publish_as "test"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ class AuthorSerializer < ActiveModel::Serializer
2
+ attributes :id, :first_name
3
+ end
@@ -0,0 +1 @@
1
+ require 'support/serializers/author_serializer'
data/spec/test.db CHANGED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Ayre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-16 00:00:00.000000000 Z
11
+ date: 2014-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_attr
@@ -276,6 +276,20 @@ dependencies:
276
276
  - - ">="
277
277
  - !ruby/object:Gem::Version
278
278
  version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: active_model_serializers
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
279
293
  description: Uses RabbitMQ and ActiveRecord for publishing and consuming model events
280
294
  from any service
281
295
  email:
@@ -308,12 +322,16 @@ files:
308
322
  - lib/active_pubsub/version.rb
309
323
  - spec/active_pubsub/config_spec.rb
310
324
  - spec/active_pubsub/connection_spec.rb
325
+ - spec/active_pubsub/publish_with_serializer_spec.rb
311
326
  - spec/active_pubsub/publishable_spec.rb
312
327
  - spec/active_pubsub/publisher_spec.rb
313
328
  - spec/spec_helper.rb
314
329
  - spec/support/db/setup.rb
315
330
  - spec/support/models.rb
331
+ - spec/support/models/author.rb
316
332
  - spec/support/models/post.rb
333
+ - spec/support/serializers.rb
334
+ - spec/support/serializers/author_serializer.rb
317
335
  - spec/test.db
318
336
  homepage: https://github.com/jasonayre/active_pubsub
319
337
  licenses:
@@ -343,10 +361,14 @@ summary: Pubsub using RabbitMQ and ActiveRecord, observe model events from diffe
343
361
  test_files:
344
362
  - spec/active_pubsub/config_spec.rb
345
363
  - spec/active_pubsub/connection_spec.rb
364
+ - spec/active_pubsub/publish_with_serializer_spec.rb
346
365
  - spec/active_pubsub/publishable_spec.rb
347
366
  - spec/active_pubsub/publisher_spec.rb
348
367
  - spec/spec_helper.rb
349
368
  - spec/support/db/setup.rb
350
369
  - spec/support/models.rb
370
+ - spec/support/models/author.rb
351
371
  - spec/support/models/post.rb
372
+ - spec/support/serializers.rb
373
+ - spec/support/serializers/author_serializer.rb
352
374
  - spec/test.db