remotable 0.2.5.beta1 → 0.2.5.beta2

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: dced86b6d1612537910a489e785e2dbb9b280018
4
- data.tar.gz: db13ecad5bf99f21719f5e03ed4057fce8ed14f1
3
+ metadata.gz: bafa573e3a1665e4e5e26c14d06326d953de1232
4
+ data.tar.gz: 13cf353936b00ab92a8a1d1fd2dfc9d35098288f
5
5
  SHA512:
6
- metadata.gz: 9fcb24667b7b4914f7d64efd18a7e27f8906e22adbc17c14ca2191d05a53f31d3e25a9d9fb58dbd244d47fad34bd63a9b7908d1526d871271dd980664a7bddbb
7
- data.tar.gz: 189ac92190ec9add70eb40d364d434b7706dba41b49459e276500db31db14f99b15f63cd1270d5ca33aebf9e2bf8399bdf32731c445620634c33c45f6b17d1df
6
+ metadata.gz: 1df144f380b385f74558f8c5a8003a0b74962ac948fd72c23f4b97b5b0a459f3c1eddb6bf529c0c1b42f5dd915de7998fac23f46948b6efefc9b9d9b3cf09a3f
7
+ data.tar.gz: 8f8585e47f6dade2c263787546ff5ab0f7a95a291df5066d246d827296ed9b83d9b5255039d2ef10ca33dfdaecf70eaff7ab935767ba3c2bbfd9849cc5c38ac9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remotable (0.2.4)
4
+ remotable (0.2.5.beta2)
5
5
  activerecord
6
6
  activeresource
7
7
  activesupport
@@ -24,6 +24,22 @@ module Remotable
24
24
 
25
25
 
26
26
 
27
+ # If we use `remote_key` to explicitly set the path where
28
+ # this resource ought to be found, then we should use the
29
+ # same path when updating or destroying this resource.
30
+ #
31
+ # To accomplish this, we need to override ActiveResource's
32
+ # element_path to return the canonical path for this resource.
33
+
34
+ attr_accessor :remote_key_path
35
+
36
+ def element_path(*args)
37
+ return remote_key_path if remote_key_path
38
+ super
39
+ end
40
+
41
+
42
+
27
43
  module ClassMethods
28
44
 
29
45
  IF_MODIFIED_SINCE = "If-Modified-Since".freeze
@@ -63,7 +79,9 @@ module Remotable
63
79
  def find_by!(path)
64
80
  expanded_path = expanded_path_for(path)
65
81
  Remotable.logger.info "[remotable:#{name.underscore}] GET #{expanded_path} (timeout: #{timeout})"
66
- find(:one, :from => expanded_path)
82
+ find(:one, :from => expanded_path).tap do |resource|
83
+ resource.remote_key_path = expanded_path if resource
84
+ end
67
85
  rescue ::ActiveResource::TimeoutError
68
86
  $!.extend Remotable::TimeoutError
69
87
  raise
@@ -1,3 +1,3 @@
1
1
  module Remotable
2
- VERSION = "0.2.5.beta1"
2
+ VERSION = "0.2.5.beta2"
3
3
  end
@@ -211,6 +211,29 @@ class ActiveResourceTest < ActiveSupport::TestCase
211
211
  end
212
212
  end
213
213
 
214
+ test "should be able to update resources by different attributes" do
215
+ tenant = RemoteWithKey.where(id: Factory(:tenant).id).first
216
+ new_name = "Totally Wonky"
217
+
218
+ RemoteTenant.run_simulation do |s|
219
+ s.show(nil, {
220
+ :id => tenant.id,
221
+ :slug => tenant.slug,
222
+ :church_name => tenant.name
223
+ }, :path => "/api/accounts/by_slug/#{tenant.slug}.json", :headers => if_modified_since(tenant))
224
+
225
+ s.update(nil, :path => "/api/accounts/by_slug/#{tenant.slug}.json")
226
+
227
+ tenant.nosync = false
228
+ tenant.name = new_name
229
+ assert_equal true, tenant.any_remote_changes?
230
+
231
+ tenant.save!
232
+
233
+ # pending "Not sure how to test that an update happened"
234
+ end
235
+ end
236
+
214
237
  test "should fail to update a record locally when failing to update one remotely" do
215
238
  tenant = Factory(:tenant)
216
239
  new_name = "Totally Wonky"
@@ -327,6 +350,25 @@ class ActiveResourceTest < ActiveSupport::TestCase
327
350
  end
328
351
  end
329
352
 
353
+
354
+ test "should destroy resources by different attributes" do
355
+ tenant = RemoteWithKey.where(id: Factory(:tenant).id).first
356
+ new_name = "Totally Wonky"
357
+
358
+ RemoteTenant.run_simulation do |s|
359
+ s.show(nil, {
360
+ :id => tenant.id,
361
+ :slug => tenant.slug,
362
+ :church_name => tenant.name
363
+ }, :path => "/api/accounts/by_slug/#{tenant.slug}.json", :headers => if_modified_since(tenant))
364
+
365
+ s.destroy(nil, :path => "/api/accounts/by_slug/#{tenant.slug}.json")
366
+
367
+ tenant.nosync = false
368
+ tenant.destroy
369
+ end
370
+ end
371
+
330
372
  test "should fail to destroy a record locally when failing to destroy one remotely" do
331
373
  tenant = Factory(:tenant)
332
374
 
@@ -31,7 +31,7 @@ class RemoteWithKey < ActiveRecord::Base
31
31
  self.table_name = "tenants"
32
32
 
33
33
  remote_model RemoteTenant
34
- attr_remote :slug
34
+ attr_remote :slug, :church_name => :name
35
35
  remote_key :slug
36
36
  end
37
37
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5.beta1
4
+ version: 0.2.5.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Lail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-10 00:00:00.000000000 Z
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource