Commit 61249683 authored by Kushal Pandya's avatar Kushal Pandya

jprovaznik: Add `epic_show_app_data` and `epic_endpoint_query_params`

parent 2c060a54
module EpicsHelper
def epic_meta_data
author = @epic.author
def epic_show_app_data(epic, opts)
author = epic.author
group = epic.group
data = {
created: @epic.created_at,
epic_meta = {
created: epic.created_at,
author: {
name: author.name,
url: user_path(author),
username: "@#{author.username}",
src: avatar_icon_for_user(@epic.author)
src: opts[:author_icon]
},
start_date: @epic.start_date,
end_date: @epic.end_date
start_date: epic.start_date,
end_date: epic.end_date
}
data.to_json
{
initial: opts[:initial].merge(labels: epic.labels).to_json,
meta: epic_meta.to_json,
namespace: group.path,
labels_path: group_labels_path(group, format: :json, only_group_labels: true, include_ancestor_groups: true),
labels_web_url: group_labels_path(group),
epics_web_url: group_epics_path(group)
}
end
def epic_endpoint_query_params(opts)
opts[:data] ||= {}
opts[:data][:endpoint_query_params] = {
only_group_labels: true,
include_ancestor_groups: true,
include_descendant_groups: true
}.to_json
opts
end
end
......@@ -3,18 +3,32 @@ require 'spec_helper'
describe EpicsHelper do
include ApplicationHelper
describe '#epic_meta_data' do
describe '#epic_show_app_data' do
it 'returns the correct json' do
user = create(:user)
@epic = create(:epic, author: user)
expect(JSON.parse(epic_meta_data).keys).to match_array(%w[created author start_date end_date])
expect(JSON.parse(epic_meta_data)['author']).to eq({
data = epic_show_app_data(@epic, initial: {}, author_icon: 'icon_path')
meta_data = JSON.parse(data[:meta])
expected_keys = %i(initial meta namespace labels_path labels_web_url epics_web_url)
expect(data.keys).to match_array(expected_keys)
expect(meta_data.keys).to match_array(%w[created author start_date end_date])
expect(meta_data['author']).to eq({
'name' => user.name,
'url' => "/#{user.username}",
'username' => "@#{user.username}",
'src' => "#{avatar_icon_for_user(user)}"
'src' => 'icon_path'
})
end
end
describe '#epic_endpoint_query_params' do
it 'it includes epic specific options in JSON format' do
opts = epic_endpoint_query_params({})
expected = "{\"only_group_labels\":true,\"include_ancestor_groups\":true,\"include_descendant_groups\":true}"
expect(opts[:data][:endpoint_query_params]).to eq(expected)
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