From 8fe2d6d0a6edb9be4c9ac1d29b6179dbc70da6d4 Mon Sep 17 00:00:00 2001 From: Mark Rada Date: Fri, 16 Sep 2011 18:24:17 -0400 Subject: [PATCH] Tests and documentation updates for attachment related stuff --- lib/jiraSOAP/entities/attachment.rb | 2 +- lib/jiraSOAP/jira_service.rb | 12 ++++++++- test/attachments_test.rb | 42 ++++++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/lib/jiraSOAP/entities/attachment.rb b/lib/jiraSOAP/entities/attachment.rb index 9ee6f07..ee29617 100644 --- a/lib/jiraSOAP/entities/attachment.rb +++ b/lib/jiraSOAP/entities/attachment.rb @@ -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] diff --git a/lib/jiraSOAP/jira_service.rb b/lib/jiraSOAP/jira_service.rb index 47d2e71..38ca752 100755 --- a/lib/jiraSOAP/jira_service.rb +++ b/lib/jiraSOAP/jira_service.rb @@ -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. # @@ -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 diff --git a/test/attachments_test.rb b/test/attachments_test.rb index 7cb00c8..cc5cad4 100644 --- a/test/attachments_test.rb +++ b/test/attachments_test.rb @@ -16,14 +16,50 @@ 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]) @@ -31,11 +67,11 @@ def test_add_one_attachment 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