rapuncel 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/README.md +39 -33
  2. data/{Rakefile.rb → Rakefile} +1 -1
  3. data/lib/rapuncel.rb +2 -1
  4. data/lib/rapuncel/adapters/net_http_adapter.rb +6 -6
  5. data/lib/rapuncel/base.rb +2 -2
  6. data/lib/rapuncel/client.rb +21 -13
  7. data/lib/rapuncel/connection.rb +2 -2
  8. data/lib/rapuncel/core_ext/array.rb +9 -16
  9. data/lib/rapuncel/core_ext/big_decimal.rb +7 -0
  10. data/lib/rapuncel/core_ext/boolean.rb +10 -13
  11. data/lib/rapuncel/core_ext/float.rb +4 -7
  12. data/lib/rapuncel/core_ext/hash.rb +17 -27
  13. data/lib/rapuncel/core_ext/integer.rb +2 -10
  14. data/lib/rapuncel/core_ext/nil.rb +7 -0
  15. data/lib/rapuncel/core_ext/object.rb +6 -6
  16. data/lib/rapuncel/core_ext/string.rb +5 -7
  17. data/lib/rapuncel/core_ext/symbol.rb +2 -3
  18. data/lib/rapuncel/core_ext/time.rb +5 -8
  19. data/lib/rapuncel/proxy.rb +39 -14
  20. data/lib/rapuncel/request.rb +7 -6
  21. data/lib/rapuncel/response.rb +60 -31
  22. data/rapuncel.gemspec +2 -3
  23. data/test/functional/client_test.rb +38 -7
  24. data/test/functional_test_helper.rb +2 -2
  25. data/test/test_server.rb +3 -3
  26. data/test/unit/array_test.rb +14 -14
  27. data/test/unit/boolean_test.rb +6 -6
  28. data/test/unit/float_test.rb +7 -7
  29. data/test/unit/hash_test.rb +16 -16
  30. data/test/unit/nil_test.rb +16 -0
  31. data/test/unit/object_test.rb +29 -29
  32. data/test/unit/proxy_test.rb +9 -9
  33. data/test/unit/response_test.rb +69 -5
  34. data/test/unit/string_test.rb +15 -7
  35. metadata +13 -53
  36. data/lib/rapuncel/adapters/typhoeus_adapter.rb +0 -33
  37. data/lib/rapuncel/fault.rb +0 -10
  38. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-adapters-typhoeus_adapter_rb.html +0 -231
  39. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-base_rb.html +0 -105
  40. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-client_rb.html +0 -321
  41. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-connection_rb.html +0 -513
  42. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-core_ext-array_rb.html +0 -303
  43. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-core_ext-boolean_rb.html +0 -255
  44. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-core_ext-float_rb.html +0 -177
  45. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-core_ext-hash_rb.html +0 -297
  46. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-core_ext-integer_rb.html +0 -177
  47. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-core_ext-object_rb.html +0 -297
  48. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-core_ext-string_rb.html +0 -159
  49. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-core_ext-time_rb.html +0 -165
  50. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-fault_rb.html +0 -93
  51. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-proxy_rb.html +0 -393
  52. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-request_rb.html +0 -351
  53. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel-response_rb.html +0 -399
  54. data/test/coverage/-Users-mariantheisen-Projects-Kayoom-rapuncel-lib-rapuncel_rb.html +0 -201
  55. data/test/coverage/functional_test_helper_rb.html +0 -141
  56. data/test/coverage/index.html +0 -410
  57. data/test/coverage/jquery-1.3.2.min.js +0 -19
  58. data/test/coverage/jquery.tablesorter.min.js +0 -15
  59. data/test/coverage/print.css +0 -12
  60. data/test/coverage/rcov.js +0 -42
  61. data/test/coverage/screen.css +0 -270
  62. data/test/coverage/test_helper_rb.html +0 -291
  63. data/test/coverage/test_server_rb.html +0 -231
@@ -1,12 +1,12 @@
1
1
  require 'test_helper'
2
2
  require 'test_server'
3
3
 
4
- class FunctionalTest < ActiveSupport::TestCase
4
+ class FunctionalTest < ActiveSupport::TestCase
5
5
  def setup
6
6
  @test_server = TestServer.new
7
7
  @test_server.start
8
8
  end
9
-
9
+
10
10
  def teardown
11
11
  @test_server.stop
12
12
  end
data/test/test_server.rb CHANGED
@@ -43,12 +43,12 @@ class TestServer
43
43
  s.add_handler(Num::INTERFACE, Num.new)
44
44
  end
45
45
  end
46
-
46
+
47
47
  def start
48
48
  Thread.new { @server.serve }
49
49
  end
50
-
50
+
51
51
  def stop
52
52
  @server.shutdown
53
- end
53
+ end
54
54
  end
@@ -8,37 +8,37 @@ class ArrayTest < ActiveSupport::TestCase
8
8
 
9
9
  assert_select xml, '/array/data/value', 10
10
10
  end
11
-
11
+
12
12
  def test_array arr
13
13
  xml = arr.to_xml_rpc
14
-
14
+
15
15
  xml_node = Nokogiri::XML(xml).children.first
16
-
16
+
17
17
  reparsed = Array.from_xml_rpc xml_node
18
-
18
+
19
19
  reparsed
20
20
  end
21
-
22
-
21
+
22
+
23
23
  test "An array, converted to xml and parsed back should be itself" do
24
24
  arr1 = (1..10).to_a
25
25
  arr2 = arr1.map &:to_s
26
-
26
+
27
27
  arr3 = [arr1, arr2]
28
-
28
+
29
29
  arr4 = ["hello", arr3]
30
-
30
+
31
31
  reparsed1 = test_array arr1
32
32
  reparsed2 = test_array arr2
33
33
  reparsed3 = test_array arr3
34
34
  reparsed4 = test_array arr4
35
-
35
+
36
36
  [reparsed1, reparsed2, reparsed3, reparsed4].zip([arr1, arr2, arr3, arr4]).each do |b|
37
37
  assert_equal *b
38
38
  end
39
-
39
+
40
40
  end
41
-
41
+
42
42
  test "real world repsonse" do
43
43
  response_body = <<-XML
44
44
  <array><data>
@@ -86,9 +86,9 @@ class ArrayTest < ActiveSupport::TestCase
86
86
  </struct></value>
87
87
  </data></array>
88
88
  XML
89
-
89
+
90
90
  arr = Object.from_xml_rpc response_body
91
-
91
+
92
92
  assert_kind_of Array, arr
93
93
  assert_equal 3, arr.size
94
94
  end
@@ -11,24 +11,24 @@ class BooleanTest < ActiveSupport::TestCase
11
11
  assert_select false.to_xml_rpc, '/boolean', 1
12
12
  assert_select false.to_xml_rpc, '/boolean', '0'
13
13
  end
14
-
14
+
15
15
  test "true.to_xml_rpc reparsed must be true" do
16
16
  xml=true.to_xml_rpc
17
17
  xml_node = Nokogiri::XML(xml).children.first
18
-
18
+
19
19
  assert Rapuncel::Boolean.from_xml_rpc(xml_node) #I assume assert takes a boolean?
20
20
  assert Rapuncel::Boolean.from_xml_rpc(xml_node) == true #is this different? just in case the other function gives back something non nil/false which is not necessarily true
21
21
  end
22
-
22
+
23
23
  test "false.to_xml_rpc reparsed must be false" do
24
24
  xml=false.to_xml_rpc
25
25
  xml_node = Nokogiri::XML(xml).children.first
26
-
26
+
27
27
  assert !Rapuncel::Boolean.from_xml_rpc(xml_node)
28
28
  end
29
-
29
+
30
30
  test "anything else should evaluate to what now?" do
31
31
  assert true
32
32
  end
33
-
33
+
34
34
  end
@@ -4,20 +4,20 @@ class FloatTest < ActiveSupport::TestCase
4
4
  test "A float should be a number between 'double' tags" do
5
5
  num=1.123456
6
6
  xml=num.to_xml_rpc
7
-
7
+
8
8
  assert_select xml, '/double', 1
9
9
  assert_select xml, '/double', num.to_s
10
-
10
+
11
11
  end
12
-
12
+
13
13
  test "A float converted to xml and back should be the same number!" do
14
14
  num=1.123456
15
15
  xml=num.to_xml_rpc
16
-
16
+
17
17
  xml_node=Nokogiri::XML(xml).children.first #make a nokogiri xml_node containing the float
18
-
18
+
19
19
  assert_equal num, Float.from_xml_rpc(xml_node)
20
20
  end
21
-
22
-
21
+
22
+
23
23
  end
@@ -2,24 +2,24 @@ require 'test_helper'
2
2
  require 'active_support/core_ext/hash/keys'
3
3
 
4
4
  class TestHelper < ActiveSupport::TestCase
5
-
6
-
7
-
8
-
5
+
6
+
7
+
8
+
9
9
  def to_and_from_xml_rpc hash
10
10
  xml = hash.to_xml_rpc
11
11
 
12
12
  xml_node = Nokogiri::XML(xml).children.first
13
-
13
+
14
14
  Hash.from_xml_rpc xml_node
15
15
  end
16
-
16
+
17
17
  test 'Hash#to_xml_rpc' do
18
18
  xml = {
19
19
  :abc => 'one and two',
20
20
  40 => %w(foo bar bee)
21
21
  }.to_xml_rpc
22
-
22
+
23
23
  assert_select xml, '/struct', 1
24
24
  assert_select xml, '/struct/member', 2
25
25
  assert_select xml, '/struct/member/name', 'abc', 1
@@ -27,28 +27,28 @@ class TestHelper < ActiveSupport::TestCase
27
27
  assert_select xml, '/struct/member/name', '40', 1
28
28
  assert_select xml, '/struct/member/value/array/data/value', 3
29
29
  end
30
-
31
-
30
+
31
+
32
32
  test "A hash to xml and back should be itself" do
33
33
  hash1 = {:a => "b", :c => "d", :A => "B"}
34
34
  arr1 = (1..10).to_a
35
35
  hash2 = {:arr => arr1, :text => "sheeee"}
36
36
  hash3 = hash1.merge({:jooooo => hash2})
37
-
37
+
38
38
  hash4 = Hash[*(1..10).to_a] #separate, non symbol keys
39
-
39
+
40
40
  hashes = [hash1, hash2, hash3]
41
-
41
+
42
42
  results = hashes.map do |h|
43
43
  to_and_from_xml_rpc h
44
44
  end
45
-
45
+
46
46
  result4 = to_and_from_xml_rpc hash4 #separate, non symbol keys
47
-
47
+
48
48
  hashes.zip(results).each do |hr|
49
49
  assert_equal *hr
50
- end
51
-
50
+ end
51
+
52
52
  assert_equal hash4.stringify_keys.symbolize_keys, result4
53
53
  end
54
54
  end
@@ -0,0 +1,16 @@
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
@@ -4,79 +4,79 @@ class ObjectTest < ActiveSupport::TestCase
4
4
  class TestObject
5
5
  attr_accessor :a, :b, :c
6
6
  end
7
-
7
+
8
8
  test 'Object#to_xml_rpc should collect instance_variables in a Hash and return Hash#to_xml_rpc' do
9
9
  obj = TestObject.new
10
10
  obj.a = "one"
11
11
  obj.b = "two"
12
-
12
+
13
13
  assert_equal({'a' => 'one', 'b' => 'two'}, obj.send(:_collect_ivars_in_hash))
14
-
14
+
15
15
  obj.a.expects :to_xml_rpc
16
16
  obj.b.expects :to_xml_rpc
17
-
17
+
18
18
  obj.to_xml_rpc
19
19
  end
20
-
20
+
21
21
  test "Object.from_xml_rpc should accept nodes as strings" do
22
22
  xml = "<int>42</int>"
23
-
24
- Integer.expects :from_xml_rpc
23
+
24
+ Integer.expects :from_xml_rpc
25
25
  Object.from_xml_rpc xml
26
26
  end
27
-
27
+
28
28
  test "Object.from_xml_rpc should accept Nokogiri nodes" do
29
29
  xml = Nokogiri::XML.parse("<int>42</int>").root
30
-
30
+
31
31
  Integer.expects :from_xml_rpc
32
32
  Object.from_xml_rpc xml
33
33
  end
34
-
34
+
35
35
  test "Object.from_xml_rpc should delegate int nodes" do
36
36
  xml = "<int>42</int>"
37
-
38
- Integer.expects :from_xml_rpc
37
+
38
+ Integer.expects :from_xml_rpc
39
39
  Object.from_xml_rpc xml
40
40
  end
41
-
41
+
42
42
  test "Object.from_xml_rpc should delegate string nodes" do
43
43
  xml = "<string>foo<string>"
44
-
45
- String.expects :from_xml_rpc
44
+
45
+ String.expects :from_xml_rpc
46
46
  Object.from_xml_rpc xml
47
47
  end
48
-
48
+
49
49
  test "Object.from_xml_rpc should delegate array nodes" do
50
50
  xml = "<array>42</array>"
51
-
52
- Array.expects :from_xml_rpc
51
+
52
+ Array.expects :from_xml_rpc
53
53
  Object.from_xml_rpc xml
54
54
  end
55
-
55
+
56
56
  test "Object.from_xml_rpc should delegate hash nodes" do
57
57
  xml = "<struct>42</struct>"
58
-
59
- Hash.expects :from_xml_rpc
58
+
59
+ Hash.expects :from_xml_rpc
60
60
  Object.from_xml_rpc xml
61
61
  end
62
-
62
+
63
63
  test "Object.from_xml_rpc should delegate boolean nodes" do
64
64
  xml = "<boolean>1</boolean>"
65
-
66
- Rapuncel::Boolean.expects :from_xml_rpc
65
+
66
+ Rapuncel::Boolean.expects :from_xml_rpc
67
67
  Object.from_xml_rpc xml
68
68
  end
69
-
69
+
70
70
  test "Object.from_xml_rpc should delegate double nodes" do
71
71
  xml = "<double>42.23</double>"
72
-
73
- Float.expects :from_xml_rpc
72
+
73
+ Float.expects :from_xml_rpc
74
74
  Object.from_xml_rpc xml
75
75
  end
76
-
76
+
77
77
  test "Object.from_xml_rpc should delegate Time nodes" do
78
78
  xml = "<dateTime.iso8601>2010-11-25T11:44:46+01:00</dateTime.iso8601>"
79
-
79
+
80
80
  Time.expects :from_xml_rpc
81
81
  Object.from_xml_rpc xml
82
82
  end
@@ -2,14 +2,14 @@ require 'test_helper'
2
2
 
3
3
  class ProxyTest < ActiveSupport::TestCase
4
4
  class TestClient
5
- def execute_to_ruby request
6
- request
5
+ def call_to_ruby request, *args
6
+ [request] + args
7
7
  end
8
8
  end
9
9
 
10
10
  test "Proxy should still provide __ methods" do
11
11
  t = Object.new
12
- t.expects(:execute_to_ruby).never
12
+ t.expects(:call_to_ruby).never
13
13
 
14
14
  p = Rapuncel::Proxy.new t
15
15
 
@@ -24,7 +24,7 @@ class ProxyTest < ActiveSupport::TestCase
24
24
  p = Rapuncel::Proxy.new t
25
25
  request = p.inspect
26
26
 
27
- assert_equal 'inspect', request.method_name
27
+ assert_equal 'inspect', request.first
28
28
  end
29
29
 
30
30
  test "Proxy should delegate non-existing methods to Client" do
@@ -33,8 +33,8 @@ class ProxyTest < ActiveSupport::TestCase
33
33
  p = Rapuncel::Proxy.new t
34
34
  request = p.whatever 'arg1', 'foobar', 1234
35
35
 
36
- assert_equal 'whatever', request.method_name
37
- assert_equal ['arg1', 'foobar', 1234], request.arguments
36
+ assert_equal 'whatever', request.first
37
+ assert_equal ['arg1', 'foobar', 1234], request[1..-1]
38
38
  end
39
39
 
40
40
  test "Proxy should dynamically define methods as soon as needed" do
@@ -42,11 +42,11 @@ class ProxyTest < ActiveSupport::TestCase
42
42
 
43
43
  p = Rapuncel::Proxy.new t
44
44
 
45
- assert !p.respond_to?('foobar')
45
+ assert p.respond_to?('foobar')
46
+ assert !Rapuncel::Proxy.instance_methods.include?('foobar')
46
47
 
47
48
  p.foobar
48
49
 
49
- v = Rapuncel::Proxy.new t
50
- assert v.respond_to?('foobar')
50
+ assert Rapuncel::Proxy.instance_methods.include?('foobar')
51
51
  end
52
52
  end
@@ -3,10 +3,10 @@ require 'test_helper'
3
3
 
4
4
  class ResponseTest < ActiveSupport::TestCase
5
5
  class MockReponse
6
- attr_accessor :body
6
+ attr_accessor :body, :code
7
7
 
8
- def initialize body, success = true
9
- @body, @success = body, success
8
+ def initialize body, success = true, code = 200
9
+ @body, @success, @code = body, success, code
10
10
  end
11
11
 
12
12
  def success?
@@ -14,7 +14,7 @@ class ResponseTest < ActiveSupport::TestCase
14
14
  end
15
15
  end
16
16
 
17
- test 'Response should be not an Array' do
17
+ test 'Response should not be an Array' do
18
18
  mock = MockReponse.new <<-XML
19
19
  <?xml version='1.0'?>
20
20
  <methodResponse>
@@ -30,7 +30,71 @@ class ResponseTest < ActiveSupport::TestCase
30
30
 
31
31
  r = Rapuncel::Response.new mock
32
32
 
33
+
34
+ assert r.success?
35
+ assert !r.fault?
36
+ assert !r.error?
33
37
  assert_equal "foo foo foo", r.to_ruby
38
+ assert_equal "foo foo foo", r.result
39
+ end
40
+
41
+ test "Response should handle faults" do
42
+ mock = MockReponse.new <<-XML
43
+ <?xml version='1.0'?>
44
+ <methodResponse>
45
+ <fault>
46
+ <value>
47
+ <struct>
48
+ <member>
49
+ <name>
50
+ faultCode
51
+ </name>
52
+ <value>
53
+ <int>
54
+ 42
55
+ </int>
56
+ </value>
57
+ </member>
58
+ <member>
59
+ <name>
60
+ faultString
61
+ </name>
62
+ <value>
63
+ <string>
64
+ Don't panic.
65
+ </string>
66
+ </value>
67
+ </member>
68
+ </struct>
69
+ </value>
70
+ </fault>
71
+ </methodResponse>
72
+ XML
73
+
74
+ r = Rapuncel::Response.new mock
75
+
76
+ assert r.fault?
77
+ assert !r.success?
78
+ assert !r.error?
79
+
80
+ assert_kind_of Hash, r.to_ruby
81
+ assert_kind_of Hash, r.fault
82
+
83
+ assert_equal 42, r.fault[:faultCode]
84
+ end
85
+
86
+ test "Response should handle errors" do
87
+ mock = MockReponse.new "Not Found", false, 404
88
+
89
+ r = Rapuncel::Response.new mock
90
+
91
+ assert r.error?
92
+ assert !r.fault?
93
+ assert !r.success?
94
+
95
+ assert_kind_of Hash, r.to_ruby
96
+ assert_kind_of Hash, r.error
97
+
98
+ assert_equal 404, r.error[:http_code]
34
99
  end
35
-
36
100
  end