protobuf-activerecord 2.1.0.rc2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWVlMmI0NmI3ODc3MjI1NDk3NTUyMDhlODIyZDE0ODg3NGNmODlhZQ==
5
+ data.tar.gz: !binary |-
6
+ NjEwNzFlMTAyZGE1Yzk5NGZjNDVjZmJlYmU5ODExYjFkNWIwMTVjOA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NzkzN2ZkMGY3YzdiN2NlZjAwZTAwZjMzZDc0NTQzMjMwNzgzOWY2NDg1MWQ5
10
+ YzBhZTI3ZmFjMGIzOWRlYjgxMmRhN2Y1NDZlNGE4MzI5OTY3NWVjZjljNzc1
11
+ NjU4MjUxZjRlNGE5NmI3MzMzMzc0YWM1YTRmYTQxMDQwYTMzMDA=
12
+ data.tar.gz: !binary |-
13
+ ZmY0YWY3OGRkNTdkNzAwYzQ1YTkzZjVhZjk5ZDAwMGUzMDdkNjUyNGY2MzBk
14
+ ODY4ZGZlYWQ2NmFmOGQyNjdiZjY4MmI4NDI1YWZhNzEzY2MwYWQyZWFkZGUx
15
+ OWM0NDc5MWRmYjhhYjYwMGQ4YzE5NzE4ZjgzNjkxNDY4NGFjOTM=
data/README.md CHANGED
@@ -202,11 +202,25 @@ class User < ActiveRecord::Base
202
202
 
203
203
  scope :by_name, lambda { |*values| where(:name => values) }
204
204
 
205
- field_scope :name, :by_name
205
+ field_scope :name, :scope => :by_name
206
206
  end
