remotable 0.5.0 → 0.5.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
  SHA256:
3
- metadata.gz: eb1390c1e1b04414cc0c44807a064f1d5d879c891a01988abcd7b919d9d53f37
4
- data.tar.gz: 5f5b316b09904143182ba07de7225f1151328bc1dd12b52a3e5797b0b1f8dc03
3
+ metadata.gz: 137c22fc6804e7a6d4261c63b139287c06aa44020f315318982d9c301cac6676
4
+ data.tar.gz: caaef13d6e976628e0d94d6dc0a5c615c1a50b14e48b1b66f4d2393e179b2548
5
5
  SHA512:
6
- metadata.gz: ef0d217377d44f7ea675da8ff0faf6718654502abec68cc2f388bc1d1ab95ecf7325aa20733608575d51842390510e9799326149b7ab31b075bcc8fe9902e188
7
- data.tar.gz: 134e43c05eb6da221d66d1ae14bdb93f42d89c22a7b32336d505a81c3ad11e18f63ca5e52ca7838cebb52035221abbd9638473aa32c2bdef310c84bbd39e687c
6
+ metadata.gz: af3a795753d0f1dd53964c02355cc37845228316f3c2361fc9cca3270baede2355f63d88b997e43a93df320930072d1a3bac8a4038795aa4b9322aaaef9ad921
7
+ data.tar.gz: 42bb95792ed9035a6b4766b4370852ef27b17ceebce9a24d98bc43aac766057ddd67d493a420e2526f0a12e8022f6efe260a21b64e491a6e0a1ef033ec2b538b
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ### 0.5.1
4
+ * **Bugfix** Addressed an issue where `Remotable.with_remote_model` could leave a model with the wrong `remote_model` when used in a multithreaded environment.
5
+
6
+ ***
7
+
8
+ _TODO: Backfill for previous releases_
data/lib/remotable.rb CHANGED
@@ -5,6 +5,7 @@ require "remotable/validate_models"
5
5
  require "remotable/with_remote_model_proxy"
6
6
  require "remotable/errors"
7
7
  require "remotable/logger_wrapper"
8
+ require "active_resource/threadsafe_attributes"
8
9
 
9
10
 
10
11
  # Remotable keeps a locally-stored ActiveRecord
@@ -36,6 +37,7 @@ require "remotable/logger_wrapper"
36
37
  module Remotable
37
38
  extend Nosync
38
39
  extend ValidateModels
40
+ include ThreadsafeAttributes
39
41
 
40
42
  # By default, Remotable will validate the models you
41
43
  # supply it via +remote_model+. You can set validate_models
@@ -53,6 +55,8 @@ module Remotable
53
55
  Remotable.log_level = :debug
54
56
  end
55
57
 
58
+ threadsafe_attribute :_remote_model, :__remotable_included
59
+
56
60
 
57
61
 
58
62
  # == remote_model( model [optional] )
@@ -88,17 +92,17 @@ module Remotable
88
92
  #
89
93
  def remote_model(*args)
90
94
  if args.length >= 1
91
- @remote_model = args.first
95
+ self._remote_model = args.first
92
96
 
93
- @__remotable_included ||= begin
97
+ self.__remotable_included ||= begin
94
98
  require "remotable/active_record_extender"
95
99
  include Remotable::ActiveRecordExtender
96
100
  true
97
101
  end
98
102
 
99
- extend_remote_model(@remote_model) if @remote_model
103
+ extend_remote_model(_remote_model) if _remote_model
100
104
  end
101
- @remote_model
105
+ _remote_model
102
106
  end
103
107
 
104
108
 
@@ -1,3 +1,3 @@
1
1
  module Remotable
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "test_helper"
2
2
  require "remotable"
3
3
  require "support/bespoke"
4
+ require "support/concurrently"
4
5
 
5
6
 
6
7
  class RemotableTest < ActiveSupport::TestCase
@@ -57,6 +58,24 @@ class RemotableTest < ActiveSupport::TestCase
57
58
  end
58
59
  end
59
60
 
61
+ test "should support temporary models in a threaded environment" do
62
+ first_slug = "404"
63
+ second_slug = "405"
64
+
65
+ afterwards do
66
+ BespokeTenant.where(slug: [ first_slug, second_slug ]).delete_all
67
+ end
68
+
69
+ concurrently do
70
+ assert_nil BespokeTenant.find_by_slug(first_slug), "Expected not to find the first model initially"
71
+ assert_not_nil BespokeTenant.with_remote_model(BespokeModel2.new) {
72
+ BespokeTenant.find_by_slug(first_slug)
73
+ sleep rand
74
+ }, "Expected to find the first model with the temporary tenant"
75
+ assert_nil BespokeTenant.find_by_slug(second_slug), "Expected not to find the second model when searching with the original model again"
76
+ end
77
+ end
78
+
60
79
 
61
80
 
62
81
  # ========================================================================= #
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Lail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-04 00:00:00.000000000 Z
11
+ date: 2020-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -232,6 +232,7 @@ files:
232
232
  - ".simplecov"
233
233
  - ".travis.yml"
234
234
  - Appraisals
235
+ - CHANGELOG.md
235
236
  - Gemfile
236
237
  - MIT-LICENSE
237
238
  - README.mdown
@@ -289,7 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
290
  - !ruby/object:Gem::Version
290
291
  version: '0'
291
292
  requirements: []
292
- rubygems_version: 3.0.3
293
+ rubygems_version: 3.1.2
293
294
  signing_key:
294
295
  specification_version: 4
295
296
  summary: Binds an ActiveRecord model to a remote resource and keeps the two synchronized