wash_out 0.9.0 → 0.11.0.beta.1

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.travis.yml +31 -3
  4. data/Appraisals +17 -8
  5. data/Gemfile +2 -2
  6. data/README.md +68 -8
  7. data/Rakefile +6 -7
  8. data/app/helpers/wash_out_helper.rb +59 -24
  9. data/app/views/{wash_with_soap → wash_out}/document/error.builder +1 -1
  10. data/app/views/{wash_with_soap → wash_out}/document/response.builder +1 -3
  11. data/app/views/{wash_with_soap → wash_out}/document/wsdl.builder +16 -16
  12. data/app/views/{wash_with_soap → wash_out}/rpc/error.builder +1 -1
  13. data/app/views/{wash_with_soap → wash_out}/rpc/response.builder +1 -3
  14. data/app/views/{wash_with_soap → wash_out}/rpc/wsdl.builder +17 -17
  15. data/gemfiles/rails_3.2.13.gemfile +21 -0
  16. data/gemfiles/rails_4.0.0.gemfile +20 -0
  17. data/gemfiles/rails_4.1.0.gemfile +20 -0
  18. data/gemfiles/rails_4.2.0.gemfile +20 -0
  19. data/gemfiles/rails_5.0.0.beta2.gemfile +19 -0
  20. data/lib/wash_out/dispatcher.rb +94 -48
  21. data/lib/wash_out/model.rb +1 -1
  22. data/lib/wash_out/param.rb +14 -1
  23. data/lib/wash_out/router.rb +46 -18
  24. data/lib/wash_out/soap.rb +5 -3
  25. data/lib/wash_out/soap_config.rb +2 -0
  26. data/lib/wash_out/version.rb +1 -1
  27. data/lib/wash_out/wsse.rb +27 -6
  28. data/lib/wash_out.rb +18 -5
  29. data/spec/dummy/config/environments/test.rb +1 -0
  30. data/spec/fixtures/nested_refs_to_arrays.xml +19 -0
  31. data/spec/fixtures/ref_to_one_array.xml +11 -0
  32. data/spec/fixtures/refs_to_arrays.xml +16 -0
  33. data/spec/lib/wash_out/dispatcher_spec.rb +135 -13
  34. data/spec/lib/wash_out/middleware_spec.rb +8 -8
  35. data/spec/lib/wash_out/param_spec.rb +43 -11
  36. data/spec/lib/wash_out/router_spec.rb +50 -0
  37. data/spec/lib/wash_out/type_spec.rb +9 -9
  38. data/spec/lib/wash_out_spec.rb +196 -88
  39. data/spec/spec_helper.rb +24 -4
  40. metadata +26 -17
@@ -12,20 +12,127 @@ describe WashOut::Dispatcher do
12
12
  end
13
13
  end
14
14
 
15
- it "finds nested hashes" do
16
- WashOut::Dispatcher.deep_select(:foo => 1){|k,v| k == :foo}.should == [1]
17
- WashOut::Dispatcher.deep_select({:foo => {:foo => 1}}){|k,v| k == :foo}.should == [{:foo => 1}, 1]
15
+ describe ".deep_select" do
16
+ blk = lambda{|v| v.is_a?(Hash) && v.has_key?(:@id)}
17
+
18
+ it "find no elements if there aren't any ids" do
19
+ expect(WashOut::Dispatcher.deep_select({k: {v: :v2}}, &blk)).to eq []
20
+ end
21
+
22
+ it "finds elements with ids in a hash" do
23
+ expect(WashOut::Dispatcher.deep_select({k: {:@id => 5, x: :y}}, &blk)).to eq [{:@id => 5, x: :y}]
24
+ end
25
+
26
+ it "finds elements with ids in a array" do
27
+ expect(WashOut::Dispatcher.deep_select({k: [{:@id => 5, x: :y}]}, &blk)).to eq [{:@id => 5, x: :y}]
28
+ end
29
+
30
+ it "finds elements with ids in hashes" do
31
+ expect(WashOut::Dispatcher.deep_select(
32
+ {
33
+ k: {:@id => 5, x: :y},
34
+ k2: {:@id => 6, n: :m}
35
+ }, &blk)).to eq [{:@id => 5, x: :y}, {:@id => 6, n: :m}]
36
+ end
37
+
38
+ it "finds elements in a hash and in a array" do
39
+ expect(WashOut::Dispatcher.deep_select(
40
+ {
41
+ k: [{:@id => 5, x: :y}],
42
+ k2: {:@id => 6, n: :m}
43
+ }, &blk)).to contain_exactly({:@id => 5, x: :y}, {:@id => 6, n: :m})
44
+ end
45
+
46
+ it "finds elements with ids in multiple arrays" do
47
+ expect(WashOut::Dispatcher.deep_select(
48
+ {
49
+ k: [{:@id => 5, x: :y}],
50
+ k2: [{:@id => 6, n: :m}]
51
+ }, &blk)).to eq [{:@id => 5, x: :y}, {:@id => 6, n: :m}]
52
+ end
18
53
  end
