protobuf 2.5.3 → 2.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,6 +32,8 @@ module Protobuf
32
32
  @message_class, @rule, @type, @name, @tag = \
33
33
  message_class, rule, type, name, tag
34
34
 
35
+ set_rule_predicates
36
+
35
37
  @getter_method_name = name
36
38
  @setter_method_name = "#{name}=".to_sym
37
39
  @default = options.delete(:default)
@@ -39,7 +41,6 @@ module Protobuf
39
41
  @packed = repeated? && options.delete(:packed)
40
42
  @deprecated = options.delete(:deprecated)
41
43
 
42
- set_rule_predicates
43
44
  set_default_value
44
45
  warn_excess_options(options) unless options.empty?
45
46
  validate_packed_field if packed?
@@ -165,7 +166,7 @@ module Protobuf
165
166
  @message_class.class_eval do
166
167
  define_method(field.setter_method_name) do |val|
167
168
  field.warn_if_deprecated
168
-
169
+
169
170
  if val.is_a?(Array)
170
171
  val = val.dup
171
172
  val.compact!
@@ -216,7 +217,7 @@ module Protobuf
216
217
  end
217
218
 
218
219
  def set_default_value
219
- @default_value = case
220
+ @default_value = case
220
221
  when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze
221
222
  when required? then nil
222
223
  when optional? then typed_default_value
@@ -1,4 +1,4 @@
1
1
  module Protobuf
2
- VERSION = '2.5.3'
2
+ VERSION = '2.5.4'
3
3
  PROTOC_VERSION = '2.4.1'
4
4
  end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Protobuf::Field::Int32Field do
4
+
5
+ it_behaves_like :packable_field, described_class
6
+
7
+ end
@@ -2,26 +2,26 @@ require 'spec_helper'
2
2
 
3
3
  describe Protobuf::Message do
4
4
 
5
- describe '#initialize' do
6
- it "does not try to set attributes which have nil values" do
5
+ describe '#initialize' do
6
+ it "does not try to set attributes which have nil values" do
7
7
  Test::EnumTestMessage.any_instance.should_not_receive("non_default_enum=")
8
8
  test_enum = Test::EnumTestMessage.new(:non_default_enum => nil)
9
9
  end
10
10
 
11
- it "takes a hash as an initialization argument" do
11
+ it "takes a hash as an initialization argument" do
12
12
  test_enum = Test::EnumTestMessage.new(:non_default_enum => 2)
13
13
  test_enum.non_default_enum.should eq(2)
14
14
  end
15
15
 
16
- it "initializes with an object that responds to #to_hash" do
17
- hashie_object = OpenStruct.new(:to_hash => { :non_default_enum => 2 })
16
+ it "initializes with an object that responds to #to_hash" do
17
+ hashie_object = OpenStruct.new(:to_hash => { :non_default_enum => 2 })
18
18
  test_enum = Test::EnumTestMessage.new(hashie_object)
19
19
  test_enum.non_default_enum.should eq(2)
20
20
  end
21
21
  end
22
22
 
23
23
  describe '#encode' do
24
- context "encoding" do
24
+ context "encoding" do
25
25
  it "accepts UTF-8 strings into string fields" do
26
26
  message = ::Test::Resource.new(:name => "Kyle Redfearn\u0060s iPad")
27
27
 
@@ -46,7 +46,7 @@ describe Protobuf::Message do
46
46
  end
47
47
  end
48
48
 
49
- context "repeated fields" do
49
+ context "repeated fields" do
50
50
  let(:message) { ::Test::Resource.new(:name => "something") }
51
51
 
52
52
  it "does not raise an error when repeated fields are []" do
@@ -56,24 +56,24 @@ describe Protobuf::Message do
56
56
  }.to_not raise_error
57
57
  end
58
58
 
59
- it "sets the value to nil when empty array is passed" do
59
+ it "sets the value to nil when empty array is passed" do
60
60
  message.repeated_enum = []
61
61
  message.instance_variable_get("@values")[:repeated_enum].should be_nil
62
62
  end
63
63
 
64
- it "does not compact the edit original array" do
64
+ it "does not compact the edit original array" do
65
65
  a = [nil].freeze
66
66
  message.repeated_enum = a
67
67
  message.repeated_enum.should eq([])
68
68
  a.should eq([nil].freeze)
69
69
  end
70
70
 
71
- it "compacts the set array" do
71
+ it "compacts the set array" do
72
72
  message.repeated_enum = [nil]
73
73
  message.repeated_enum.should eq([])
74
74
  end
75
75
 
76
- it "raises TypeError when a non-array replaces it" do
76
+ it "raises TypeError when a non-array replaces it" do
77
77
  expect {
78
78
  message.repeated_enum = 2
79
79
  }.to raise_error(/value of type/)
@@ -81,66 +81,66 @@ describe Protobuf::Message do
81
81
  end
82
82
  end
83
83
 
84
- describe "boolean predicate methods" do
84
+ describe "boolean predicate methods" do
85
85
  subject { Test::ResourceFindRequest.new(:name => "resource") }
86
86
 
87
87
  it { should respond_to(:active?) }
88
88
 
89
- it "sets the predicate to true when the boolean value is true" do
89
+ it "sets the predicate to true when the boolean value is true" do
90
90
  subject.active = true
91
91
  subject.active?.should be_true
92
92
  end
93
93
 
94
- it "sets the predicate to false when the boolean value is false" do
94
+ it "sets the predicate to false when the boolean value is false" do
95
95
  subject.active = false
96
96
  subject.active?.should be_false
97
97
  end
98
98
 
99
- it "does not put predicate methods on non-boolean fields" do
99
+ it "does not put predicate methods on non-boolean fields" do
100
100
  Test::ResourceFindRequest.new(:name => "resource").should_not respond_to(:name?)
101
101
  end
102
102
  end
103
103
 
104
- describe "#respond_to_and_has?" do
104
+ describe "#respond_to_and_has?" do
105
105
  subject { Test::EnumTestMessage.new(:non_default_enum => 2) }
106
106
 
107
- it "is false when the message does not have the field" do
107
+ it "is false when the message does not have the field" do
108
108
  subject.respond_to_and_has?(:other_field).should be_false
109
109
  end
110
110
 
111
- it "is true when the message has the field" do
111
+ it "is true when the message has the field" do
112
112
  subject.respond_to_and_has?(:non_default_enum).should be_true
113
113
  end
114
114
  end
115
115
 
116
- describe "#respond_to_has_and_present?" do
116
+ describe "#respond_to_has_and_present?" do
117
117
  subject { Test::EnumTestMessage.new(:non_default_enum => 2) }
118
118
 
119
- it "is false when the message does not have the field" do
119
+ it "is false when the message does not have the field" do
120
120
  subject.respond_to_and_has_and_present?(:other_field).should be_false
121
121
  end
122
122
 
123
- it "is false when the field is repeated and a value is not present" do
123
+ it "is false when the field is repeated and a value is not present" do
124
124
  subject.respond_to_and_has_and_present?(:repeated_enums).should be_false
125
125
  end
126
126
 
127
- it "is false when the field is repeated and the value is empty array" do
127
+ it "is false when the field is repeated and the value is empty array" do
128
128
  subject.repeated_enums = []
129
129
  subject.respond_to_and_has_and_present?(:repeated_enums).should be_false
130
130
  end
131
131
 
132
- it "is true when the field is repeated and a value is present" do
132
+ it "is true when the field is repeated and a value is present" do
133
133
  subject.repeated_enums = [2]
134
134
  subject.respond_to_and_has_and_present?(:repeated_enums).should be_true
135
135
  end
136
136
 
