rapuncel 0.0.4 → 0.0.5.RC1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/Gemfile +3 -0
  2. data/README.md +35 -24
  3. data/Rakefile +11 -11
  4. data/lib/rapuncel.rb +9 -17
  5. data/lib/rapuncel/adapters/net_http_adapter.rb +7 -5
  6. data/lib/rapuncel/base_64_string.rb +31 -0
  7. data/lib/rapuncel/client.rb +2 -2
  8. data/lib/rapuncel/connection.rb +35 -58
  9. data/lib/rapuncel/request.rb +1 -38
  10. data/lib/rapuncel/response.rb +17 -30
  11. data/lib/rapuncel/xml_rpc_deserializer.rb +110 -0
  12. data/lib/rapuncel/xml_rpc_serializer.rb +148 -0
  13. data/rapuncel.gemspec +3 -2
  14. data/spec/functional/client_spec.rb +53 -0
  15. data/spec/spec_helper.rb +48 -0
  16. data/{test → spec}/test_server.rb +0 -1
  17. data/spec/unit/array_spec.rb +41 -0
  18. data/spec/unit/base64_spec.rb +30 -0
  19. data/spec/unit/boolean_spec.rb +39 -0
  20. data/spec/unit/connection_spec.rb +22 -0
  21. data/spec/unit/float_spec.rb +38 -0
  22. data/spec/unit/hash_spec.rb +54 -0
  23. data/spec/unit/int_spec.rb +23 -0
  24. data/spec/unit/nil_spec.rb +7 -0
  25. data/spec/unit/object_spec.rb +24 -0
  26. data/spec/unit/proxy_spec.rb +29 -0
  27. data/spec/unit/request_spec.rb +28 -0
  28. data/{test/unit/response_test.rb → spec/unit/response_spec.rb} +29 -44
  29. data/spec/unit/string_spec.rb +35 -0
  30. data/spec/unit/time_spec.rb +20 -0
  31. metadata +77 -104
  32. data/lib/rapuncel/base.rb +0 -7
  33. data/lib/rapuncel/core_ext/array.rb +0 -23
  34. data/lib/rapuncel/core_ext/big_decimal.rb +0 -7
  35. data/lib/rapuncel/core_ext/boolean.rb +0 -29
  36. data/lib/rapuncel/core_ext/float.rb +0 -11
  37. data/lib/rapuncel/core_ext/hash.rb +0 -32
  38. data/lib/rapuncel/core_ext/integer.rb +0 -11
  39. data/lib/rapuncel/core_ext/nil.rb +0 -7
  40. data/lib/rapuncel/core_ext/object.rb +0 -49
  41. data/lib/rapuncel/core_ext/string.rb +0 -12
  42. data/lib/rapuncel/core_ext/symbol.rb +0 -7
  43. data/lib/rapuncel/core_ext/time.rb +0 -14
  44. data/rapuncel-0.0.3.gem +0 -0
  45. data/test/functional/client_test.rb +0 -54
  46. data/test/functional_test_helper.rb +0 -13
  47. data/test/test_helper.rb +0 -38
  48. data/test/unit/array_test.rb +0 -97
  49. data/test/unit/boolean_test.rb +0 -34
  50. data/test/unit/connection_test.rb +0 -29
  51. data/test/unit/float_test.rb +0 -23
  52. data/test/unit/hash_test.rb +0 -54
  53. data/test/unit/int_test.rb +0 -27
  54. data/test/unit/nil_test.rb +0 -16
  55. data/test/unit/object_test.rb +0 -83
  56. data/test/unit/proxy_test.rb +0 -52
  57. data/test/unit/request_test.rb +0 -34
  58. data/test/unit/string_test.rb +0 -40
  59. data/test/unit/time_test.rb +0 -23
