fixed issue occurring for progress bars without a value
This commit is contained in:
@ -33,8 +33,8 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def progress_bar(value)
|
def progress_bar(value)
|
||||||
content_tag(:div, class: 'progress') do
|
content_tag(:div, class: value ? 'progress' : 'disabled progress') do
|
||||||
content_tag(:div, "#{value}%", :'aria-valuemax' => 100, :'aria-valuemin' => 0, :'aria-valuenow' => value, class: 'progress-bar progress-bar-striped', role: 'progressbar', style: "width: #{[value, 100].min}%;")
|
content_tag(:div, value ? "#{value}%" : '', :'aria-valuemax' => 100, :'aria-valuemin' => 0, :'aria-valuenow' => value, class: 'progress-bar progress-bar-striped', role: 'progressbar', style: "width: #{[value || 0, 100].min}%;")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -182,6 +182,14 @@ describe ExercisesController do
|
|||||||
expect_template(:show)
|
expect_template(:show)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'GET #statistics' do
|
||||||
|
before(:each) { get :statistics, id: exercise.id }
|
||||||
|
|
||||||
|
expect_assigns(exercise: :exercise)
|
||||||
|
expect_status(200)
|
||||||
|
expect_template(:statistics)
|
||||||
|
end
|
||||||
|
|
||||||
describe 'POST #submit' do
|
describe 'POST #submit' do
|
||||||
let(:output) { {} }
|
let(:output) { {} }
|
||||||
let(:request) { post :submit, format: :json, id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id} }
|
let(:request) { post :submit, format: :json, id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id} }
|
||||||
|
@ -43,18 +43,37 @@ describe ApplicationHelper do
|
|||||||
|
|
||||||
describe '#progress_bar' do
|
describe '#progress_bar' do
|
||||||
let(:html) { progress_bar(value) }
|
let(:html) { progress_bar(value) }
|
||||||
let(:value) { 42 }
|
|
||||||
|
|
||||||
it "builds nested 'div' tags" do
|
context 'with a value' do
|
||||||
expect(html).to have_css('div.progress div.progress-bar')
|
let(:value) { 42 }
|
||||||
|
|
||||||
|
it "builds nested 'div' tags" do
|
||||||
|
expect(html).to have_css('div.progress div.progress-bar')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'assigns the correct text' do
|
||||||
|
expect(html).to have_text("#{value}%")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'uses the correct width' do
|
||||||
|
expect(html).to have_css("div.progress-bar[style='width: 42%;']")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns the correct text' do
|
context 'without a value' do
|
||||||
expect(html).to have_text("#{value}%")
|
let(:value) { nil }
|
||||||
end
|
|
||||||
|
|
||||||
it 'uses the correct width' do
|
it 'does not raise an error' do
|
||||||
expect(html).to have_css("div.progress-bar[style='width: 42%;']")
|
expect { html }.not_to raise_error
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'assigns the correct classes' do
|
||||||
|
expect(html).to have_css('div.disabled.progress div.progress-bar')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'uses the correct width' do
|
||||||
|
expect(html).to have_css("div.progress-bar[style='width: 0%;']")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user