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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3d7459c7c110bd97134b19fcb6e03c50d703cf0
4
- data.tar.gz: a9f5db72facad0d01bf4ef55ed1fd21a80f35ac0
3
+ metadata.gz: 9447a65d47084decc7ffdf256ca74e0fd75769a5
4
+ data.tar.gz: 81d3ea3553ddf7822a45201f95222052a5489870
5
5
  SHA512:
6
- metadata.gz: 9fadf115d0f333b94d6bee3940f23b1938ae0fa74ff16c3d1edda12acfcbac70f6c39717de88b716fbf3e51cbe2586ce98812c9a26c5a44abdaf241170a1e9d9
7
- data.tar.gz: dfb1883e308d92f1b34cd1e038fbfeebf3b9594f1b35e2ba4a7a5130153c877a892e1d8d48bf9d77d8fb20e880d32e12b42b40e8fe283d6e4242e6c7fb7d2e04
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
@@ -1,5 +1,5 @@
1
1
  module Protobuf
2
2
  module ActiveRecord
3
- VERSION = "3.0.0"
3
+ VERSION = "3.0.1"
4
4
  end
5
5
  end
@@ -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)
@@ -3,6 +3,7 @@ message UserMessage {
3
3
  optional string name = 2;
4
4
  optional string email = 3;
5
5
  optional string email_domain = 4 [deprecated = true];
6
+ optional string password = 5;
6
7
  }
7
8
 
8
9
  message UserSearchMessage {
@@ -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.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-19 00:00:00.000000000 Z
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.0.6
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