137
- it "is true when the message has the field" do
137
+ it "is true when the message has the field" do
138
138
  subject.respond_to_and_has_and_present?(:non_default_enum).should be_true
139
139
  end
140
140
 
141
- context "#API" do
141
+ context "#API" do
142
142
  subject { Test::EnumTestMessage.new(:non_default_enum => 2) }
143
-
143
+
144
144
  it { should respond_to(:respond_to_and_has_and_present?) }
145
145
  it { should respond_to(:responds_to_and_has_and_present?) }
146
146
  it { should respond_to(:responds_to_has?) }
@@ -150,7 +150,7 @@ describe Protobuf::Message do
150
150
  it { should respond_to(:respond_to_and_has_present?) }
151
151
  it { should respond_to(:responds_to_and_has_present?) }
152
152
  end
153
-
153
+
154
154
  end
155
155
 
156
156
  describe '#to_hash' do
@@ -230,13 +230,13 @@ describe Protobuf::Message do
230
230
  end
231
231
  end
232
232
 
233
- describe "#define_setter" do
233
+ describe "#define_setter" do
234
234
  subject { ::Test::Resource.new }
235
- it "allows string fields to be set to nil" do
235
+ it "allows string fields to be set to nil" do
236
236
  expect { subject.name = nil }.to_not raise_error
237
237
  end
238
238
 
239
- it "does not allow string fields to be set to Numeric" do
239
+ it "does not allow string fields to be set to Numeric" do
240
240
  expect { subject.name = 1}.to raise_error(/name/)
241
241
  end
242
242
  end
data/spec/support/all.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'support/packed_field'
1
2
  require 'support/tolerance_matcher'
2
3
  require 'support/server'
3
4
 
@@ -0,0 +1,21 @@
1
+ shared_examples_for :packable_field do |klass|
2
+
3
+ before(:all) do
4
+ unless defined?(PackableFieldTest)
5
+ class PackableFieldTest < ::Protobuf::Message; end
6
+ end
7
+
8
+ field_klass = klass
9
+ field_name = "#{klass.name.split('::').last.underscore}_packed_field".to_sym
10
+ tag_num = PackableFieldTest.fields.size + 1
11
+ PackableFieldTest.repeated(field_klass, field_name, tag_num, :packed => true)
12
+ end
13
+
14
+ let(:field_name) { "#{klass.name.split('::').last.underscore}_packed_field" }
15
+ let(:message_instance) { PackableFieldTest.new(field_name => [100, 200, 300]) }
16
+
17
+ subject { message_instance.fields.last }
18
+
19
+ it { should be_packed }
20
+
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.5.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-13 00:00:00.000000000Z
13
+ date: 2012-12-14 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &2152836940 !ruby/object:Gem::Requirement
17
+ requirement: &2152945820 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2152836940
25
+ version_requirements: *2152945820
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: ffi
28
- requirement: &2152835280 !ruby/object:Gem::Requirement
28
+ requirement: &2152944640 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2152835280
36
+ version_requirements: *2152944640
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: multi_json
39
- requirement: &2152832940 !ruby/object:Gem::Requirement
39
+ requirement: &2152943780 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2152832940
47
+ version_requirements: *2152943780
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: thor
50
- requirement: &2152832000 !ruby/object:Gem::Requirement
50
+ requirement: &2152941960 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *2152832000
58
+ version_requirements: *2152941960
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: eventmachine
61
- requirement: &2152831080 !ruby/object:Gem::Requirement
61
+ requirement: &2152940580 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2152831080
69
+ version_requirements: *2152940580
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: ffi-rzmq
72
- requirement: &2152830180 !ruby/object:Gem::Requirement
72
+ requirement: &2152938380 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2152830180
80
+ version_requirements: *2152938380
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: pry
83
- requirement: &2152826140 !ruby/object:Gem::Requirement
83
+ requirement: &2152937320 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *2152826140
91
+ version_requirements: *2152937320
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: pry-nav
94
- requirement: &2152825640 !ruby/object:Gem::Requirement
94
+ requirement: &2152933300 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *2152825640
102
+ version_requirements: *2152933300
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rake
105
- requirement: &2152824140 !ruby/object:Gem::Requirement
105
+ requirement: &2152932360 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *2152824140
113
+ version_requirements: *2152932360
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: rake-compiler
116
- requirement: &2152821940 !ruby/object:Gem::Requirement
116
+ requirement: &2152930920 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *2152821940
124
+ version_requirements: *2152930920
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
- requirement: &2152820960 !ruby/object:Gem::Requirement
127
+ requirement: &2152928760 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *2152820960
135
+ version_requirements: *2152928760
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: simplecov
138
- requirement: &2152819380 !ruby/object:Gem::Requirement
138
+ requirement: &2152927780 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,10 +143,10 @@ dependencies:
143
143
  version: '0'
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *2152819380
146
+ version_requirements: *2152927780
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: yard
149
- requirement: &2152816340 !ruby/object:Gem::Requirement
149
+ requirement: &2152925680 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ! '>='
@@ -154,7 +154,7 @@ dependencies:
154
154
  version: '0'
