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

Updates for attachment spec. #459

Open
wants to merge 5 commits 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
24 changes: 20 additions & 4 deletions spec/jira/resource/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
subject(:attachment) do
described_class.new(
client,
issue: JIRA::Resource::Issue.new(client),
attrs: { 'author' => { 'foo' => 'bar' } }
issue: JIRA::Resource::Issue.new(client, attrs: { 'id' => issue_id }),
attrs: { 'author' => { 'foo' => 'bar' }, 'id' => attachment_id }
)
end

let(:issue_id) { 27_676 }
let(:attachment_id) { 30_076 }
let(:client) do
double(
'client',
Expand Down Expand Up @@ -68,11 +70,13 @@
)
end

let(:attachment_url) { 'https://localhost:2990/secure/attachment/32323/myfile.txt' }
let(:client) do
JIRA::Client.new(username: 'username', password: 'password', auth_type: :basic, use_ssl: false)
end
let(:attachment_file_contents) { 'file contents' }
let(:attachment_url) { 'https://localhost:2990/secure/attachment/32323/myfile.txt' }
let(:issue_id) { 3232 }
let(:issue) { JIRA::Resource::Issue.new(client, attrs: { 'id' => issue_id }) }

before do
stub_request(:get, attachment_url).to_return(body: attachment_file_contents)
Expand Down Expand Up @@ -115,7 +119,7 @@
].to_json
)
end
let(:issue) { JIRA::Resource::Issue.new(client) }
let(:issue) { JIRA::Resource::Issue.new(client, attrs: { 'id' => issue_id }) }

describe '#save' do
subject { attachment.save('file' => path_to_file) }
Expand All @@ -125,6 +129,8 @@
end

it 'successfully update the attachment' do
expect(client).to receive(:post_multipart).and_return(response).with("/jira/rest/api/2/issue/#{issue.id}/attachments/#{attachment.id}", anything, anything)

subject

expect(attachment.filename).to eq file_name
Expand Down Expand Up @@ -225,4 +231,14 @@
end
end
end

context 'an attachment is on an issue' do
describe '#delete' do
it 'removes the attachment' do
expect(client).to receive(:delete).with("/jira/rest/api/2/issue/#{issue_id}/attachments/#{attachment_id}")

attachment.delete
end
end
end
end
Loading