Commit 38f289cf authored by nmilojevic1's avatar nmilojevic1

Fix project export presenter

- Fix specs for #description method
- Remove as_json override, use description method
parent ebd8fabb
...@@ -3,14 +3,16 @@ ...@@ -3,14 +3,16 @@
module Projects module Projects
module ImportExport module ImportExport
class ProjectExportPresenter < Gitlab::View::Presenter::Delegated class ProjectExportPresenter < Gitlab::View::Presenter::Delegated
include ActiveModel::Serializers::JSON
presents :project presents :project
def project_members def project_members
super + converted_group_members super + converted_group_members
end end
def as_json(*_args) def description
self.respond_to?(:override_description) ? super.merge("description" => override_description) : super self.respond_to?(:override_description) ? override_description : super
end end
private private
......
...@@ -5,26 +5,44 @@ require 'spec_helper' ...@@ -5,26 +5,44 @@ require 'spec_helper'
describe Projects::ImportExport::ProjectExportPresenter do describe Projects::ImportExport::ProjectExportPresenter do
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) } let_it_be(:project) { create(:project, group: group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
subject { described_class.new(project, current_user: user) }
describe '#description' do
context "override_description not provided" do
it "keeps original description" do
expect(subject.description).to eq(project.description)
end
end
context "override_description provided" do
let(:description) { "overridden description" } let(:description) { "overridden description" }
subject { described_class.new(project, current_user: user, override_description: description) } subject { described_class.new(project, current_user: user, override_description: description) }
describe '#as_json' do
context "override_description provided" do
it "overrides description" do it "overrides description" do
expect(subject.as_json["description"]).to eq(description) expect(subject.description).to eq(description)
end
end end
end end
describe '#as_json' do
context "override_description not provided" do context "override_description not provided" do
subject { described_class.new(project, current_user: user) }
it "keeps original description" do it "keeps original description" do
expect(subject.as_json["description"]).to eq(project.description) expect(subject.as_json["description"]).to eq(project.description)
end end
end end
context "override_description provided" do
let(:description) { "overridden description" }
subject { described_class.new(project, current_user: user, override_description: description) }
it "overrides description" do
expect(subject.as_json["description"]).to eq(description)
end
end
end end
describe '#project_members' do describe '#project_members' do
......
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