Skip to content

Commit

Permalink
Tests and documentation updates for attachment related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrous26 committed Sep 16, 2011
1 parent fcda72d commit 8fe2d6d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/jiraSOAP/entities/attachment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##
# Only contains the metadata for an attachment. The URI for an attachment
# appears to be of the form
# "{JIRA::JIRAService.endpoint_url}/secure/attachment/{#id}/{#file_name}"
# "{JIRA::JIRAService.endpoint_url}/secure/attachment/{#id}/{#file_name}".
class JIRA::Attachment < JIRA::NamedEntity

# @return [String]
Expand Down
12 changes: 11 additions & 1 deletion lib/jiraSOAP/jira_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ class JIRA::JIRAService < Handsoap::Service
# @return [String]
attr_reader :endpoint_url

class << self
##
# Expose endpoint URL
#
# @return [String]
def endpoint_url
@@endpoint_url
end
end

##
# Initialize _and_ log in. Fancy.
#
Expand All @@ -36,7 +46,7 @@ def self.instance_with_endpoint url, user, password

# @param [String,URI::HTTP,NSURL] endpoint for the JIRA server
def initialize endpoint
@endpoint_url = endpoint.to_s
@@endpoint_url = @endpoint_url = endpoint.to_s
self.class.endpoint({
uri:"#{endpoint_url}/rpc/soap/jirasoapservice-v2",
version:2
Expand Down
42 changes: 39 additions & 3 deletions test/attachments_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,62 @@ def image2
@image2 ||= "colemak-#{Time.now.to_f}.png"
end

def attachment1
@attachment ||= JIRA::Attachment.new.tap do |x|
x.content = File.read(File.join(File.dirname(__FILE__), '..', 'Rakefile'))
x.file_name = "Rakefile-#{Time.now.to_f}"
end
end

def attachment2
@attachment ||= JIRA::Attachment.new.tap do |x|
x.content = File.read(File.join(File.dirname(__FILE__), '..', 'jiraSOAP.gemspec'))
x.file_name = "Rakefile-#{Time.now.to_f}"
end
end

def test_returns_true
assert_equal true,
db.add_attachments_to_issue_with_key(key, attachment1)
end

def test_attachment_data_is_unaltered # for some definition of unaltered
skip 'Need to implement the method for getting attachments first'
end

def test_add_one_attachment
db.add_attachments_to_issue_with_key key, attachment1
issue = db.issue_with_key key
refute_nil issue.attachment_names.find { |x| x == attachment1.file_name }
end

def test_add_two_attachments
db.add_attachments_to_issue_with_key key, attachment1, attachment2
issue = db.issue_with_key key
refute_nil issue.attachment_names.find { |x| x == attachment1.file_name }
refute_nil issue.attachment_names.find { |x| x == attachment2.file_name }
end

def test_returns_true_base64
assert_equal true,
db.add_base64_encoded_attachments_to_issue_with_key(key,
[image1],
[switcheroo])
end

def test_add_one_attachment
def test_add_one_attachment_base64
db.add_base64_encoded_attachments_to_issue_with_key(key,
[image1],
[switcheroo])
issue = db.issue_with_key key
refute_nil issue.attachment_names.find { |x| x == image1 }
end

def test_add_two_attachments
def test_add_two_attachments_base64
db.add_base64_encoded_attachments_to_issue_with_key(key,
[image1, image2],
[switcheroo, colemak])
issue = db.get_issue_with_key key
issue = db.issue_with_key key
refute_nil issue.attachment_names.find { |x| x == image1 }
refute_nil issue.attachment_names.find { |x| x == image2 }
end
Expand Down

0 comments on commit 8fe2d6d

Please sign in to comment.