19
54
 
20
- it "replaces nested hashed" do
21
- WashOut::Dispatcher.deep_replace_href({:foo => {:@href => 1}}, {1 => 2}).should == {:foo => 2}
22
- WashOut::Dispatcher.deep_replace_href({:bar => {:foo => {:@href => 1}}}, {1 => 2}).should == {:bar => {:foo => 2}}
55
+ describe ".deep_replace_href" do
56
+ it "replaces nested hashed" do
57
+ expect(WashOut::Dispatcher.deep_replace_href(
58
+ {:foo => {:@href => 1}},
59
+ {1 => 2})).to eq(
60
+ {:foo => 2}
61
+ )
62
+ end
63
+
64
+ it "replaces deeper nested hashes" do
65
+ expect(WashOut::Dispatcher.deep_replace_href(
66
+ {:bar => {:foo => {:@href => 1}}},
67
+ {1 => 2}
68
+ )).to eq(
69
+ {:bar => {:foo => 2}}
70
+ )
71
+ end
72
+
73
+ it "replace nested refs" do
74
+ hash = {fizz: {:@href => "#id4"}}
75
+ replaces = {
76
+ "#id4" => {:@href => "#id6"},
77
+ "#id6" => {foo: :bar}
78
+ }
79
+ expect(WashOut::Dispatcher.deep_replace_href(hash, replaces)).to eq({
80
+ fizz: {foo: :bar}})
81
+ end
82
+
83
+ it "replace really nested refs" do
84
+ hash = {fizz: {:@href => "#id4"}}
85
+ replaces = {
86
+ "#id4" => {:@href => "#id6"},
87
+ "#id6" => {:@href => "#id7"},
88
+ "#id7" => {foo: :bar}
89
+ }
90
+ expect(WashOut::Dispatcher.deep_replace_href(hash, replaces)).to eq({
91
+ fizz: {foo: :bar}})
92
+ end
93
+
94
+ it "replaces arrays in nested hashes" do
95
+ hash = {
96
+ fizz: {:@href => "#id4"},
97
+ Array: [
98
+ {Item: [{:@href => "#id6"}, {:@href => "#id7"}]},
99
+ {Item: {loo: :iioo}}
100
+ ]
101
+ }
102
+ replaces = {
103
+ "#id4" => {Item: [{:@href => "#id6"}, {:@href => "#id7"}]},
104
+ "#id6" => {foo: :bar},
105
+ "#id7" => {baz: :bats}
106
+ }
107
+ expect(WashOut::Dispatcher.deep_replace_href(hash, replaces)).to eq({
108
+ fizz: {Item: [
109
+ {foo: :bar},
110
+ {baz: :bats}
111
+ ]},
112
+ Array: [
113
+ {Item: [{foo: :bar}, {baz: :bats}]},
114
+ {Item: {loo: :iioo}}
115
+ ]
116
+ })
117
+ end
118
+
119
+ it "can traverse arrays that do not contain hashes" do
120
+ hash = {
121
+ fizz: {:@href => "#id1"},
122
+ }
123
+ replaces = {
124
+ "#id1" => {Item: ["1", "2"]},
125
+ }
126
+ expect(WashOut::Dispatcher.deep_replace_href(hash, replaces)).to eq({
127
+ fizz: {Item: ["1", "2"]},
128
+ })
129
+ end
23
130
  end
24
131
 
25
132
  xit "parses typical request" do
26
133
  dispatcher = Dispatcher.mock("<foo>1</foo>")
27
134
  dispatcher._parse_soap_parameters
