File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11class SerializableTask < JSONAPI ::Serializable ::Resource
22 type 'tasks'
33
4+ has_one :latest_submission
45 has_many :submissions
56 belongs_to :framework
67
Original file line number Diff line number Diff line change 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
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
You can’t perform that action at this time.
0 commit comments