Commit 5becd865 authored by Jarka Košanová's avatar Jarka Košanová

Create basic functions for OpenProjectService

- associate with data fields
- add specs
parent 22d211d0
# frozen_string_literal: true
class OpenProjectService < IssueTrackerService
validates :url, public_url: true, presence: true, if: :activated?
validates :api_url, public_url: true, allow_blank: true, if: :activated?
validates :token, presence: true, if: :activated?
validates :project_identifier_code, presence: true, if: :activated?
data_field :url, :api_url, :token, :closed_status_id, :project_identifier_code
def data_fields
open_project_tracker_data || self.build_open_project_tracker_data
end
def self.to_param
'open_project'
end
end
# frozen_string_literal: true # frozen_string_literal: true
class OpenProjectTrackerData < ApplicationRecord class OpenProjectTrackerData < ApplicationRecord
include Services::DataFields
# When the Open Project is fresh installed, the default closed status id is "13" based on current version: v8. # When the Open Project is fresh installed, the default closed status id is "13" based on current version: v8.
DEFAULT_CLOSED_STATUS_ID = "13" DEFAULT_CLOSED_STATUS_ID = "13"
include Services::DataFields
attr_encrypted :url, encryption_options attr_encrypted :url, encryption_options
attr_encrypted :api_url, encryption_options attr_encrypted :api_url, encryption_options
attr_encrypted :token, encryption_options attr_encrypted :token, encryption_options
......
...@@ -126,6 +126,26 @@ FactoryBot.define do ...@@ -126,6 +126,26 @@ FactoryBot.define do
end end
end end
factory :open_project_service do
project
active { true }
transient do
url { 'http://openproject.example.com' }
api_url { 'http://openproject.example.com/issues/:id' }
token { 'supersecret' }
closed_status_id { '15' }
project_identifier_code { 'PRJ-1' }
end
after(:build) do |service, evaluator|
create(:open_project_tracker_data, service: service,
url: evaluator.url, api_url: evaluator.api_url, token: evaluator.token,
closed_status_id: evaluator.closed_status_id, project_identifier_code: evaluator.project_identifier_code
)
end
end
trait :jira_cloud_service do trait :jira_cloud_service do
url { 'https://mysite.atlassian.net' } url { 'https://mysite.atlassian.net' }
username { 'jira_user' } username { 'jira_user' }
......
...@@ -9,4 +9,12 @@ FactoryBot.define do ...@@ -9,4 +9,12 @@ FactoryBot.define do
factory :issue_tracker_data do factory :issue_tracker_data do
service service
end end
factory :open_project_tracker_data do
service
url { 'http://openproject.example.com'}
token { 'supersecret' }
project_identifier_code { 'PRJ-1' }
closed_status_id { '15' }
end
end end
...@@ -252,6 +252,7 @@ services: ...@@ -252,6 +252,7 @@ services:
- service_hook - service_hook
- jira_tracker_data - jira_tracker_data
- issue_tracker_data - issue_tracker_data
- open_project_tracker_data
hooks: hooks:
- project - project
- web_hook_logs - web_hook_logs
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
describe JiraTrackerData do describe JiraTrackerData do
let(:service) { create(:jira_service, active: false, properties: {}) } let(:service) { create(:jira_service, active: false) }
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:service) } it { is_expected.to belong_to(:service) }
......
# frozen_string_literal: true
require 'spec_helper'
describe OpenProjectService do
describe 'Validations' do
context 'when service is active' do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:url) }
it { is_expected.to validate_presence_of(:token) }
it { is_expected.to validate_presence_of(:project_identifier_code) }
it_behaves_like 'issue tracker service URL attribute', :url
it_behaves_like 'issue tracker service URL attribute', :api_url
end
context 'when service is inactive' do
before do
subject.active = false
end
it { is_expected.not_to validate_presence_of(:url) }
it { is_expected.not_to validate_presence_of(:token) }
it { is_expected.not_to validate_presence_of(:project_identifier_code) }
end
end
describe 'Associations' do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
end
# frozen_string_literal: true
require 'spec_helper'
describe OpenProjectTrackerData do
describe 'Associations' do
it { is_expected.to belong_to(:service) }
end
describe 'closed_status_id' do
it 'returns the set value' do
expect(build(:open_project_tracker_data).closed_status_id).to eq('15')
end
it 'returns the default value if not set' do
expect(build(:open_project_tracker_data, closed_status_id: nil).closed_status_id).to eq('13')
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment