Skip to content

models/version: Fix msrv regex #6394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class Version extends Model {
get msrv() {
let rustVersion = this.rust_version;
// add `.0` suffix if the `rust-version` field only has two version components
return /^.+\..+$/.test(rustVersion) ? `${rustVersion}.0` : rustVersion;
return /^[^.]+\.[^.]+$/.test(rustVersion) ? `${rustVersion}.0` : rustVersion;
}

get isNew() {
Expand Down
15 changes: 15 additions & 0 deletions tests/models/version-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ module('Model | Version', function (hooks) {
assert.false(versions[0].isNew);
});

test('msrv', async function (assert) {
let version = await this.store.createRecord('version');
assert.strictEqual(version.msrv, undefined);

version.rust_version = '1.69.1';
assert.strictEqual(version.msrv, '1.69.1');

version.rust_version = '1.69';
assert.strictEqual(version.msrv, '1.69.0');

// this is not actually allowed by the backend
version.rust_version = '1';
assert.strictEqual(version.msrv, '1');
});

module('semver', function () {
async function prepare(context, { num }) {
let { server, store } = context;
Expand Down