207
207
  ```
208
208
 
209
- This tells Protoable that the name field should be searchable and that the scope with the given name should be used to build the search scope.
209
+ This tells Protoable that the name field should be searchable and that the :scope with the given name should be used to build the search scope.
210
+
211
+ `field_scope` can also be called with just a field name:
212
+
213
+ ```Ruby
214
+ class User < ActiveRecord::Base
215
+ include Protoable
216
+
217
+ scope :by_name, lambda { |*values| where(:name => values) }
218
+
219
+ field_scope :name
220
+ end
221
+ ```
222
+
223
+ If no scope is given, Protoable assumes that a scope matching the given field prefixed with `by_`, in this case `by_name`.
210
224
 
211
225
  Now that your class is configured with some searchable fields, you can use the `search_scope` method to build ARel scopes from a protobuf message.
212
226
 
@@ -48,6 +48,7 @@ module Protoable
48
48
 
49
49
  scope_name = case
50
50
  when args.present? then
51
+ warn "WARNING: Passing scopes directly to field_scope is deprecated and will be removed in 3.0. Use :scope => xxx instead."
51
52
  args.first
52
53
  when options.include?(:scope) then
53
54
  options[:scope]
@@ -1,5 +1,5 @@
1
1
  module Protobuf
2
2
  module ActiveRecord
3
- VERSION = "2.1.0.rc2"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
@@ -20,8 +20,8 @@ Gem::Specification.new do |gem|
20
20
  ##
21
21
  # Dependencies
22
22
  #
23
- gem.add_dependency "activerecord"
24
- gem.add_dependency "activesupport"
23
+ gem.add_dependency "activerecord", "~> 3.1"
24
+ gem.add_dependency "activesupport", "~> 3.1"
25
25
  gem.add_dependency "heredity"
26
26
  gem.add_dependency "protobuf", ">= 2.1.3"
27
27
 
@@ -1,6 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Protoable::Scope do
4
+ before do
5
+ @field_parsers = User.instance_variable_get("@_searchable_field_parsers")
6
+ @fields = User.instance_variable_get("@_searchable_fields")
7
+ end
8
+
9
+ after do
10
+ User.instance_variable_set("@_searchable_field_parsers", @field_parsers)
11
+ User.instance_variable_set("@_searchable_fields", @fields)
12
+ end
13
+
14
+
4
15
  describe ".search_scope" do
5
16
  let(:request) { UserSearchMessage.new(:guid => ["foo"], :email => ["foo@test.co"]) }
6
17
 
@@ -37,9 +48,6 @@ describe Protoable::Scope do
37
48
  end
38
49
 
39
50
  describe ".field_scope" do
40
- before { @fields = User.instance_variable_get("@_searchable_fields") }
41
- after { User.instance_variable_set("@_searchable_fields", @fields) }
42
-
43
51
  context "when scope is passed in the old style" do
44
52
  it "defines the given field as searchable using the given scope" do
45
53
  User.field_scope :guid, :by_guid
@@ -69,9 +77,6 @@ describe Protoable::Scope do
69
77
  end
70
78
 
71
79
  context "when :parser is defined" do
72
- before { @field_parsers = User.instance_variable_get("@_searchable_field_parsers") }
73
- after { User.instance_variable_set("@_searchable_field_parsers", @field_parsers) }
74
-
75
80
  it "defines the given field as parseable using the given :parser" do
76
81
  User.field_scope :guid, :parser => :parser
77
82
  User.searchable_field_parsers[:guid].should eq :parser
@@ -80,20 +85,51 @@ describe Protoable::Scope do
80
85
  end
81
86
 
82
87
  describe ".parse_search_values" do
83
- it "converts single values to collections"
88
+
89
+ it "converts single values to collections" do
90
+ proto = UserMessage.new(:email => "the.email@test.in")
91
+
92
+ User.field_scope :email
93
+ User.parse_search_values(proto, :email).should eq ["the.email@test.in"]
94
+ end
84
95
 
85
96
  context "when a field parser is defined" do
97
+ before { User.field_scope :guid, :parser => parser }
98
+
99
+ let(:proto) { UserSearchMessage.new(:guid => ["foo"]) }
100
+
86
101
  context "and the parser responds to :to_sym" do
87
- it "calls `send`, passing it the parser and value"
102
+ let(:parser) { double('parser', :to_sym => :parser_to_sym) }
103
+
104
+ it "passes the value to the parser" do
105
+ User.should_receive(:parser_to_sym).with([ "foo" ])
106
+ User.parse_search_values(proto, :guid)
107
+ end
88
108
  end
89
109
 
90
110
  context "and the parser does not respond to :to_sym" do
91
- it "calls the parser, passing it the value"
111
+ let(:parser) { double('parser') }
112
+
113
+ it "passes the value to the parser" do
114
+ parser.should_receive(:call).with(["foo"])
115
+ User.parse_search_values(proto, :guid)
116
+ end
92
117
  end
93
118
  end
94
119
 
95
120
  context "when the field is an enum" do
96
- it "maps values to integers"
121
+ it "maps values to integers" do
122
+ TheEnum = Class.new(::Protobuf::Enum) do
123
+ define :VALUE, 1
124
+ end
125
+
126
+ TheMessage = Class.new(::Protobuf::Message) do
127
+ optional TheEnum, :the_enum_value, 1
128
+ end
129
+
130
+ proto = TheMessage.new(:the_enum_value => TheEnum::VALUE)
131
+ User.parse_search_values(proto, :the_enum_value)[0].should be 1
132
+ end
97
133
  end
98
134
  end
99
135
  end
@@ -219,7 +219,7 @@ describe Protoable::Serialization do
219
219
  end
220
220
 
221
221
  it "converts attributes values for protobuf messages" do
222
- user.should_receive(:_protobuf_convert_attributes_to_fields).any_number_of_times
222
+ user.stub(:_protobuf_convert_attributes_to_fields)
223
223
  user.fields_from_record
224
224
  end
225
225
  end
@@ -185,11 +185,13 @@ describe Protoable::Transformation do
185
185
 
186
186
  describe ".convert_int64_to_datetime" do
187
187
  let(:datetime) { DateTime.current }
188
- let(:int64) { datetime.to_time.to_i }
188
+ let(:int64) { datetime.to_i }
189
189
 
190
190
  it "initializes a new DateTime object from the value" do
191
191
  Timecop.freeze(DateTime.current) do
192
- User.convert_int64_to_datetime(int64).should eq datetime
192
+ expected_datetime = Time.at(datetime.to_i)
193
+ converted_datetime = User.convert_int64_to_datetime(int64)
194
+ converted_datetime.should eq expected_datetime
193
195
  end
194
196
  end
195
197
  end
@@ -211,4 +213,4 @@ describe Protoable::Transformation do
211
213
  user.attributes_from_proto(proto)
212
214
  end
213
215
  end
214
- end
216
+ end
metadata CHANGED
@@ -1,52 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.rc2
5
- prerelease: 6
4
+ version: 2.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Adam Hutchison
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-22 00:00:00.000000000 Z
11
+ date: 2013-07-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: '3.1'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: '3.1'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: activesupport
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: '3.1'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: '3.1'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: heredity
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: protobuf
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: geminabox
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ! '>='
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ! '>='
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: rspec
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ! '>='
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ! '>='
124
109
  - !ruby/object:Gem::Version
@@ -126,7 +111,6 @@ dependencies:
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: rspec-pride
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ! '>='
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ! '>='
140
123
  - !ruby/object:Gem::Version
@@ -142,7 +125,6 @@ dependencies:
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: pry-nav
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
129
  - - ! '>='
148
130
  - !ruby/object:Gem::Version
@@ -150,7 +132,6 @@ dependencies:
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
136
  - - ! '>='
156
137
  - !ruby/object:Gem::Version
@@ -158,7 +139,6 @@ dependencies:
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: simplecov
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
143
  - - ! '>='
164
144
  - !ruby/object:Gem::Version
@@ -166,7 +146,6 @@ dependencies:
166
146
  type: :development
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
150
  - - ! '>='
172
151
  - !ruby/object:Gem::Version
@@ -174,7 +153,6 @@ dependencies:
174
153
  - !ruby/object:Gem::Dependency
175
154
  name: sqlite3
176
155
  requirement: !ruby/object:Gem::Requirement
177
- none: false
178
156
  requirements:
179
157
  - - ! '>='
180
158
  - !ruby/object:Gem::Version
@@ -182,7 +160,6 @@ dependencies:
182
160
  type: :development
183
161
  prerelease: false
184
162
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
163
  requirements:
187
164
  - - ! '>='
188
165
  - !ruby/object:Gem::Version
@@ -190,7 +167,6 @@ dependencies:
190
167
  - !ruby/object:Gem::Dependency
191
168
  name: timecop
192
169
  requirement: !ruby/object:Gem::Requirement
193
- none: false
194
170
  requirements:
195
171
  - - ! '>='
196
172
  - !ruby/object:Gem::Version
@@ -198,7 +174,6 @@ dependencies:
198
174
  type: :development
199
175
  prerelease: false
200
176
  version_requirements: !ruby/object:Gem::Requirement
201
- none: false
202
177
  requirements:
203
178
  - - ! '>='
204
179
  - !ruby/object:Gem::Version
@@ -244,30 +219,26 @@ files:
244
219
  - spec/support/protobuf/user.pb.rb
245
220
  homepage: http://github.com/liveh2o/protobuf-activerecord
246
221
  licenses: []
222
+ metadata: {}
247
223
  post_install_message:
248
224
  rdoc_options: []
249
225
  require_paths:
250
226
  - lib
251
227
  required_ruby_version: !ruby/object:Gem::Requirement
252
- none: false
253
228
  requirements:
254
229
  - - ! '>='
255
230
  - !ruby/object:Gem::Version
256
231
  version: '0'
257
- segments:
258
- - 0
259
- hash: 1857702975333087595
260
232
  required_rubygems_version: !ruby/object:Gem::Requirement
261
- none: false
262
233
  requirements:
263
- - - ! '>'
234
+ - - ! '>='
264
235
  - !ruby/object:Gem::Version
265
- version: 1.3.1
236
+ version: '0'
266
237
  requirements: []
267
238
  rubyforge_project:
268
- rubygems_version: 1.8.25
239
+ rubygems_version: 2.0.5
269
240
  signing_key:
270
- specification_version: 3
241
+ specification_version: 4
271
242
  summary: Google Protocol Buffers integration for Active Record
272
243
  test_files:
273
244
  - spec/protoable/columns_spec.rb