remotable 0.3.0 → 0.4.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,20 +16,20 @@ end
16
16
  class Tenant < ActiveRecord::Base
17
17
  remote_model RemoteTenant
18
18
  attr_remote :slug, :church_name => :name, :id => :remote_id
19
- find_by :name, :path => "by_nombre/:name"
20
- find_by :slug
19
+ fetch_with :name, :path => "by_nombre/:name"
20
+ fetch_with :slug
21
21
  end
22
22
 
23
23
  class RemoteWithoutKey < ActiveRecord::Base
24
24
  self.table_name = "tenants"
25
-
25
+
26
26
  remote_model RemoteTenant
27
27
  attr_remote :id => :remote_id
28
28
  end
29
29
 
30
30
  class RemoteWithKey < ActiveRecord::Base
31
31
  self.table_name = "tenants"
32
-
32
+
33
33
  remote_model RemoteTenant
34
34
  attr_remote :slug, :church_name => :name
35
35
  remote_key :slug
@@ -37,7 +37,7 @@ end
37
37
 
38
38
  class RemoteWithCompositeKey < ActiveRecord::Base
39
39
  self.table_name = "tenants"
40
-
40
+
41
41
  remote_model RemoteTenant
42
42
  attr_remote :group_id, :slug
43
43
  remote_key [:group_id, :slug], :path => "groups/:group_id/tenants/:slug"
@@ -2,53 +2,53 @@ require "active_record"
2
2
 
3
3
 
4
4
  class BespokeModel
5
-
5
+
6
6
  def new_resource
7
7
  BespokeResource.new
8
8
  end
9
-
9
+
10
10
  def find_by(remote_attr, value)
11
11
  nil
12
12
  end
13
-
13
+
14
14
  end
15
15
 
16
16
  class BespokeModel2
17
-
17
+
18
18
  def new_resource
19
19
  BespokeResource.new
20
20
  end
21
-
21
+
22
22
  def find_by(remote_attr, value)
23
23
  BespokeResource.new(remote_attr => value)
24
24
  end
25
-
25
+
26
26
  end
27
27
 
28
28
  class BespokeResource
29
-
29
+
30
30
  def initialize(attributes={})
31
31
  @attributes = attributes
32
32
  end
33
-
33
+
34
34
  delegate :key?, :[], :[]=, :to => :@attributes
35
-
35
+
36
36
  def save
37
37
  true
38
38
  end
39
-
39
+
40
40
  def errors
41
41
  {}
42
42
  end
43
-
43
+
44
44
  def destroy
45
45
  end
46
-
46
+
47
47
  end
48
48
 
49
49
  class BespokeTenant < ActiveRecord::Base
50
50
  self.table_name = "tenants"
51
-
51
+
52
52
  remote_model BespokeModel.new
53
53
  attr_remote :slug, :name
54
54
  remote_key :slug
@@ -0,0 +1,62 @@
1
+ require "active_support/concern"
2
+ require "active_support/test_case"
3
+
4
+ module Idioms
5
+ module Test
6
+ module Concurrently
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ setup do
11
+ @_concurrency_teardown = nil
12
+ end
13
+
14
+ teardown do
15
+ cleanup_concurrency
16
+ end
17
+ end
18
+
19
+ def afterwards(&block)
20
+ @_concurrency_teardown = block
21
+ end
22
+
23
+ def concurrently(threads: 2)
24
+ threads.times.map do
25
+ Thread.new do
26
+ begin
27
+ yield
28
+ ensure
29
+ #
30
+ # When Rails checks a connection out of the connection
31
+ # pool, it is checked out on behalf of your current
32
+ # thread. So for each concurrent execution of the block
33
+ # of code under test, we'll be dragging a new connection
34
+ # out of the connection pool. It's up to us to turn it in.
35
+ #
36
+ ActiveRecord::Base.connection.close
37
+ end
38
+ end
39
+ end.each(&:join)
40
+ end
41
+
42
+ # Database work done on separate threads is not done
43
+ # inside of the transaction that wraps each test and
44
+ # gets rolled back.
45
+ #
46
+ # As a result, we need to clean up our changes to the
47
+ # database manually _outside of the test's transaction_.
48
+ #
49
+ # The way to run our cleanup code outside of the
50
+ # transaction is to perform it on a separate thread.
51
+ #
52
+ def cleanup_concurrency
53
+ return unless @_concurrency_teardown
54
+ concurrently(threads: 1, &@_concurrency_teardown)
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+
61
+
62
+ ActiveSupport::TestCase.send :include, Idioms::Test::Concurrently
@@ -3,7 +3,7 @@ require "active_record"
3
3
 
4
4
  class NullTestTenant < ActiveRecord::Base
5
5
  self.table_name = "tenants"
6
-
6
+
7
7
  remote_model Remotable::NullRemote
8
8
  attr_remote :slug, :name
9
9
  remote_key :slug
@@ -19,7 +19,10 @@ ActiveRecord::Schema.define(:version => 20110507152635) do
19
19
  t.integer "group_id"
