Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions lib/pivotal-tracker/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions spec/pivotal-tracker/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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