protobuf-activerecord 3.4.4.pre → 3.4.4

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: da307ffdb292153c946b5e4d6fb51c601d19f887
4
- data.tar.gz: '0548445446f601abd66b34b34cab4bbe8f4237b3'
3
+ metadata.gz: b94b8ba65793cc1162ee6905716c95d8ba2afb16
4
+ data.tar.gz: 02fd2e40603b22fc90c9f44f81d724c9940f5054
5
5
  SHA512:
6
- metadata.gz: 7779dd21a08bde0e8dc52ee6cc84170811dc59ad13dbc4ee43a46c04ffc41912620c2599964ecc20452432f6159c2367eac0203a7c41bc6fe958dae65da278d1
7
- data.tar.gz: 972422ff88ff326053604bf64b15cd0c63360146960ea815c81beb7684dbf535282aa27b8e4b640deec9890d6bb7d27cf6846005b4ac1aabe282d89c5cc5e33c
6
+ metadata.gz: 1c2ceafcbbfe007d619a96fb3289443fa1dfbffef453e139359618d36e4b845a575cefad8bfe248ef3b9ab8aacfe9233325a727941a60cb0cd7ab1176c15bcf7
7
+ data.tar.gz: 678912754b8c1a7ec44a7d69c9232d4971bd6d225526a098e795a9a864a494c9b36a29badf1b4cb3217df56039bb5f02653c298c40e92d2339ba6575cb2b2d3b
@@ -139,6 +139,16 @@ module Protobuf
139
139
  @protobuf_message
140
140
  end
141
141
 
142
+ def _protobuf_write_collection_assocation_method(field)
143
+ self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
144
+ def _protobuf_active_record_serialize_#{field}
145
+ value = #{field}.to_a # Terminate the association
146
+ rescue NameError # Has happened when field is not on model or ignored from db
147
+ return nil
148
+ end
149
+ RUBY
150
+ end
151
+
142
152
  def _protobuf_write_convert_to_fields_method(field)
143
153
  is_datetime_time_or_timestamp_column = _protobuf_date_datetime_time_or_timestamp_column?(field)
144
154
  is_date_column = _protobuf_date_column?(field)
@@ -246,6 +256,14 @@ module Protobuf
246
256
  fields
247
257
  end
248
258
 
259
+ # :nodoc:
260
+ def _is_collection_association?(field)
261
+ reflection = self.class.reflect_on_association(field)
262
+ return false unless reflection
263
+
264
+ reflection.macro == :has_many
265
+ end
266
+
249
267
  # :nodoc:
250
268
  def _normalize_options(options)
251
269
  options ||= {}
@@ -295,7 +313,11 @@ module Protobuf
295
313
  when _protobuf_field_transformers.has_key?(field) then
296
314
  self.class._protobuf_write_field_transformer_method(field)
297
315
  when respond_to?(field) then
298
- self.class._protobuf_write_convert_to_fields_method(field)
316
+ if _is_collection_association?(field)
317
+ self.class._protobuf_write_collection_assocation_method(field)
318
+ else
319
+ self.class._protobuf_write_convert_to_fields_method(field)
320
+ end
299
321
  else
300
322
  self.class._protobuf_write_nil_method(field)
301
323
  end
@@ -1,5 +1,5 @@
1
1
  module Protobuf
2
2
  module ActiveRecord
3
- VERSION = "3.4.4.pre"
3
+ VERSION = "3.4.4"
4
4
  end
5
5
  end
@@ -165,6 +165,15 @@ describe Protobuf::ActiveRecord::Serialization do
165
165
  expect(fields).to include(:token)
166
166
  end
167
167
  end
168
+
169
+ context "when a field is a collection association" do
170
+ let(:user) { User.create(attributes) }
171
+
172
+ it "terminates the association proxy" do
173
+ fields = user.fields_from_record(:include => :photos)
174
+ expect(fields[:photos]).to be_an(Array)
175
+ end
176
+ end
168
177
  end
169
178
 
170
179
  describe "#to_proto" do
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.4.4.pre
4
+ version: 3.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hutchison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-26 00:00:00.000000000 Z
11
+ date: 2017-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -245,9 +245,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
245
245
  version: '0'
246
246
  required_rubygems_version: !ruby/object:Gem::Requirement
247
247
  requirements:
248
- - - ">"
248
+ - - ">="
249
249
  - !ruby/object:Gem::Version
250
- version: 1.3.1
250
+ version: '0'
251
251
  requirements: []
252
252
  rubyforge_project:
253
253
  rubygems_version: 2.6.13