cherby 0.0.4 → 0.0.5

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.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cherby"
3
- s.version = "0.0.4"
3
+ s.version = "0.0.5"
4
4
  s.summary = "Cherwell-Ruby bridge"
5
5
  s.description = <<-EOS
6
6
  Cherby is a Ruby wrapper for the Cherwell Web Service.
@@ -217,6 +217,28 @@ module Cherby
217
217
  field.content = value.to_s
218
218
  end
219
219
 
220
+ # Return true if `other_object` has the same values in all fields
221
+ # given by`field_names`.
222
+ #
223
+ # @param [BusinessObject] other_object
224
+ # The object to compare with
225
+ # @param [Array<String>] field_names
226
+ # Names of fields whose values you want to compare. If omitted,
227
+ # compare *all* fields for equality.
228
+ #
229
+ # @return [Boolean]
230
+ # True if all fields are equal, false if any differ
231
+ #
232
+ def fields_equal?(other_object, *field_names)
233
+ if field_names.empty?
234
+ return self.to_hash == other_object.to_hash
235
+ else
236
+ return field_names.all? do |field|
237
+ self[field] == other_object[field]
238
+ end
239
+ end
240
+ end
241
+
220
242
  # Copy designated fields from one BusinessObject to another.
221
243
  #
222
244
  # @example
@@ -17,24 +17,6 @@ module Cherby
17
17
  return id.to_s =~ /\d+/
18
18
  end
19
19
 
20
- # Mark this incident as complete by filling in relevant fields.
21
- # FIXME: Parameterize these, instead of assuming Jira relationship.
22
- #
23
- def complete!(comments = "Closed in Jira => automated close.")
24
- self["CloseDescription"] = comments
25
- self["LastModDateTime"] = DateTime.now.to_s
26
- self["Stat_NumberOfTouches"] = self["Stat_NumberOfTouches"].to_i + 1
27
- #self["PhaseInvestigateStatus"] = "Complete"
28
- self["PhaseResolveStatus"] = "Complete"
29
- #self["PhaseCloseStatus"] = "Complete"
30
- self["ClosureCode"] = "Completed"
31
- self["CMDBUpdate"] = "No"
32
- self["BusinessService"] = "Not Applicable"
33
- self["RequestType"] = "Not Applicable"
34
- self["SubCategory"] = "JIRA"
35
- self["SubcategoryNonHR"] = "JIRA"
36
- end
37
-
38
20
  # Return Task instances for all tasks associated with this Incident.
39
21
  #
40
22
  # @return [Array<Task>]
@@ -92,21 +74,6 @@ module Cherby
92
74
  @dom.at_css('RelationshipList').add_child(rel_node)
93
75
  end
94
76
 
95
- # Return True if this Incident has important fields differing from the
96
- # given Incident.
97
- #
98
- # @param [Incident] incident
99
- # The Incident to compare this one to.
100
- #
101
- # @return [Boolean]
102
- # `true` if the incidents differn `false` otherwise.
103
- #
104
- def differs_from?(incident)
105
- return true if self['Status'] != incident['Status']
106
- return true if self['JIRAID'] != incident['JIRAID']
107
- return false
108
- end
109
-
110
77
  # DO NOT REMOVE: use the follow code for code-gen of Cherwell consts
111
78
  =begin
112
79
  def extract_lines(css, l)
@@ -14,12 +14,6 @@ module Cherby
14
14
  return !id.to_s.empty?
15
15
  end
16
16
 
17
- # Return True if this Task has important fields differing from the given Task.
18
- def differs_from?(task)
19
- return true if self['Status'] != task['Status']
20
- return false
21
- end
22
-
23
17
  # Add a JournalNote to this Task. Since Tasks cannot directly have JournalNotes
24
18
  # associated with them, this just appends the note's content to the Technician Notes
25
19
  # field (aka 'CompletionDetails') in the Task.
@@ -298,6 +298,47 @@ describe Cherby::BusinessObject do
298
298
  end
299
299
  end
300
300
 
