remotable 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,32 +11,34 @@ class RemoteTenant < ActiveResource::Base
11
11
  self.password = "password"
12
12
  end
13
13
 
14
+
15
+
14
16
  class Tenant < ActiveRecord::Base
15
17
  remote_model RemoteTenant
16
18
  attr_remote :slug, :church_name => :name, :id => :remote_id
17
- find_by :name => "by_nombre/:name"
18
- end
19
-
20
-
21
-
22
- class RemoteTenant2 < ActiveResource::Base
19
+ find_by :name, :path => "by_nombre/:name"
20
+ find_by :slug
23
21
  end
24
22
 
25
23
  class RemoteWithoutKey < ActiveRecord::Base
26
24
  set_table_name "tenants"
27
25
 
28
- remote_model RemoteTenant2
26
+ remote_model RemoteTenant
29
27
  attr_remote :id => :remote_id
30
28
  end
31
29
 
32
-
33
- class RemoteTenant3 < ActiveResource::Base
34
- end
35
-
36
30
  class RemoteWithKey < ActiveRecord::Base
37
31
  set_table_name "tenants"
38
32
 
39
- remote_model RemoteTenant3
33
+ remote_model RemoteTenant
40
34
  attr_remote :slug
41
35
  remote_key :slug
42
36
  end
37
+
38
+ class RemoteWithCompositeKey < ActiveRecord::Base
39
+ set_table_name "tenants"
40
+
41
+ remote_model RemoteTenant
42
+ attr_remote :group_id, :slug
43
+ remote_key [:group_id, :slug], :path => "groups/:group_id/tenants/:slug"
44
+ end
@@ -0,0 +1,57 @@
1
+ require "active_record"
2
+
3
+
4
+ class BespokeModel
5
+
6
+ def new_resource
7
+ BespokeResource.new
8
+ end
9
+
10
+ def find_by(remote_attr, value)
11
+ nil
12
+ end
13
+
14
+ end
15
+
16
+ class BespokeModel2
17
+
18
+ def new_resource
19
+ BespokeResource.new
20
+ end
21
+
22
+ def find_by(remote_attr, value)
23
+ BespokeResource.new(remote_attr => value)
24
+ end
25
+
26
+ end
27
+
28
+ class BespokeResource
29
+
30
+ def initialize(attributes={})
31
+ self.slug = attributes[:slug]
32
+ self.name = attributes[:name]
33
+ end
34
+
35
+ attr_accessor :slug, :name
36
+
37
+ def save
38
+ true
39
+ end
40
+
41
+ def errors
42
+ {}
43
+ end
44
+
45
+ def destroy
46
+ end
47
+
48
+ end
49
+
50
+ class BespokeTenant < ActiveRecord::Base
51
+ set_table_name "tenants"
52
+
53
+ remote_model BespokeModel.new
54
+ attr_remote :slug, :name
55
+ remote_key :slug
56
+ end
57
+
@@ -16,6 +16,7 @@ ActiveRecord::Schema.define(:version => 20110507152635) do
16
16
  t.string "slug"
17
17
  t.string "name"
18
18
  t.integer "remote_id"
19
+ t.integer "group_id"
19
20
  t.datetime "created_at"
20
21
  t.datetime "updated_at"
21
22
  t.datetime "expires_at", :null => false
@@ -5,6 +5,7 @@ require 'rails/test_help'
5
5
  require 'active_support/core_ext'
6
6
  require 'factory_girl'
7
7
  require 'turn'
8
+ require 'database_cleaner'
8
9
 
9
10
 
10
11
  require 'active_record'
@@ -18,3 +19,15 @@ load File.join(File.dirname(__FILE__), "support", "schema.rb")
18
19
 
19
20
 
20
21
  require 'factories/tenants'
22
+
23
+
24
+ DatabaseCleaner.strategy = :transaction
25
+
26
+ class ActiveSupport::TestCase
27
+ setup do
28
+ DatabaseCleaner.start
29
+ end
30
+ teardown do
31
+ DatabaseCleaner.clean
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ require "test_helper"
2
+ require "remotable"
3
+ require "rr"
4
+
5
+
6
+ class UnderstandingTest < ActiveSupport::TestCase
7
+ include RR::Adapters::TestUnit
8
+
9
+ # This test fails with an Error if `hello` is never called on `o`
10
+ test "I know how rr works :)" do
11
+ o = Object.new
12
+ mock(o).hello('bob', 'jane') { 'hi' }
13
+ assert_equal 'hi', o.hello('bob', 'jane')
14
+ end
15
+
16
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: remotable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Robert Lail
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-19 00:00:00 -05:00
13
+ date: 2012-02-20 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -58,7 +58,7 @@ dependencies:
58
58
  prerelease: false
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
61
- name: turn
61
+ name: minitest
62
62
  requirement: &id005 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
