Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Fixed bug 1321345 #335

Merged
merged 1 commit into from
May 20, 2014
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
20 changes: 15 additions & 5 deletions app/models/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,25 @@ YUI.add('juju-models', function(Y) {
} else {
// Because the packageName is not set if the
// model was created from the core delta.
var charm = this.get('charm');
var charmUrl = this.get('charm'),
charmName;
// If there is no charm as well, well you have bigger problems :)
// but this helps so that we don't need to provide charm data
// for every test suite.
if (charm) {
charm = charm.split('/');
charm = charm[charm.length - 1].split('-')[0];
if (charmUrl) {
var urlParts = charmUrl.split('/');
var nameParts = urlParts[urlParts.length - 1].split('-');
var possibleVersion = nameParts[nameParts.length - 1];
// Expected === and instead saw ==
/* jshint -W116 */
if (possibleVersion == parseInt(possibleVersion, 10)) {
// The charmUrl contains the version so we can drop that and
// reconstruct the name.
nameParts.pop();
}
charmName = nameParts.join('-');
}
return charm || undefined;
return charmName;
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/test_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,15 @@ describe('test_model.js', function() {
assert.equal(services.length, 1);
assert.deepEqual(services, [rails]);
});

it('can properly parse the charm url for the package name', function() {
assert.equal(rails.get('packageName'), 'rails');
var jujuGui = new models.Service({
id: 'juju-gui',
charm: 'cs:/trusty/juju-gui-90'
});
assert.equal(jujuGui.get('packageName'), 'juju-gui');
});
});

describe('db.charms.addFromCharmData', function() {
Expand Down