protip 0.30.7 → 0.30.8

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: 7d239a033b1eb1195452fe0e5c213f6e895ea58d
4
- data.tar.gz: e9fbd5cb9aea18eadb29511fe538558c1e0221d5
3
+ metadata.gz: 7b700562f8cedc2912054670d12c0c41a5ad3f84
4
+ data.tar.gz: 0d7570c79be4b391c252482d161aa10acf739fc1
5
5
  SHA512:
6
- metadata.gz: f59804b61df3ad5234f43ced5a88ee600d2d03dfafe4360967bc4d38d08acbdeefd7a5220d863c76ffd11a2f29d31bc2d25fb04c26981426f2013c523df650a6
7
- data.tar.gz: 16a50621105d9940f5d7e136e61b1072a782ff595332f8335bbbe220abf4f474aa9e106cab1a0d610b323d2aad1c6e8c459f4a75cd2a5bb01c680298d3881a44
6
+ metadata.gz: 42fdc7f6b8a8b18128edae66d2af7d62f7e83ac7556bfd3dd4ebaabe26161daecde74932762f39da43fee776225cc66257240668bbbb16611c6c733f65ac3cfa
7
+ data.tar.gz: f58984dd3bbc99af11bee730cc577fca94e1623c1b282c17b32ea0f292b7095086835a53f544d641625af5313538d22edd331c993214dc69acc62283b3e62afa
@@ -302,7 +302,21 @@ module Protip
302
302
  keys.each do |key|
303
303
  old_value = old_attributes[key]
304
304
  new_value = message[key]
305
- unless old_value.class == new_value.class && old_value == new_value
305
+ begin
306
+ changed = !(old_value.class == new_value.class && old_value == new_value)
307
+ rescue TypeError => e
308
+
309
+ # Workaround for a protip bug when comparing messages with
310
+ # nested messages where the left side is non-nil and the
311
+ # right side is nil.
312
+ if e.message == 'wrong argument type nil (expected Message)'
313
+ changed = true
314
+ else
315
+ raise e
316
+ end
317
+ end
318
+
319
+ if changed
306
320
  send "#{key}_will_change!"
307
321
  end
308
322
  end
@@ -36,6 +36,12 @@ module Protip::ResourceTest # Namespace for internal constants
36
36
  optional :oneof_string1, :string, 12
37
37
  optional :oneof_string2, :string, 13
38
38
  end
39
+
40
+ optional :double_nested_message, :message, 14, 'double_nested_message'
41
+ end
42
+
43
+ add_message 'double_nested_message' do
44
+ optional :nested_message, :message, 1, 'nested_message'
39
45
  end
40
46
 
41
47
  add_message 'resource_query' do
@@ -57,7 +63,7 @@ module Protip::ResourceTest # Namespace for internal constants
57
63
  end
58
64
  pool
59
65
  end
60
- %w(nested_message resource_message resource_query action_query action_response).each do |name|
66
+ %w(nested_message resource_message resource_query action_query action_response double_nested_message).each do |name|
61
67
  let(:"#{name}_class") do
62
68
  pool.lookup(name).msgclass
63
69
  end
@@ -563,6 +569,10 @@ module Protip::ResourceTest # Namespace for internal constants
563
569
  transformer.stubs(:to_object).
564
570
  with(nested_message_class.new(number: 62), nested_message_field).
565
571
  returns(72)
572
+
573
+ transformer.stubs(:to_object).
574
+ with(double_nested_message_class.any_instance, anything).
575
+ returns(100)
566
576
  end
567
577
  it 'marks messages as changed if they are changed as Ruby values' do
568
578
  setter.set nested_message: 42
@@ -591,6 +601,20 @@ module Protip::ResourceTest # Namespace for internal constants
591
601
  refute resource.changed?, 'resource was marked as changed'
592
602
  refute resource.string_changed?, 'field was marked as changed'
593
603
  end
604
+
605
+ # Test our workaround for a protobuf bug when comparing
606
+ # messages with sub-messages that are non-nil on the left,
607
+ # nil on the right.
608
+ it 'recognizes when double-nested messages are changed to nil values' do
609
+ # Initially the field should have its nested message set.
610
+ resource.message.double_nested_message = double_nested_message_class.new(
611
+ nested_message: nested_message_class.new(number: 10)
612
+ )
613
+
614
+ # Then give it a field with a nil nested message to
615
+ # trigger the protobuf bug.
616
+ setter.set double_nested_message: double_nested_message_class.new
617
+ end
594
618
  end
595
619
  end
596
620
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.7
4
+ version: 0.30.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - AngelList
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-22 00:00:00.000000000 Z
11
+ date: 2017-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -266,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
266
  version: '0'
267
267
  requirements: []
268
268
  rubyforge_project:
269
- rubygems_version: 2.4.5.1
269
+ rubygems_version: 2.5.1
270
270
  signing_key:
271
271
  specification_version: 4
272
272
  summary: Resources backed by protobuf messages