pjdavis-roart 0.1.2 → 0.1.3

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.
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ ==0.1.3 / 2009-08-18
2
+ Can now update tickets with #save. Returns true if saved, raises an error if not.
3
+
1
4
  ==0.1.2 / 2009-08-18
2
5
  Added Create ticket functionality. Ticket.new will create a ticket in the RT system and return that ticket.
3
6
 
@@ -1,6 +1,14 @@
1
1
  class Hash
2
2
  def to_content_format
3
- fields = self.map { |key,value| "#{key.to_s.camelize}: #{value}" unless value.nil? }
3
+ fields = self.map do |key,value|
4
+ unless value.nil?
5
+ if key.to_s.match(/^cf_.+/)
6
+ "CF-#{key.to_s[3..key.to_s.length].camelize.humanize}: #{value}"
7
+ else
8
+ "#{key.to_s.camelize}: #{value}"
9
+ end
10
+ end
11
+ end
4
12
  content = fields.compact.join("\n")
5
13
  end
6
14
 
@@ -15,4 +15,7 @@ class String
15
15
  self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
16
16
  end
17
17
 
18
+ def humanize
19
+ self.gsub(/_id$/, "").gsub(/_/, " ").capitalize
20
+ end
18
21
  end
data/lib/roart/roart.rb CHANGED
@@ -14,7 +14,10 @@ module Roart
14
14
  def add_methods!
15
15
  @attributes.each do |key, value|
16
16
  (class << self; self; end).send :define_method, key do
17
- return value
17
+ return @attributes[key]
18
+ end
19
+ (class << self; self; end).send :define_method, "#{key}=" do |new_val|
20
+ @attributes[key] = new_val
18
21
  end
19
22
  end
20
23
  end
data/lib/roart/ticket.rb CHANGED
@@ -2,7 +2,7 @@ module Roart
2
2
 
3
3
  module Tickets
4
4
 
5
- DefaultAttributes = %w(queue owner creator subject status priority initial_priority final_priority requestors cc admin_cc created starts started due resolved told last_updated time_estimated time_worked time_left full logs)
5
+ DefaultAttributes = %w(queue owner creator subject status priority initial_priority final_priority requestors cc admin_cc created starts started due resolved told last_updated time_estimated time_worked time_left)
6
6
  RequiredAttributes = %w(queue subject)
7
7
 
8
8
  end
@@ -11,6 +11,8 @@ module Roart
11
11
 
12
12
  include Roart::MethodFunctions
13
13
 
14
+ attr_reader :full, :history
15
+
14
16
  # Creates a new ticket. Attributes queue and subject are required. Expects a hash with the attributes of the ticket.
15
17
  #
16
18
  # ticket = MyTicket.new(:queue => "Some Queue", :subject => "The System is Down.")
@@ -25,6 +27,7 @@ module Roart
25
27
  else
26
28
  raise ArgumentError, "Expects a hash."
27
29
  end
30
+ @history = false
28
31
  add_methods!
29
32
  end
30
33
 
@@ -47,6 +50,21 @@ module Roart
47
50
  @histories ||= Roart::History.default(:ticket => self)
48
51
  end
49
52
 