20
20
  t.datetime "created_at"
21
21
  t.datetime "updated_at"
22
+ t.datetime "remote_updated_at"
22
23
  t.datetime "expires_at", :null => false
23
24
  end
24
25
 
26
+ add_index "tenants", ["slug"], name: "index_tenants_on_slug", unique: true, using: :btree
27
+
25
28
  end
@@ -13,7 +13,7 @@ require 'active_record'
13
13
 
14
14
  ActiveRecord::Base.establish_connection(
15
15
  :adapter => "sqlite3",
16
- :database => ":memory:",
16
+ :database => "tmp/test.db",
17
17
  :verbosity => "quiet")
18
18
 
19
19
  load File.join(File.dirname(__FILE__), "support", "schema.rb")
@@ -5,12 +5,12 @@ require "rr"
5
5
 
6
6
  class UnderstandingTest < ActiveSupport::TestCase
7
7
  include RR::Adapters::TestUnit
8
-
8
+
9
9
  # This test fails with an Error if `hello` is never called on `o`
10
10
  test "I know how rr works :)" do
11
11
  o = Object.new
12
12
  mock(o).hello('bob', 'jane') { 'hi' }
13
13
  assert_equal 'hi', o.hello('bob', 'jane')
14
14
  end
15
-
15
+
16
16
  end
metadata CHANGED
@@ -1,187 +1,187 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0.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-05-28 00:00:00.000000000 Z
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.1.0
62
- - - <
62
+ - - "<"
63
63
  - !ruby/object:Gem::Version
64
64
  version: 5.0.0
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - '>='
69
+ - - ">="
70
70
  - !ruby/object:Gem::Version
71
71
  version: 3.1.0
72
- - - <
72
+ - - "<"
73
73
  - !ruby/object:Gem::Version
74
74
  version: 5.0.0
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: turn
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - '>='
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - '>='
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: pry
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - '>='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: factory_girl
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - ~>
107
+ - - "~>"
108
108
  - !ruby/object:Gem::Version
109
109
  version: 2.0.4
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - ~>
114
+ - - "~>"
115
115
  - !ruby/object:Gem::Version
116
116
  version: 2.0.4
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: sqlite3
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - '>='
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - '>='
128
+ - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: active_resource_simulator
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
- - - '>='
135
+ - - ">="
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
- - - '>='
142
+ - - ">="
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: simplecov
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
- - - '>='
149
+ - - ">="
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
- - - '>='
156
+ - - ">="
157
157
  - !ruby/object:Gem::Version
158
158
  version: '0'
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: rr
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
- - - '>='
163
+ - - ">="
164
164
  - !ruby/object:Gem::Version
165
165
  version: '0'
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
- - - '>='
170
+ - - ">="
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: database_cleaner
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
- - - '>='
177
+ - - ">="
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  type: :development
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
- - - '>='
184
+ - - ">="
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  description: Remotable keeps a locally-stored ActiveRecord synchronized with a remote
@@ -192,8 +192,8 @@ executables: []
192
192
  extensions: []
193
193
  extra_rdoc_files: []
194
194
  files:
195
- - .gitignore
196
- - .simplecov
195
+ - ".gitignore"
196
+ - ".simplecov"
197
197
  - Gemfile
198
198
  - Gemfile.lock
199
199
  - MIT-LICENSE
@@ -223,10 +223,12 @@ files:
223
223
  - test/remotable_test.rb
224
224
  - test/support/active_resource.rb
225
225
  - test/support/bespoke.rb
226
+ - test/support/concurrently.rb
226
227
  - test/support/null.rb
227
228
  - test/support/schema.rb
228
229
  - test/test_helper.rb
229
230
  - test/understanding_test.rb
231
+ - tmp/.keep
230
232
  homepage: ''
231
233
  licenses: []
232
234
  metadata: {}
@@ -236,17 +238,17 @@ require_paths:
236
238
  - lib
237
239
  required_ruby_version: !ruby/object:Gem::Requirement
238
240
  requirements:
239
- - - '>='
241
+ - - ">="
240
242
  - !ruby/object:Gem::Version
241
243
  version: '0'
242
244
  required_rubygems_version: !ruby/object:Gem::Requirement
243
245
  requirements:
244
- - - '>='
246
+ - - ">"
245
247
  - !ruby/object:Gem::Version
246
- version: '0'
248
+ version: 1.3.1
247
249
  requirements: []
248
250
  rubyforge_project: remotable
249
- rubygems_version: 2.2.1
251
+ rubygems_version: 2.2.2
250
252
  signing_key:
251
253
  specification_version: 4
252
254
  summary: Binds an ActiveRecord model to a remote resource and keeps the two synchronized
@@ -259,6 +261,7 @@ test_files:
259
261
  - test/remotable_test.rb
260
262
  - test/support/active_resource.rb
261
263
  - test/support/bespoke.rb
264
+ - test/support/concurrently.rb
262
265
  - test/support/null.rb
263
266
  - test/support/schema.rb
264
267
  - test/test_helper.rb