@@ -69,7 +69,7 @@ dependencies:
69
69
  prerelease: false
70
70
  version_requirements: *id005
71
71
  - !ruby/object:Gem::Dependency
72
- name: factory_girl
72
+ name: turn
73
73
  requirement: &id006 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
@@ -80,7 +80,7 @@ dependencies:
80
80
  prerelease: false
81
81
  version_requirements: *id006
82
82
  - !ruby/object:Gem::Dependency
83
- name: sqlite3
83
+ name: factory_girl
84
84
  requirement: &id007 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
@@ -91,7 +91,7 @@ dependencies:
91
91
  prerelease: false
92
92
  version_requirements: *id007
93
93
  - !ruby/object:Gem::Dependency
94
- name: active_resource_simulator
94
+ name: sqlite3
95
95
  requirement: &id008 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
@@ -102,7 +102,7 @@ dependencies:
102
102
  prerelease: false
103
103
  version_requirements: *id008
104
104
  - !ruby/object:Gem::Dependency
105
- name: simplecov
105
+ name: active_resource_simulator
106
106
  requirement: &id009 !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements:
@@ -112,6 +112,39 @@ dependencies:
112
112
  type: :development
113
113
  prerelease: false
114
114
  version_requirements: *id009
115
+ - !ruby/object:Gem::Dependency
116
+ name: simplecov
117
+ requirement: &id010 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: *id010
126
+ - !ruby/object:Gem::Dependency
127
+ name: rr
128
+ requirement: &id011 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: "0"
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: *id011
137
+ - !ruby/object:Gem::Dependency
138
+ name: database_cleaner
139
+ requirement: &id012 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: "0"
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: *id012
115
148
  description: Remotable keeps a locally-stored ActiveRecord synchronized with a remote resource.
116
149
  email:
117
150
  - robert.lail@cph.org
@@ -134,16 +167,23 @@ files:
134
167
  - lib/remotable/adapters/active_resource.rb
135
168
  - lib/remotable/core_ext.rb
136
169
  - lib/remotable/core_ext/enumerable.rb
170
+ - lib/remotable/core_ext/object.rb
137
171
  - lib/remotable/core_ext/uri.rb
138
172
  - lib/remotable/nosync.rb
173
+ - lib/remotable/validate_models.rb
139
174
  - lib/remotable/version.rb
175
+ - lib/remotable/with_remote_model_proxy.rb
140
176
  - remotable.gemspec
177
+ - test/active_resource_test.rb
178
+ - test/bespoke_test.rb
141
179
  - test/factories/tenants.rb
142
180
  - test/nosync_test.rb
143
181
  - test/remotable_test.rb
144
182
  - test/support/active_resource.rb
183
+ - test/support/bespoke.rb
145
184
  - test/support/schema.rb
146
185
  - test/test_helper.rb
186
+ - test/understanding_test.rb
147
187
  has_rdoc: true
148
188
  homepage: ""
149
189
  licenses: []
@@ -158,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
198
  requirements:
159
199
  - - ">="
160
200
  - !ruby/object:Gem::Version
161
- hash: -3964453781744969533
201
+ hash: -758603566209047915
162
202
  segments:
163
203
  - 0
164
204
  version: "0"
@@ -167,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
207
  requirements:
168
208
  - - ">="
169
209
  - !ruby/object:Gem::Version
170
- hash: -3964453781744969533
210
+ hash: -758603566209047915
171
211
  segments:
172
212
  - 0
173
213
  version: "0"
@@ -179,9 +219,13 @@ signing_key:
179
219
  specification_version: 3
180
220
  summary: Binds an ActiveRecord model to a remote resource and keeps the two synchronized
181
221
  test_files:
222
+ - test/active_resource_test.rb
223
+ - test/bespoke_test.rb
182
224
  - test/factories/tenants.rb
183
225
  - test/nosync_test.rb
184
226
  - test/remotable_test.rb
185
227
  - test/support/active_resource.rb
228
+ - test/support/bespoke.rb
186
229
  - test/support/schema.rb
187
230
  - test/test_helper.rb
231
+ - test/understanding_test.rb