active_remote 1.7.0 → 1.7.1

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: a53038e5bd4f39ffbba6356eaeeb8de9c55ee2aa
4
- data.tar.gz: 694f516e1adb22e5fd3ed9c68395b6081a54d389
3
+ metadata.gz: 4e0a0b815dc24d0ba8c884b135055cc9fb42fbc0
4
+ data.tar.gz: 59144b3bb85ecebf7e660e0b5a93a27db60f7751
5
5
  SHA512:
6
- metadata.gz: 179ff3825b682860f3600cf90735a783c49f175f764ed56779d859b230da021961f7124faac2561fbc029d0ee9924f37c00532b2190a11d4495f1e5525c25fd9
7
- data.tar.gz: 1f3d111e0cc746926899f9aba30f2c82e32caeb4eddca8250debdcf1830c877588d4e0c29cc3a36352e253c98562d21ea5ee34de1ed8aa8831ebbef34116f8f8
6
+ metadata.gz: ac81f4a6f6f7206306e2712a0fb5fe6d90f72228ce63667f480f609d32243e3bee20ad3465cd2766893994ee01c34733a411c9ee5e047cb89781de47d4262d78
7
+ data.tar.gz: 471a29c7b76006c8d8fd86835196a3ad5dbbbe76c419c9e5cca6d7f1b86e195fb9b2b149185348fa34df1e8875aba8260a9821838e689ced9d75c9b2b0cd3062
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  ##
27
27
  # Development Dependencies
28
28
  #
29
+ s.add_development_dependency "better_receive"
29
30
  s.add_development_dependency "rake"
30
31
  s.add_development_dependency "rspec"
31
32
  s.add_development_dependency "rspec-pride"
@@ -38,6 +38,7 @@ module ActiveRemote
38
38
 
39
39
  def initialize(*)
40
40
  @attributes ||= {}
41
+ @new_record = true
41
42
 
42
43
  skip_dirty_tracking do
43
44
  run_callbacks :initialize do
@@ -119,11 +119,25 @@ module ActiveRemote
119
119
  return respond_to?(:errors) && errors.present?
120
120
  end
121
121
 
122
+ # Instantiate a record with the given remote attributes. Generally used
123
+ # when retrieving records that already exist, so @new_record is set to false.
124
+ #
125
+ def instantiate(record)
126
+ skip_dirty_tracking do
127
+ assign_attributes(record)
128
+ end
129
+
130
+ run_callbacks :initialize
131
+
132
+ @new_record = false
133
+ self
134
+ end
135
+
122
136
  # Returns true if the remote record hasn't been saved yet; otherwise,
123
137
  # returns false.
124
138
  #
125
139
  def new_record?
126
- return self[:guid].nil?
140
+ @new_record
127
141
  end
128
142
 
129
143
  # Returns true if the remote record has been saved; otherwise, returns false.
@@ -207,6 +221,7 @@ module ActiveRemote
207
221
  assign_attributes(last_response.to_hash)
208
222
  add_errors_from_response
209
223
 
224
+ @new_record = has_errors?
210
225
  success?
211
226
  end
212
227
  end
@@ -31,9 +31,10 @@ module ActiveRemote
31
31
  def serialize_records
32
32
  return nil unless last_response.respond_to?(:records)
33
33
 
34
- last_response.records.map do |record|
35
- remote = self.class.new(record.to_hash)
36
- remote
34
+ last_response.records.map do |remote_record|
35
+ record = self.class.allocate
36
+ record.instantiate(remote_record.to_hash)
37
+ record
37
38
  end
38
39
  end
39
40
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRemote
2
- VERSION = "1.7.0"
2
+ VERSION = "1.7.1"
3
3
  end
@@ -146,7 +146,7 @@ describe ActiveRemote::Persistence do
146
146
 
147
147
  describe "#new_record?" do
148
148
  context "when the record is persisted" do
149
- subject { Tag.new(:guid => 'foo') }
149
+ subject { Tag.allocate.instantiate(:guid => 'foo') }
150
150
 
151
151
  its(:new_record?) { should be_false }
152
152
  end
@@ -159,13 +159,13 @@ describe ActiveRemote::Persistence do
159
159
  end
160
160
 
161
161
  describe "#persisted?" do
162
- context "when the record has a guid" do
163
- subject { Tag.new(:guid => 'foo') }
162
+ context "when the record is persisted" do
163
+ subject { Tag.allocate.instantiate(:guid => 'foo') }
164
164
 
165
165
  its(:persisted?) { should be_true }
166
166
  end
167
167
 
168
- context "when the record does not have a guid" do
168
+ context "when the record is not persisted" do
169
169
  subject { Tag.new }
170
170
 
171
171
  its(:persisted?) { should be_false }
@@ -194,7 +194,7 @@ describe ActiveRemote::Persistence do
194
194
  context "when the record is not new" do
195
195
  let(:attributes) { { 'guid' => 'foo' } }
196
196
 
197
- subject { Tag.new(attributes) }
197
+ subject { Tag.allocate.instantiate(attributes) }
198
198
 
199
199
  it "updates the record" do
200
200
  subject.should_receive(:execute).with(:update, attributes)
@@ -204,14 +204,14 @@ describe ActiveRemote::Persistence do
204
204
 
205
205
  context "when the record is saved" do
206
206
  it "returns true" do
207
- subject.should_receive(:has_errors?) { false }
207
+ subject.better_stub(:has_errors?) { false }
208
208
  subject.save.should be_true
209
209
  end
210
210
  end
211
211
 
212
212
  context "when the record is not saved" do
213
213
  it "returns false" do
214
- subject.should_receive(:has_errors?) { true }
214
+ subject.better_stub(:has_errors?) { true }
215
215
  subject.save.should be_false
216
216
  end
217
217
  end
@@ -267,7 +267,7 @@ describe ActiveRemote::Persistence do
267
267
  after { Tag.any_instance.unstub(:execute) }
268
268
 
269
269
  it "runs update callbacks" do
270
- tag = Tag.new({:guid => "123"})
270
+ tag = Tag.allocate.instantiate({:guid => "123"})
271
271
  tag.should_receive(:after_update_callback)
272
272
  tag.update_attributes({})
273
273
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hutchison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-24 00:00:00.000000000 Z
11
+ date: 2013-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_attr
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: better_receive
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -226,8 +240,41 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
240
  version: '0'
227
241
  requirements: []
228
242
  rubyforge_project:
229
- rubygems_version: 2.0.3
243
+ rubygems_version: 2.1.11
230
244
  signing_key:
231
245
  specification_version: 4
232
246
  summary: Active Record for your platform
233
- test_files: []
247
+ test_files:
248
+ - spec/core_ext/date_time_spec.rb
249
+ - spec/lib/active_remote/association_spec.rb
250
+ - spec/lib/active_remote/base_spec.rb
251
+ - spec/lib/active_remote/bulk_spec.rb
252
+ - spec/lib/active_remote/dirty_spec.rb
253
+ - spec/lib/active_remote/dsl_spec.rb
254
+ - spec/lib/active_remote/integration_spec.rb
255
+ - spec/lib/active_remote/persistence_spec.rb
256
+ - spec/lib/active_remote/publication_spec.rb
257
+ - spec/lib/active_remote/rpc_spec.rb
258
+ - spec/lib/active_remote/search_spec.rb
259
+ - spec/lib/active_remote/serialization_spec.rb
260
+ - spec/lib/active_remote/serializers/json_spec.rb
261
+ - spec/lib/active_remote/serializers/protobuf_spec.rb
262
+ - spec/spec_helper.rb
263
+ - spec/support/definitions/author.proto
264
+ - spec/support/definitions/post.proto
265
+ - spec/support/definitions/support/protobuf/category.proto
266
+ - spec/support/definitions/support/protobuf/error.proto
267
+ - spec/support/definitions/tag.proto
268
+ - spec/support/helpers.rb
269
+ - spec/support/models.rb
270
+ - spec/support/models/author.rb
271
+ - spec/support/models/category.rb
272
+ - spec/support/models/message_with_options.rb
273
+ - spec/support/models/post.rb
274
+ - spec/support/models/tag.rb
275
+ - spec/support/protobuf.rb
276
+ - spec/support/protobuf/author.pb.rb
277
+ - spec/support/protobuf/category.pb.rb
278
+ - spec/support/protobuf/error.pb.rb
279
+ - spec/support/protobuf/post.pb.rb
280
+ - spec/support/protobuf/tag.pb.rb