Commit 630dfbff authored by Jan Provaznik's avatar Jan Provaznik

Don't convert issuable_initial_data into JSON

Instead of converting hash into JSON inside
issuable_initial_data method, return hash and convert
to JSON later. This allows us to easily extend basic
issuable data with resource specific values. For example
for Epic these data should include also labels, so we can then
do something like:
issuable_initial_data(@epic).merge(labels: @epic.labels).to_json
parent 7fca5980
......@@ -237,7 +237,7 @@ module IssuablesHelper
data.merge!(updated_at_by(issuable))
data.to_json
data
end
def updated_at_by(issuable)
......
......@@ -58,7 +58,7 @@
.issue-details.issuable-details
.detail-page-description.content-block
%script#js-issuable-app-initial-data{ type: "application/json" }= issuable_initial_data(@issue)
%script#js-issuable-app-initial-data{ type: "application/json" }= issuable_initial_data(@issue).to_json
#js-issuable-app
%h2.title= markdown_field(@issue, :title)
- if @issue.description.present?
......
......@@ -16,4 +16,4 @@
= webpack_bundle_tag 'common_vue'
= webpack_bundle_tag 'epic_show'
#epic-show-app{ data: { initial: issuable_initial_data(@epic), meta: epic_meta_data } }
#epic-show-app{ data: { initial: issuable_initial_data(@epic).to_json, meta: epic_meta_data } }
......@@ -168,54 +168,54 @@ describe IssuablesHelper do
allow(helper).to receive(:can?).and_return(true)
end
it 'returns the correct json for an issue' do
it 'returns the correct data for an issue' do
issue = create(:issue, author: user, description: 'issue text')
@project = issue.project
expected_data = {
'endpoint' => "/#{@project.full_path}/issues/#{issue.iid}",
'updateEndpoint' => "/#{@project.full_path}/issues/#{issue.iid}.json",
'canUpdate' => true,
'canDestroy' => true,
'canAdmin' => true,
'issuableRef' => "##{issue.iid}",
'markdownPreviewPath' => "/#{@project.full_path}/preview_markdown",
'markdownDocsPath' => '/help/user/markdown',
'issuableTemplates' => [],
'projectPath' => @project.path,
'projectNamespace' => @project.namespace.path,
'initialTitleHtml' => issue.title,
'initialTitleText' => issue.title,
'initialDescriptionHtml' => '<p dir="auto">issue text</p>',
'initialDescriptionText' => 'issue text',
'initialTaskStatus' => '0 of 0 tasks completed'
endpoint: "/#{@project.full_path}/issues/#{issue.iid}",
updateEndpoint: "/#{@project.full_path}/issues/#{issue.iid}.json",
canUpdate: true,
canDestroy: true,
canAdmin: true,
issuableRef: "##{issue.iid}",
markdownPreviewPath: "/#{@project.full_path}/preview_markdown",
markdownDocsPath: '/help/user/markdown',
issuableTemplates: [],
projectPath: @project.path,
projectNamespace: @project.namespace.path,
initialTitleHtml: issue.title,
initialTitleText: issue.title,
initialDescriptionHtml: '<p dir="auto">issue text</p>',
initialDescriptionText: 'issue text',
initialTaskStatus: '0 of 0 tasks completed'
}
expect(JSON.parse(helper.issuable_initial_data(issue))).to eq(expected_data)
expect(helper.issuable_initial_data(issue)).to eq(expected_data)
end
it 'returns the correct json for an epic' do
it 'returns the correct data for an epic' do
epic = create(:epic, author: user, description: 'epic text')
@group = epic.group
expected_data = {
'endpoint' => "/groups/#{@group.full_path}/-/epics/#{epic.iid}",
'updateEndpoint' => "/groups/#{@group.full_path}/-/epics/#{epic.iid}.json",
'issueLinksEndpoint' => "/groups/#{@group.full_path}/-/epics/#{epic.iid}/issues",
'canUpdate' => true,
'canDestroy' => true,
'canAdmin' => true,
'issuableRef' => "&#{epic.iid}",
'markdownPreviewPath' => "/groups/#{@group.full_path}/preview_markdown",
'markdownDocsPath' => '/help/user/markdown',
'issuableTemplates' => nil,
'groupPath' => @group.path,
'initialTitleHtml' => epic.title,
'initialTitleText' => epic.title,
'initialDescriptionHtml' => '<p dir="auto">epic text</p>',
'initialDescriptionText' => 'epic text',
'initialTaskStatus' => '0 of 0 tasks completed'
endpoint: "/groups/#{@group.full_path}/-/epics/#{epic.iid}",
updateEndpoint: "/groups/#{@group.full_path}/-/epics/#{epic.iid}.json",
issueLinksEndpoint: "/groups/#{@group.full_path}/-/epics/#{epic.iid}/issues",
canUpdate: true,
canDestroy: true,
canAdmin: true,
issuableRef: "&#{epic.iid}",
markdownPreviewPath: "/groups/#{@group.full_path}/preview_markdown",
markdownDocsPath: '/help/user/markdown',
issuableTemplates: nil,
groupPath: @group.path,
initialTitleHtml: epic.title,
initialTitleText: epic.title,
initialDescriptionHtml: '<p dir="auto">epic text</p>',
initialDescriptionText: 'epic text',
initialTaskStatus: '0 of 0 tasks completed'
}
expect(JSON.parse(helper.issuable_initial_data(epic))).to eq(expected_data)
expect(helper.issuable_initial_data(epic)).to eq(expected_data)
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