Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ pkg/*
.DS_STORE
doc
.ruby-version

.rakeTasks
20 changes: 12 additions & 8 deletions lib/jira/resource/sprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SprintFactory < JIRA::BaseFactory # :nodoc:

class Sprint < JIRA::Base
def self.find(client, key)
response = client.get("#{client.options[:site]}/rest/agile/1.0/sprint/#{key}")
response = client.get(agile_path(client, key))
json = parse_json(response.body)
client.Sprint.build(json)
end
Expand All @@ -19,7 +19,7 @@ def issues(options = {})

def add_issue(issue)
request_body = { issues: [issue.id] }.to_json
response = client.post(client.options[:site] + "/rest/agile/1.0/sprint/#{id}/issue", request_body)
response = client.post("#{agile_path}/issue", request_body)
true
end

Expand Down Expand Up @@ -47,8 +47,8 @@ def get_sprint_details_attribute(attribute_name)
end

def get_sprint_details
search_url = client.options[:site] + '/rest/greenhopper/1.0/rapid/charts/sprintreport?rapidViewId=' +
rapidview_id.to_s + '&sprintId=' + id.to_s
search_url =
"#{client.options[:site]}#{client.options[:client_path]}/rest/greenhopper/1.0/rapid/charts/sprintreport?rapidViewId=#{rapidview_id}&sprintId=#{id}"
begin
response = client.get(search_url)
rescue StandardError
Expand Down Expand Up @@ -76,12 +76,12 @@ def rapidview_id

def save(attrs = {}, _path = nil)
attrs = @attrs if attrs.empty?
super(attrs, agile_url)
super(attrs, agile_path)
end

def save!(attrs = {}, _path = nil)
attrs = @attrs if attrs.empty?
super(attrs, agile_url)
super(attrs, agile_path)
end

# WORK IN PROGRESS
Expand All @@ -93,8 +93,12 @@ def complete

private

def agile_url
"#{client.options[:site]}/rest/agile/1.0/sprint/#{id}"
def agile_path
self.class.agile_path(client, id)
end

def self.agile_path(client, key)
"#{client.options[:context_path]}/rest/agile/1.0/sprint/#{key}"
end
end
end
Expand Down
34 changes: 23 additions & 11 deletions spec/jira/resource/sprint_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
require 'spec_helper'

describe JIRA::Resource::Sprint do
describe 'peristence' do
let(:sprint) { described_class.new(client) }
let(:client) { double('Client', options: { site: 'https://foo.bar.com' }) }
let(:client) do
client = double(options: { site: 'https://foo.bar.com', context_path: '/jira' })
allow(client).to receive(:Sprint).and_return(JIRA::Resource::SprintFactory.new(client))
client
end
let(:sprint) { described_class.new(client) }
let(:agile_sprint_path) { "#{sprint.client.options[:context_path]}/rest/agile/1.0/sprint/#{sprint.id}" }

describe '::find' do
let(:response) { double('Response', body: '{"some_detail":"some detail"}') }

it 'fetches the sprint from JIRA' do
expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/111').and_return(response)
expect(JIRA::Resource::Sprint.find(client, '111')).to be_a(JIRA::Resource::Sprint)
end
end

describe 'peristence' do
describe '#save' do
let(:agile_sprint_url) { "#{sprint.client.options[:site]}/rest/agile/1.0/sprint/#{sprint.id}" }
let(:instance_attrs) { { start_date: '2016-06-01' } }

before do
Expand All @@ -17,31 +30,30 @@
let(:given_attrs) { { start_date: '2016-06-10' } }

it 'calls save on the super class with the given attributes & agile url' do
expect_any_instance_of(JIRA::Base).to receive(:save).with(given_attrs, agile_sprint_url)
expect_any_instance_of(JIRA::Base).to receive(:save).with(given_attrs, agile_sprint_path)

sprint.save(given_attrs)
end
end

context 'when attributes are not specified' do
it 'calls save on the super class with the instance attributes & agile url' do
expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_url)
expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_path)

sprint.save
end
end

context 'when providing the path argument' do
it 'ignores it' do
expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_url)
expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_path)

sprint.save({}, 'mavenlink.com')
end
end
end

describe '#save!' do
let(:agile_sprint_url) { "#{sprint.client.options[:site]}/rest/agile/1.0/sprint/#{sprint.id}" }
let(:instance_attrs) { { start_date: '2016-06-01' } }

before do
Expand All @@ -52,23 +64,23 @@
let(:given_attrs) { { start_date: '2016-06-10' } }

it 'calls save! on the super class with the given attributes & agile url' do
expect_any_instance_of(JIRA::Base).to receive(:save!).with(given_attrs, agile_sprint_url)
expect_any_instance_of(JIRA::Base).to receive(:save!).with(given_attrs, agile_sprint_path)

sprint.save!(given_attrs)
end
end

context 'when attributes are not specified' do
it 'calls save! on the super class with the instance attributes & agile url' do
expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_url)
expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_path)

sprint.save!
end
end

context 'when providing the path argument' do
it 'ignores it' do
expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_url)
expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_path)

sprint.save!({}, 'mavenlink.com')
end
Expand Down