53
+ def save
54
+ uri = "#{self.class.connection.server}/REST/1.0/ticket/#{self.id}/edit"
55
+ payload = @attributes.clone
56
+ payload.delete(:id)
57
+ payload = payload.to_content_format
58
+ resp = self.class.connection.post(uri, :content => payload)
59
+ resp = resp.split("\n")
60
+ raise "Ticket Update Failed" unless resp.first.include?("200")
61
+ if resp[2].match(/^# Ticket (\d+) updated./)
62
+ return true
63
+ else
64
+ raise "Ticket Create Failed"
65
+ end
66
+ end
67
+
50
68
  protected
51
69
 
52
70
  def create
@@ -140,6 +158,7 @@ module Roart
140
158
  object.instance_variable_set("@attributes", attrs)
141
159
  object.send("add_methods!")
142
160
  end
161
+ object.instance_variable_set("@history", false)
143
162
  object
144
163
  end
145
164
 
@@ -181,8 +200,9 @@ module Roart
181
200
  page = page_array(uri)
182
201
  page.extend(Roart::TicketPage)
183
202
  page = page.to_hash
184
- page.update(:full => true)
185
- self.instantiate(page)
203
+ ticket = self.instantiate(page)
204
+ ticket.instance_variable_set("@full", true)
205
+ ticket
186
206
  end
187
207
 
188
208
  def get_ticket_by_id(id) #:nodoc:
@@ -9,12 +9,16 @@ module Roart
9
9
  self.delete_if{|x| !x.include?(":")}
10
10
  self.each do |ln|
11
11
  ln = ln.split(":")
12
- key = ln.delete_at(0).strip.underscore
13
- value = ln.join(":").strip
14
- hash[key.to_sym] = value
12
+ if ln[0] && ln[0].match(/^CF-.+/)
13
+ key = ln.delete_at(0)
14
+ key = "cf_" + key[3..key.length].gsub(/ /, "_")
15
+ else
16
+ key = ln.delete_at(0).strip.underscore
17
+ value = ln.join(":").strip
18
+ hash[key.to_sym] = value
19
+ end
15
20
  end
16
21
  hash[:id] = hash[:id].split("/").last.to_i
17
- hash.update(:history => false)
18
22
  hash
19
23
  end
20
24
 
data/lib/roart.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  module Roart
3
3
 
4
4
  # :stopdoc:
5
- VERSION = '0.1.2'
5
+ VERSION = '0.1.3'
6
6
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
7
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
8
  # :startdoc:
@@ -8,4 +8,9 @@ describe 'hash extentions' do
8
8
  payload.to_content_format.include?("Queue: My Queue").should be_true
9
9
  end
10
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
+
11
16
  end
@@ -12,13 +12,6 @@ describe 'ticket page' do
12
12
  hash[:id].should == 10
13
13
  hash[:subject].should == 'asdf'
14
14
  end
15
-
16
- it 'should not have a history' do
17
- array = ["id : 10", "subject : asdf"]
18
- array.extend(Roart::TicketPage)
19
- hash = array.to_hash
20
- hash[:history].should be_false
21
- end
22
15
 
23
16
  end
24
17
 
@@ -39,11 +32,6 @@ describe 'ticket page' do
39
32
  @array.last[:id].should == 234
40
33
  end
41
34
 
42
- it 'should keep history false' do
43
- @array.first[:history].should be_false
44
- @array.last[:history].should be_false
45
- end
46
-
47
35
  end
48
36
 
49
37
  describe 'ticket history hash' do
@@ -284,6 +284,13 @@ describe "Ticket" do
284
284
 
285
285
  describe 'ticket methods' do
286
286
 
287
+
288
+ it 'should change the ticket' do
289
+ ticket = Roart::Ticket.send(:instantiate,{:subject => 'A New Ticket', :queue => 'My Queue', :id => 1})
290
+ ticket.subject = 'An Old Ticket'
291
+ ticket.subject.should == 'An Old Ticket'
292
+ end
293
+
287
294
  it 'should be able to load the full ticket' do
288
295
  search_array = ['1:subject']
289
296
  search_array.extend(Roart::TicketPage)
@@ -303,26 +310,73 @@ describe "Ticket" do
303
310
  fields.compact.join("\n")
304
311
  end
305
312
 
306
- before do
307
- post_data = @payload = {:subject => 'A New Ticket', :queue => 'My Queue'}
308
- post_data.update(:id => 'ticket/new')
309
- post_data = to_content_format(post_data)
310
- mock_connection = mock('connection')
311
- 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.")
312
- mock_connection.should_receive(:server).and_return('uri')
313
- Roart::Ticket.should_receive(:connection).twice.and_return(mock_connection)
314
- end
313
+ describe 'creating tickets' do
315
314
 
316
- it 'should be able to create a ticket' do
317
- ticket = Roart::Ticket.new(@payload)
318
- end
315
+ before do
316
+ post_data = @payload = {:subject => 'A New Ticket', :queue => 'My Queue'}
317
+ post_data.update(:id => 'ticket/new')
318
+ post_data = to_content_format(post_data)
319
+ mock_connection = mock('connection')
320
+ 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.")
321
+ mock_connection.should_receive(:server).and_return('uri')
322
+ Roart::Ticket.should_receive(:connection).twice.and_return(mock_connection)
323
+ end
324
+
325
+ it 'should be able to create a ticket' do
326
+ ticket = Roart::Ticket.new(@payload)
327
+ end
328
+
329
+ it 'should return a newly created ticket' do
330
+ ticket = Roart::Ticket.new(@payload)
331
+ ticket.class.should == Roart::Ticket
332
+ ticket.id.should == 267783
333
+ end
319
334
 
320
- it 'should return a newly created ticket' do
321
- ticket = Roart::Ticket.new(@payload)
322
- ticket.class.should == Roart::Ticket
323
- ticket.id.should == 267783
324
335
  end
325
336
 
337
+ describe 'updating tickets' do
338
+
339
+ before do
340
+ @post_data = @payload = {:subject => 'A New Ticket', :queue => 'My Queue'}
341
+ @post_data[:subject] = 'An Old Ticket'
342
+ @post_data = to_content_format(@post_data)
343
+ @mock_connection = mock('connection')
344
+ @mock_connection.should_receive(:server).and_return('uri')
345
+ Roart::Ticket.should_receive(:connection).twice.and_return(@mock_connection)
346
+ end
347
+
348
+ it 'should be able to update a ticket' do
349
+ @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.")
350
+ ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
351
+ ticket.subject = 'An Old Ticket'
352
+ ticket.save.should == true
353
+ end
354
+
355
+ it 'should keep the same id' do
356
+ @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.")
357
+ ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
358
+ ticket.subject = 'An Old Ticket'
359
+ ticket.save
360
+ ticket.id.should == 1
361
+ end
362
+
363
+ it 'should save the ticket' do
364
+ @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.")
365
+ ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
366
+ ticket.subject = 'An Old Ticket'
367
+ ticket.save
368
+ ticket.subject.should == 'An Old Ticket'
369
+ end
370
+
371
+ it 'should raise an error on failed save' do
372
+ @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!.")
373
+ ticket = Roart::Ticket.send(:instantiate, @payload.update(:id => 1))
374
+ ticket.subject = 'An Old Ticket'
375
+ lambda {ticket.save}.should raise_error
376
+ end
377
+
378
+ end
379
+
326
380
  end
327
381
 
328
382
  describe 'histories' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pjdavis-roart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - PJ Davis
@@ -57,7 +57,6 @@ files:
57
57
  - lib/roart/roart.rb
58
58
  - lib/roart/ticket.rb
59
59
  - lib/roart/ticket_page.rb
60
- - roart.gemspec
61
60
  - spec/roart/connection_spec.rb
62
61
  - spec/roart/core/array_spec.rb
63
62
  - spec/roart/core/hash_spec.rb
@@ -70,7 +69,6 @@ files:
70
69
  - spec/spec_helper.rb
71
70
  - spec/test_data/full_history.txt
72
71
  - spec/test_data/single_history.txt
73
- - test/test_roart.rb
74
72
  has_rdoc: true
75
73
  homepage: http://github.com/pjdavis/roart
76
74
  licenses:
@@ -99,5 +97,5 @@ rubygems_version: 1.3.5
99
97
  signing_key:
100
98
  specification_version: 3
101
99
  summary: Interface for working with Request Tracker (RT) tickets inspired by ActiveRecord
102
- test_files:
103
- - test/test_roart.rb
100
+ test_files: []
101
+
data/roart.gemspec DELETED
@@ -1,38 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{roart}
5
- s.version = "0.1.2"
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-18}
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/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/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", "test/test_roart.rb"]
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
- s.test_files = ["test/test_roart.rb"]
22
-
23
- if s.respond_to? :specification_version then
24
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 3
26
-
27
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- s.add_runtime_dependency(%q<mechanize>, [">= 0.9.0"])
29
- s.add_development_dependency(%q<bones>, [">= 2.5.1"])
30
- else
31
- s.add_dependency(%q<mechanize>, [">= 0.9.0"])
32
- s.add_dependency(%q<bones>, [">= 2.5.1"])
33
- end
34
- else
35
- s.add_dependency(%q<mechanize>, [">= 0.9.0"])
36
- s.add_dependency(%q<bones>, [">= 2.5.1"])
37
- end
38
- end
data/test/test_roart.rb DELETED
File without changes