28
- dispatcher.params.should == {:foo => "1"}
135
+ expect(dispatcher.params).to eq({:foo => "1"})
29
136
  end
30
137
 
31
138
  xit "parses href request" do
@@ -45,11 +152,26 @@ describe WashOut::Dispatcher do
45
152
  </root>
46
153
  XML
47
154
  dispatcher._parse_soap_parameters
48
- dispatcher.params[:root][:request][:entities].should == {
155
+ expect(dispatcher.params[:root][:request][:entities]).to eq({
49
156
  :foo => {:bar=>"1"},
50
157
  :sub => {:foo=>"1", :@id=>"id2"},
51
158
  :@id => "id1"
52
- }
159
+ })
160
+ end
161
+
162
+ describe "#_map_soap_parameters" do
163
+ let(:dispatcher) { Dispatcher.new }
164
+ let(:soap_config) { WashOut::SoapConfig.new(camelize_wsdl: false) }
165
+
166
+ before do
167
+ allow(dispatcher).to receive(:action_spec).and_return(in: WashOut::Param.parse_def(soap_config, { foo: { "@bar" => :string, empty: :string } } ))
168
+ allow(dispatcher).to receive(:xml_data).and_return(foo: { "@bar" => "buzz", empty: { :"@xsi:type" => "xsd:string" } })
169
+ end
170
+
171
+ it "should handle empty strings that have been parsed wrong by nori, but preserve attrs" do
172
+ dispatcher._map_soap_parameters
173
+ expect(dispatcher.params).to eq("foo" => { "bar" => "buzz", "empty" => nil })
174
+ end
53
175
  end
54
176
 
55
177
  describe "#_load_params" do
@@ -58,25 +180,25 @@ describe WashOut::Dispatcher do
58
180
  it "should load params for an array" do
59
181
  spec = WashOut::Param.parse_def(soap_config, {:my_array => [:integer] } )
60
182
  xml_data = {:my_array => [1, 2, 3]}
61
- dispatcher._load_params(spec, xml_data).should == {"my_array" => [1, 2, 3]}
183
+ expect(dispatcher._load_params(spec, xml_data)).to eq({"my_array" => [1, 2, 3]})
62
184
  end
63
185
 
64
186
  it "should load params for an empty array" do
65
187
  spec = WashOut::Param.parse_def(soap_config, {:my_array => [:integer] } )
66
188
  xml_data = {}
67
- dispatcher._load_params(spec, xml_data).should == {}
189
+ expect(dispatcher._load_params(spec, xml_data)).to eq({})
68
190
  end
69
191
 
70
192
  it "should load params for a nested array" do
71
193
  spec = WashOut::Param.parse_def(soap_config, {:nested => {:my_array => [:integer]}} )
72
194
  xml_data = {:nested => {:my_array => [1, 2, 3]}}
73
- dispatcher._load_params(spec, xml_data).should == {"nested" => {"my_array" => [1, 2, 3]}}
195
+ expect(dispatcher._load_params(spec, xml_data)).to eq({"nested" => {"my_array" => [1, 2, 3]}})
74
196
  end
75
197
 
76
198
  it "should load params for an empty nested array" do
77
199
  spec = WashOut::Param.parse_def(soap_config, {:nested => {:empty => [:integer] }} )
78
200
  xml_data = {:nested => nil}
79
- dispatcher._load_params(spec, xml_data).should == {"nested" => {}}
201
+ expect(dispatcher._load_params(spec, xml_data)).to eq({"nested" => {}})
80
202
  end
81
203
 
82
204
  end
@@ -11,23 +11,23 @@ describe WashOut::Middleware do
11
11
  end
12
12
 
13
13
  env = {}
14
- lambda {
14
+ expect {
15
15
  WashOut::Middleware.raise_or_render_rexml_parse_error err, env
16
- }.should raise_exception
16
+ }.to raise_exception(REXML::ParseException)
17
17
 
18
18
  env['HTTP_SOAPACTION'] = 'pretend_action'
19
19
  env['rack.errors'] = double 'logger', {:puts => true}
20
20
  env['rack.input'] = double 'basic-rack-input', {:string => '<hi>'}
21
21
  result = WashOut::Middleware.raise_or_render_rexml_parse_error err, env
22
- result[0].should == 400
23
- result[1]['Content-Type'].should == 'text/xml'
22
+ expect(result[0]).to eq 400
23
+ expect(result[1]['Content-Type']).to eq 'text/xml'
24
24
  msg = result[2][0]
