Commit 6627d2e9 authored by Rémy Coutable's avatar Rémy Coutable Committed by Ruben Davila

Merge branch 'fix/import-services' into 'master'

Fixes issue with rails reserved keyword type exporting/importing services.

The attribute `type`in services was being ignored by Import/Export. Added `type` as a method call in the export, as `type` gets ignored invoking `to_json`, manually adding this as a method in `import_export.yml` solves the problem.

On a different note, I found assigning a title directly to `CustomIssueTrackerService` didn't play very well with `prop_accessor`:

```ruby
> CustomIssueTrackerService.new(title: 'asdf')
NoMethodError: undefined method `[]=' for nil:NilClass
> CustomIssueTrackerService.new(title: nil)
NoMethodError: undefined method `[]=' for nil:NilClass
```

This was also causing the Import/Export to failed... So I added a custom setter that fixed the problem.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/22461

See merge request !6499
Conflicts:
	spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
parent c7a78971
...@@ -9,6 +9,10 @@ class CustomIssueTrackerService < IssueTrackerService ...@@ -9,6 +9,10 @@ class CustomIssueTrackerService < IssueTrackerService
end end
end end
def title=(value)
self.properties['title'] = value if self.properties
end
def description def description
if self.properties && self.properties['description'].present? if self.properties && self.properties['description'].present?
self.properties['description'] self.properties['description']
......
...@@ -73,5 +73,7 @@ excluded_attributes: ...@@ -73,5 +73,7 @@ excluded_attributes:
methods: methods:
statuses: statuses:
- :type - :type
services:
- :type
merge_request_diff: merge_request_diff:
- :utf8_st_diffs - :utf8_st_diffs
...@@ -6943,6 +6943,7 @@ ...@@ -6943,6 +6943,7 @@
"note_events": true, "note_events": true,
"build_events": true, "build_events": true,
"category": "issue_tracker", "category": "issue_tracker",
"type": "CustomIssueTrackerService",
"default": true, "default": true,
"wiki_page_events": true "wiki_page_events": true
}, },
......
...@@ -111,6 +111,10 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do ...@@ -111,6 +111,10 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
expect(saved_project_json['issues'].first['label_links'].first['label']).not_to be_empty expect(saved_project_json['issues'].first['label_links'].first['label']).not_to be_empty
end end
it 'saves the correct service type' do
expect(saved_project_json['services'].first['type']).to eq('CustomIssueTrackerService')
end
it 'has project feature' do it 'has project feature' do
project_feature = saved_project_json['project_feature'] project_feature = saved_project_json['project_feature']
expect(project_feature).not_to be_empty expect(project_feature).not_to be_empty
...@@ -161,6 +165,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do ...@@ -161,6 +165,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver, services: true do
commit_id: ci_pipeline.sha) commit_id: ci_pipeline.sha)
create(:event, target: milestone, project: project, action: Event::CREATED, author: user) create(:event, target: milestone, project: project, action: Event::CREATED, author: user)
create(:service, project: project, type: 'CustomIssueTrackerService', category: 'issue_tracker')
project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED) project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED)
project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::ENABLED) project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::ENABLED)
......
...@@ -25,5 +25,21 @@ describe CustomIssueTrackerService, models: true do ...@@ -25,5 +25,21 @@ describe CustomIssueTrackerService, models: true do
it { is_expected.not_to validate_presence_of(:issues_url) } it { is_expected.not_to validate_presence_of(:issues_url) }
it { is_expected.not_to validate_presence_of(:new_issue_url) } it { is_expected.not_to validate_presence_of(:new_issue_url) }
end end
context 'title' do
let(:issue_tracker) { described_class.new(properties: {}) }
it 'sets a default title' do
issue_tracker.title = nil
expect(issue_tracker.title).to eq('Custom Issue Tracker')
end
it 'sets the custom title' do
issue_tracker.title = 'test title'
expect(issue_tracker.title).to eq('test title')
end
end
end 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