@@ -1,29 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ConnectionTest < ActiveSupport::TestCase
4
- test "Connection.new should return an AuthConnection if user, password or auth_method is set" do
5
- assert_kind_of Rapuncel::AuthConnection, Rapuncel::Connection.build(:auth_method => 'basic')
6
- assert_kind_of Rapuncel::AuthConnection, Rapuncel::Connection.build(:user => '')
7
- assert_kind_of Rapuncel::AuthConnection, Rapuncel::Connection.build(:password => '')
8
- end
9
-
10
- test "Connection should not choke on extra 'http://' in @host" do
11
- connection = Rapuncel::Connection.build :host => "http://example.org"
12
-
13
- assert_equal "example.org", connection.host
14
- end
15
-
16
- test "Connection should accept path beginning with or without /" do
17
- connection = Rapuncel::Connection.build :host => "http://example.org", :path => "abcd"
18
-
19
- assert_equal "/abcd", connection.path
20
- end
21
-
22
- test "Connection.new should return an ApiKeyAuthConnection if api_key is set" do
23
- assert_kind_of Rapuncel::ApiKeyAuthConnection, Rapuncel::Connection.build(:api_key => 'xyz')
24
- end
25
-
26
- test "ApiKeyAuthConnection should contain api key in headers" do
27
- assert_equal 'xyz', Rapuncel::Connection.build(:api_key => 'xyz').headers['X-ApiKey']
28
- end
29
- end
@@ -1,23 +0,0 @@
1
- require 'test_helper'
2
-
3
- class FloatTest < ActiveSupport::TestCase
4
- test "A float should be a number between 'double' tags" do
5
- num=1.123456
6
- xml=num.to_xml_rpc
7
-
8
- assert_select xml, '/double', 1
9
- assert_select xml, '/double', num.to_s
10
-
11
- end
12
-
13
- test "A float converted to xml and back should be the same number!" do
14
- num=1.123456
15
- xml=num.to_xml_rpc
16
-
17
- xml_node=Nokogiri::XML(xml).children.first #make a nokogiri xml_node containing the float
18
-
19
- assert_equal num, Float.from_xml_rpc(xml_node)
20
- end
21
-
22
-
23
- end
@@ -1,54 +0,0 @@
1
- require 'test_helper'
2
- require 'active_support/core_ext/hash/keys'
3
-
4
- class TestHelper < ActiveSupport::TestCase
5
-
6
-
7
-
8
-
9
- def to_and_from_xml_rpc hash
10
- xml = hash.to_xml_rpc
11
-
12
- xml_node = Nokogiri::XML(xml).children.first
13
-
14
- Hash.from_xml_rpc xml_node
15
- end
16
-
17
- test 'Hash#to_xml_rpc' do
18
- xml = {
19
- :abc => 'one and two',
20
- 40 => %w(foo bar bee)
21
- }.to_xml_rpc
22
-
23
- assert_select xml, '/struct', 1
24
- assert_select xml, '/struct/member', 2
25
- assert_select xml, '/struct/member/name', 'abc', 1
26
- assert_select xml, '/struct/member/value/string', 'one and two', 1
27
- assert_select xml, '/struct/member/name', '40', 1
28
- assert_select xml, '/struct/member/value/array/data/value', 3
29
- end
30
-
31
-
32
- test "A hash to xml and back should be itself" do
33
- hash1 = {:a => "b", :c => "d", :A => "B"}
34
- arr1 = (1..10).to_a
35
- hash2 = {:arr => arr1, :text => "sheeee"}
36
- hash3 = hash1.merge({:jooooo => hash2})
37
-
38
- hash4 = Hash[*(1..10).to_a] #separate, non symbol keys
39
-
40
- hashes = [hash1, hash2, hash3]
41
-
42
- results = hashes.map do |h|
43
- to_and_from_xml_rpc h
44
- end
45
-
46
- result4 = to_and_from_xml_rpc hash4 #separate, non symbol keys
47
-
48
- hashes.zip(results).each do |hr|
49
- assert_equal *hr
50
- end
51
-
52
- assert_equal hash4.stringify_keys.symbolize_keys, result4
53
- end
54
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- class IntTest < ActiveSupport::TestCase
4
-
5
- def test_number num = 1
6
- assert_select num.to_xml_rpc, '/int', 1
7
- assert_select num.to_xml_rpc, '/int', num.to_s
8
- end
9
-
10
- test "should convert the number 1234567 to the string '<int>1234567</int>'" do
11
- num = 1234567
12
-
13
- test_number num
14
- end
15
-
16
- test "should warn if numbers go out of 4 byte signed integer range [#{(-2**31).to_s}, #{(2**31-1)}], e.g #{(2**31).to_s},
17
- but should still give the right result as long as ruby can handle the number" do
18
- num = 2**31
19
-
20
- test_number num
21
- end
22
-
23
- test "An int converted to xml and back should be the same number!" do
24
- num = 234132
25
- assert_equal num, Integer.from_xml_rpc(Nokogiri::XML(num.to_xml_rpc).children.first)
26
- end
27
- end
@@ -1,16 +0,0 @@
1
- require 'test_helper'
2
-
3
- class NilTest < ActiveSupport::TestCase
4
-
5
- test "nil should have the same response as false" do
6
- assert_equal false.to_xml_rpc, nil.to_xml_rpc
7
- end
8
-
9
- test "nil must evaluate to /boolean/0, as does false" do
10
- assert_select nil.to_xml_rpc, '/boolean', 1
11
- assert_select nil.to_xml_rpc, '/boolean', '0'
12
- end
13
-
14
-
15
-
16
- end
@@ -1,83 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ObjectTest < ActiveSupport::TestCase
4
- class TestObject
5
- attr_accessor :a, :b, :c
6
- end
7
-
8
- test 'Object#to_xml_rpc should collect instance_variables in a Hash and return Hash#to_xml_rpc' do
9
- obj = TestObject.new
10
- obj.a = "one"
11
- obj.b = "two"
12
-
13
- assert_equal({'a' => 'one', 'b' => 'two'}, obj.send(:_collect_ivars_in_hash))
14
-
15
- obj.a.expects :to_xml_rpc
16
- obj.b.expects :to_xml_rpc
17
-
18
- obj.to_xml_rpc
19
- end
20
-
21
- test "Object.from_xml_rpc should accept nodes as strings" do
22
- xml = "<int>42</int>"
23
-
24
- Integer.expects :from_xml_rpc
25
- Object.from_xml_rpc xml
26
- end
27
-
28
- test "Object.from_xml_rpc should accept Nokogiri nodes" do
29
- xml = Nokogiri::XML.parse("<int>42</int>").root
30
-
31
- Integer.expects :from_xml_rpc
32
- Object.from_xml_rpc xml
33
- end
34
-
35
- test "Object.from_xml_rpc should delegate int nodes" do
36
- xml = "<int>42</int>"
37
-
38
- Integer.expects :from_xml_rpc
39
- Object.from_xml_rpc xml
40
- end
41
-
42
- test "Object.from_xml_rpc should delegate string nodes" do
43
- xml = "<string>foo<string>"
44
-
45
- String.expects :from_xml_rpc
46
- Object.from_xml_rpc xml
47
- end
48
-
49
- test "Object.from_xml_rpc should delegate array nodes" do
50
- xml = "<array>42</array>"
51
-
52
- Array.expects :from_xml_rpc
53
- Object.from_xml_rpc xml
54
- end
55
-
56
- test "Object.from_xml_rpc should delegate hash nodes" do
57
- xml = "<struct>42</struct>"
58
-
59
- Hash.expects :from_xml_rpc
60
- Object.from_xml_rpc xml
61
- end
62
-
63
- test "Object.from_xml_rpc should delegate boolean nodes" do
64
- xml = "<boolean>1</boolean>"
65
-
66
- Rapuncel::Boolean.expects :from_xml_rpc
67
- Object.from_xml_rpc xml
68
- end
69
-
70
- test "Object.from_xml_rpc should delegate double nodes" do
71
- xml = "<double>42.23</double>"
72
-
73
- Float.expects :from_xml_rpc
74
- Object.from_xml_rpc xml
75
- end
76
-
77
- test "Object.from_xml_rpc should delegate Time nodes" do
78
- xml = "<dateTime.iso8601>2010-11-25T11:44:46+01:00</dateTime.iso8601>"
79
-
80
- Time.expects :from_xml_rpc
81
- Object.from_xml_rpc xml
82
- end
83
- end
@@ -1,52 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ProxyTest < ActiveSupport::TestCase
4
- class TestClient
5
- def call_to_ruby request, *args
6
- [request] + args
7
- end
8
- end
9
-
10
- test "Proxy should still provide __ methods" do
11
- t = Object.new
12
- t.expects(:call_to_ruby).never
13
-
14
- p = Rapuncel::Proxy.new t
15
-
16
- p.__inspect__
17
- p.__tap__ {}
18
- p.__freeze__
19
- end
20
-
21
- test "Proxy should delegate standard Object instance methods to Client" do
22
- t = TestClient.new
23
-
24
- p = Rapuncel::Proxy.new t
25
- request = p.inspect
26
-
27
- assert_equal 'inspect', request.first
28
- end
29
-
30
- test "Proxy should delegate non-existing methods to Client" do
31
- t = TestClient.new
32
-
33
- p = Rapuncel::Proxy.new t
34
- request = p.whatever 'arg1', 'foobar', 1234
35
-
36
- assert_equal 'whatever', request.first
37
- assert_equal ['arg1', 'foobar', 1234], request[1..-1]
38
- end
39
-
40
- test "Proxy should dynamically define methods as soon as needed" do
41
- t = TestClient.new
42
-
43
- p = Rapuncel::Proxy.new t
44
-
45
- assert p.respond_to?('foobar')
46
- assert !Rapuncel::Proxy.instance_methods.include?('foobar')
47
-
48
- p.foobar
49
-
50
- assert (Rapuncel::Proxy.instance_methods.include?('foobar') || Rapuncel::Proxy.instance_methods.include?(:foobar))
51
- end
52
- end
@@ -1,34 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RequestTest < ActiveSupport::TestCase
4
- def get_test_request
5
- Rapuncel::Request.new 'test_method', "one argument", "another"
6
- end
7
-
8
- test "Serialized request shuold have xml version=1.0" do
9
- xml = get_test_request.to_xml_rpc
10
-
11
- assert xml.match(/<\?xml version=['"]1.0/)
12
- end
13
-
14
- test "Serialized request should have 1 methodCall tag" do
15
- xml = get_test_request.to_xml_rpc
16
- assert_select xml, '/methodCall', 1
17
- end
18
-
19
- test "Serialized request should contain methodName" do
20
- xml = get_test_request.to_xml_rpc
21
-
22
- assert_select xml, '/methodCall/methodName', 'test_method'
23
- end
24
-
25
- test "Serialized request should contain params" do
26
- xml = get_test_request.to_xml_rpc
27
-
28
- assert_select xml, '/methodCall/params', 1
29
- assert_select xml, '/methodCall/params/param/value', 2
30
-
31
- assert_select xml, '/methodCall/params/param/value', 'one argument', 1
32
- assert_select xml, '/methodCall/params/param/value', 'another', 1
33
- end
34
- end
@@ -1,40 +0,0 @@
1
- require 'test_helper'
2
-
3
-
4
- class StringTest < ActiveSupport::TestCase
5
-
6
-
7
- test "A string should simply be written between two <string></string> tags" do
8
- str = "blabla"
9
- xml = str.to_xml_rpc
10
- assert_select xml, '/string', 1
11
- assert_select xml, '/string', str
12
- end
13
-
14
- test "A symbol should simply be written between two <string></string> tags" do
15
- sym = :blabla
16
- xml = sym.to_xml_rpc
17
- assert_select xml, '/string', 1
18
- assert_select xml, '/string', sym.to_s
19
- end
20
-
21
-
22
- test "A string to_xml_rpc from_xml_rpc should be itself, even with whitespace" do #weird characters too?? or do we need base64 for that
23
- str = "yabba dabba doo! \t"
24
- xml = str.to_xml_rpc
25
-
26
-
27
- xml_node = Nokogiri::XML(xml).children.first
28
-
29
- assert_equal str, String.from_xml_rpc(xml_node)
30
- end
31
-
32
- test "CRLF and CR should be normalized" do
33
- str = "one\r\ntwo\rthree\nfour"
34
- xml = str.to_xml_rpc
35
-
36
- xml_node = Nokogiri::XML(xml).children.first
37
-
38
- assert_equal "one\ntwo\nthree\nfour", String.from_xml_rpc(xml_node)
39
- end
40
- end
@@ -1,23 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TimeTest < ActiveSupport::TestCase
4
-
5
- test "Time.now should be written down in the iso 8601 standard between dateTime.iso8601 tags" do
6
- t = Time.now
7
- xml = t.to_xml_rpc
8
-
9
- assert_select xml, '/dateTime.iso8601', 1
10
- assert_select xml, '/dateTime.iso8601', t.iso8601
11
- end
12
-
13
- test "A time converted to xml and reparsed should be equal to its starting point" do
14
- t = Time.now
15
- xml = t.to_xml_rpc
16
-
17
- xml_node = Nokogiri::XML(xml).children.first
18
-
19
- reparsed = Time.from_xml_rpc(xml_node)
20
-
21
- assert_equal t.to_i, reparsed.to_i # can't use assert_equal here! need to find a decent equality operator!!
22
- end
23
- end