Skip to content

Commit

Permalink
Merge pull request #6068 from avalonmediasystem/nil_encodes
Browse files Browse the repository at this point in the history
Prevent bad encode status from breaking encode record pages
  • Loading branch information
masaball authored Oct 8, 2024
2 parents 0e9c865 + c985ce8 commit 18e3388
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/controllers/encode_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def paged_index
"recordsFiltered": filtered_records_total,
"data": @encode_records.collect do |encode|
encode_presenter = EncodePresenter.new(encode)
encode_status = encode_presenter.status.downcase
encode_status = encode_presenter.status&.downcase
unless encode_status == 'completed'
progress_class = 'progress-bar-striped'
end
Expand Down Expand Up @@ -117,7 +117,7 @@ def set_encode_record

def format_progress(presenter)
# Set progress = 100.0 when job failed
if presenter.status.casecmp("failed") == 0
if presenter.status&.casecmp("failed") == 0
100.0
else
presenter.progress
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/encode_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(encode_record)
delegate :id, :adapter, :display_title, :master_file_id, :media_object_id, :created_at, :progress, to: :encode_record

def status
@encode_record.state.capitalize
@encode_record.state&.capitalize
end

def global_id
Expand Down
32 changes: 31 additions & 1 deletion spec/controllers/encode_records_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
expect(response).to render_template('errors/restricted_pid')
end
end

context "when state is nil" do
let(:encode_record_test) { FactoryBot.create(:encode_record, state: nil) }
it "returns a success response" do
get :index, params: {}, session: valid_session
expect(response).to be_successful
end
end
end

describe "GET #show" do
Expand All @@ -75,10 +83,18 @@
let(:user) { FactoryBot.create(:user) }

it "redirects to restricted content page" do
get :index, params: {}, session: valid_session
get :show, params: { id: encode_record_test.to_param }, session: valid_session
expect(response).to render_template('errors/restricted_pid')
end
end

context "when state is nil" do
let(:encode_record_test) { FactoryBot.create(:encode_record, state: nil) }
it "returns a success response" do
get :show, params: { id: encode_record_test.to_param }, session: valid_session
expect(response).to be_successful
end
end
end

describe "POST #paged_index" do
Expand Down Expand Up @@ -134,6 +150,20 @@
expect(parsed_response['data'][1][3]).to eq('Title 997')
end
end

context "when state is nil" do
let(:params) { { start: 0, length: 20, order: { '0': { column: 3, dir: 'asc' } }, search: { value: '' } } }
before do
FactoryBot.create(:encode_record, state: nil)
end

it "returns a success response" do
post :paged_index, format: 'json', params: params, session: valid_session
expect(response).to be_successful
parsed_response = JSON.parse(response.body)
expect(parsed_response['recordsTotal']).to eq(12)
end
end
end

describe "POST #progress" do
Expand Down

0 comments on commit 18e3388

Please sign in to comment.