rews 0.2.12 → 0.5.0

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.
@@ -2,15 +2,19 @@ require File.expand_path("../../spec_helper", __FILE__)
2
2
 
3
3
  module Rews
4
4
  describe Item do
5
+ def client
6
+ Object.new
7
+ end
8
+
5
9
  describe "read_items" do
6
10
  it "should parse a list of zero items correctly" do
7
- c = Object.new
11
+ c = client
8
12
  items = Item.read_items(c, nil)
9
13
  items.should == []
10
14
  end
11
15
 
12
16
  it "should parse a list of one items correctly" do
13
- c = Object.new
17
+ c = client
14
18
  items = Item.read_items(c, {:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
15
19
  items.length.should == 1
16
20
  item = items.first
@@ -19,9 +23,9 @@ module Rews
19
23
  end
20
24
 
21
25
  it "should parse a list of more than one item correctly" do
22
- c = Object.new
26
+ c = client
23
27
  items = Item.read_items(c, {:message=>[{:item_id=>{:id=>"abc", :change_key=>"def"}},
24
- {:item_id=>{:id=>"ghi", :change_key=>"jkl"}}]})
28
+ {:item_id=>{:id=>"ghi", :change_key=>"jkl"}}]})
25
29
  items.length.should == 2
26
30
  item1 = items.first
27
31
  item1.item_id.should == Item::ItemId.new(c, {:id=>"abc", :change_key=>"def"})
@@ -34,13 +38,13 @@ module Rews
34
38
 
35
39
  describe "read_get_item_response_messages" do
36
40
  it "should parse a list of zero items correctly" do
37
- c = Object.new
41
+ c = client
38
42
  items = Item.read_get_item_response_messages(c, {:items=>nil})
39
43
  items.should == []
40
44
  end
41
45
 
42
46
  it "should parse a list of one items correctly" do
43
- c = Object.new
47
+ c = client
44
48
  items = Item.read_get_item_response_messages(c, {:items=>{:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}}})
45
49
  items.length.should == 1
46
50
  item = items.first
@@ -49,7 +53,7 @@ module Rews
49
53
  end
50
54
 
51
55
  it "should parse a list of more than one items correctly" do
52
- c = Object.new
56
+ c = client
53
57
  items = Item.read_get_item_response_messages(c, {:items=>{:message=>[{:item_id=>{:id=>"abc", :change_key=>"def"}},
54
58
  {:item_id=>{:id=>"ghi", :change_key=>"jkl"}}]}})
55
59
  items.length.should == 2
@@ -64,13 +68,13 @@ module Rews
64
68
 
65
69
  describe Item::Item do
66
70
  it "should parse the item_id and attributes from the XML hash" do
67
- client = Object.new
71
+ c = client
68
72
 
69
- i = Item::Item.new(client, 'Message', {:item_id=>{:id=>'1234', :change_key=>'abcd'}, :foo=>100})
73
+ i = Item::Item.new(c, 'Message', {:item_id=>{:id=>'1234', :change_key=>'abcd'}, :foo=>100})
70
74
 
71
- i.client.should == client
75
+ i.client.should == c
72
76
  i.item_class.should == 'Message'
73
- i.item_id.should == Item::ItemId.new(client, {:id=>'1234', :change_key=>'abcd'})
77
+ i.item_id.should == Item::ItemId.new(c, {:id=>'1234', :change_key=>'abcd'})
74
78
 
75
79
  i[:foo].should == 100
76
80
  end
@@ -80,8 +84,8 @@ module Rews
80
84
 
81
85
  describe "to_xml" do
82
86
  it "should generate an ItemId with change_key by default" do
83
- client = Object.new
84
- xml = Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"}).to_xml
87
+ c = client
88
+ xml = Item::ItemId.new(c, {:id=>"abc", :change_key=>"def"}).to_xml
85
89
  doc = Nokogiri::XML(xml)
86
90
  id=doc.children.first