155
155
  type: :development
156
156
  prerelease: false
157
- version_requirements: *2152816340
157
+ version_requirements: *2152925680
158
158
  description: Google Protocol Buffers v2.4.1 Serialization and RPC implementation for
159
159
  Ruby.
160
160
  email:
@@ -347,6 +347,7 @@ files:
347
347
  - spec/lib/protobuf/cli_spec.rb
348
348
  - spec/lib/protobuf/enum_spec.rb
349
349
  - spec/lib/protobuf/enum_value_spec.rb
350
+ - spec/lib/protobuf/field/int32_field_spec.rb
350
351
  - spec/lib/protobuf/logger_spec.rb
351
352
  - spec/lib/protobuf/message_spec.rb
352
353
  - spec/lib/protobuf/rpc/client_spec.rb
@@ -367,6 +368,7 @@ files:
367
368
  - spec/lib/protobuf_spec.rb
368
369
  - spec/spec_helper.rb
369
370
  - spec/support/all.rb
371
+ - spec/support/packed_field.rb
370
372
  - spec/support/server.rb
371
373
  - spec/support/test/enum.pb.rb
372
374
  - spec/support/test/enum.proto
@@ -432,7 +434,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
432
434
  version: '0'
433
435
  segments:
434
436
  - 0
435
- hash: -2693083503849752754
437
+ hash: 4529234402316407150
436
438
  required_rubygems_version: !ruby/object:Gem::Requirement
437
439
  none: false
438
440
  requirements:
@@ -441,7 +443,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
441
443
  version: '0'
442
444
  segments:
443
445
  - 0
444
- hash: -2693083503849752754
446
+ hash: 4529234402316407150
445
447
  requirements: []
446
448
  rubyforge_project:
447
449
  rubygems_version: 1.8.15
@@ -457,6 +459,7 @@ test_files:
457
459
  - spec/lib/protobuf/cli_spec.rb
458
460
  - spec/lib/protobuf/enum_spec.rb
459
461
  - spec/lib/protobuf/enum_value_spec.rb
462
+ - spec/lib/protobuf/field/int32_field_spec.rb
460
463
  - spec/lib/protobuf/logger_spec.rb
461
464
  - spec/lib/protobuf/message_spec.rb
462
465
  - spec/lib/protobuf/rpc/client_spec.rb
@@ -477,6 +480,7 @@ test_files:
477
480
  - spec/lib/protobuf_spec.rb
478
481
  - spec/spec_helper.rb
479
482
  - spec/support/all.rb
483
+ - spec/support/packed_field.rb
480
484
  - spec/support/server.rb
481
485
  - spec/support/test/enum.pb.rb
482
486
  - spec/support/test/enum.proto