301
+ describe "#fields_equal?" do
302
+ before(:each) do
303
+ xml = '<BusinessObject Name="MySubclass"><FieldList/></BusinessObject>'
304
+ @obj1 = MySubclass.new(xml)
305
+ @obj2 = MySubclass.new(xml)
306
+
307
+ @obj1['Status'] = 'Open'
308
+ @obj2['Status'] = 'Open'
309
+ @obj1['Comment'] = 'Whatever'
310
+ @obj2['Comment'] = 'Whatever'
311
+ end
312
+
313
+ context "compare specific fields" do
314
+ it "returns true if all fields are equal" do
315
+ @obj1.fields_equal?(@obj2, 'Status').should be_true
316
+ @obj1.fields_equal?(@obj2, 'Comment').should be_true
317
+ @obj1.fields_equal?(@obj2, 'Status', 'Comment').should be_true
318
+ end
319
+
320
+ it "returns false if any field differs" do
321
+ @obj1['ID'] = '123'
322
+ @obj2['ID'] = '456'
323
+ @obj1.fields_equal?(@obj2, 'ID').should be_false
324
+ @obj1.fields_equal?(@obj2, 'ID', 'Status').should be_false
325
+ @obj1.fields_equal?(@obj2, 'Status', 'ID').should be_false
326
+ end
327
+ end
328
+
329
+ context "compare all fields (default)" do
330
+ it "returns true if all fields are equal" do
331
+ @obj1.fields_equal?(@obj2).should be_true
332
+ end
333
+
334
+ it "returns false if any field differs" do
335
+ @obj1['ID'] = '123'
336
+ @obj2['ID'] = '456'
337
+ @obj1.fields_equal?(@obj2).should be_false
338
+ end
339
+ end
340
+ end #fields_equal?
341
+
301
342
  describe "#copy_fields_from" do
302
343
  before(:each) do
303
344
  xml = %Q{
@@ -29,23 +29,6 @@ module Cherby
29
29
  end
30
30
  end #exists?
31
31
 
32
- describe "#complete!" do
33
- it "sets appropriate fields to indicate incident completion" do
34
- @incident.complete!('Testing completion')
35
-
36
- @incident['CloseDescription'].should == 'Testing completion'
37
- @incident['PhaseResolveStatus'].should == 'Complete'
38
- @incident['ClosureCode'].should == 'Completed'
39
- @incident['CMDBUpdate'].should == 'No'
40
- @incident['SubCategory'].should == 'JIRA'
41
- @incident['SubcategoryNonHR'].should == 'JIRA'
42
- end
43
- end #complete!
44
-
45
- describe "#reopen!" do
46
- it "TODO"
47
- end #reopen!
48
-
49
32
  describe "#tasks" do
50
33
  it "returns an array of Task instances" do
51
34
  @incident.tasks.count.should == 5
@@ -87,22 +70,6 @@ module Cherby
87
70
  last_journal_note['Details'].should == 'New note on incident'
88
71
  end
89
72
  end #add_journal_note
90
-
91
- describe "#differs_from?" do
92
- it "false when comparing with self" do
93
- @incident.differs_from?(@incident).should be_false
94
- end
95
- it "false when comparing with an identical Incident" do
96
- incident2 = Cherby::Incident.new(@incident_xml)
97
- incident2.differs_from?(@incident).should be_false
98
- end
99
- it "true if certain fields are different" do
100
- incident2 = Cherby::Incident.new(@incident_xml)
101
- @incident['Status'] = 'New'
102
- incident2['Status'] = 'Assigned'
103
- incident2.differs_from?(@incident).should be_true
104
- end
105
- end #differs_from?
106
73
  end # Instance methods
107
74
 
108
75
  context "Inherited instance methods" do
@@ -37,28 +37,6 @@ module Cherby
37
37
  end
38
38
  end #exists?
39
39
 
40
- describe "#differs_from?" do
41
- it "false when compared with itself" do
42
- task = Task.new(@task_xml)
43
- task.differs_from?(task).should be_false
44
- end
45
-
46
- it "false when compared with a task with identical fields" do
47
- task1 = Task.new(@task_xml)
48
- task2 = Task.new(@task_xml)
49
- task2.differs_from?(task1).should be_false
50
- end
51
-
52
- it "true if certain fields are different" do
53
- task1 = Task.new(@task_xml)
54
- task2 = Task.new(@task_xml)
55
- task1['Status'] = 'New'
56
- task2['Status'] = 'Assigned'
57
- task1.differs_from?(task2).should be_true
58
- task2.differs_from?(task1).should be_true
59
- end
60
- end #differs_from?
61
-
62
40
  describe "#add_journal_note" do
63
41
  it "adds a note to the Task" do
64
42
  task = Task.new(@task_xml)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cherby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-07 00:00:00.000000000 Z
12
+ date: 2014-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httpclient