prefer unit test on model over view test

This commit is contained in:
Mike Greiling 2017-01-02 11:42:08 -06:00
parent 1c5a506588
commit dc3d40ff28
2 changed files with 22 additions and 35 deletions

View file

@ -243,4 +243,26 @@ describe CommitStatus, models: true do
.to be_a Gitlab::Ci::Status::Success
end
end
describe '#sortable_name' do
subject { commit_status.sortable_name }
tests = {
'karma' => ['karma'],
'karma 0 20' => ['karma ', 0, ' ', 20],
'karma 10 20' => ['karma ', 10, ' ', 20],
'karma 50:100' => ['karma ', 50, ':', 100],
'karma 1.10' => ['karma ', 1, '.', 10],
'karma 1.5.1' => ['karma ', 1, '.', 5, '.', 1],
'karma 1 a' => ['karma ', 1, ' a']
}
tests.each do |name, sortable_name|
it "'#{name}' sorts as '#{sortable_name}'" do
commit_status.name = name
is_expected.to eq(sortable_name)
end
end
end
end

View file

@ -45,41 +45,6 @@ describe 'projects/pipelines/show' do
expect(rendered).to have_text('jenkins')
end
it 'lists builds in the correct sort order' do
create_build('test', 1, 'karma 0 20', :created)
create_build('test', 1, 'karma 12 20', :created)
create_build('test', 1, 'karma 1 20', :created)
create_build('test', 1, 'karma 10 20', :created)
create_build('test', 1, 'karma 11 20', :created)
create_build('test', 1, 'karma 2 20', :created)
create_build('test', 1, 'test 1.10', :created)
create_build('test', 1, 'test 1.5.1', :created)
create_build('test', 1, 'test 1 a', :created)
render
# spaced builds order
expected_order_1 = [
'karma 0 20',
'karma 1 20',
'karma 2 20',
'karma 10 20',
'karma 11 20',
'karma 12 20'
].join(' ')
expect(rendered).to have_text(expected_order_1)
# decimal builds order
expected_order_2 = [
'test 1 a',
'test 1.5.1',
'test 1.10'
].join(' ')
expect(rendered).to have_text(expected_order_2)
end
private
def create_build(stage, stage_idx, name, status)