protobuf-activerecord 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -52,7 +52,8 @@ module Protoable
52
52
 
53
53
  attributes = attribute_fields.inject({}) do |hash, (key, value)|
54
54
  if _protobuf_attribute_transformers.has_key?(key)
55
- hash[key] = _protobuf_attribute_transformers[key].call(proto)
55
+ attribute = _protobuf_attribute_transformers[key].call(proto)
56
+ hash[key] = attribute unless attribute.nil?
56
57
  else
57
58
  hash[key] = _protobuf_convert_fields_to_columns(key, value)
58
59
  end
@@ -1,5 +1,5 @@
1
1
  module Protobuf
2
2
  module ActiveRecord
3
- VERSION = "1.2.0"
3
+ VERSION = "1.2.1"
4
4
  end
5
5
  end
@@ -38,6 +38,34 @@ describe Protoable::Persistence do
38
38
  end
39
39
  end
40
40
 
41
+ context "when a transformer is a callable that returns nil" do
42
+ before do
43
+ transformers = User._protobuf_attribute_transformers
44
+ User.stub(:_protobuf_attribute_transformers).and_return(
45
+ {:account_id => lambda { |proto| nil }}.merge(transformers)
46
+ )
47
+ end
48
+
49
+ it "does not set the attribute" do
50
+ attribute_fields = User.attributes_from_proto(proto)
51
+ attribute_fields.should eq user_attributes
52
+ end
53
+ end
54
+
55
+ context "when a transformer is a callable that returns a value" do
56
+ before do
57
+ transformers = User._protobuf_attribute_transformers
58
+ User.stub(:_protobuf_attribute_transformers).and_return(
59
+ {:account_id => lambda { |proto| 1 }}.merge(transformers)
60
+ )
61
+ end
62
+
63
+ it "sets the attribute" do
64
+ attribute_fields = User.attributes_from_proto(proto)
65
+ attribute_fields.should eq user_attributes.merge(:account_id => 1)
66
+ end
67
+ end
68
+
41
69
  context "when a transformer is not defined for the attribute" do
42
70
  before {
43
71
  User.stub(:_protobuf_convert_fields_to_columns) do |key, value|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -240,7 +240,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
240
240
  version: '0'
241
241
  segments:
242
242
  - 0
243
- hash: -2528683046288754753
243
+ hash: 3146829003992540419
244
244
  required_rubygems_version: !ruby/object:Gem::Requirement
245
245
  none: false
246
246
  requirements:
@@ -249,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
249
  version: '0'
250
250
  segments:
251
251
  - 0
252
- hash: -2528683046288754753
252
+ hash: 3146829003992540419
253
253
  requirements: []
254
254
  rubyforge_project:
255
255
  rubygems_version: 1.8.24