wrest 1.0.0.beta1 → 1.0.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +14 -2
- data/LICENCE +7 -0
- data/README.rdoc +15 -69
- data/lib/wrest/components/container/alias_accessors.rb +1 -1
- data/lib/wrest/components/container/alias_accessors.rbc +905 -0
- data/lib/wrest/components/container/typecaster.rb +5 -5
- data/lib/wrest/components/container/typecaster.rbc +1985 -0
- data/lib/wrest/components/container.rb +11 -12
- data/lib/wrest/components/container.rbc +2466 -0
- data/lib/wrest/components/mutators/base.rbc +702 -0
- data/lib/wrest/components/mutators/camel_to_snake_case.rbc +360 -0
- data/lib/wrest/components/mutators/xml_mini_type_caster.rbc +679 -0
- data/lib/wrest/components/mutators/xml_simple_type_caster.rbc +559 -0
- data/lib/wrest/components/mutators.rbc +650 -0
- data/lib/wrest/components/translators/content_types.rbc +339 -0
- data/lib/wrest/components/translators/json.rbc +462 -0
- data/lib/wrest/components/translators/xml.rbc +457 -0
- data/lib/wrest/components/translators.rbc +517 -0
- data/lib/wrest/components.rbc +217 -0
- data/lib/wrest/core_ext/hash/conversions.rbc +501 -0
- data/lib/wrest/core_ext/hash.rbc +182 -0
- data/lib/wrest/core_ext/string/conversions.rbc +471 -0
- data/lib/wrest/core_ext/string.rbc +182 -0
- data/lib/wrest/curl/response.rb +8 -0
- data/lib/wrest/curl.rbc +704 -0
- data/lib/wrest/exceptions.rbc +312 -0
- data/lib/wrest/http_shared/headers.rb +0 -7
- data/lib/wrest/http_shared/headers.rbc +353 -0
- data/lib/wrest/http_shared/standard_headers.rbc +336 -0
- data/lib/wrest/http_shared/standard_tokens.rbc +316 -0
- data/lib/wrest/http_shared.rbc +279 -0
- data/lib/wrest/native/connection_factory.rbc +445 -0
- data/lib/wrest/native/delete.rbc +371 -0
- data/lib/wrest/native/get.rb +26 -0
- data/lib/wrest/native/get.rbc +855 -0
- data/lib/wrest/native/options.rbc +347 -0
- data/lib/wrest/native/post.rbc +388 -0
- data/lib/wrest/native/put.rbc +388 -0
- data/lib/wrest/native/redirection.rbc +520 -0
- data/lib/wrest/native/request.rb +4 -2
- data/lib/wrest/native/request.rbc +1675 -0
- data/lib/wrest/native/response.rb +53 -2
- data/lib/wrest/native/response.rbc +2150 -0
- data/lib/wrest/native/session.rbc +1372 -0
- data/lib/wrest/native.rbc +513 -0
- data/lib/wrest/resource/base.rbc +2115 -0
- data/lib/wrest/resource.rbc +163 -0
- data/lib/wrest/uri.rbc +2599 -0
- data/lib/wrest/uri_template.rbc +505 -0
- data/lib/wrest/version.rb +1 -1
- data/lib/wrest/version.rbc +372 -0
- data/lib/wrest.rb +1 -1
- data/lib/wrest.rbc +1900 -0
- metadata +99 -102
- data/Rakefile +0 -495
- data/VERSION.yml +0 -5
- data/bin/jwrest +0 -3
- data/examples/delicious.rb +0 -72
- data/examples/facebook.rb +0 -101
- data/examples/imgur_multipart.rb +0 -24
- data/examples/keep_alive.rb +0 -37
- data/examples/redirection.rb +0 -27
- data/examples/twitter.rb +0 -78
- data/examples/twitter_public_timeline.rb +0 -32
- data/examples/wow_realm_status.rb +0 -67
- data/init.rb +0 -0
- data/spec/custom_matchers/custom_matchers.rb +0 -2
- data/spec/rcov.opts +0 -4
- data/spec/spec.opts.disable +0 -6
- data/spec/unit/spec_helper.rb +0 -35
- data/spec/unit/wrest/components/attributes_container/alias_accessors_spec.rb +0 -49
- data/spec/unit/wrest/components/attributes_container/typecaster_spec.rb +0 -83
- data/spec/unit/wrest/components/attributes_container_spec.rb +0 -254
- data/spec/unit/wrest/components/mutators/base_spec.rb +0 -42
- data/spec/unit/wrest/components/mutators/camel_to_snake_spec.rb +0 -22
- data/spec/unit/wrest/components/mutators/xml_mini_type_caster_spec.rb +0 -75
- data/spec/unit/wrest/components/mutators/xml_simple_type_caster_spec.rb +0 -47
- data/spec/unit/wrest/components/mutators_spec.rb +0 -21
- data/spec/unit/wrest/components/translators/xml_spec.rb +0 -16
- data/spec/unit/wrest/components/translators_spec.rb +0 -18
- data/spec/unit/wrest/core_ext/hash/conversions_spec.rb +0 -22
- data/spec/unit/wrest/core_ext/string/conversions_spec.rb +0 -39
- data/spec/unit/wrest/curl/request_spec.rb +0 -19
- data/spec/unit/wrest/curl/response_spec.rb +0 -16
- data/spec/unit/wrest/http/response_spec.rb +0 -24
- data/spec/unit/wrest/native/redirection_spec.rb +0 -42
- data/spec/unit/wrest/native/request_spec.rb +0 -71
- data/spec/unit/wrest/native/response_spec.rb +0 -72
- data/spec/unit/wrest/native/session_spec.rb +0 -74
- data/spec/unit/wrest/resource/base_spec.rb +0 -274
- data/spec/unit/wrest/uri_spec.rb +0 -273
- data/spec/unit/wrest/uri_template_spec.rb +0 -38
- data/wrest.gemspec +0 -168
data/examples/imgur_multipart.rb
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 - 2010 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require 'pp'
|
|
11
|
-
require File.expand_path(File.dirname(__FILE__) + "/../lib/wrest")
|
|
12
|
-
|
|
13
|
-
# See http://code.google.com/p/imgur-api
|
|
14
|
-
imgur_key = 'f6561f62e13422bb25a1e738e9927d3b' # use your own key, this one is fake
|
|
15
|
-
file_path = 'VoA10.png'
|
|
16
|
-
|
|
17
|
-
# Using the eminently sensible Base64 encoded imgur file upload API
|
|
18
|
-
pp 'http://imgur.com/api/upload.xml'.to_uri.post_form(:image => [IO.read(file_path)].pack('m'), :key => imgur_key).deserialise
|
|
19
|
-
|
|
20
|
-
# If an API requires multipart posts - like the Facebook API - you can do that too
|
|
21
|
-
require 'wrest/multipart'
|
|
22
|
-
File.open(file_path) do |file|
|
|
23
|
-
pp 'http://imgur.com/api/upload.xml'.to_uri.post_multipart(:image => UploadIO.new(file, "image/png", file_path), :key => imgur_key).deserialise
|
|
24
|
-
end
|
data/examples/keep_alive.rb
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.expand_path(File.dirname(__FILE__) + "/../lib/wrest")
|
|
11
|
-
require 'pp'
|
|
12
|
-
|
|
13
|
-
Wrest.logger = Logger.new(STDOUT)
|
|
14
|
-
Wrest.logger.level = Logger::DEBUG # Set this to Logger::INFO or higher to disable request logging
|
|
15
|
-
include Wrest
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# This is a basic example demonstrating using keep-alive connections.
|
|
19
|
-
# Observe the requests logs - they will look something like this:
|
|
20
|
-
# --> (GET 12207030 12546830) http://github.com:80/api/v1/json/kaiwren
|
|
21
|
-
#
|
|
22
|
-
# The second number after the GET is a hash identifying the connection used.
|
|
23
|
-
# You will notice that all requests have the same hash therefore use the same connection.
|
|
24
|
-
|
|
25
|
-
Http::Session.new('http://github.com/api/v1/json') do |s|
|
|
26
|
-
puts "Response Connection Header - a response token of 'Keep-Alive' indicates that the server has created a keep-alive connection"
|
|
27
|
-
puts
|
|
28
|
-
puts s.get('/kaiwren')['Connection']
|
|
29
|
-
puts s.get('/niranjan')['Connection']
|
|
30
|
-
|
|
31
|
-
puts
|
|
32
|
-
puts '*' * 10
|
|
33
|
-
puts
|
|
34
|
-
|
|
35
|
-
pp s.get('/kaiwren').deserialise
|
|
36
|
-
pp s.get('/niranjan').deserialise
|
|
37
|
-
end
|
data/examples/redirection.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.expand_path(File.dirname(__FILE__) + "/../lib/wrest")
|
|
11
|
-
require 'pp'
|
|
12
|
-
|
|
13
|
-
Wrest.logger = Logger.new(STDOUT)
|
|
14
|
-
Wrest.logger.level = Logger::DEBUG # Set this to Logger::INFO or higher to disable request logging
|
|
15
|
-
|
|
16
|
-
# google.com redirects to www.google.com so this is live test for redirection
|
|
17
|
-
pp 'http://google.com'.to_uri.get.body
|
|
18
|
-
|
|
19
|
-
puts '', '*'*70, ''
|
|
20
|
-
|
|
21
|
-
# Do a get with auto follow redirects turned off
|
|
22
|
-
pp 'http://google.com'.to_uri(:follow_redirects => false).get.body
|
|
23
|
-
|
|
24
|
-
puts '', '*'*70, ''
|
|
25
|
-
|
|
26
|
-
# Do a get with auto follow redirects limited, causing an exception.
|
|
27
|
-
'http://google.com'.to_uri(:follow_redirects_limit => 1).get.body
|
data/examples/twitter.rb
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.expand_path(File.dirname(__FILE__) + "/../lib/wrest")
|
|
11
|
-
require 'pp'
|
|
12
|
-
|
|
13
|
-
Wrest.logger = Logger.new(STDOUT)
|
|
14
|
-
Wrest.logger.level = Logger::DEBUG # Set this to Logger::INFO or higher to disable request logging
|
|
15
|
-
|
|
16
|
-
# This example shows a more object oriented approach
|
|
17
|
-
# to accessing Twitter using Wrest.
|
|
18
|
-
#
|
|
19
|
-
# Twitter is your twitter account. Every tweet is wrapped in
|
|
20
|
-
# an instance of Tweet. Every Tweet has one TwitterUser.
|
|
21
|
-
|
|
22
|
-
class Twitter
|
|
23
|
-
def initialize(options)
|
|
24
|
-
@uri = "https://twitter.com".to_uri(options)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# which can be :friends, :user or :public
|
|
28
|
-
# options[:query] can be things like since, since_id, count, etc.
|
|
29
|
-
def timeline(which = :friends, options={})
|
|
30
|
-
@uri["/statuses/#{which}_timeline.json"].get(options).deserialise.collect{|tweet| Tweet.new(tweet)}
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def post(text)
|
|
34
|
-
Tweet.new @uri['/statuses/update.json'].post('', {'User-Agent' => "Wrest/#{Wrest::VERSION::STRING}"}, :status => text).deserialise
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
class TwitterUser
|
|
39
|
-
# This will turn this class into a wrapper
|
|
40
|
-
# for the deserialised data from a response.
|
|
41
|
-
#
|
|
42
|
-
# All the keys in the hash are exposed as methods.
|
|
43
|
-
include Wrest::Components::Container
|
|
44
|
-
|
|
45
|
-
# We'd prefer the user's profile url to be
|
|
46
|
-
# a Wrest::Uri rather than a String, wouldn't we?
|
|
47
|
-
#
|
|
48
|
-
# Remember, using typecasting _will_
|
|
49
|
-
# slow down instance construction marginally, so turn it on
|
|
50
|
-
# only if you need it.
|
|
51
|
-
typecast :url => lambda{|url| url.to_uri}
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
class Tweet
|
|
55
|
-
include Wrest::Components::Container
|
|
56
|
-
|
|
57
|
-
typecast :user => lambda{|user| TwitterUser.new(user) }
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
twitter = Twitter.new(:username => 'ponnappa', :password => 'ha!likeImchecking*that*in')
|
|
62
|
-
|
|
63
|
-
pp twitter.post("This tweet via the Twitter example in #wrest #{Wrest::VERSION::STRING}, http://github.com/kaiwren/wrest")
|
|
64
|
-
|
|
65
|
-
puts '', '*'*70, ''
|
|
66
|
-
|
|
67
|
-
tweets = twitter.timeline(:friends, :since_id => 20751449)
|
|
68
|
-
|
|
69
|
-
# Print the name of the first user in my timeline.
|
|
70
|
-
puts tweets.first.user.name
|
|
71
|
-
|
|
72
|
-
puts '', '*'*70, ''
|
|
73
|
-
|
|
74
|
-
# Just remember that not everyone on Twitter has a
|
|
75
|
-
# url. On the other hand, some have more than one.
|
|
76
|
-
# This is just a cute little example that deals with
|
|
77
|
-
# the simple case of a single url.
|
|
78
|
-
puts tweets.first.user.url.get.body
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.expand_path(File.dirname(__FILE__) + "/../lib/wrest")
|
|
11
|
-
require 'pp'
|
|
12
|
-
|
|
13
|
-
Wrest.logger = Logger.new(STDOUT)
|
|
14
|
-
Wrest.logger.level = Logger::DEBUG # Set this to Logger::INFO or higher to disable request logging
|
|
15
|
-
|
|
16
|
-
# Optionally uncomment the following line to use the significantly faster libcurl library.
|
|
17
|
-
# This uses the patron gem - (sudo) gem install patron
|
|
18
|
-
# IMPORTANT: Libcurl support is currently in alpha and is both incomplete and unstable!
|
|
19
|
-
# Wrest.use_curl
|
|
20
|
-
|
|
21
|
-
# This is a basic example demonstrating GET and json deserialisation. The timeout field is optional, of course (it defaults to 60), but you can reduce it to a low number like 1 to force the request to timeout.
|
|
22
|
-
|
|
23
|
-
response = 'http://twitter.com/statuses/public_timeline.json'.to_uri(:timeout => 5).get
|
|
24
|
-
|
|
25
|
-
puts "Code: #{response.code}"
|
|
26
|
-
puts "Message: #{response.message}"
|
|
27
|
-
puts "Headers: #{response.headers.inspect}"
|
|
28
|
-
puts
|
|
29
|
-
puts "Deserialised Body: #{response.deserialise.inspect}"
|
|
30
|
-
puts '*' * 50
|
|
31
|
-
puts '*' * 50
|
|
32
|
-
puts "Body: #{response.body.inspect}"
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# Copyright 2009 Sidu Ponnappa
|
|
2
|
-
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
7
|
-
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8
|
-
# See the License for the specific language governing permissions and limitations under the License.
|
|
9
|
-
|
|
10
|
-
require File.expand_path(File.dirname(__FILE__) + "/../lib/wrest")
|
|
11
|
-
|
|
12
|
-
Wrest.logger = Logger.new(STDOUT)
|
|
13
|
-
Wrest.logger.level = Logger::DEBUG # Set this to Logger::INFO or higher to disable request logging
|
|
14
|
-
|
|
15
|
-
# Optionally uncomment the following line to use the significantly faster libcurl library.
|
|
16
|
-
# This uses the patron gem - (sudo) gem install patron
|
|
17
|
-
# IMPORTANT: Libcurl support is currently in alpha and is both incomplete and unstable!
|
|
18
|
-
# Wrest.use_curl
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
include Wrest
|
|
22
|
-
|
|
23
|
-
class Realm
|
|
24
|
-
include Components::Container
|
|
25
|
-
|
|
26
|
-
typecast :t => lambda{|type|
|
|
27
|
-
case type
|
|
28
|
-
when '1' then 'Normal'
|
|
29
|
-
when '2' then 'PvP'
|
|
30
|
-
when '3' then 'RP'
|
|
31
|
-
when '4' then 'RP PvP'
|
|
32
|
-
end
|
|
33
|
-
},
|
|
34
|
-
:s => lambda{|status|
|
|
35
|
-
case status
|
|
36
|
-
when '1' then 'Available'
|
|
37
|
-
else 'Unavailable'
|
|
38
|
-
end
|
|
39
|
-
},
|
|
40
|
-
:l => lambda{|load|
|
|
41
|
-
case load
|
|
42
|
-
when '1' then 'Low'
|
|
43
|
-
when '2' then 'Normal'
|
|
44
|
-
when '3' then 'High'
|
|
45
|
-
when '4' then 'Max'
|
|
46
|
-
end
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
alias_accessors :t => :type,
|
|
50
|
-
:s => :status,
|
|
51
|
-
:l => :load,
|
|
52
|
-
:n => :name
|
|
53
|
-
|
|
54
|
-
def available?
|
|
55
|
-
self.s == 'Available'
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
realms = "http://www.worldofwarcraft.com/realmstatus/status.xml".to_uri.get.deserialise['page']['rs']['r'].collect{|data| Realm.new(data)}
|
|
60
|
-
|
|
61
|
-
puts "Status of Nagrand: #{realms.find{|realm| realm.name == 'Nagrand'}.status}"
|
|
62
|
-
puts
|
|
63
|
-
puts "Listing All Available Realms:"
|
|
64
|
-
puts
|
|
65
|
-
puts "Realm\tLoad\tType"
|
|
66
|
-
puts "-----------"
|
|
67
|
-
realms.select(&:available?).each{|realm| puts "#{realm.name}\t#{realm.load}\t#{realm.type}" }
|
data/init.rb
DELETED
|
File without changes
|
data/spec/rcov.opts
DELETED
data/spec/spec.opts.disable
DELETED
data/spec/unit/spec_helper.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/../../lib/wrest")
|
|
2
|
-
require "#{Wrest::Root}/wrest/curl" unless RUBY_PLATFORM =~ /java/
|
|
3
|
-
require 'rspec'
|
|
4
|
-
|
|
5
|
-
['/../custom_matchers/**/*.rb'].each{|directory|
|
|
6
|
-
Dir["#{File.expand_path(File.dirname(__FILE__) + directory)}"].each { |file|
|
|
7
|
-
require file
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
Wrest.logger = Logger.new(File.open("#{Wrest::Root}/../log/test.log", 'a'))
|
|
12
|
-
|
|
13
|
-
def p(*args)
|
|
14
|
-
# super *(args << caller[0])
|
|
15
|
-
super *(args << '<br/>')
|
|
16
|
-
# super *args
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def puts(*args)
|
|
20
|
-
# super *(args << caller[0])
|
|
21
|
-
super *(['<pre>'] + args + ['</pre>'])
|
|
22
|
-
# super *args
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
RSpec.configure do |config|
|
|
26
|
-
config.include(CustomMatchers)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def build_ok_response(body = '')
|
|
30
|
-
mock(Net::HTTPOK).tap do |response|
|
|
31
|
-
response.stub!(:code).and_return('200')
|
|
32
|
-
response.stub!(:message).and_return('OK')
|
|
33
|
-
response.stub!(:body).and_return(body)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
2
|
-
|
|
3
|
-
module Wrest::Components
|
|
4
|
-
describe Container::AliasAccessors do
|
|
5
|
-
before :each do
|
|
6
|
-
@Demon = Class.new
|
|
7
|
-
@Demon.class_eval do
|
|
8
|
-
include Wrest::Components::Container
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "should provide a macro to enable aliasing accessors" do
|
|
13
|
-
lambda{ @Demon.class_eval{ alias_accessors :shiriki => :chambala } }.should_not raise_error(NoMethodError)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe 'aliasing' do
|
|
17
|
-
before :each do
|
|
18
|
-
@Demon.class_eval{ alias_accessors :sex => :gender, :age => :maturity }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "should provide an accessor methods when we alias to an attribute" do
|
|
22
|
-
demon = @Demon.new
|
|
23
|
-
demon.should respond_to(:gender)
|
|
24
|
-
demon.should respond_to(:gender=)
|
|
25
|
-
demon.should respond_to(:gender?)
|
|
26
|
-
demon.should respond_to(:maturity)
|
|
27
|
-
demon.should respond_to(:maturity=)
|
|
28
|
-
demon.should respond_to(:maturity?)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "should ensure that the aliased getter method delegates to the actual getter" do
|
|
32
|
-
demon = @Demon.new :sex => 'male'
|
|
33
|
-
demon.gender.should == 'male'
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "should ensure that the aliased setter method delegates to the actual getter" do
|
|
37
|
-
demon = @Demon.new
|
|
38
|
-
demon.should_receive(:sex=).with('male')
|
|
39
|
-
demon.gender = 'male'
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "should ensure that the aliased query method delegates to the actual queryier" do
|
|
43
|
-
demon = @Demon.new :age => '1000'
|
|
44
|
-
demon.gender?.should be_false
|
|
45
|
-
demon.maturity?.should be_true
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
2
|
-
|
|
3
|
-
module Wrest::Components
|
|
4
|
-
describe Container::Typecaster do
|
|
5
|
-
before :each do
|
|
6
|
-
@Demon = Class.new
|
|
7
|
-
@Demon.class_eval do
|
|
8
|
-
include Wrest::Components::Container
|
|
9
|
-
include Wrest::Components::Container::Typecaster
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "should know how to apply a lambda to the string value of a given key casting it to a new type" do
|
|
14
|
-
@Demon.class_eval{ typecast :age => lambda{|id_string| id_string.to_i} }
|
|
15
|
-
kai_wren = @Demon.new('age' => '1')
|
|
16
|
-
kai_wren.age.should == 1
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe "where the value is not a typecastable type" do
|
|
20
|
-
it "string should not typecast" do
|
|
21
|
-
@Demon.class_eval{ typecast :age => lambda{|id_string| id_string.to_i} }
|
|
22
|
-
kai_wren = @Demon.new('age' => :ooga)
|
|
23
|
-
kai_wren.age.should == :ooga
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "hash should not typecast" do
|
|
27
|
-
class TestUser
|
|
28
|
-
include Wrest::Components::Container
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
@Demon.class_eval{ typecast :user => lambda{|user| TestUser.new(user)}}
|
|
32
|
-
|
|
33
|
-
kai_wren = @Demon.new('user' => {'foo' => 'bar'})
|
|
34
|
-
kai_wren.user.class.should == TestUser
|
|
35
|
-
kai_wren.user.foo.should == 'bar'
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "array should not typecast" do
|
|
39
|
-
@Demon.class_eval{ typecast :addresses => lambda{|addresses| addresses.first} }
|
|
40
|
-
kai_wren = @Demon.new('addresses' => ['foo', 'bar'])
|
|
41
|
-
kai_wren.addresses.should == 'foo'
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "should leave nils unchanged" do
|
|
46
|
-
@Demon.class_eval{ typecast :age => lambda{|id_string| id_string.to_i} }
|
|
47
|
-
kai_wren = @Demon.new('age' => nil)
|
|
48
|
-
kai_wren.age.should be_nil
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "should provide helpers for typcasting common types" do
|
|
52
|
-
@Demon.class_eval{ typecast :age => as_integer }
|
|
53
|
-
kai_wren = @Demon.new('age' => '1500')
|
|
54
|
-
kai_wren.age.should == 1500
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe 'in subclasses' do
|
|
58
|
-
before :each do
|
|
59
|
-
@Sidhe = Class.new
|
|
60
|
-
@Sidhe.class_eval do
|
|
61
|
-
include Wrest::Components::Container
|
|
62
|
-
include Wrest::Components::Container::Typecaster
|
|
63
|
-
|
|
64
|
-
typecast :age => as_integer
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "should inherit all defined typecasts" do
|
|
69
|
-
@ChineseSidhe = Class.new(@Sidhe)
|
|
70
|
-
kai_wren = @ChineseSidhe.new('age' => '1500')
|
|
71
|
-
kai_wren.age.should == 1500
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "should discard all typecasts from parent if defined in child" do
|
|
75
|
-
@ChineseSidhe = Class.new(@Sidhe)
|
|
76
|
-
@ChineseSidhe.class_eval{ typecast :born_in => as_integer }
|
|
77
|
-
kai_wren = @ChineseSidhe.new('age' => '1500', 'born_in' => '509')
|
|
78
|
-
kai_wren.age.should == '1500'
|
|
79
|
-
kai_wren.born_in.should == 509
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|