hypertext_client 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.0.7 (October 11, 2010)
2
+
3
+ Properly set camel cased parent class name
4
+
1
5
  ## 0.0.6 (October 7, 2010)
2
6
 
3
7
  More improvements to camel-cased class names
@@ -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.6'
21
+ VERSION = '0.0.7'
22
22
 
23
23
  extend ActiveSupport::Concern
24
24
  # Include HTTParty
@@ -94,7 +94,7 @@ module HypertextClient
94
94
 
95
95
  def belongs_to(*classes)
96
96
  self.parents += classes.select {|c| c.respond_to? :model_name}
97
- base_url self.base_endpoint + '/' + self.parents.map {|parent| parent.model_name.split('::').last.parameterize}.map{|name| "#{name.pluralize}/|#{name.singularize}|"} * '/'
97
+ base_url self.base_endpoint + '/' + self.parents.map {|parent| parent.model_name.demodulize.underscore}.map{|name| "#{name.pluralize}/|#{name.singularize}|"} * '/'
98
98
  end
99
99
 
100
100
  # Override HTTParty's methods to allow assumptions about a '/' path.
@@ -116,7 +116,7 @@ module HypertextClient
116
116
  options = args.first
117
117
  raise MissingArgumentError.new("Options hash required; must include parent ids") unless options.is_a? Hash
118
118
  self.parents.each do |parent|
119
- key = parent.model_name.split('::').last.parameterize.singularize.to_sym
119
+ key = parent.model_name.demodulize.singularize.underscore.to_sym
120
120
  raise MissingArgumentError.new("Missing required argument: #{key}") unless options.has_key? key
121
121
  base_uri self.base_uri.gsub("|#{key}|", options[key])
122
122
  end
@@ -38,7 +38,12 @@ FakeWeb.register_uri(:get,
38
38
  :content_type => 'application/json')
39
39
 
40
40
  FakeWeb.register_uri(:get,
41
- FAKE_ENDPOINT + '/camelcase_classes/example',
41
+ FAKE_ENDPOINT + '/camel_cases/example',
42
+ :body => {:property => 'exists'}.to_json,
43
+ :content_type => 'application/json')
44
+
45
+ FakeWeb.register_uri(:get,
46
+ FAKE_ENDPOINT + '/camel_cases/example/camel_case_inheritors/123',
42
47
  :body => {:property => 'exists'}.to_json,
43
48
  :content_type => 'application/json')
44
49
 
@@ -65,10 +70,14 @@ class SkynetClient::Button < ObjectStruct
65
70
  belongs_to Widget
66
71
  end
67
72
 
68
- class SkynetClient::CamelcaseClass < ObjectStruct
73
+ class SkynetClient::CamelCase < ObjectStruct
69
74
  include SkynetClient
70
75
  end
71
76
 
77
+ class SkynetClient::CamelCaseInheritor < ObjectStruct
78
+ include SkynetClient
79
+ belongs_to SkynetClient::CamelCase
80
+ end
72
81
 
73
82
  class HypertextClientTest < MiniTest::Unit::TestCase
74
83
  include ActiveModel::Lint::Tests
@@ -126,7 +135,15 @@ class HypertextClientTest < MiniTest::Unit::TestCase
126
135
  end
127
136
 
128
137
  def test_gets_camelcased_classes_correctly
129
- example = SkynetClient::CamelcaseClass.get 'example'
138
+ example = SkynetClient::CamelCase.get 'example'
130
139
  assert_equal example.property, "exists"
131
140
  end
141
+
142
+ def test_requires_camelcase_id
143
+ assert_raises HypertextClient::MissingArgumentError do
144
+ example = SkynetClient::CamelCaseInheritor.get('123')
145
+ end
146
+ example = SkynetClient::CamelCaseInheritor.get('123', :camel_case => 'example')
147
+ assert example
148
+ end
132
149
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Quid, Inc.
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-07 00:00:00 -07:00
17
+ date: 2010-10-11 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency