socialcast-rapuncel 0.0.7.RC1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe TrueClass, FalseClass do
4
+ describe "Serialization" do
5
+ it 'represents true as 1' do
6
+ Rapuncel::XmlRpc::Serializer[true].should have_xpath('/boolean', :content => '1')
7
+ end
8
+
9
+ it 'represents false as 0' do
10
+ Rapuncel::XmlRpc::Serializer[false].should have_xpath('/boolean', :content => '0')
11
+ end
12
+ end
13
+
14
+ describe "Deserialization" do
15
+ it 'reads 1 as true' do
16
+ xml = <<-XML
17
+ <boolean>1</boolean>
18
+ XML
19
+
20
+ Rapuncel::XmlRpc::Deserializer[xml].should be_a TrueClass
21
+ end
22
+
23
+ it 'reads 0 as false' do
24
+ xml = <<-XML
25
+ <boolean>0</boolean>
26
+ XML
27
+
28
+ Rapuncel::XmlRpc::Deserializer[xml].should be_a FalseClass
29
+ end
30
+
31
+ it 'reads anything else as false' do
32
+ xml = <<-XML
33
+ <boolean>abcd</boolean>
34
+ XML
35
+
36
+ Rapuncel::XmlRpc::Deserializer[xml].should be_a FalseClass
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'logger'
3
+
4
+ describe Rapuncel::Client do
5
+ let(:logger) { nil }
6
+ subject { Rapuncel::Client.new :logger => logger }
7
+
8
+ it { should_not respond_to :logger }
9
+ it { should_not respond_to :log_level }
10
+
11
+ describe "with Logging enabled" do
12
+ let(:logger) { Logger.new(STDOUT) }
13
+
14
+ it { should respond_to :logger }
15
+ it { should respond_to :log_level }
16
+ end
17
+
18
+ describe "log devices" do
19
+ describe 'Symbol' do
20
+ let(:logger) { :stdout }
21
+
22
+ its(:logger) { should be_a Logger }
23
+ end
24
+
25
+ describe 'String' do
26
+ let(:logger) { 'stdout' }
27
+
28
+ its(:logger) { should be_a Logger }
29
+ end
30
+
31
+ describe 'IO' do
32
+ let(:logger) { File.open('/dev/null', 'w') }
33
+
34
+ its(:logger) { should be_a Logger }
35
+ end
36
+
37
+ describe 'true' do
38
+ let(:logger) { true }
39
+
40
+ its(:logger) { should be_a Logger }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rapuncel::Connection do
4
+ it 'can use the host option with or without an extra "http://"' do
5
+ connection = Rapuncel::Connection.new :host => "http://example.org"
6
+
7
+ connection.host.should == "example.org"
8
+ end
9
+
10
+ it 'can use the path option with or without leading "/"' do
11
+ connection = Rapuncel::Connection.new :host => "http://example.org", :path => "abcd"
12
+
13
+ connection.path.should == "/abcd"
14
+ end
15
+
16
+ it 'can set the ssl option via host' do
17
+ connection = Rapuncel::Connection.new :host => "https://example.org", :path => "abcd"
18
+
19
+ connection.ssl.should be_true
20
+ end
21
+ end
22
+
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Custom serialization" do
4
+ module CustomSerialization
5
+ class Serializer < Rapuncel::XmlRpc::Serializer
6
+ end
7
+
8
+ class Deserializer < Rapuncel::XmlRpc::Deserializer
9
+ end
10
+ end
11
+
12
+ it 'client selects custom (de)serializer, if provided by Symbol' do
13
+ client = Rapuncel::Client.new :serialization => :CustomSerialization
14
+
15
+ client.send(:serializer).should == CustomSerialization::Serializer
16
+ end
17
+
18
+ it 'client selects custom (de)serializer, if provided by Class' do
19
+ client = Rapuncel::Client.new :serialization => CustomSerialization
20
+
21
+ client.send(:serializer).should == CustomSerialization::Serializer
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Float do
4
+ describe "Serialization" do
5
+ it "can serialize Floats" do
6
+ number = 1.23456
7
+ Rapuncel::XmlRpc::Serializer[number].should have_xpath('/double', :content => "1.23456")
8
+ end
9
+
10
+ it "can serialize BigDecimal" do
11
+ number = BigDecimal.new '1.23456'
12
+ Rapuncel::XmlRpc::Serializer[number].should have_xpath('/double', :content => "1.23456")
13
+ end
14
+ end
15
+
16
+ describe "Deserialization" do
17
+ it "can deserialize double" do
18
+ xml = <<-XML
19
+ <double>1.23456</double>
20
+ XML
21
+ number = Rapuncel::XmlRpc::Deserializer[xml]
22
+ number.should be_a Float
23
+ number.should == 1.23456
24
+ end
25
+
26
+ it "can optionally deserialize all double to BigDecimal" do
27
+ Rapuncel::XmlRpc::Deserializer.double_as_bigdecimal = true
28
+
29
+ xml = <<-XML
30
+ <double>1.23456</double>
31
+ XML
32
+ number = Rapuncel::XmlRpc::Deserializer[xml]
33
+
34
+ number.should be_a BigDecimal
35
+ number.to_s("F").should == "1.23456"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'active_support/core_ext/hash/keys'
3
+
4
+ describe Hash do
5
+ describe "Serialization" do
6
+ before do
7
+ @hash = {
8
+ :abc => 'one and two',
9
+ 40 => %w(foo bar bee),
10
+ BigDecimal.new('1.23') => "abcd"
11
+ }
12
+
13
+ @xml = Rapuncel::XmlRpc::Serializer[@hash]
14
+ end
15
+
16
+ it 'preserves number of key-value pairs' do
17
+ @xml.should have_xpath('/struct/member', :count => 3)
18
+ end
19
+
20
+ it 'projects all keys to plain strings' do
21
+ @xml.should have_xpath('/struct/member/name', :content => 'abc')
22
+ @xml.should have_xpath('/struct/member/name', :content => '40')
23
+ @xml.should have_xpath('/struct/member/name', :content => '1.23')
24
+ end
25
+ end
26
+
27
+ describe "Deserialization" do
28
+ before do
29
+ @xml = <<-XML
30
+ <struct>
31
+ <member><name>abcd</name>
32
+ <value><int>123></int></value></member>
33
+ <member><name>456</name>
34
+ <value><string>xyz</string></value></member>
35
+ </struct>
36
+ XML
37
+
38
+ @hash = Rapuncel::XmlRpc::Deserializer[@xml]
39
+ end
40
+
41
+ it 'preserves number of key-value pairs' do
42
+ @hash.length.should == 2
43
+ end
44
+
45
+ it 'converts all keys to symbols' do
46
+ @hash.keys.should be_all{|key| Symbol === key}
47
+ end
48
+
49
+ it 'casts values to their types' do
50
+ @hash[:abcd].should == 123
51
+ @hash[:'456'].should == 'xyz'
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Integer do
4
+ it "serialization" do
5
+ Rapuncel::XmlRpc::Serializer[123].should have_xpath('/int', :content => "123")
6
+ end
7
+
8
+ it "deserialization of int" do
9
+ xml = <<-XML
10
+ <int>123</int>
11
+ XML
12
+
13
+ Rapuncel::XmlRpc::Deserializer[xml].should == 123
14
+ end
15
+
16
+ it 'deserialization of i4' do
17
+ xml = <<-XML
18
+ <i4>123</i4>
19
+ XML
20
+
21
+ Rapuncel::XmlRpc::Deserializer[xml].should == 123
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe NilClass do
4
+ it 'serializes like false' do
5
+ Rapuncel::XmlRpc::Serializer[nil].should have_xpath('/boolean', :content => '0')
6
+ end
7
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Object do
4
+ class TestObject
5
+ attr_accessor :a, :b, :c
6
+ end
7
+
8
+ class TestObjectWithOwnBehavior < TestObject
9
+ def to_xmlrpc serializer
10
+ serializer.builder.string "custom thing"
11
+ end
12
+ end
13
+
14
+ describe "Serialization of an arbitrary Object" do
15
+ it "serializes all instance variables like a hash" do
16
+ obj = TestObject.new
17
+ obj.a = "one"
18
+ obj.b = "two"
19
+
20
+ xml = Rapuncel::XmlRpc::Serializer[obj]
21
+ xml.should have_xpath('/struct/member', :count => 2)
22
+
23
+ reparsed_object = Rapuncel::XmlRpc::Deserializer[xml]
24
+ reparsed_object.should == {
25
+ :a => 'one',
26
+ :b => 'two'
27
+ }
28
+ end
29
+
30
+ end
31
+
32
+ describe "Serialization of an Object with #to_xmlrpc" do
33
+ it "uses this method to serialize" do
34
+ obj = TestObjectWithOwnBehavior.new
35
+
36
+ obj.a = 'one'
37
+
38
+ xml = Rapuncel::XmlRpc::Serializer[obj]
39
+ xml.should have_xpath('/string')
40
+
41
+ reparsed_object = Rapuncel::XmlRpc::Deserializer[xml]
42
+ reparsed_object.should == "custom thing"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rapuncel::Proxy do
4
+ before do
5
+ @client = mock "Rapuncel::Client"
6
+ @proxy = Rapuncel::Proxy.new @client
7
+ end
8
+
9
+ it "provides unproxied __ methods" do
10
+ @client.should_not_receive :call_to_ruby
11
+
12
+ @proxy.__inspect__
13
+ @proxy.__tap__ {}
14
+ @proxy.__freeze__
15
+ @proxy.__send__ :__inspect__
16
+ end
17
+
18
+ it 'proxies inspect, freeze, tap' do
19
+ %w(inspect freeze tap).each do |method|
20
+ @client.should_receive(:call_to_ruby).with(method)
21
+ @proxy.__send__ method
22
+ end
23
+ end
24
+
25
+ it 'proxies any method call' do
26
+ @client.should_receive(:call_to_ruby).with("abcd", 1, "foo")
27
+ @proxy.abcd 1, "foo"
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Rapuncel::Request do
5
+ describe "Serialization" do
6
+ before do
7
+ @request = Rapuncel::Request.new 'test_method', "one argument", "another"
8
+ @xml = Rapuncel::XmlRpc::Serializer[@request]
9
+ end
10
+
11
+ it 'should be in xml version=1.0' do
12
+ @xml.should =~ /<\?xml version=['"]1.0['"]/
13
+ end
14
+
15
+ it 'should contain a methodCall' do
16
+ @xml.should have_xpath('/methodCall', :count => 1)
17
+ end
18
+
19
+ it 'should contain the method name' do
20
+ @xml.should have_xpath('/methodCall/methodName', :content => "test_method")
21
+ end
22
+
23
+ it 'should contain the method arguments in correct order' do
24
+ @xml.should have_xpath('/methodCall/params/param[1]/value/string', :content => "one argument")
25
+ @xml.should have_xpath('/methodCall/params/param[2]/value/string', :content => "another")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rapuncel::Response do
4
+ class HttpResponse
5
+ attr_accessor :body, :code
6
+
7
+ def initialize body, success = true, code = 200
8
+ @body, @success, @code = body, success, code
9
+ end
10
+
11
+ def success?
12
+ @success
13
+ end
14
+ end
15
+
16
+ it 'parses successful response' do
17
+ successful_response = HttpResponse.new <<-XML
18
+ <?xml version='1.0'?>
19
+ <methodResponse>
20
+ <params>
21
+ <param>
22
+ <value>
23
+ <string>foo foo foo</string>
24
+ </value>
25
+ </param>
26
+ </params>
27
+ </methodResponse>
28
+ XML
29
+
30
+ response = Rapuncel::Response.new successful_response, Rapuncel::XmlRpc::Deserializer
31
+ response.should be_success
32
+
33
+ response.result.should == "foo foo foo"
34
+ end
35
+
36
+ it 'parses fault response' do
37
+ fault_response = HttpResponse.new <<-XML
38
+ <?xml version='1.0'?>
39
+ <methodResponse>
40
+ <fault>
41
+ <value>
42
+ <struct>
43
+ <member>
44
+ <name>
45
+ faultCode
46
+ </name>
47
+ <value>
48
+ <int>
49
+ 42
50
+ </int>
51
+ </value>
52
+ </member>
53
+ <member>
54
+ <name>
55
+ faultString
56
+ </name>
57
+ <value>
58
+ <string>
59
+ Don't panic.
60
+ </string>
61
+ </value>
62
+ </member>
63
+ </struct>
64
+ </value>
65
+ </fault>
66
+ </methodResponse>
67
+ XML
68
+
69
+ response = Rapuncel::Response.new fault_response, Rapuncel::XmlRpc::Deserializer
70
+ response.should be_fault
71
+
72
+ response.to_ruby.should be_a Hash
73
+ response.to_ruby[:faultCode].should == 42
74
+ end
75
+
76
+ it 'should handle errors' do
77
+ error_response = HttpResponse.new "Not Found", false, 404
78
+
79
+ response = Rapuncel::Response.new error_response, Rapuncel::XmlRpc::Deserializer
80
+ response.should be_error
81
+
82
+ response.to_ruby.should be_a Hash
83
+ response.to_ruby[:http_code].should == 404
84
+ end
85
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe String, Symbol do
4
+ it 'serialization of a String' do
5
+ string = "foobar"
6
+ xml = Rapuncel::XmlRpc::Serializer[string]
7
+ xml.should have_xpath('/string', :content => "foobar")
8
+ end
9
+
10
+ it 'serialization of a Symbol' do
11
+ symbol = :foobar
12
+ xml = Rapuncel::XmlRpc::Serializer[symbol]
13
+ xml.should have_xpath('/string', :content => "foobar")
14
+ end
15
+
16
+ it 'preservation of trailing an leading whitespaces' do
17
+ string = "\n\t abcd\n \t"
18
+ xml = Rapuncel::XmlRpc::Serializer[string]
19
+ xml.should have_xpath('/string', :content => "\n\t abcd\n \t")
20
+ end
21
+
22
+ it 'deserialization of a String' do
23
+ xml = <<-XML
24
+ <string>abcd\nefgh \n\t</string>
25
+ XML
26
+ string = Rapuncel::XmlRpc::Deserializer[xml]
27
+ string.should == "abcd\nefgh \n\t"
28
+ end
29
+
30
+ it 'normalization of linebreaks' do
31
+ string = "one\r\ntwo\rthree\nfour"
32
+ string2 = Rapuncel::XmlRpc::Deserializer[Rapuncel::XmlRpc::Serializer[string]]
33
+ string2.should == "one\ntwo\nthree\nfour"
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Time do
4
+ it 'serialization' do
5
+ time = Time.now
6
+ xml = Rapuncel::XmlRpc::Serializer[time]
7
+ xml.should have_xpath('/dateTime.iso8601', :content => time.iso8601)
8
+ end
9
+
10
+ it 'deserialization' do
11
+ time = Time.now
12
+ xml = <<-XML
13
+ <dateTime.iso8601>#{time.iso8601}</dateTime.iso8601>
14
+ XML
15
+
16
+ parsed_time = Rapuncel::XmlRpc::Deserializer[xml]
17
+ parsed_time.should be_a Time
18
+ parsed_time.to_i.should == time.to_i
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: socialcast-rapuncel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7.RC1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Michael Eickenberg
9
+ - Marian Theisen
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-09-13 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ requirement: &2159869340 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2159869340
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ requirement: &2159868840 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2159868840
37
+ - !ruby/object:Gem::Dependency
38
+ name: cookiejar
39
+ requirement: &2159868340 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 0.3.0
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2159868340
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: &2159867880 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 2.6.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2159867880
59
+ - !ruby/object:Gem::Dependency
60
+ name: rake
61
+ requirement: &2159867500 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2159867500
70
+ description: Rapuncel is a simple XML-RPC Client based on Nokogiri, thus provides
71
+ a fast and easy way to interact with XML-RPC services.
72
+ email: marian@cice-online.net
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - lib/rapuncel/adapters/curb_adapter.rb
80
+ - lib/rapuncel/adapters/net_http_adapter.rb
81
+ - lib/rapuncel/base_64_string.rb
82
+ - lib/rapuncel/client/logging.rb
83
+ - lib/rapuncel/client.rb
84
+ - lib/rapuncel/connection.rb
85
+ - lib/rapuncel/proxy.rb
86
+ - lib/rapuncel/request.rb
87
+ - lib/rapuncel/response.rb
88
+ - lib/rapuncel/xml_rpc/deserializer.rb
89
+ - lib/rapuncel/xml_rpc/serializer.rb
90
+ - lib/rapuncel.rb
91
+ - MIT-LICENSE
92
+ - Rakefile
93
+ - rapuncel-0.0.6.RC3.gem
94
+ - rapuncel.gemspec
95
+ - README.md
96
+ - socialcast-rapuncel-0.0.7.RC1.gem
97
+ - spec/functional/client_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/test_server.rb
100
+ - spec/unit/array_spec.rb
101
+ - spec/unit/base64_spec.rb
102
+ - spec/unit/boolean_spec.rb
103
+ - spec/unit/client_spec.rb
104
+ - spec/unit/connection_spec.rb
105
+ - spec/unit/custom_serialization_spec.rb
106
+ - spec/unit/float_spec.rb
107
+ - spec/unit/hash_spec.rb
108
+ - spec/unit/int_spec.rb
109
+ - spec/unit/nil_spec.rb
110
+ - spec/unit/object_spec.rb
111
+ - spec/unit/proxy_spec.rb
112
+ - spec/unit/request_spec.rb
113
+ - spec/unit/response_spec.rb
114
+ - spec/unit/string_spec.rb
115
+ - spec/unit/time_spec.rb
116
+ homepage: http://github.com/cice/rapuncel
117
+ licenses: []
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>'
132
+ - !ruby/object:Gem::Version
133
+ version: 1.3.1
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.10
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Simple XML-RPC Client
140
+ test_files: []