hypertext_client 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/lib/hypertext_client/hypertext_client.rb +4 -2
- data/test/test_hypertext_client.rb +22 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
# Hypertext provides an HTTP client based on HTTParty, with a few assumptions baked in.
|
20
20
|
module HypertextClient
|
21
|
-
VERSION = '0.0.
|
21
|
+
VERSION = '0.0.9'
|
22
22
|
|
23
23
|
extend ActiveSupport::Concern
|
24
24
|
# Include HTTParty
|
@@ -114,13 +114,15 @@ module HypertextClient
|
|
114
114
|
end
|
115
115
|
|
116
116
|
if self.parents.count > 0 && !(path =~ %r(http://))
|
117
|
+
full_uri = "#{base_uri}"
|
117
118
|
options = args.first
|
118
119
|
raise MissingArgumentError.new("Options hash required; must include parent ids") unless options.is_a? Hash
|
119
120
|
self.parents.each do |parent|
|
120
121
|
key = parent.model_name.demodulize.singularize.underscore.to_sym
|
121
122
|
raise MissingArgumentError.new("Missing required argument: #{key}") unless options.has_key? key
|
122
|
-
|
123
|
+
full_uri.gsub!("|#{key}|", options[key])
|
123
124
|
end
|
125
|
+
path = full_uri + path
|
124
126
|
end
|
125
127
|
|
126
128
|
response = super(path, *args)
|
@@ -47,10 +47,20 @@ FakeWeb.register_uri(:any,
|
|
47
47
|
:body => [{:property => 'exists'}].to_json,
|
48
48
|
:content_type => 'application/json')
|
49
49
|
|
50
|
+
FakeWeb.register_uri(:any,
|
51
|
+
FAKE_ENDPOINT + '/camel_cases/example/camel_case_inheritors',
|
52
|
+
:body => [{:property => 'exists'}].to_json,
|
53
|
+
:content_type => 'application/json')
|
54
|
+
|
50
55
|
FakeWeb.register_uri(:any,
|
51
56
|
FAKE_ENDPOINT + '/camel_cases/example/camel_case_inheritors/123',
|
52
57
|
:body => {:property => 'exists'}.to_json,
|
53
58
|
:content_type => 'application/json')
|
59
|
+
|
60
|
+
FakeWeb.register_uri(:any,
|
61
|
+
FAKE_ENDPOINT + '/camel_cases/different_example/camel_case_inheritors',
|
62
|
+
:body => {:property => 'exists'}.to_json,
|
63
|
+
:content_type => 'application/json')
|
54
64
|
|
55
65
|
|
56
66
|
module SkynetClient
|
@@ -162,8 +172,20 @@ class HypertextClientTest < MiniTest::Unit::TestCase
|
|
162
172
|
assert_equal '/camel_cases/example/camel_case_inheritors/123', FakeWeb.last_request.path
|
163
173
|
end
|
164
174
|
|
175
|
+
def test_dont_duplicate_first_param_as_parent_id
|
176
|
+
example = SkynetClient::CamelCaseInheritor.delete(123, :camel_case => 'example')
|
177
|
+
assert_equal '/camel_cases/example/camel_case_inheritors/123', FakeWeb.last_request.path
|
178
|
+
end
|
179
|
+
|
165
180
|
def test_build_collection_url_from_hash_for_sub_model
|
166
181
|
example = SkynetClient::CamelCaseInheritor.get(:camel_case => 'example')
|
167
182
|
assert_equal '/camel_cases/example/camel_case_inheritors', FakeWeb.last_request.path
|
168
183
|
end
|
184
|
+
|
185
|
+
def test_base_uri_should_reset_after_call
|
186
|
+
example = SkynetClient::CamelCaseInheritor.get(:camel_case => 'example')
|
187
|
+
assert_equal '/camel_cases/example/camel_case_inheritors', FakeWeb.last_request.path
|
188
|
+
example = SkynetClient::CamelCaseInheritor.get(:camel_case => 'different_example')
|
189
|
+
assert_equal '/camel_cases/different_example/camel_case_inheritors', FakeWeb.last_request.path
|
190
|
+
end
|
169
191
|
end
|