roart 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/roart.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{roart}
5
+ s.version = "0.1.4"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["PJ Davis"]
9
+ s.date = %q{2009-08-19}
10
+ s.description = %q{Interface for working with Request Tracker (RT) tickets inspired by ActiveRecord.}
11
+ s.email = %q{pj.davis@gmail.com}
12
+ s.extra_rdoc_files = ["History.txt", "README.rdoc", "spec/test_data/full_history.txt", "spec/test_data/single_history.txt"]
13
+ s.files = ["History.txt", "README.rdoc", "Rakefile", "lib/roart.rb", "lib/roart/callbacks.rb", "lib/roart/connection.rb", "lib/roart/core/array.rb", "lib/roart/core/hash.rb", "lib/roart/core/string.rb", "lib/roart/errors.rb", "lib/roart/history.rb", "lib/roart/roart.rb", "lib/roart/ticket.rb", "lib/roart/ticket_page.rb", "roart.gemspec", "spec/roart/callbacks_spec.rb", "spec/roart/connection_spec.rb", "spec/roart/core/array_spec.rb", "spec/roart/core/hash_spec.rb", "spec/roart/core/string_spec.rb", "spec/roart/history_spec.rb", "spec/roart/roart_spec.rb", "spec/roart/ticket_page_spec.rb", "spec/roart/ticket_spec.rb", "spec/roart_spec.rb", "spec/spec_helper.rb", "spec/test_data/full_history.txt", "spec/test_data/single_history.txt"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/pjdavis/roart}
16
+ s.rdoc_options = ["--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{roart}
19
+ s.rubygems_version = %q{1.3.2}
20
+ s.summary = %q{Interface for working with Request Tracker (RT) tickets inspired by ActiveRecord}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<mechanize>, [">= 0.9.0"])
28
+ s.add_development_dependency(%q<bones>, [">= 2.5.1"])
29
+ else
30
+ s.add_dependency(%q<mechanize>, [">= 0.9.0"])
31
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<mechanize>, [">= 0.9.0"])
35
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
36
+ end
37
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. spec_helper])
2
+
3
+ describe 'ticket callbacks' do
4
+
5
+ describe 'create callbacks' do
6
+
7
+ before do
8
+ post_data = @payload = {:subject => 'A New Ticket', :queue => 'My Queue'}
9
+ post_data.update(:id => 'ticket/new')
10
+ post_data = to_content_format(post_data)
11
+ mock_connection = mock('connection')
12
+ mock_connection.should_receive(:post).with('uri/REST/1.0/ticket/new', {:content => post_data}).and_return("RT/3.6.6 200 Ok\n\n# Ticket 267783 created.")
13
+ mock_connection.should_receive(:server).and_return('uri')
14
+ Roart::Ticket.should_receive(:connection).twice.and_return(mock_connection)
15
+ end
16
+
17
+ it 'should call before_create callback' do
18
+
19
+ ticket = Roart::Ticket.new(@payload)
20
+ ticket.should_receive(:before_create)
21
+ ticket.should_receive(:after_create)
22
+ ticket.save
23
+ end
24
+
25
+ end
26
+
27
+ describe 'update callbacks' do
28
+
29
+ before do
30
+ @post_data = @payload = {:subject => 'A New Ticket', :queue => 'My Queue'}
31
+ @post_data[:subject] = 'An Old Ticket'
32
+ @post_data = to_content_format(@post_data)
33
+ @mock_connection = mock('connection')
34
+ @mock_connection.should_receive(:server).and_return('uri')
35
+ Roart::Ticket.should_receive(:connection).twice.and_return(@mock_connection)
36
+ end
37
+
38
+ it 'should call before_update callbacks' do
39
+ @mock_connection.should_receive(:post).with('uri/REST/1.0/ticket/1/edit', {:content => @post_data}).and_return("RT/3.6.6 200 Ok\n\n# Ticket 267783 updated.")
40
+ ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
41
+ ticket.instance_variable_set("@saved", false)
42
+ ticket.should_receive(:before_update)
43
+ ticket.should_receive(:after_update)
44
+ ticket.save
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,7 @@
1
+
2
+ require File.join(File.dirname(__FILE__), %w[ .. spec_helper])
3
+
4
+ describe "Connection" do
5
+
6
+
7
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. .. spec_helper])
2
+
3
+ describe 'array extentions' do
4
+
5
+ it 'should turn an array to a nil valued hash' do
6
+ array = %w[key1 key2]
7
+ hash = array.to_hash
8
+ hash.has_key?(:key1).should be_true
9
+ hash.has_key?(:key2).should be_true
10
+ hash[:key1].should be_nil
11
+ end
12
+
13
+ end
@@ -0,0 +1,16 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. .. spec_helper])
2
+
3
+ describe 'hash extentions' do
4
+
5
+ it 'should format the content correctly' do
6
+ payload = {:subject => "A New Ticket", :queue => 'My Queue'}
7
+ payload.to_content_format.include?("Subject: A New Ticket").should be_true
8
+ payload.to_content_format.include?("Queue: My Queue").should be_true
9
+ end
10
+
11
+ it 'should handel custom fields' do
12
+ payload = {:cf_stuff => 'field'}
13
+ payload.to_content_format.should == "CF-Stuff: field"
14
+ end
15
+
16
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. .. spec_helper])
2
+
3
+ describe 'string extentions' do
4
+
5
+ it 'should underscore a word' do
6
+ 'SomeGuy'.underscore.should == 'some_guy'
7
+ end
8
+
9
+ it 'should camelcase a word' do
10
+ 'some_guy'.camelize.should == 'SomeGuy'
11
+ end
12
+
13
+ end
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. spec_helper])
2
+
3
+ describe "History" do
4
+
5
+ it 'should have a ticket' do
6
+ search_array = ['1:subject']
7
+ search_array.extend(Roart::TicketPage)
8
+ full_ticket = Roart::Ticket.send(:instantiate, {:id => 1, :subject => 'subject', :full => true})
9
+ @ticket = Roart::Ticket.send(:instantiate, search_array.to_search_array ).first
10
+ Roart::History.should_receive(:get_page).and_return('200')
11
+
12
+ history = @ticket.histories
13
+ history.ticket.should == @ticket
14
+
15
+ end
16
+
17
+ describe 'getting ticket history' do
18
+
19
+ it 'should create the crect URI' do
20
+ connection = mock('connection', :rest_path => 'REST/1.0/')
21
+ myclass = mock('class', :connection => connection)
22
+ ticket = mock(:ticket, :id => 1, :class => myclass)
23
+ hash = mock(:options_hash, :[] => ticket)
24
+ Roart::History.should_receive(:default_options).and_return(hash)
25
+ Roart::History.send(:uri_for, ticket).should == 'REST/1.0/ticket/1/history?format=l'
26
+ end
27
+ end
28
+
29
+ describe 'reading history pages' do
30
+
31
+ before do
32
+ @page = File.open(File.join(File.dirname(__FILE__), %w[ .. test_data full_history.txt])).readlines.join
33
+ @ticket = mock('ticket')
34
+ Roart::History.should_receive(:get_page).and_return(@page)
35
+ @histories = Roart::History.default(:ticket => @ticket)
36
+ end
37
+
38
+ it 'should have the right number of histories' do
39
+ @histories.size.should == 5
40
+ end
41
+
42
+ it 'should have a ticket' do
43
+ @histories.first.ticket.should == @ticket
44
+ end
45
+
46
+ it 'should have an id' do
47
+ @histories.first.id.should == 34725
48
+ end
49
+
50
+ it 'should return itself for all' do
51
+ @histories.all.should == @histories
52
+ end
53
+
54
+ it 'should return the ticket' do
55
+ @histories.ticket.should == @ticket
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,11 @@
1
+
2
+ require File.join(File.dirname(__FILE__), %w[ .. spec_helper])
3
+
4
+ describe "Roart" do
5
+
6
+ it "should raise an error if there aren't required fields" do
7
+ attributes = {:subject => "Not Enough Stuff"}
8
+ lambda { Roart::check_keys!(attributes, Roart::Tickets::RequiredAttributes) }.should raise_error(Roart::ArgumentError)
9
+ end
10
+
11
+ end
@@ -0,0 +1,59 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. spec_helper])
2
+
3
+ describe 'ticket page' do
4
+
5
+ describe 'ticket hash' do
6
+
7
+ it 'should convert an array to a hash' do
8
+ array = ["id : 10", "subject : asdf"]
9
+ array.extend(Roart::TicketPage)
10
+ hash = array.to_hash
11
+ hash.has_key?(:id).should be_true
12
+ hash[:id].should == 10
13
+ hash[:subject].should == 'asdf'
14
+ end
15
+
16
+ end
17
+
18
+ describe 'search array' do
19
+
20
+ before do
21
+ @array = ["123 : Subject", "234 : Subject"]
22
+ @array.extend(Roart::TicketPage)
23
+ @array = @array.to_search_array
24
+ end
25
+
26
+ it 'should make an array of search results' do
27
+ @array.size.should == 2
28
+ end
29
+
30
+ it 'should put search elements into the search array' do
31
+ @array.first[:id].should == 123
32
+ @array.last[:id].should == 234
33
+ end
34
+
35
+ end
36
+
37
+ describe 'ticket history hash' do
38
+
39
+ before do
40
+ @page = File.open(File.join(File.dirname(__FILE__), %w[ .. test_data single_history.txt])).readlines.join
41
+ @page = @page.split("\n")
42
+ @page.extend(Roart::TicketPage)
43
+ end
44
+
45
+ it 'should give back the hash of history' do
46
+ @page.to_history_hash.class.should == Hash
47
+ end
48
+
49
+ it 'should have some content' do
50
+ @page.to_history_hash[:content].should_not be_nil
51
+ end
52
+
53
+ it 'should have the create type' do
54
+ @page.to_history_hash[:type].should == 'Create'
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,440 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. spec_helper])
2
+
3
+ describe "Ticket" do
4
+
5
+ it "should have a connection" do
6
+ Roart::Connection.should_receive(:new).with('some options').and_return(true)
7
+ Roart::Ticket.connection('some options').should == true
8
+ end
9
+
10
+ it "should find the first ticket" do
11
+ Roart::Ticket.should_receive(:find_initial).with(:my => 'options').and_return('a ticket')
12
+ Roart::Ticket.find(:first, :my => 'options').should == 'a ticket'
13
+ end
14
+
15
+ it 'should find all tickets' do
16
+ Roart::Ticket.should_receive(:find_all).with(:my => 'options').and_return(%w[array of tickets])
17
+ Roart::Ticket.find(:all, :my => 'options').should == ['array', 'of', 'tickets']
18
+ end
19
+
20
+ it 'should find a ticket by id' do
21
+ Roart::Ticket.should_receive(:find_by_ids).with([12345],{}).and_return('a ticket')
22
+ Roart::Ticket.find(12345).should == 'a ticket'
23
+ end
24
+
25
+ describe "find initial" do
26
+
27
+ it 'should set options to include :limit => 1' do
28
+ Roart::Ticket.should_receive(:find_all).with({:limit => 1}).and_return(['ticket', 'not seen'])
29
+ Roart::Ticket.send(:find_initial)
30
+ end
31
+
32
+ it 'should not overwrite the options hash' do
33
+ Roart::Ticket.should_receive(:find_all).with({:queue => 'queue', :limit => 1}).and_return(['ticket', 'not seen'])
34
+ Roart::Ticket.send(:find_initial, :queue => 'queue')
35
+ end
36
+
37
+ it 'should return 1 ticket object' do
38
+ Roart::Ticket.should_receive(:find_all).with({:limit => 1}).and_return(['ticket', 'not seen'])
39
+ Roart::Ticket.send(:find_initial).should == 'ticket'
40
+ end
41
+
42
+ end
43
+
44
+ describe 'page array' do
45
+
46
+ it 'should raise an error if not a 200 response' do
47
+ connection = mock('connection', :get => 'some error message')
48
+ Roart::Ticket.should_receive(:connection).and_return(connection)
49
+ lambda do
50
+ Roart::Ticket.send(:page_array, 'www.whatever')
51
+ end.should raise_error(Roart::TicketSystemInterfaceError)
52
+ end
53
+
54
+ it 'should raise an error if nothing is returned' do
55
+ connection = mock('connection', :get => nil)
56
+ Roart::Ticket.should_receive(:connection).and_return(connection)
57
+ lambda do
58
+ Roart::Ticket.send(:page_array, 'www.whatever')
59
+ end.should raise_error(Roart::TicketSystemError)
60
+ end
61
+
62
+ it 'should give back an array of strings' do
63
+ connection = mock('connection', :get => "200 OK\n23:SomeTicket\n33:Another")
64
+ Roart::Ticket.should_receive(:connection).and_return(connection)
65
+ Roart::Ticket.send(:page_array, 'uri').should == ['23:SomeTicket', '33:Another']
66
+ end
67
+
68
+ end
69
+
70
+ describe 'getting tickets from URI' do
71
+
72
+ describe 'search' do
73
+
74
+ it 'should give an array of tickets' do
75
+ Roart::Ticket.should_receive(:page_array).with('uri').and_return(['23:SomeTicket', '33:Another'])
76
+ Roart::Ticket.send(:get_tickets_from_search_uri, 'uri').size.should == 2
77
+ end
78
+
79
+ it 'should not have full tickets' do
80
+ Roart::Ticket.should_receive(:page_array).with('uri').and_return(['23:SomeTicket', '33:Another'])
81
+ Roart::Ticket.send(:get_tickets_from_search_uri, 'uri').each do |ticket|
82
+ ticket.full.should_not be_true
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ describe 'full ticket' do
89
+
90
+ it 'should give a ticket' do
91
+ Roart::Ticket.should_receive(:page_array).with('uri').and_return(['id:23', 'subject:someticket'])
92
+ Roart::Ticket.send(:get_ticket_from_uri, 'uri').is_a?(Roart::Ticket).should be_true
93
+ end
94
+
95
+ it 'should be a full ticket' do
96
+ Roart::Ticket.should_receive(:page_array).with('uri').and_return(['id:23', 'subject:someticket'])
97
+ Roart::Ticket.send(:get_ticket_from_uri, 'uri').full.should be_true
98
+ end
99
+
100
+ end
101
+
102
+ describe 'getting ticket from id' do
103
+
104
+ it 'should give a ticket' do
105
+ connection = mock('connection', :server => "server")
106
+ Roart::Ticket.should_receive(:connection).and_return(connection)
107
+ Roart::Ticket.should_receive(:get_ticket_from_uri).with('server' + '/REST/1.0/ticket/' + 12345.to_s).and_return('a ticket')
108
+ Roart::Ticket.send(:get_ticket_by_id, 12345).should == 'a ticket'
109
+ end
110
+
111
+ end
112
+
113
+ describe 'find methods' do
114
+
115
+ it 'should get all tickets from an options hash' do
116
+ Roart::Ticket.should_receive('construct_search_uri').with('searches').and_return('uri')
117
+ Roart::Ticket.should_receive('get_tickets_from_search_uri').with('uri').and_return(['tickets'])
118
+ Roart::Ticket.send(:find_all, 'searches').should == ['tickets']
119
+ end
120
+
121
+ it 'should find tickets from id' do
122
+ Roart::Ticket.should_receive(:get_ticket_by_id).with('id').and_return('a ticket')
123
+ Roart::Ticket.send(:find_by_ids, ['id'], {}).should == 'a ticket'
124
+ end
125
+
126
+ end
127
+
128
+ describe 'building a search uri' do
129
+
130
+ before do
131
+ @connection = mock('connection', :server => "server")
132
+ @search_string = "/REST/1.0/search/ticket?"
133
+ Roart::Ticket.should_receive(:connection).and_return(@connection)
134
+ @query = @connection.server + @search_string + 'query= '
135
+ end
136
+
137
+ describe 'queues' do
138
+
139
+ it 'should include a queue' do
140
+ Roart::Ticket.send(:construct_search_uri, {:queue => 'myQueue'}).should == @query + "Queue = 'myQueue'"
141
+ end
142
+
143
+ it 'should take multiple queues' do
144
+ Roart::Ticket.send(:construct_search_uri, {:queue => ['myQueue', 'another']}).should == @query + "( Queue = 'myQueue' OR Queue = 'another' )"
145
+ end
146
+
147
+ end
148
+
149
+ describe 'dates' do
150
+
151
+ before do
152
+ @time = Time.now
153
+ end
154
+
155
+ it 'should accept a date' do
156
+ Roart::Ticket.send(:construct_search_uri, {:created => @time}).should == @query + "( Created > '#{dbtime(@time)}' )"
157
+ end
158
+
159
+ it 'should accept an array of dates' do
160
+ Roart::Ticket.send(:construct_search_uri, {:created => [@time, @time + 300]}).should == @query + "( Created > '#{dbtime(@time)}' AND Created < '#{dbtime(@time + 300)}' )"
161
+ end
162
+
163
+ it 'should accept a range of dates' do
164
+ Roart::Ticket.send(:construct_search_uri, {:created => (@time..(@time + 300))}).should == @query + "( Created > '#{dbtime(@time)}' AND Created < '#{dbtime(@time + 300)}' )"
165
+ end
166
+
167
+ it 'should accept an array of strings' do
168
+ Roart::Ticket.send(:construct_search_uri, {:created => %w[cat dog]}).should == @query + "( Created > 'cat' AND Created < 'dog' )"
169
+ end
170
+
171
+ it 'should accept a string' do
172
+ Roart::Ticket.send(:construct_search_uri, {:created => 'time'}).should == @query + "( Created > 'time' )"
173
+ end
174
+
175
+ describe 'date fields' do
176
+
177
+ it 'should search started' do
178
+ Roart::Ticket.send(:construct_search_uri, {:started => 'time'}).should == @query + "( Started > 'time' )"
179
+ end
180
+
181
+ it 'should search resolved' do
182
+ Roart::Ticket.send(:construct_search_uri, {:resolved => 'time'}).should == @query + "( Resolved > 'time' )"
183
+ end
184
+
185
+ it 'should search told' do
186
+ Roart::Ticket.send(:construct_search_uri, {:told => 'time'}).should == @query + "( Told > 'time' )"
187
+ end
188
+
189
+ it 'should search last_updated' do
190
+ Roart::Ticket.send(:construct_search_uri, {:last_updated => 'time'}).should == @query + "( LastUpdated > 'time' )"
191
+ end
192
+
193
+ it 'should search starts' do
194
+ Roart::Ticket.send(:construct_search_uri, {:starts => 'time'}).should == @query + "( Starts > 'time' )"
195
+ end
196
+
197
+ it 'should search due' do
198
+ Roart::Ticket.send(:construct_search_uri, {:due => 'time'}).should == @query + "( Due > 'time' )"
199
+ end
200
+
201
+ it 'should search updated' do
202
+ Roart::Ticket.send(:construct_search_uri, {:updated => 'time'}).should == @query + "( Updated > 'time' )"
203
+ end
204
+
205
+ end
206
+
207
+ end
208
+
209
+ describe 'searches' do
210
+
211
+ it 'should accept a string' do
212
+ Roart::Ticket.send(:construct_search_uri, {:subject => 'fish'}).should == @query + "Subject LIKE 'fish'"
213
+ end
214
+
215
+ it 'should accept an array' do
216
+ Roart::Ticket.send(:construct_search_uri, {:subject => %w[cramanation station]}).should == @query + "( Subject LIKE 'cramanation' AND Subject LIKE 'station' )"
217
+ end
218
+
219
+ describe 'search fields' do
220
+
221
+ it 'should search content' do
222
+ Roart::Ticket.send(:construct_search_uri, {:content => 'fish'}).should == @query + "Content LIKE 'fish'"
223
+ end
224
+
225
+ it 'should search content_type' do
226
+ Roart::Ticket.send(:construct_search_uri, {:content_type => 'fish'}).should == @query + "ContentType LIKE 'fish'"
227
+ end
228
+
229
+ it 'should search file_name' do
230
+ Roart::Ticket.send(:construct_search_uri, {:file_name => 'fish'}).should == @query + "FileName LIKE 'fish'"
231
+ end
232
+
233
+ end
234
+
235
+ end
236
+
237
+ describe 'status' do
238
+
239
+ it 'should accept a string' do
240
+ Roart::Ticket.send(:construct_search_uri, {:status => 'new'}).should == @query + "Status = 'new'"
241
+ end
242
+
243
+ it 'should accept a symbol' do
244
+ Roart::Ticket.send(:construct_search_uri, {:status => :new}).should == @query + "Status = 'new'"
245
+ end
246
+
247
+ it 'should accept an array' do
248
+ Roart::Ticket.send(:construct_search_uri, {:status => ['new', 'open']}).should == @query + "( Status = 'new' OR Status = 'open' )"
249
+ end
250
+
251
+ end
252
+
253
+ describe 'custom_fields' do
254
+
255
+ it 'should accept a hash with string values' do
256
+ Roart::Ticket.send(:construct_search_uri, {:custom_fields => {:phone => '8675309'}}).should == @query + "'CF.{phone}' = '8675309'"
257
+ end
258
+
259
+ it 'should accept a hash with string values' do
260
+ Roart::Ticket.send(:construct_search_uri, {:custom_fields => {:phone => ['8675309', '5553265']}}).should == @query + "( 'CF.{phone}' = '8675309' OR 'CF.{phone}' = '5553265' )"
261
+ end
262
+
263
+ end
264
+
265
+ describe 'multiple find options' do
266
+
267
+ it 'should allow multiple find options' do
268
+ query = Roart::Ticket.send(:construct_search_uri, {:status => 'new', :queue => 'MyQueue'})
269
+ query.include?("Status = 'new'").should be_true
270
+ query.include?("Queue = 'MyQueue'").should be_true
271
+ end
272
+
273
+ it "should search for :queue => 'A Queue', :status => [:new, :open]" do
274
+ query = Roart::Ticket.send(:construct_search_uri, {:queue => 'A Queue', :status => [:new, :open]})
275
+ query.include?("( Status = 'new' OR Status = 'open' )").should be_true
276
+ query.include?("Queue = 'A Queue'").should be_true
277
+ end
278
+
279
+ end
280
+
281
+ end
282
+
283
+ end
284
+
285
+ describe "the default queue" do
286
+
287
+ before do
288
+ @connection = mock('connection', :server => "server")
289
+ @search_string = "/REST/1.0/search/ticket?"
290
+ @query = @connection.server + @search_string + 'query= '
291
+ class MyTicket < Roart::Ticket; end
292
+ MyTicket.instance_variable_set("@default_queue", 'myQueue')
293
+ MyTicket.should_receive(:connection).and_return(@connection)
294
+ end
295
+
296
+
297
+ it 'should have a default queue' do
298
+ MyTicket.send(:construct_search_uri, :status => :new).should == @query + "Queue = 'myQueue' AND Status = 'new'"
299
+ end
300
+
301
+ it 'should search without options and return the default queue' do
302
+ MyTicket.send(:construct_search_uri).should == @query + "Queue = 'myQueue'"
303
+ end
304
+
305
+ end
306
+
307
+ describe 'ticket methods' do
308
+
309
+
310
+ it 'should change the ticket' do
311
+ ticket = Roart::Ticket.send(:instantiate,{:subject => 'A New Ticket', :queue => 'My Queue', :id => 1})
312
+ ticket.subject = 'An Old Ticket'
313
+ ticket.subject.should == 'An Old Ticket'
314
+ end
315
+
316
+ it 'should be able to load the full ticket' do
317
+ search_array = ['1:subject']
318
+ search_array.extend(Roart::TicketPage)
319
+ full_ticket = Roart::Ticket.send(:instantiate, {:id => 1, :subject => 'subject', :full => true})
320
+ ticket = Roart::Ticket.send(:instantiate, search_array.to_search_array ).first
321
+ Roart::Ticket.should_receive(:find).with(1).and_return(full_ticket)
322
+ ticket.load_full!
323
+ ticket.full.should be_true
324
+ end
325
+
326
+ end
327
+
328
+ describe 'manipulating tickets' do
329
+
330
+ describe 'creating tickets' do
331
+
332
+ before do
333
+ post_data = @payload = {:subject => 'A New Ticket', :queue => 'My Queue'}
334
+ post_data.update(:id => 'ticket/new')
335
+ post_data = to_content_format(post_data)
336
+ mock_connection = mock('connection')
337
+ mock_connection.should_receive(:post).with('uri/REST/1.0/ticket/new', {:content => post_data}).and_return("RT/3.6.6 200 Ok\n\n# Ticket 267783 created.")
338
+ mock_connection.should_receive(:server).and_return('uri')
339
+ Roart::Ticket.should_receive(:connection).twice.and_return(mock_connection)
340
+ end
341
+
342
+ it 'should be able to save a new ticket' do
343
+ ticket = Roart::Ticket.new(@payload)
344
+ ticket.save
345
+ end
346
+
347
+ it 'should be able to create a ticket' do
348
+ ticket = Roart::Ticket.create(@payload)
349
+ end
350
+
351
+ it 'should return a newly created ticket' do
352
+ ticket = Roart::Ticket.new(@payload)
353
+ ticket.class.should == Roart::Ticket
354
+ ticket.save
355
+ ticket.id.should == 267783
356
+ end
357
+
358
+ end
359
+
360
+ describe 'updating tickets' do
361
+
362
+ before do
363
+ @post_data = @payload = {:subject => 'A New Ticket', :queue => 'My Queue'}
364
+ @post_data[:subject] = 'An Old Ticket'
365
+ @post_data = to_content_format(@post_data)
366
+ @mock_connection = mock('connection')
367
+ @mock_connection.should_receive(:server).and_return('uri')
368
+ Roart::Ticket.should_receive(:connection).twice.and_return(@mock_connection)
369
+ end
370
+
371
+ it 'should be able to update a ticket' do
372
+ @mock_connection.should_receive(:post).with('uri/REST/1.0/ticket/1/edit', {:content => @post_data}).and_return("RT/3.6.6 200 Ok\n\n# Ticket 267783 updated.")
373
+ ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
374
+ ticket.subject = 'An Old Ticket'
375
+ ticket.save.should == true
376
+ end
377
+
378
+ it 'should keep the same id' do
379
+ @mock_connection.should_receive(:post).with('uri/REST/1.0/ticket/1/edit', {:content => @post_data}).and_return("RT/3.6.6 200 Ok\n\n# Ticket 267783 updated.")
380
+ ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
381
+ ticket.subject = 'An Old Ticket'
382
+ ticket.save
383
+ ticket.id.should == 1
384
+ end
385
+
386
+ it 'should save the ticket' do
387
+ @mock_connection.should_receive(:post).with('uri/REST/1.0/ticket/1/edit', {:content => @post_data}).and_return("RT/3.6.6 200 Ok\n\n# Ticket 267783 updated.")
388
+ ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
389
+ ticket.subject = 'An Old Ticket'
390
+ ticket.save
391
+ ticket.subject.should == 'An Old Ticket'
392
+ end
393
+
394
+ it 'should raise an error on failed save' do
395
+ @mock_connection.should_receive(:post).with('uri/REST/1.0/ticket/1/edit', {:content => @post_data}).and_return("RT/3.6.6 400 Not OK\n\n# U's A SUKKA, FOO!.")
396
+ ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
397
+ ticket.subject = 'An Old Ticket'
398
+ lambda {ticket.save}.should raise_error
399
+ end
400
+
401
+ end
402
+
403
+ end
404
+
405
+ describe 'histories' do
406
+
407
+ before(:each) do
408
+ search_array = ['1:subject']
409
+ search_array.extend(Roart::TicketPage)
410
+ full_ticket = Roart::Ticket.send(:instantiate, {:id => 1, :subject => 'subject', :full => true})
411
+ @mock_connection = mock('connection')
412
+ @mock_connection.should_receive(:get).with('uri').and_return('200')
413
+ @ticket = Roart::Ticket.send(:instantiate, search_array.to_search_array).first
414
+ @ticket.class.should_receive(:connection).and_return(@mock_connection)
415
+ Roart::History.should_receive(:uri_for).with(@ticket).and_return('uri')
416
+ end
417
+
418
+ it 'should return history objects' do
419
+ @ticket.histories.class.should == Roart::HistoryArray
420
+ end
421
+
422
+ it 'should have a default of the ticket id' do
423
+ @ticket.histories.ticket.should == @ticket
424
+ end
425
+
426
+ it 'should only spawn 1 dup class for each ticket' do
427
+ @ticket.histories.should === @ticket.histories
428
+ end
429
+
430
+ it 'should have a last history that is equal to the last value' do
431
+ @ticket.histories.last.should == @ticket.histories[@ticket.histories.size - 1]
432
+ end
433
+
434
+ it 'should have count, which is equal to size' do
435
+ @ticket.histories.count.should == @ticket.histories.size
436
+ end
437
+
438
+ end
439
+
440
+ end