ludo-roart 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +45 -0
- data/README.rdoc +89 -0
- data/Rakefile +35 -0
- data/lib/roart.rb +52 -0
- data/lib/roart/callbacks.rb +25 -0
- data/lib/roart/connection.rb +65 -0
- data/lib/roart/connection_adapter.rb +21 -0
- data/lib/roart/connection_adapters/mechanize_adapter.rb +32 -0
- data/lib/roart/core/content_formatter.rb +12 -0
- data/lib/roart/core/hash.rb +22 -0
- data/lib/roart/errors.rb +13 -0
- data/lib/roart/history.rb +115 -0
- data/lib/roart/roart.rb +35 -0
- data/lib/roart/ticket.rb +461 -0
- data/lib/roart/ticket_page.rb +78 -0
- data/lib/roart/validations.rb +230 -0
- data/roart.gemspec +39 -0
- data/spec/roart/callbacks_spec.rb +49 -0
- data/spec/roart/connection_adapter_spec.rb +11 -0
- data/spec/roart/connection_spec.rb +54 -0
- data/spec/roart/core/hash_spec.rb +22 -0
- data/spec/roart/history_spec.rb +60 -0
- data/spec/roart/roart_spec.rb +11 -0
- data/spec/roart/ticket_page_spec.rb +93 -0
- data/spec/roart/ticket_spec.rb +553 -0
- data/spec/roart/validation_spec.rb +152 -0
- data/spec/roart_spec.rb +8 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/test_data/full_history.txt +126 -0
- data/spec/test_data/search_ticket.txt +13 -0
- data/spec/test_data/single_history.txt +26 -0
- data/spec/test_data/ticket.txt +31 -0
- metadata +151 -0
@@ -0,0 +1,22 @@
|
|
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
|
+
it 'should use our content formatter for strings' do
|
17
|
+
payload = {:subject => 'A new ticket', :queue => 'My queue', :text => "A text"}
|
18
|
+
Roart::ContentFormatter.should_receive(:format_string).at_least(:once)
|
19
|
+
payload.to_content_format
|
20
|
+
end
|
21
|
+
|
22
|
+
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,93 @@
|
|
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 'reading a ticket' do
|
19
|
+
|
20
|
+
before do
|
21
|
+
@page = File.open(File.join(File.dirname(__FILE__), %w[ .. test_data ticket.txt])).readlines.join
|
22
|
+
@page = @page.split("\n")
|
23
|
+
@page.extend(Roart::TicketPage)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should include custom fields' do
|
27
|
+
@page.to_hash[:cf_BTN].should == '1035328269'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should be a hash' do
|
31
|
+
@page.to_hash.class.should == HashWithIndifferentAccess
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'search array' do
|
37
|
+
|
38
|
+
before do
|
39
|
+
@array = ["123 : Subject", "234 : Subject"]
|
40
|
+
@array.extend(Roart::TicketPage)
|
41
|
+
@array = @array.to_search_array
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should make an array of search results' do
|
45
|
+
@array.size.should == 2
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should put search elements into the search array' do
|
49
|
+
@array.first[:id].should == 123
|
50
|
+
@array.last[:id].should == 234
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "search list array" do
|
56
|
+
before do
|
57
|
+
@array = [['id:234', 'subject:SomeTicket', ], ['id:432','subject:Another']]
|
58
|
+
@array.extend(Roart::TicketPage)
|
59
|
+
@array = @array.to_search_list_array
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return an array of hashes" do
|
63
|
+
@array.first.class.should == HashWithIndifferentAccess
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should put the search elements into the array" do
|
67
|
+
@array.first[:id].should == 234
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'ticket history hash' do
|
72
|
+
|
73
|
+
before do
|
74
|
+
@page = File.open(File.join(File.dirname(__FILE__), %w[ .. test_data single_history.txt])).readlines.join
|
75
|
+
@page = @page.split("\n")
|
76
|
+
@page.extend(Roart::TicketPage)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should give back the hash of history' do
|
80
|
+
@page.to_history_hash.class.should == HashWithIndifferentAccess
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should have some content' do
|
84
|
+
@page.to_history_hash[:content].should_not be_nil
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should have the create type' do
|
88
|
+
@page.to_history_hash[:type].should == 'Create'
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,553 @@
|
|
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 => 'some options', :adapter => "www").and_return(true)
|
7
|
+
Roart::Ticket.connection(:some => 'some options', :adapter => "www").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_list_array).with('uri&format=l').and_return([['id:234', 'subject:SomeTicket', ], ['id:432','subject:Another']])
|
76
|
+
Roart::Ticket.send(:get_tickets_from_search_uri, 'uri').size.should == 2
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should have full tickets' do
|
80
|
+
Roart::Ticket.should_receive(:page_list_array).with('uri&format=l').and_return([['id:234', 'subject:SomeTicket', ], ['id:432','subject:Another']])
|
81
|
+
Roart::Ticket.send(:get_tickets_from_search_uri, 'uri').each do |ticket|
|
82
|
+
ticket.full.should be_true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should give back an array of arrays of strings' do
|
87
|
+
test_data = File.open(File.dirname(__FILE__) + "/../test_data/search_ticket.txt").readlines.join("\n")
|
88
|
+
connection = mock('connection', :get => test_data)
|
89
|
+
Roart::Ticket.should_receive(:connection).and_return(connection)
|
90
|
+
Roart::Ticket.send(:page_list_array, 'uri').should == [["id: ticket/3033", "Queue: Canada Express", "Subject: Canada Express", "Status: new"], ["id: ticket/2354", "Queue: Canada Express", "Subject: Canada Express", "Status: open"]]
|
91
|
+
end
|
92
|
+
|
93
|
+
describe ' search with no matches' do
|
94
|
+
it 'should give an empty array for :all' do
|
95
|
+
results = 'RT/3.6.6 200 Ok
|
96
|
+
|
97
|
+
No matching results.'
|
98
|
+
connection = mock('connection', :server => 'server', :get => results)
|
99
|
+
Roart::Ticket.should_receive(:connection).and_return(connection)
|
100
|
+
Roart::Ticket.send(:get_tickets_from_search_uri, 'uri').should == []
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'full ticket' do
|
107
|
+
|
108
|
+
it 'should give a ticket' do
|
109
|
+
Roart::Ticket.should_receive(:page_array).with('uri').and_return(['id:23', 'subject:someticket'])
|
110
|
+
Roart::Ticket.send(:get_ticket_from_uri, 'uri').is_a?(Roart::Ticket).should be_true
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should be a full ticket' do
|
114
|
+
Roart::Ticket.should_receive(:page_array).with('uri').and_return(['id:23', 'subject:someticket'])
|
115
|
+
Roart::Ticket.send(:get_ticket_from_uri, 'uri').full.should be_true
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'getting ticket from id' do
|
121
|
+
|
122
|
+
it 'should give a ticket' do
|
123
|
+
connection = mock('connection', :server => "server")
|
124
|
+
Roart::Ticket.should_receive(:connection).and_return(connection)
|
125
|
+
Roart::Ticket.should_receive(:get_ticket_from_uri).with('server' + '/REST/1.0/ticket/' + 12345.to_s).and_return('a ticket')
|
126
|
+
Roart::Ticket.send(:get_ticket_by_id, 12345).should == 'a ticket'
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should raise when searching for an id with no results' do
|
130
|
+
results = 'RT/3.6.6 200 Ok
|
131
|
+
|
132
|
+
No matching results.'
|
133
|
+
connection = mock('connection', :server => 'server', :get => results)
|
134
|
+
Roart::Ticket.stub!(:connection).and_return(connection)
|
135
|
+
lambda {Roart::Ticket.send(:get_ticket_by_id, 123)}.should raise_error("No ticket matching search criteria found.")
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
describe 'find methods' do
|
141
|
+
|
142
|
+
it 'should get all tickets from an options hash' do
|
143
|
+
Roart::Ticket.should_receive('construct_search_uri').with('searches').and_return('uri')
|
144
|
+
Roart::Ticket.should_receive('get_tickets_from_search_uri').with('uri').and_return(['tickets'])
|
145
|
+
Roart::Ticket.send(:find_all, 'searches').should == ['tickets']
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should find tickets from id' do
|
149
|
+
Roart::Ticket.should_receive(:get_ticket_by_id).with('id').and_return('a ticket')
|
150
|
+
Roart::Ticket.send(:find_by_ids, ['id'], {}).should == 'a ticket'
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
describe 'building a search uri' do
|
156
|
+
|
157
|
+
before do
|
158
|
+
@connection = mock('connection', :server => "server")
|
159
|
+
@search_string = "/REST/1.0/search/ticket?"
|
160
|
+
Roart::Ticket.should_receive(:connection).and_return(@connection)
|
161
|
+
@query = @connection.server + @search_string + 'query= '
|
162
|
+
end
|
163
|
+
|
164
|
+
describe 'queues' do
|
165
|
+
|
166
|
+
it 'should include a queue' do
|
167
|
+
Roart::Ticket.send(:construct_search_uri, {:queue => 'myQueue'}).should == @query + "Queue = 'myQueue'"
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should take multiple queues' do
|
171
|
+
Roart::Ticket.send(:construct_search_uri, {:queue => ['myQueue', 'another']}).should == @query + "( Queue = 'myQueue' OR Queue = 'another' )"
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
describe 'dates' do
|
177
|
+
|
178
|
+
before do
|
179
|
+
@time = Time.now
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should accept a date' do
|
183
|
+
Roart::Ticket.send(:construct_search_uri, {:created => @time}).should == @query + "( Created > '#{dbtime(@time)}' )"
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should accept an array of dates' do
|
187
|
+
Roart::Ticket.send(:construct_search_uri, {:created => [@time, @time + 300]}).should == @query + "( Created > '#{dbtime(@time)}' AND Created < '#{dbtime(@time + 300)}' )"
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should accept a range of dates' do
|
191
|
+
Roart::Ticket.send(:construct_search_uri, {:created => (@time..(@time + 300))}).should == @query + "( Created > '#{dbtime(@time)}' AND Created < '#{dbtime(@time + 300)}' )"
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should accept an array of strings' do
|
195
|
+
Roart::Ticket.send(:construct_search_uri, {:created => %w[cat dog]}).should == @query + "( Created > 'cat' AND Created < 'dog' )"
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'should accept a string' do
|
199
|
+
Roart::Ticket.send(:construct_search_uri, {:created => 'time'}).should == @query + "( Created > 'time' )"
|
200
|
+
end
|
201
|
+
|
202
|
+
describe 'date fields' do
|
203
|
+
|
204
|
+
it 'should search started' do
|
205
|
+
Roart::Ticket.send(:construct_search_uri, {:started => 'time'}).should == @query + "( Started > 'time' )"
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should search resolved' do
|
209
|
+
Roart::Ticket.send(:construct_search_uri, {:resolved => 'time'}).should == @query + "( Resolved > 'time' )"
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'should search told' do
|
213
|
+
Roart::Ticket.send(:construct_search_uri, {:told => 'time'}).should == @query + "( Told > 'time' )"
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'should search last_updated' do
|
217
|
+
Roart::Ticket.send(:construct_search_uri, {:last_updated => 'time'}).should == @query + "( LastUpdated > 'time' )"
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should search starts' do
|
221
|
+
Roart::Ticket.send(:construct_search_uri, {:starts => 'time'}).should == @query + "( Starts > 'time' )"
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'should search due' do
|
225
|
+
Roart::Ticket.send(:construct_search_uri, {:due => 'time'}).should == @query + "( Due > 'time' )"
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'should search updated' do
|
229
|
+
Roart::Ticket.send(:construct_search_uri, {:updated => 'time'}).should == @query + "( Updated > 'time' )"
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
describe 'searches' do
|
237
|
+
|
238
|
+
it 'should accept a string' do
|
239
|
+
Roart::Ticket.send(:construct_search_uri, {:subject => 'fish'}).should == @query + "Subject LIKE 'fish'"
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should accept an array' do
|
243
|
+
Roart::Ticket.send(:construct_search_uri, {:subject => %w[cramanation station]}).should == @query + "( Subject LIKE 'cramanation' AND Subject LIKE 'station' )"
|
244
|
+
end
|
245
|
+
|
246
|
+
describe 'search fields' do
|
247
|
+
|
248
|
+
it 'should search content' do
|
249
|
+
Roart::Ticket.send(:construct_search_uri, {:content => 'fish'}).should == @query + "Content LIKE 'fish'"
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'should search content_type' do
|
253
|
+
Roart::Ticket.send(:construct_search_uri, {:content_type => 'fish'}).should == @query + "ContentType LIKE 'fish'"
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'should search file_name' do
|
257
|
+
Roart::Ticket.send(:construct_search_uri, {:file_name => 'fish'}).should == @query + "FileName LIKE 'fish'"
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
describe 'status' do
|
265
|
+
|
266
|
+
it 'should accept a string' do
|
267
|
+
Roart::Ticket.send(:construct_search_uri, {:status => 'new'}).should == @query + "Status = 'new'"
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'should accept a symbol' do
|
271
|
+
Roart::Ticket.send(:construct_search_uri, {:status => :new}).should == @query + "Status = 'new'"
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'should accept an array' do
|
275
|
+
Roart::Ticket.send(:construct_search_uri, {:status => ['new', 'open']}).should == @query + "( Status = 'new' OR Status = 'open' )"
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
|
280
|
+
describe 'custom_fields' do
|
281
|
+
|
282
|
+
it 'should accept a hash with string values' do
|
283
|
+
Roart::Ticket.send(:construct_search_uri, {:custom_fields => {:phone => '8675309'}}).should == @query + "'CF.{phone}' = '8675309'"
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'should accept a hash with string values' do
|
287
|
+
Roart::Ticket.send(:construct_search_uri, {:custom_fields => {:phone => ['8675309', '5553265']}}).should == @query + "( 'CF.{phone}' = '8675309' OR 'CF.{phone}' = '5553265' )"
|
288
|
+
end
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
describe 'multiple find options' do
|
293
|
+
|
294
|
+
it 'should allow multiple find options' do
|
295
|
+
query = Roart::Ticket.send(:construct_search_uri, {:status => 'new', :queue => 'MyQueue'})
|
296
|
+
query.include?("Status = 'new'").should be_true
|
297
|
+
query.include?("Queue = 'MyQueue'").should be_true
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should search for :queue => 'A Queue', :status => [:new, :open]" do
|
301
|
+
query = Roart::Ticket.send(:construct_search_uri, {:queue => 'A Queue', :status => [:new, :open]})
|
302
|
+
query.include?("( Status = 'new' OR Status = 'open' )").should be_true
|
303
|
+
query.include?("Queue = 'A Queue'").should be_true
|
304
|
+
end
|
305
|
+
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|
309
|
+
|
310
|
+
end
|
311
|
+
|
312
|
+
describe "the default queue" do
|
313
|
+
|
314
|
+
before do
|
315
|
+
@connection = mock('connection', :server => "server")
|
316
|
+
@search_string = "/REST/1.0/search/ticket?"
|
317
|
+
@query = @connection.server + @search_string + 'query= '
|
318
|
+
class MyTicket < Roart::Ticket; end
|
319
|
+
MyTicket.instance_variable_set("@default_queue", 'myQueue')
|
320
|
+
MyTicket.should_receive(:connection).and_return(@connection)
|
321
|
+
end
|
322
|
+
|
323
|
+
|
324
|
+
it 'should have a default queue' do
|
325
|
+
MyTicket.send(:construct_search_uri, :status => :new).should == @query + "Queue = 'myQueue' AND Status = 'new'"
|
326
|
+
end
|
327
|
+
|
328
|
+
it 'should search without options and return the default queue' do
|
329
|
+
MyTicket.send(:construct_search_uri).should == @query + "Queue = 'myQueue'"
|
330
|
+
end
|
331
|
+
|
332
|
+
end
|
333
|
+
|
334
|
+
describe 'ticket methods' do
|
335
|
+
|
336
|
+
|
337
|
+
it 'should change the ticket' do
|
338
|
+
ticket = Roart::Ticket.send(:instantiate,{:subject => 'A New Ticket', :queue => 'My Queue', :id => 1})
|
339
|
+
ticket.subject = 'An Old Ticket'
|
340
|
+
ticket.subject.should == 'An Old Ticket'
|
341
|
+
end
|
342
|
+
|
343
|
+
it 'should be able to load the full ticket' do
|
344
|
+
search_array = ['1:subject']
|
345
|
+
search_array.extend(Roart::TicketPage)
|
346
|
+
full_ticket = Roart::Ticket.send(:instantiate, {:id => 1, :subject => 'subject', :full => true})
|
347
|
+
ticket = Roart::Ticket.send(:instantiate, search_array.to_search_array ).first
|
348
|
+
Roart::Ticket.should_receive(:find).with(1).and_return(full_ticket)
|
349
|
+
ticket.load_full!
|
350
|
+
ticket.full.should be_true
|
351
|
+
end
|
352
|
+
|
353
|
+
end
|
354
|
+
|
355
|
+
describe 'manipulating tickets' do
|
356
|
+
|
357
|
+
describe 'creating tickets' do
|
358
|
+
|
359
|
+
before do
|
360
|
+
post_data = @payload = {:queue => 'My Queue', :subject => 'A New Ticket'}
|
361
|
+
post_data.update(:id => 'ticket/new')
|
362
|
+
post_data = to_content_format(post_data)
|
363
|
+
mock_connection = mock('connection')
|
364
|
+
Roart::Ticket.should_receive(:connection).twice.and_return(mock_connection)
|
365
|
+
mock_connection.should_receive(:server).and_return('uri')
|
366
|
+
mock_connection.should_receive(:post).
|
367
|
+
with('uri/REST/1.0/ticket/new', {:content => post_data}).
|
368
|
+
and_return(response_body)
|
369
|
+
end
|
370
|
+
|
371
|
+
let(:ticket) { Roart::Ticket.new(@payload) }
|
372
|
+
|
373
|
+
context "on success" do
|
374
|
+
let(:response_body) { "RT/3.6.6 200 Ok\n\n# Ticket 267783 created." }
|
375
|
+
|
376
|
+
it 'should be able to save a new ticket' do
|
377
|
+
ticket.new_record?.should be_true
|
378
|
+
ticket.save
|
379
|
+
ticket.new_record?.should be_false
|
380
|
+
end
|
381
|
+
|
382
|
+
it 'should be able to create a ticket' do
|
383
|
+
ticket = Roart::Ticket.create(@payload)
|
384
|
+
end
|
385
|
+
|
386
|
+
it 'should return a newly created ticket' do
|
387
|
+
ticket.class.should == Roart::Ticket
|
388
|
+
ticket.save
|
389
|
+
ticket.id.should == 267783
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'should NOT have errors' do
|
393
|
+
ticket.save
|
394
|
+
ticket.errors.should be_empty
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'should be saved' do
|
398
|
+
ticket.save
|
399
|
+
ticket.saved.should == true
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
context "on failure" do
|
404
|
+
let(:response_body) { "RT/4.0.5 200 Ok\n\n# Could not create ticket.\n# Status 'huj' isn't a valid status for tickets in this queue." }
|
405
|
+
|
406
|
+
it 'should return an unsaved ticket' do
|
407
|
+
ticket.class.should == Roart::Ticket
|
408
|
+
ticket.save
|
409
|
+
ticket.id.should == 'ticket/new'
|
410
|
+
ticket.should be_new_record
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'should return false' do
|
414
|
+
ticket.save.should == false
|
415
|
+
end
|
416
|
+
|
417
|
+
it 'should have errors' do
|
418
|
+
ticket.save
|
419
|
+
ticket.errors.size.should == 1
|
420
|
+
ticket.errors[:base].should == ["# Status 'huj' isn't a valid status for tickets in this queue."]
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
end
|
425
|
+
|
426
|
+
describe 'updating tickets' do
|
427
|
+
|
428
|
+
before do
|
429
|
+
@payload = {:queue => 'My Queue', :subject => 'An Old Ticket'}.with_indifferent_access
|
430
|
+
@post_data = {:queue => 'My Queue', :subject => 'An Old Ticket'}.with_indifferent_access
|
431
|
+
@payload[:subject] = 'A New Ticket'
|
432
|
+
@post_data = to_content_format(@post_data)
|
433
|
+
@mock_connection = mock('connection')
|
434
|
+
@mock_connection.should_receive(:server).and_return('uri')
|
435
|
+
Roart::Ticket.should_receive(:connection).twice.and_return(@mock_connection)
|
436
|
+
@mock_connection.should_receive(:post).
|
437
|
+
with('uri/REST/1.0/ticket/1/edit', {:content => @post_data}).
|
438
|
+
and_return(response_body)
|
439
|
+
end
|
440
|
+
|
441
|
+
context "on success" do
|
442
|
+
let(:response_body) { "RT/3.6.6 200 Ok\n\n# Ticket 267783 updated." }
|
443
|
+
|
444
|
+
it 'should be able to update a ticket' do
|
445
|
+
ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
|
446
|
+
ticket.subject = 'An Old Ticket'
|
447
|
+
ticket.save.should == true
|
448
|
+
end
|
449
|
+
|
450
|
+
it 'should keep the same id' do
|
451
|
+
ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
|
452
|
+
ticket.subject = 'An Old Ticket'
|
453
|
+
ticket.save
|
454
|
+
ticket.id.should == 1
|
455
|
+
end
|
456
|
+
|
457
|
+
it 'should save the ticket' do
|
458
|
+
ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
|
459
|
+
ticket.subject = 'An Old Ticket'
|
460
|
+
ticket.save
|
461
|
+
ticket.subject.should == 'An Old Ticket'
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
context "on 502 failure" do
|
466
|
+
let(:response_body) { "RT/3.6.6 502 Not OK\n\n# Dead gateway" }
|
467
|
+
|
468
|
+
it 'should raise an error on failed save' do
|
469
|
+
ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
|
470
|
+
ticket.subject = 'An Old Ticket'
|
471
|
+
expect { ticket.save }.to raise_error(Roart::TicketSystemError)
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
context "on 200 failure" do
|
476
|
+
let(:response_body) { "RT/3.6.6 200 Probably OK\n\n# Could not update ticket\n# Queue is missing" }
|
477
|
+
|
478
|
+
it 'should set errors' do
|
479
|
+
ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
|
480
|
+
ticket.subject = 'An Old Ticket'
|
481
|
+
expect { ticket.save }.not_to raise_error
|
482
|
+
ticket.errors.size.should == 1
|
483
|
+
ticket.errors[:base].should == ["# Queue is missing"]
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
context "on 400 failure" do
|
488
|
+
let(:response_body) { "RT/3.6.6 400 Not OK\n\n# U's A SUKKA, FOO!." }
|
489
|
+
|
490
|
+
it 'should set errors' do
|
491
|
+
ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
|
492
|
+
ticket.subject = 'An Old Ticket'
|
493
|
+
expect { ticket.save }.not_to raise_error
|
494
|
+
ticket.errors.size.should == 1
|
495
|
+
ticket.errors[:base].should == ["# U's A SUKKA, FOO!."]
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
context "on 409 failure" do
|
500
|
+
let(:response_body) { "RT/4.0.5 409 Syntax Error\n# Ticket 13 updated.\n# status2: Unknown field.\n\nid: \nStatus2: huj"}
|
501
|
+
|
502
|
+
it 'should set errors' do
|
503
|
+
ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
|
504
|
+
ticket.subject = 'An Old Ticket'
|
505
|
+
expect { ticket.save }.not_to raise_error
|
506
|
+
ticket.errors.size.should == 2
|
507
|
+
ticket.errors[:base].should == [
|
508
|
+
"# Ticket 13 updated.",
|
509
|
+
"# status2: Unknown field."
|
510
|
+
]
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
end
|
515
|
+
|
516
|
+
end
|
517
|
+
|
518
|
+
describe 'histories' do
|
519
|
+
|
520
|
+
before(:each) do
|
521
|
+
search_array = ['1:subject']
|
522
|
+
search_array.extend(Roart::TicketPage)
|
523
|
+
full_ticket = Roart::Ticket.send(:instantiate, {:id => 1, :subject => 'subject', :full => true})
|
524
|
+
@mock_connection = mock('connection')
|
525
|
+
@mock_connection.should_receive(:get).with('uri').and_return('200')
|
526
|
+
@ticket = Roart::Ticket.send(:instantiate, search_array.to_search_array).first
|
527
|
+
@ticket.class.should_receive(:connection).and_return(@mock_connection)
|
528
|
+
Roart::History.should_receive(:uri_for).with(@ticket).and_return('uri')
|
529
|
+
end
|
530
|
+
|
531
|
+
it 'should return history objects' do
|
532
|
+
@ticket.histories.class.should == Roart::HistoryArray
|
533
|
+
end
|
534
|
+
|
535
|
+
it 'should have a default of the ticket id' do
|
536
|
+
@ticket.histories.ticket.should == @ticket
|
537
|
+
end
|
538
|
+
|
539
|
+
it 'should only spawn 1 dup class for each ticket' do
|
540
|
+
@ticket.histories.should === @ticket.histories
|
541
|
+
end
|
542
|
+
|
543
|
+
it 'should have a last history that is equal to the last value' do
|
544
|
+
@ticket.histories.last.should == @ticket.histories[@ticket.histories.size - 1]
|
545
|
+
end
|
546
|
+
|
547
|
+
it 'should have count, which is equal to size' do
|
548
|
+
@ticket.histories.count.should == @ticket.histories.size
|
549
|
+
end
|
550
|
+
|
551
|
+
end
|
552
|
+
|
553
|
+
end
|