Skip to content

Commit

Permalink
API exposes the latest submission for a task
Browse files Browse the repository at this point in the history
To be able to show the user the status of their task, we need to be able
to get the most recent submission. This makes it available as part of
the API.
  • Loading branch information
tekin committed Jul 31, 2018
1 parent 92178cd commit 5afccb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/serializable/serializable_task.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class SerializableTask < JSONAPI::Serializable::Resource
type 'tasks'

has_one :latest_submission
has_many :submissions
belongs_to :framework

Expand Down
18 changes: 17 additions & 1 deletion spec/requests/v1/tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
expect(json['data'][2]).to have_attribute(:status).with_value('in_progress')
end

it 'can optionally return included models' do
it 'can optionally include submissions' do
task = FactoryBot.create(:task)
submission = FactoryBot.create(:submission, task: task, aasm_state: 'pending')

Expand All @@ -75,6 +75,22 @@
expect(json['included'][0])
.to have_attribute(:status).with_value('pending')
end

it 'can optionally include the latest_submission' do
task = FactoryBot.create(:task)
submission = FactoryBot.create(:submission, task: task, aasm_state: 'pending')

get '/v1/tasks?include=latest_submission'

expect(response).to be_successful
expect(json['data'][0]).to have_id(task.id)
expect(json['data'][0])
.to have_relationship(:latest_submission)
.with_data('id' => submission.id, 'type' => 'submissions')

expect(json['included'][0])
.to have_attribute(:status).with_value('pending')
end
end

describe 'GET /tasks?filter[status]=' do
Expand Down

0 comments on commit 5afccb8

Please sign in to comment.