25
- msg.should include 'Error parsing SOAP Request XML'
26
- msg.should include 'soap:Fault'
27
- msg.should_not include __FILE__
25
+ expect(msg).to include 'Error parsing SOAP Request XML'
26
+ expect(msg).to include 'soap:Fault'
27
+ expect(msg).not_to include __FILE__
28
28
 
29
29
  env['rack.input'] = double 'passenger-input', {:read => '<hi>'}
30
30
  result = WashOut::Middleware.raise_or_render_rexml_parse_error err, env
31
- result[0].should == 400
31
+ expect(result[0]).to eq 400
32
32
  end
33
33
  end
@@ -21,9 +21,9 @@ describe WashOut::Param do
21
21
  soap_config = WashOut::SoapConfig.new({ camelize_wsdl: false })
22
22
  map = WashOut::Param.parse_def soap_config, Abraka2
23
23
 
24
- map.should be_a_kind_of(Array)
25
- map[0].name.should == 'foo'
26
- map[0].map[0].name.should == 'test'
24
+ expect(map).to be_a_kind_of(Array)
25
+ expect(map[0].name).to eq 'foo'
26
+ expect(map[0].map[0].name).to eq 'test'
27
27
  end
28
28
 
29
29
  it "respects camelization setting" do
@@ -31,16 +31,16 @@ describe WashOut::Param do
31
31
 
32
32
  map = WashOut::Param.parse_def soap_config, Abraka2
33
33
 
34
- map.should be_a_kind_of(Array)
35
- map[0].name.should == 'Foo'
36
- map[0].map[0].name.should == 'Test'
34
+ expect(map).to be_a_kind_of(Array)
35
+ expect(map[0].name).to eq 'Foo'
36
+ expect(map[0].map[0].name).to eq 'Test'
37
37
  end
38
38
  end
39
39
 
40
40
  it "should accept nested empty arrays" do
41
41
  soap_config = WashOut::SoapConfig.new({ camelize_wsdl: false })
42
42
  map = WashOut::Param.parse_def(soap_config, {:nested => {:some_attr => :string, :empty => [:integer] }} )
43
- map[0].load( {:nested => nil}, :nested).should == {}
43
+ expect(map[0].load( {:nested => nil}, :nested)).to eq({})
44
44
  end
45
45
 
46
46
  describe "booleans" do
@@ -50,13 +50,45 @@ describe WashOut::Param do
50
50
  let(:map) { WashOut::Param.parse_def(soap_config, :value => :boolean) }
51
51
 
52
52
  it "should accept 'true' and '1'" do
53
- map[0].load({:value => true}, :value).should be_true
54
- map[0].load({:value => "1"}, :value).should be_true
53
+ expect(map[0].load({:value => true}, :value)).to be true
54
+ expect(map[0].load({:value => "1"}, :value)).to be true
55
55
  end
56
56
 
57
57
  it "should accept 'false' and '0'" do
58
- map[0].load({:value => false}, :value).should be_false
59
- map[0].load({:value => "0"}, :value).should be_false
58
+ expect(map[0].load({:value => false}, :value)).to be false
59
+ expect(map[0].load({:value => "0"}, :value)).to be false
60
+ end
61
+ end
62
+
63
+ describe 'longs' do
64
+ let(:soap_config) { WashOut::SoapConfig.new({ camelize_wsdl: false }) }
65
+ let(:map) { WashOut::Param.parse_def(soap_config, :value => :long) }
66
+
67
+ it "should accept positive long" do
68
+ expect(map[0].load({:value => 9223372036854775807}, :value)).to eq 9223372036854775807
69
+ end
70
+
71
+ it "should accept negative long" do
72
+ expect(map[0].load({:value => -9223372036854775807}, :value)).to eq -9223372036854775807
73
+ end
74
+ end
75
+
76
+ describe '#flat_copy' do
77
+ it 'should copy everything' do
78
+ soap_config = WashOut::SoapConfig.new({})
79
+ type = :foo
80
+ multiplied = "of course"
81
+
82
+ param = WashOut::Param.new(soap_config, 'name', type, multiplied)
83
+ param.source_class = "middle class"
84
+ evil_clone = param.flat_copy
85
+
86
+ expect(evil_clone.source_class).to eq "middle class"
87
+ expect(evil_clone.name).to eq 'name'
88
+ expect(evil_clone.raw_name).to eq 'name'
89
+ expect(evil_clone.type).to eq "foo"
90
+ expect(evil_clone.multiplied).to eq "of course"
91
+ expect(evil_clone.soap_config).to eq soap_config
60
92
  end
