Skip to content

Commit 1344069

Browse files
authored
Merge pull request #22 from dxw/234-linking-to-in-progress-task
234 API exposes the latest submission for a task
2 parents 92178cd + 5afccb8 commit 1344069

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

app/serializable/serializable_task.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class SerializableTask < JSONAPI::Serializable::Resource
22
type 'tasks'
33

4+
has_one :latest_submission
45
has_many :submissions
56
belongs_to :framework
67

spec/requests/v1/tasks_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
expect(json['data'][2]).to have_attribute(:status).with_value('in_progress')
6262
end
6363

64-
it 'can optionally return included models' do
64+
it 'can optionally include submissions' do
6565
task = FactoryBot.create(:task)
6666
submission = FactoryBot.create(:submission, task: task, aasm_state: 'pending')
6767

@@ -75,6 +75,22 @@
7575
expect(json['included'][0])
7676
.to have_attribute(:status).with_value('pending')
7777
end
78+
79+
it 'can optionally include the latest_submission' do
80+
task = FactoryBot.create(:task)
81+
submission = FactoryBot.create(:submission, task: task, aasm_state: 'pending')
82+
83+
get '/v1/tasks?include=latest_submission'
84+
85+
expect(response).to be_successful
86+
expect(json['data'][0]).to have_id(task.id)
87+
expect(json['data'][0])
88+
.to have_relationship(:latest_submission)
89+
.with_data('id' => submission.id, 'type' => 'submissions')
90+
91+
expect(json['included'][0])
92+
.to have_attribute(:status).with_value('pending')
93+
end
7894
end
7995

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

0 commit comments

Comments
 (0)