87
91
  id.name.should == "ItemId"
@@ -90,8 +94,8 @@ module Rews
90
94
  end
91
95
 
92
96
  it "should generate an ItemId without change_key if requested" do
93
- client = Object.new
94
- xml = Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"}).to_xml(true)
97
+ c = client
98
+ xml = Item::ItemId.new(c, {:id=>"abc", :change_key=>"def"}).to_xml(true)
95
99
  doc = Nokogiri::XML(xml)
96
100
  id=doc.children.first
97
101
  id.name.should == "ItemId"
@@ -100,23 +104,6 @@ module Rews
100
104
  end
101
105
  end
102
106
 
103
- def mock_request(client, action, attrs, response)
104
- # deal with different call arity
105
- mock(client).savon_client.mock!.request(*[:wsdl, action, attrs].compact) do |*args|
106
- block = args.last # block is the last arg
107
-
108
- ctx = RequestProxy.new()
109
- mock(ctx.http).headers.mock!["SOAPAction"]="\"#{SCHEMA_MESSAGES}/#{action}\""
110
- ns = Object.new
111
- mock(ctx.soap).namespaces{ns}
112
- mock(ns)["xmlns:t"]=Rews::SCHEMA_TYPES
113
- mock(ctx.soap).body=(anything)
114
-
115
- ctx.eval_with_delegation(&block)
116
- response
117
- end
118
- end
119
-
120
107
  describe "get_item" do
121
108
  def test_get_item(client, item_shape, ignore_change_keys, result)
122
109
  shape = Object.new
@@ -129,7 +116,7 @@ module Rews
129
116
  response = Object.new
130
117
  mock(response).to_hash{{:get_item_response=>{:response_messages=>{:get_item_response_message=>{:response_class=>"Success", :items=>result}}}}}
131
118
 
132
- mock_request(client, "GetItem", nil, response)
119
+ RequestProxy.mock_request(self, client, "GetItem", nil, response)
133
120
 
134
121
  opts={}
135
122
  opts[:item_shape]=item_shape if item_shape
@@ -138,23 +125,23 @@ module Rews
138
125
  end
139
126
 
140
127
  it "should generate the BaseShape and ItemId xml and parse the response" do