61
93
  end
62
94
  end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'wash_out/router'
3
+
4
+ describe WashOut::Router do
5
+ it 'returns a 200 with empty soap action' do
6
+
7
+ mock_controller do
8
+ # nothing
9
+ end
10
+
11
+ env = {}
12
+ env['REQUEST_METHOD'] = 'GET'
13
+ env['rack.input'] = double 'basic-rack-input', {:string => ''}
14
+ result = WashOut::Router.new('Route::Space::Api').call env
15
+
16
+ expect(result[0]).to eq(500)
17
+ expect(result[1]['Content-Type']).to eq('text/xml; charset=utf-8')
18
+ end
19
+
20
+ def parse_soap_params_from_xml(filename)
21
+ xml = File.read(File.expand_path("../../../fixtures/#{filename}", __FILE__))
22
+ env = {'rack.input' => StringIO.new(xml)}
23
+
24
+ router = WashOut::Router.new('')
25
+ controller = double("controller", soap_config: WashOut::SoapConfig.new)
26
+ allow(router).to receive(:controller).and_return(controller)
27
+
28
+ router.parse_soap_parameters(env)[:Envelope][:Body]
29
+ end
30
+
31
+ it "returns refs to arrays correctly" do
32
+ body = parse_soap_params_from_xml('ref_to_one_array.xml')
33
+
34
+ expect(body[:list][:Item]).to eq(["1", "2"])
35
+ end
36
+
37
+ it "returns refs to multiple arrays correctly" do
38
+ body = parse_soap_params_from_xml('refs_to_arrays.xml')
39
+
40
+ expect(body[:first_list][:Item]).to eq(["1", "2"])
41
+ expect(body[:second_list][:Item]).to eq(["11", "22"])
42
+ end
43
+
44
+ it "returns nested refs to multiple arrays correctly" do
45
+ body = parse_soap_params_from_xml('nested_refs_to_arrays.xml')
46
+
47
+ expect(body[:parent][:first_list][:Item]).to eq(["1", "2"])
48
+ expect(body[:parent][:second_list][:Item]).to eq(["11", "22"])
49
+ end
50
+ end
@@ -1,4 +1,4 @@
1
- #encoding:utf-8
1
+ #encoding:utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -15,11 +15,11 @@ describe WashOut::Type do
15
15
  map :foo => Abraka1
16
16
  end
17
17
 
18
- Abraka1.wash_out_param_name.should == 'abraka1'
19
- Abraka1.wash_out_param_map.should == {:test => :string}
18
+ expect(Abraka1.wash_out_param_name).to eq 'abraka1'
19
+ expect(Abraka1.wash_out_param_map).to eq({:test => :string})
20
20
 
21
- Abraka2.wash_out_param_name.should == 'test'
22
- Abraka2.wash_out_param_map.should == {:foo => Abraka1}
21
+ expect(Abraka2.wash_out_param_name).to eq 'test'
22
+ expect(Abraka2.wash_out_param_map).to eq({:foo => Abraka1})
23
23
  end
24
24
 
25
25
  it "allows arrays inside custom types" do
@@ -31,11 +31,11 @@ describe WashOut::Type do
31
31
  map :foo => [:bar => Abraka1]
32
32
  end
33
33
 
34
- Abraka1.wash_out_param_name.should == 'abraka1'
35
- Abraka1.wash_out_param_map.should == {:test => :string}
34
+ expect(Abraka1.wash_out_param_name).to eq 'abraka1'
35
+ expect(Abraka1.wash_out_param_map).to eq({:test => :string})
36
36
 
37
- Abraka2.wash_out_param_name.should == 'test'
38
- Abraka2.wash_out_param_map.should == {:foo => [:bar => Abraka1]}
37
+ expect(Abraka2.wash_out_param_name).to eq 'test'
38
+ expect(Abraka2.wash_out_param_map).to eq({:foo => [:bar => Abraka1]})
39
39
  end
40
40
 
41
41
  end