remotely 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Remotely do
4
+ before do
5
+ Remotely.reset!
6
+ end
7
+
8
+ it "is configurable" do
9
+ Remotely.configure { app :configapp, "localhost:2222" }
10
+ Remotely.apps.should include(:configapp)
11
+ end
12
+
13
+ it "configures basic auth parameters" do
14
+ Remotely.configure { basic_auth "user", "password" }
15
+ Remotely.basic_auth.should == ["user", "password"]
16
+ end
17
+
18
+ it "is resetable" do
19
+ Remotely.configure { app :configapp, "localhost:2222" }
20
+ Remotely.reset!
21
+ Remotely.apps.should be_empty
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require "remotely"
2
+ require 'webmock/rspec'
3
+ require "yajl"
4
+ WebMock.disable_net_connect!
5
+ require "support/webmock"
6
+ require "support/test_classes"
7
+
8
+ RSpec.configure do |c|
9
+ c.before do
10
+ WebmockHelpers.stub!
11
+ end
12
+
13
+ def to_json(obj)
14
+ Yajl::Encoder.encode(obj)
15
+ end
16
+ end
@@ -0,0 +1,97 @@
1
+ require "ostruct"
2
+
3
+ Remotely.app :adventure_app, "http://localhost:1234"
4
+
5
+ class BaseTestClass < OpenStruct
6
+ extend ActiveModel::Naming
7
+ include Remotely::Associations
8
+ def self.base_class; self; end
9
+ end
10
+
11
+ # has_many
12
+
13
+ class HasMany < BaseTestClass
14
+ has_many_remote :things
15
+ end
16
+
17
+ class HasManyWithPath < BaseTestClass
18
+ has_many_remote :things, :path => "/custom/things"
19
+ end
20
+
21
+ class HasManyWithPathVariables < BaseTestClass
22
+ has_many_remote :things, :path => "/custom/:name/things/"
23
+ end
24
+
25
+ class HasManyWithForeignKey < BaseTestClass
26
+ has_many_remote :things, :foreign_key => :fkey
27
+ end
28
+
29
+ # has_one
30
+
31
+ class HasOne < BaseTestClass
32
+ has_one_remote :thing
33
+ end
34
+
35
+ class HasOneWithPath < BaseTestClass
36
+ has_one_remote :thing, :path => "/custom/thing"
37
+ end
38
+
39
+ class HasOneWithPathVariables < BaseTestClass
40
+ has_one_remote :thing, :path => "/custom/:name/thing"
41
+ end
42
+
43
+ class HasOneWithForeignKey < BaseTestClass
44
+ has_one_remote :thing, :foreign_key => :fkey
45
+ end
46
+
47
+ # belongs_to
48
+
49
+ class BelongsTo < BaseTestClass
50
+ belongs_to_remote :thing
51
+ end
52
+
53
+ class BelongsToWithPath < BaseTestClass
54
+ belongs_to_remote :thing, :path => "/custom/thing"
55
+ end
56
+
57
+ class BelongsToWithPathVariables < BaseTestClass
58
+ belongs_to_remote :thing, :path => "/custom/:name/thing"
59
+ end
60
+
61
+ class BelongsToWithForeignKey < BaseTestClass
62
+ belongs_to_remote :thing, :foreign_key => :fkey
63
+ end
64
+
65
+ # Generic
66
+
67
+ class Thing < Remotely::Model
68
+ end
69
+
70
+ class Adventure < Remotely::Model
71
+ app :adventure_app
72
+ uri "/adventures"
73
+ has_many_remote :members
74
+ attr_savable :name, :type
75
+ end
76
+
77
+ class Member < Remotely::Model
78
+ app :adventure_app
79
+ uri "/members"
80
+ belongs_to_remote :adventure
81
+ has_one_remote :weapon
82
+ end
83
+
84
+ class CustomMember < OpenStruct
85
+ extend ActiveModel::Naming
86
+ include Remotely::Associations
87
+ belongs_to_remote :adventure, :path => "/custom/:name/adventures"
88
+ end
89
+
90
+ class Weapon < Remotely::Model
91
+ app :adventure_app
92
+ uri "/weapons"
93
+ end
94
+
95
+ class Name
96
+ def self.find(id); end
97
+ end
@@ -0,0 +1,40 @@
1
+ module WebmockHelpers
2
+ extend self
3
+ extend WebMock::API
4
+
5
+ def stub!
6
+ stub :get, %r[/has_manies/1/things], body: [{name: "Thing"}]
7
+ stub :get, %r[/custom/things], body: [{name: "Thing"}]
8
+ stub :get, %r[/custom/stuff/things], body: [{name: "Thing"}]
9
+
10
+ stub :get, %r[/has_ones/1/thing], body: {name: "Thing"}
11
+ stub :get, %r[/custom/thing], body: {name: "Thing"}
12
+ stub :get, %r[/custom/stuff/thing], body: {name: "Thing"}
13
+
14
+ stub :get, %r[/things/1], body: {name: "Thing"}
15
+
16
+ stub :get, %r[/trucks.*], body: [{size: 17, width: 10}]
17
+
18
+ stub :get, %r[/adventures], body: [{type: "MATHEMATICAL"}, {type: "lame"}]
19
+ stub :post, %r[/adventures], lambda { |req| {body: req.body} }
20
+ stub :put, %r[/adventures]
21
+
22
+ stub :get, %r[/adventures/1], body: {type: "MATHEMATICAL"}
23
+ stub :put, %r[/adventures/1], lambda { |req| {body: req.body} }
24
+ stub :delete, %r[/adventures/1]
25
+
26
+ stub :post, %r[/members], body: lambda { |req| {body: req.body} }
27
+ stub :get, %r[/adventures/1/members], body: [{name: "Finn"}, {name: "Jake"}]
28
+ stub :get, %r[/members/3/weapons], body: [{type: "Axe"}]
29
+
30
+ stub :get, %r[/adventures/search], body: [{type: "MATHEMATICAL"}]
31
+ end
32
+
33
+ def stub(method, url, response={})
34
+ unless response.is_a?(Proc)
35
+ response[:body] = Yajl::Encoder.encode(response[:body])
36
+ response[:headers] = { "Content-Type" => "application/json" }
37
+ end
38
+ stub_request(method, url).to_return(response)
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remotely
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matte Noble
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &2152517620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2152517620
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2152517060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.6.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2152517060
36
+ - !ruby/object:Gem::Dependency
37
+ name: ZenTest
38
+ requirement: &2152516520 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2152516520
47
+ - !ruby/object:Gem::Dependency
48
+ name: autotest-growl
49
+ requirement: &2152513940 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2152513940
58
+ - !ruby/object:Gem::Dependency
59
+ name: webmock
60
+ requirement: &2152513340 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2152513340
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-debug19
71
+ requirement: &2152512920 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2152512920
80
+ - !ruby/object:Gem::Dependency
81
+ name: ruby-debug-completion
82
+ requirement: &2152512460 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2152512460
91
+ - !ruby/object:Gem::Dependency
92
+ name: activesupport
93
+ requirement: &2152511900 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: *2152511900
102
+ - !ruby/object:Gem::Dependency
103
+ name: activemodel
104
+ requirement: &2152511300 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: *2152511300
113
+ - !ruby/object:Gem::Dependency
114
+ name: faraday
115
+ requirement: &2152510660 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ~>
119
+ - !ruby/object:Gem::Version
120
+ version: 0.7.4
121
+ type: :runtime
122
+ prerelease: false
123
+ version_requirements: *2152510660
124
+ - !ruby/object:Gem::Dependency
125
+ name: yajl-ruby
126
+ requirement: &2152510160 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 0.8.2
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: *2152510160
135
+ description: Remote API based model associations.
136
+ email:
137
+ - me@mattenoble.com
138
+ executables: []
139
+ extensions: []
140
+ extra_rdoc_files: []
141
+ files:
142
+ - .autotest
143
+ - .gitignore
144
+ - .rspec
145
+ - Gemfile
146
+ - Gemfile.lock
147
+ - README.md
148
+ - Rakefile
149
+ - lib/remotely.rb
150
+ - lib/remotely/associations.rb
151
+ - lib/remotely/collection.rb
152
+ - lib/remotely/ext/url.rb
153
+ - lib/remotely/http_methods.rb
154
+ - lib/remotely/model.rb
155
+ - lib/remotely/version.rb
156
+ - remotely.gemspec
157
+ - spec/remotely/associations_spec.rb
158
+ - spec/remotely/collection_spec.rb
159
+ - spec/remotely/ext/url_spec.rb
160
+ - spec/remotely/http_methods_spec.rb
161
+ - spec/remotely/model_spec.rb
162
+ - spec/remotely_spec.rb
163
+ - spec/spec_helper.rb
164
+ - spec/support/test_classes.rb
165
+ - spec/support/webmock.rb
166
+ homepage: ''
167
+ licenses: []
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ! '>='
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 1.8.10
187
+ signing_key:
188
+ specification_version: 3
189
+ summary: Remote API based model associations.
190
+ test_files:
191
+ - spec/remotely/associations_spec.rb
192
+ - spec/remotely/collection_spec.rb
193
+ - spec/remotely/ext/url_spec.rb
194
+ - spec/remotely/http_methods_spec.rb
195
+ - spec/remotely/model_spec.rb
196
+ - spec/remotely_spec.rb
197
+ - spec/spec_helper.rb
198
+ - spec/support/test_classes.rb
199
+ - spec/support/webmock.rb