141
- client = Object.new
142
- msg = test_get_item(client,
128
+ c = client
129
+ msg = test_get_item(c,
143
130
  {:base_shape=>:IdOnly},
144
131
  nil,
145
132
  {:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
146
133
  msg.item_class.should == :message
147
- msg.item_id.should == Item::ItemId.new(client, :id=>"abc", :change_key=>"def")
134
+ msg.item_id.should == Item::ItemId.new(c, :id=>"abc", :change_key=>"def")
148
135
  end
149
136
 
150
137
  it "should generate a request with no change_key if specified" do
151
- client = Object.new
152
- msg = test_get_item(client,
138
+ c = client
139
+ msg = test_get_item(c,
153
140
  {:base_shape=>:Default},
154
141
  true,
155
142
  {:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
156
143
  msg.item_class.should == :message
157
- msg.item_id.should == Item::ItemId.new(client, :id=>"abc", :change_key=>"def")
144
+ msg.item_id.should == Item::ItemId.new(c, :id=>"abc", :change_key=>"def")
158
145
  end
159
146
 
160
147
  end
@@ -167,7 +154,7 @@ module Rews
167
154
  response = Object.new
168
155
  mock(response).to_hash{{:delete_item_response=>{:response_messages=>{:delete_item_response_message=>{:response_class=>"Success"}}}}}
169
156
 
170
- mock_request(client, "DeleteItem", {:DeleteType=>delete_type}, response)
157
+ RequestProxy.mock_request(self, client, "DeleteItem", {:DeleteType=>delete_type}, response)
171
158
 
172
159
  opts={}
173
160
  opts[:ignore_change_keys]=ignore_change_keys if ignore_change_keys
@@ -176,8 +163,99 @@ module Rews
176
163
  end
177
164
 
178
165
  it "should generate the ItemId xml and parse the response" do
179
- client = Object.new
180
- msg = test_delete_item(client, true, :HardDelete)
166
+ c = client
167
+ msg = test_delete_item(c, true, :HardDelete)
168
+ end
169
+ end
170
+
171
+ describe "update_item" do
172
+ def test_update_item(client,
173
+ conflict_resolution,
174
+ message_disposition,
175
+ ignore_change_keys,
176
+ updates,
177
+ &validate_block)
178
+
179
+ iid = Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"})
180
+ mock.proxy(iid).to_xml(ignore_change_keys)
181
+
182
+ response = Object.new
183
+ mock(response).to_hash{{:update_item_response=>{:response_messages=>{:update_item_response_message=>{:response_class=>"Success"}}}}}
184
+
185
+ RequestProxy.mock_request(self, client, "UpdateItem",
186
+ { :ConflictResolution=>conflict_resolution,
187
+ :MessageDisposition=>message_disposition},
188
+ response,
189
+ &validate_block)
190
+
191
+ opts={}
192
+ opts[:conflict_resolution]=conflict_resolution if conflict_resolution
193
+ opts[:message_disposition]=message_disposition if message_disposition
194
+ opts[:ignore_change_keys]=ignore_change_keys if !ignore_change_keys.nil?
195
+ opts[:updates]=updates
196
+ iid.update_item(opts)
197
+ end
198
+
199
+ it "should generate the body xml and parse the response" do
200
+ c = client
201
+ update=Object.new
202
+ stub(update).to_xml{"blahblah"}
203
+ msg = test_update_item(c, "AutoResolve", "SaveOnly", false, update) do |body|
204
+ rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types"})
205
+ rsxml.should == ["wsdl:ItemChanges", {"xmlns:wsdl"=>"ews_wsdl", "xmlns:t"=>"ews_types"},
206
+ ["t:ItemChange",
207
+ ["t:ItemId", {"Id"=>"abc", "ChangeKey"=>"def"}],
208
+ ["t:Updates", "blahblah"]]]
209
+ end
210
+ end
211
+
212
+ it "should raise an exception if no updates are given" do
213
+ c = client
214
+ iid = Item::ItemId.new(c, {:id=>"abc", :change_key=>"def"})
215
+
216
+ lambda {
217
+ iid.update_item({})
218
+ }.should raise_error(/no updates/)
219
+ end
220
+
221
+ end
222
+
223
+ describe "suppress_receipts" do
224
+ def test_set_is_read(client,
225
+ is_read,
226
+ &validate_block)
227
+
228
+ iid = Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"})
229
+ mock.proxy(iid).to_xml(nil)
230
+
231
+ response = Object.new
232
+ mock(response).to_hash{{:update_item_response=>{:response_messages=>{:update_item_response_message=>{:response_class=>"Success"}}}}}
233
+
234
+ RequestProxy.mock_request(self, client, "UpdateItem",
235
+ { :ConflictResolution=>"AlwaysOverwrite",
236
+ :MessageDisposition=>"SaveOnly"},
237
+ response,
238
+ &validate_block)
239
+
240
+ opts={}
241
+ opts[:conflict_resolution]="AlwaysOverwrite"
242
+ opts[:message_disposition]="SaveOnly"
243
+ iid.set_is_read(is_read)
244
+ end
245
+
246
+ it "should generate the body xml and parse the response" do
247
+ c = client
248
+ test_set_is_read(c, true) do |body|
249
+ rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types", ""=>"ews_wsdl"})
250
+ Rsxml.compare(rsxml, ["wsdl:ItemChanges", {"xmlns:wsdl"=>"ews_wsdl", "xmlns:t"=>"ews_types", "xmlns"=>"ews_wsdl"},
251
+ ["t:ItemChange",
252
+ ["t:ItemId", {"Id"=>"abc", "ChangeKey"=>"def"}],
253
+ ["t:Updates",
254
+ ["t:SetItemField",
255
+ ["t:FieldURI", {"FieldURI"=>"message:IsRead"}],
256
+ ["t:Message", ["t:IsRead", "true"]]]]]]).should == true
257
+ end
258
+
181
259
  end
182
260
  end
183
261
  end
@@ -0,0 +1,20 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+ module Rews
4
+
5
+ describe SetItemField do
6
+ it "should write Update xml" do
7
+ xml = SetItemField.new("message:IsRead",
8
+ [:message,
9
+ [:is_read, "true"]]).to_xml
10
+
11
+
12
+ rsxml = Rsxml.to_rsxml(xml, :ns=>{"t"=>"ews_types"})
13
+
14
+ rsxml.should == ["t:SetItemField", {"xmlns:t"=>"ews_types"},
15
+ ["t:FieldURI", {"FieldURI"=>"message:IsRead"}],
16
+ ["t:Message", ["t:IsRead", "true"]]]
17
+ end
18
+ end
19
+
20
+ end
@@ -25,6 +25,15 @@ module Rews
25
25
  end
26
26
  end
27
27
 
28
+ describe "rsxml_to_xml" do
29
+ it "should camelize tags and attribute names, and prefix tags with t:" do
30
+ Util.rsxml_to_xml([:foo]).should == "<t:Foo></t:Foo>"
31
+ Util.rsxml_to_xml([:foo_foo, {:bar_bar=>"blah"}]).should == '<t:FooFoo BarBar="blah"></t:FooFoo>'
32
+ Util.rsxml_to_xml([:foo_foo, {:bar_bar=>"blah"}, "foofoo", [:baz_baz, {:boo_hoo=>"10"}, "bazbaz"]]).should ==
33
+ '<t:FooFoo BarBar="blah">foofoo<t:BazBaz BooHoo="10">bazbaz</t:BazBaz></t:FooFoo>'
34
+ end
35
+ end
36
+
28
37
  describe "with_error_check" do
29
38
  it "should yield, convert the response to a hash and fetch_in the status" do
30
39
  client = Object.new
@@ -51,7 +60,7 @@ module Rews
51
60
  it "should log any unexpected exceptions and tag with the savon response" do
52
61
  client = Object.new
53
62
  exception = RuntimeError.new("boo")
54
- mock(client).log do |block|
63
+ mock(Rews).log do |block|
55
64
  logger = Object.new
56
65
  mock(logger).warn(exception)
57
66
  block.call(logger)
@@ -82,7 +91,7 @@ module Rews
82
91
  it "should log a warning and return if the response_class is Warning" do
83
92
  client = Object.new
84
93
  status = {:response_class=>"Warning", :message_text=>"boo", :response_code=>"BooWarning"}
85
- mock(client).log() do |p|
94
+ mock(Rews).log() do |p|
86
95
  logger = Object.new
87
96
  mock(logger).warn("BooWarning - boo")
88
97
  p.call(logger)
@@ -0,0 +1,21 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ module Rews
4
+ describe "log" do
5
+ it "should log to a logger if set" do
6
+ logger = Object.new
7
+ stub(Rews).logger{logger}
8
+ mock(logger).warn("boo")
9
+
10
+ Rews.log{|l| l.warn("boo")}.should == nil
11
+ end
12
+
13
+ it "should do nothing if no logger set" do
14
+ stub(Rews).logger{nil}
15
+ lambda {
16
+ Rews.log{|l| raise "boo"}.should == nil
17
+ }.should_not raise_error
18
+ end
19
+ end
20
+
21
+ end
@@ -6,6 +6,7 @@ require 'spec'
6
6
  require 'spec/autorun'
7
7
  require 'rr'
8
8
  require 'nokogiri'
9
+ require 'rsxml'
9
10
  require 'request_proxy'
10
11
 
11
12
  Spec::Runner.configure do |config|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rews
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 12
10
- version: 0.2.12
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Trampoline Systems Ltd
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-06 00:00:00 +01:00
18
+ date: 2011-05-06 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -67,9 +67,25 @@ dependencies:
67
67
  type: :runtime
68
68
  version_requirements: *id003
69
69
  - !ruby/object:Gem::Dependency
70
- name: httpclient
70
+ name: rsxml
71
71
  prerelease: false
72
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 19
78
+ segments:
79
+ - 0
80
+ - 1
81
+ - 4
82
+ version: 0.1.4
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: httpclient
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
73
89
  none: false
74
90
  requirements:
75
91
  - - ">="
@@ -81,11 +97,11 @@ dependencies:
81
97
  - 7
82
98
  version: 2.1.7
83
99
  type: :development
84
- version_requirements: *id004
100
+ version_requirements: *id005
85
101
  - !ruby/object:Gem::Dependency
86
102
  name: rspec
87
103
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
104
+ requirement: &id006 !ruby/object:Gem::Requirement
89
105
  none: false
90
106
  requirements:
91
107
  - - ">="
@@ -97,11 +113,11 @@ dependencies:
97
113
  - 9
98
114
  version: 1.2.9
99
115
  type: :development
100
- version_requirements: *id005
116
+ version_requirements: *id006
101
117
  - !ruby/object:Gem::Dependency
102
118
  name: rr
103
119
  prerelease: false
104
- requirement: &id006 !ruby/object:Gem::Requirement
120
+ requirement: &id007 !ruby/object:Gem::Requirement
105
121
  none: false
106
122
  requirements:
107
123
  - - ">="
@@ -113,11 +129,11 @@ dependencies:
113
129
  - 5
114
130
  version: 0.10.5
115
131
  type: :development
116
- version_requirements: *id006
132
+ version_requirements: *id007
117
133
  - !ruby/object:Gem::Dependency
118
134
  name: nokogiri
119
135
  prerelease: false
120
- requirement: &id007 !ruby/object:Gem::Requirement
136
+ requirement: &id008 !ruby/object:Gem::Requirement
121
137
  none: false
122
138
  requirements:
123
139
  - - ">="
@@ -129,7 +145,7 @@ dependencies:
129
145
  - 4
130
146
  version: 1.4.4
131
147
  type: :development
132
- version_requirements: *id007
148
+ version_requirements: *id008
133
149
  description: an email focussed Ruby client for Exchange Web Services atop Savon
134
150
  email: craig@trampolinesystems.com
135
151
  executables: []
@@ -152,6 +168,7 @@ files:
152
168
  - lib/rews/restriction.rb
153
169
  - lib/rews/shape.rb
154
170
  - lib/rews/sort_order.rb
171
+ - lib/rews/update.rb
155
172
  - lib/rews/util.rb
156
173
  - lib/rews/view.rb
157
174
  - spec/request_proxy.rb
@@ -161,8 +178,10 @@ files:
161
178
  - spec/rews/restriction_spec.rb
162
179
  - spec/rews/shape_spec.rb
163
180
  - spec/rews/sort_order_spec.rb
181
+ - spec/rews/update_spec.rb
164
182
  - spec/rews/util_spec.rb
165
183
  - spec/rews/view_spec.rb
184
+ - spec/rews_spec.rb
166
185
  - spec/spec.opts
167
186
  - spec/spec_helper.rb
168
187
  has_rdoc: true
@@ -207,6 +226,8 @@ test_files:
207
226
  - spec/rews/restriction_spec.rb
208
227
  - spec/rews/shape_spec.rb
209
228
  - spec/rews/sort_order_spec.rb
229
+ - spec/rews/update_spec.rb
210
230
  - spec/rews/util_spec.rb
211
231
  - spec/rews/view_spec.rb
232
+ - spec/rews_spec.rb
212
233
  - spec/spec_helper.rb