protobuf-activerecord 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/protobuf/active_record/transformation.rb +1 -0
- data/lib/protobuf/active_record/version.rb +1 -1
- data/spec/protobuf/active_record/serialization_spec.rb +5 -5
- data/spec/protobuf/active_record/transformation_spec.rb +8 -3
- data/spec/support/definitions/user.proto +1 -0
- data/spec/support/models/user.rb +3 -0
- data/spec/support/protobuf/user.pb.rb +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9447a65d47084decc7ffdf256ca74e0fd75769a5
|
4
|
+
data.tar.gz: 81d3ea3553ddf7822a45201f95222052a5489870
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 632140c448d6c4aba6ea2b633b65edf6165808b449303010160d84321167e8ab5a899d2825d74190ff9170684c43057e77fee34857cab2d3403e11cad50b84f4
|
7
|
+
data.tar.gz: 8be6c87c0e15dcd912317de22cac86bad107dc3c3c80b91ca4611c970c7eb80921483dd73b5067ace2a8d24bdab4b354ee0dd3d7f17995dd9f767e60e22a3ee2
|
@@ -33,6 +33,7 @@ module Protobuf
|
|
33
33
|
end
|
34
34
|
|
35
35
|
filtered_attributes = _filtered_attributes + _protobuf_nested_attributes
|
36
|
+
filtered_attributes += _protobuf_attribute_transformers.keys
|
36
37
|
|
37
38
|
attribute_fields = filtered_attributes.inject({}) do |hash, column_name|
|
38
39
|
symbolized_column = column_name.to_sym
|
@@ -134,20 +134,20 @@ describe Protobuf::ActiveRecord::Serialization do
|
|
134
134
|
context "when options has :except" do
|
135
135
|
it "returns all except the given field(s)" do
|
136
136
|
fields = user._filter_field_attributes(:except => :name).should
|
137
|
-
fields.should eq [ :guid, :email, :email_domain ]
|
137
|
+
fields.should eq [ :guid, :email, :email_domain, :password ]
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
142
|
describe "#_filtered_fields" do
|
143
143
|
it "returns protobuf fields" do
|
144
|
-
user._filtered_fields.should eq [ :guid, :name, :email, :email_domain ]
|
144
|
+
user._filtered_fields.should eq [ :guid, :name, :email, :email_domain, :password ]
|
145
145
|
end
|
146
146
|
|
147
147
|
context "given :deprecated => false" do
|
148
148
|
it "filters all deprecated fields" do
|
149
149
|
fields = user._filtered_fields(:deprecated => false).should
|
150
|
-
fields.should eq [ :guid, :name, :email ]
|
150
|
+
fields.should eq [ :guid, :name, :email, :password ]
|
151
151
|
end
|
152
152
|
end
|
153
153
|
end
|
@@ -204,7 +204,7 @@ describe Protobuf::ActiveRecord::Serialization do
|
|
204
204
|
}
|
205
205
|
|
206
206
|
context "when a transformer is defined for the field" do
|
207
|
-
let(:fields_from_record) { { :guid => user.guid, :name => user.name, :email => user.email, :email_domain => 'test.co' } }
|
207
|
+
let(:fields_from_record) { { :guid => user.guid, :name => user.name, :email => user.email, :email_domain => 'test.co', :password => nil } }
|
208
208
|
let(:transformer) { { :email_domain => lambda { |record| record.email.split('@').last } } }
|
209
209
|
|
210
210
|
before {
|
@@ -217,7 +217,7 @@ describe Protobuf::ActiveRecord::Serialization do
|
|
217
217
|
end
|
218
218
|
|
219
219
|
context "when a transformer is not defined for the field" do
|
220
|
-
let(:fields_from_record) { { :guid => user.guid, :name => user.name, :email => user.email, :email_domain => nil } }
|
220
|
+
let(:fields_from_record) { { :guid => user.guid, :name => user.name, :email => user.email, :email_domain => nil, :password => nil } }
|
221
221
|
|
222
222
|
it "returns a hash of protobuf fields that this object has getters for" do
|
223
223
|
user.fields_from_record.should eq fields_from_record
|
@@ -22,8 +22,13 @@ describe Protobuf::ActiveRecord::Transformation do
|
|
22
22
|
attribute_fields = User._filter_attribute_fields(proto)
|
23
23
|
attribute_fields.has_key?(:account_id).should be_true
|
24
24
|
end
|
25
|
+
|
26
|
+
it "includes fields that aren't attributes, but have attribute transformers" do
|
27
|
+
attribute_fields = User._filter_attribute_fields(proto)
|
28
|
+
attribute_fields.has_key?(:password).should be_true
|
29
|
+
end
|
25
30
|
end
|
26
|
-
|
31
|
+
|
27
32
|
describe "._protobuf_convert_fields_to_attributes" do
|
28
33
|
context "when the given field's corresponding column type is :date" do
|
29
34
|
let(:date) { Date.current }
|
@@ -171,7 +176,7 @@ describe Protobuf::ActiveRecord::Transformation do
|
|
171
176
|
end
|
172
177
|
end
|
173
178
|
end
|
174
|
-
|
179
|
+
|
175
180
|
describe ".convert_int64_to_date" do
|
176
181
|
let(:date) { Date.current }
|
177
182
|
let(:int64) { date.to_time.to_i }
|
@@ -206,7 +211,7 @@ describe Protobuf::ActiveRecord::Transformation do
|
|
206
211
|
end
|
207
212
|
end
|
208
213
|
end
|
209
|
-
|
214
|
+
|
210
215
|
describe "#attributes_from_proto" do
|
211
216
|
it "gets attributes from the given protobuf message" do
|
212
217
|
User.should_receive(:attributes_from_proto).with(proto)
|
data/spec/support/models/user.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
class User < ActiveRecord::Base
|
2
2
|
include Protobuf::ActiveRecord::Model
|
3
3
|
|
4
|
+
attr_accessor :password
|
5
|
+
|
4
6
|
scope :by_guid, lambda { |*guids| where(:guid => guids) }
|
5
7
|
scope :by_email, lambda { |*emails| where(:email => emails) }
|
6
8
|
|
7
9
|
attribute_from_proto :first_name, :extract_first_name
|
8
10
|
attribute_from_proto :last_name, :extract_last_name
|
11
|
+
attribute_from_proto :password, lambda { |proto| proto.password! }
|
9
12
|
|
10
13
|
def self.extract_first_name(proto)
|
11
14
|
if proto.has_field?(:name)
|
@@ -10,6 +10,7 @@ require 'protobuf/message'
|
|
10
10
|
class UserMessage < ::Protobuf::Message; end
|
11
11
|
class UserSearchMessage < ::Protobuf::Message; end
|
12
12
|
|
13
|
+
|
13
14
|
##
|
14
15
|
# Message Fields
|
15
16
|
#
|
@@ -18,6 +19,7 @@ class UserMessage
|
|
18
19
|
optional ::Protobuf::Field::StringField, :name, 2
|
19
20
|
optional ::Protobuf::Field::StringField, :email, 3
|
20
21
|
optional ::Protobuf::Field::StringField, :email_domain, 4, :deprecated => true
|
22
|
+
optional ::Protobuf::Field::StringField, :password, 5
|
21
23
|
end
|
22
24
|
|
23
25
|
class UserSearchMessage
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protobuf-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hutchison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -228,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
228
|
version: '0'
|
229
229
|
requirements: []
|
230
230
|
rubyforge_project:
|
231
|
-
rubygems_version: 2.
|
231
|
+
rubygems_version: 2.1.10
|
232
232
|
signing_key:
|
233
233
|
specification_version: 4
|
234
234
|
summary: Google Protocol Buffers integration for Active Record
|