Fixed issuables_helper_spec and added a test for issuable_app_data

This commit is contained in:
Luke "Jared" Bennett 2017-05-31 14:03:32 +01:00
parent 632d0c0a4c
commit b888ed59ab
No known key found for this signature in database
GPG key ID: 402ED51FB5D306C2
2 changed files with 49 additions and 23 deletions

View file

@ -199,6 +199,29 @@ module IssuablesHelper
issuable_filter_params.any? { |k| params.key?(k) }
end
def issuable_app_data(project, issue)
data = {
endpoint: realtime_changes_namespace_project_issue_path(project.namespace, project, issue),
'can-update' => can?(current_user, :update_issue, issue).to_s,
'issuable-ref' => issue.to_reference || ''
}
updated_at_by = updated_at_by(issue)
data.merge(updated_at_by)
end
def updated_at_by(issuable)
return {} unless issuable.is_edited?
{
updated_at: issuable.updated_at.to_time.iso8601,
updated_by: {
name: issuable.last_edited_by.name,
path: user_path(issuable.last_edited_by)
}
}
end
private
def sidebar_gutter_collapsed?
@ -273,27 +296,4 @@ module IssuablesHelper
container: (is_collapsed ? 'body' : nil)
}
end
def issuable_app_data(project, issue)
data = {
endpoint: realtime_changes_namespace_project_issue_path(project.namespace, project, issue),
'can-update' => can?(current_user, :update_issue, issue).to_s,
'issuable-ref' => issue.to_reference || ''
}
updated_at_by = updated_at_by(issue)
data.merge(updated_at_by)
end
def updated_at_by(issuable)
return {} unless issuable.is_edited?
{
updated_at: issuable.updated_at.to_time.iso8601,
updated_by: {
name: issuable.last_edited_by.name,
path: user_path(issuable.last_edited_by)
}
}
end
end

View file

@ -193,6 +193,32 @@ describe IssuablesHelper do
end
end
describe '#issuable_app_data' do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:issue) { create(:issue, project: project, last_edited_by: user, created_at: 3.days.ago, updated_at: 2.days.ago, last_edited_at: 2.days.ago) }
let(:issue_app_data) do
{
endpoint: realtime_changes_namespace_project_issue_path(project.namespace, project, issue),
'can-update' => "true",
'issuable-ref' => issue.to_reference || '',
updated_at: issue.updated_at.to_time.iso8601,
updated_by: {
name: user.name,
path: user_path(user)
}
}
end
before do
allow(helper).to receive(:current_user).and_return(nil)
allow(helper).to receive(:can?).with(nil, :update_issue, issue).and_return(true)
end
it { expect(helper.issuable_app_data(issue.project, issue)).to eq(issue_app_data) }
end
describe '#updated_at_by' do
let(:user) { create(:user) }
let(:unedited_issuable) { create(:issue) }