Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Added the ability to pass a file like object to upload_attachment, in ad... #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added the ability to pass a file like object to upload_attachment, in…
… addition to a file path.
jason-o-matic committed Sep 18, 2013
commit 3be75239684598279297b8be6a340cfee075eaca
5 changes: 3 additions & 2 deletions lib/pivotal-tracker/story.rb
Original file line number Diff line number Diff line change
@@ -85,8 +85,9 @@ def tasks
@tasks ||= Proxy.new(self, Task)
end

def upload_attachment(filename)
Attachment.parse(Client.connection["/projects/#{project_id}/stories/#{id}/attachments"].post(:Filedata => File.new(filename)))
def upload_attachment(file)
file = File.new(file) if file.is_a?(String)
Attachment.parse(Client.connection["/projects/#{project_id}/stories/#{id}/attachments"].post(:Filedata => file))
end

def move_to_project(new_project)
9 changes: 9 additions & 0 deletions spec/pivotal-tracker/attachment_spec.rb
Original file line number Diff line number Diff line change
@@ -58,5 +58,14 @@
resource.should be_a(PivotalTracker::Attachment)
resource.status.should == 'Pending'
end

it "should accept a file like object" do
FakeWeb.allow_net_connect = true
file = File.new(File.dirname(__FILE__) + '/../../LICENSE')
resource = @target_story.upload_attachment(file)
FakeWeb.allow_net_connect = @orig_net_lock
resource.should be_a(PivotalTracker::Attachment)
resource.status.should == 'Pending'
end
end
end