protobuf 2.5.2-java → 2.5.4-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,6 @@ rvm:
3
3
  - "1.9.2"
4
4
  - "1.9.3"
5
5
  - jruby-19mode
6
- - rbx-19mode
7
6
  - ruby-head
8
7
  - jruby-head
9
8
  script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec
@@ -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
@@ -40,7 +40,7 @@ module Protobuf
40
40
  def self.extensions(range)
41
41
  extension_fields.add_range(range)
42
42
  end
43
-
43
+
44
44
  def self.extension_field_name_to_tag
45
45
  @extension_fields_by_name ||= {}
46
46
  end
@@ -150,7 +150,7 @@ module Protobuf
150
150
  def each_field
151
151
  all_fields.each do |field|
152
152
  value = __send__(field.name)
153
- yield(field, value)
153
+ yield(field, value)
154
154
  end
155
155
  end
156
156
 
@@ -164,7 +164,7 @@ module Protobuf
164
164
  # Only way you can get here is if you are required and nil
165
165
  raise ::Protobuf::SerializationError, "#{field.name} is required on #{field.message_class}"
166
166
  else
167
- yield(field, value)
167
+ yield(field, value)
168
168
  end
169
169
  end
170
170
  end
@@ -217,7 +217,7 @@ module Protobuf
217
217
  end
218
218
 
219
219
  def respond_to_has_and_present?(key)
220
- self.respond_to_has?(key) &&
220
+ self.respond_to_has?(key) &&
221
221
  (self.__send__(key).present? || [true, false].include?(self.__send__(key)))
222
222
  end
223
223
 
@@ -261,8 +261,8 @@ module Protobuf
261
261
  return result
262
262
  end
263
263
 
264
- def to_json
265
- to_hash.to_json
264
+ def to_json(options = {})
265
+ to_hash.to_json(options)
266
266
  end
267
267
 
268
268
  def to_proto
@@ -17,6 +17,7 @@ module Protobuf
17
17
  define_method "#{type}_filter" do |*args|
18
18
  set_filters(type, *args)
19
19
  end
20
+ alias_method "#{type}_action", "#{type}_filter"
20
21
  end
21
22
 
22
23
  # Filters hash keyed based on filter type (e.g. :before, :after, :around),
@@ -1,4 +1,4 @@
1
1
  module Protobuf
2
- VERSION = '2.5.2'
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
@@ -55,6 +55,9 @@ describe Protobuf::Rpc::ServiceFilters do
55
55
  FilterTest.before_filter(:foo)
56
56
  end
57
57
 
58
+ specify { subject.class.should respond_to(:before_filter) }
59
+ specify { subject.class.should respond_to(:before_action) }
60
+
58
61
  it 'calls filters in the order they were defined' do
59
62
  subject.__send__(:run_filters, :endpoint)
60
63
  subject.called.should eq [ :verify_before, :foo, :endpoint ]
@@ -286,6 +289,9 @@ describe Protobuf::Rpc::ServiceFilters do
286
289
  FilterTest.after_filter(:foo)
287
290
  end
288
291
 
292
+ specify { subject.class.should respond_to(:after_filter) }
293
+ specify { subject.class.should respond_to(:after_action) }
294
+
289
295
  it 'calls filters in the order they were defined' do
290
296
  subject.__send__(:run_filters, :endpoint)
291
297
  subject.called.should eq [ :endpoint, :verify_after, :foo ]
@@ -320,6 +326,9 @@ describe Protobuf::Rpc::ServiceFilters do
320
326
  FilterTest.around_filter(:inner_around)
321
327
  end
322
328
 
329
+ specify { subject.class.should respond_to(:around_filter) }
330
+ specify { subject.class.should respond_to(:around_action) }
331
+
323
332
  it 'calls filters in the order they were defined' do
324
333
  subject.__send__(:run_filters, :endpoint)
325
334
  subject.called.should eq([ :outer_around_top,
@@ -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
@@ -2,7 +2,7 @@
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.5.2
5
+ version: 2.5.4
6
6
  platform: java
7
7
  authors:
8
8
  - BJ Neilsen
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-12-05 00:00:00 Z
14
+ date: 2012-12-17 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -348,6 +348,7 @@ files:
348
348
  - spec/lib/protobuf/cli_spec.rb
349
349
  - spec/lib/protobuf/enum_spec.rb
350
350
  - spec/lib/protobuf/enum_value_spec.rb
351
+ - spec/lib/protobuf/field/int32_field_spec.rb
351
352
  - spec/lib/protobuf/logger_spec.rb
352
353
  - spec/lib/protobuf/message_spec.rb
353
354
  - spec/lib/protobuf/rpc/client_spec.rb
@@ -368,6 +369,7 @@ files:
368
369
  - spec/lib/protobuf_spec.rb
369
370
  - spec/spec_helper.rb
370
371
  - spec/support/all.rb
372
+ - spec/support/packed_field.rb
371
373
  - spec/support/server.rb
372
374
  - spec/support/test/enum.pb.rb
373
375
  - spec/support/test/enum.proto