Skip to content

Commit

Permalink
Merge pull request #22 from dxw/234-linking-to-in-progress-task
Browse files Browse the repository at this point in the history
234 API exposes the latest submission for a task
  • Loading branch information
leeky authored Jul 31, 2018
2 parents 92178cd + 5afccb8 commit 1344069
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 1344069

Please sign in to comment.