Expose if action is playable in JSON

To avoid a manual build action being played (resulting in a 404),
expose `playable?` in the JSON so the frontend can disable/hide the
play button if it's not playable.
This commit is contained in:
Toon Claes 2017-03-17 17:25:17 +01:00
parent 7a62390752
commit 16cca3a0ea
5 changed files with 12 additions and 0 deletions

View File

@ -141,6 +141,7 @@ export default {
const parsedAction = {
name: gl.text.humanize(action.name),
play_path: action.play_path,
playable: action.playable,
};
return parsedAction;
});

View File

@ -11,4 +11,6 @@ class BuildActionEntity < Grape::Entity
build.project,
build)
end
expose :playable?, as: :playable
end

View File

@ -16,6 +16,7 @@ class BuildEntity < Grape::Entity
path_to(:play_namespace_project_build, build)
end
expose :playable?, as: :playable
expose :created_at
expose :updated_at

View File

@ -17,5 +17,9 @@ describe BuildActionEntity do
it 'contains path to the action play' do
expect(subject[:path]).to include "builds/#{build.id}/play"
end
it 'contains whether it is playable' do
expect(subject[:playable]).to eq build.playable?
end
end
end

View File

@ -18,6 +18,10 @@ describe BuildEntity do
expect(subject).not_to include(/variables/)
end
it 'contains whether it is playable' do
expect(subject[:playable]).to eq build.playable?
end
it 'contains timestamps' do
expect(subject).to include(:created_at, :updated_at)
end