Skip to content

Commit

Permalink
Merge pull request #13 from poteto/feature/bugfix-no-args
Browse files Browse the repository at this point in the history
Fixes a bug where the service would not invoke methods with 0 args.
  • Loading branch information
poteto committed Jul 23, 2015
2 parents 58d887a + e3e5106 commit d4d4701
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
6 changes: 2 additions & 4 deletions addon/services/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ export default Service.extend({
const adapter = get(adaptersObj, adapterName);

adapter[methodName](options);
} else if (args.length === 1) {
const options = args.pop();

} else {
adapters.forEach((adapter) => {
adapter[methodName](options);
adapter[methodName](...args);
});
}
},
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "ember-metrics",
"dependencies": {
"ember": "1.13.3",
"ember": "1.13.5",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.5",
"ember-qunit": "0.4.1",
"ember-qunit": "0.4.5",
"ember-qunit-notifications": "0.0.7",
"ember-resolver": "~0.1.18",
"jquery": "^1.11.1",
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@
],
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.0.2",
"broccoli-asset-rev": "^2.1.0",
"ember-cli": "1.13.1",
"ember-cli-app-version": "0.4.0",
"ember-cli-dependency-checker": "^1.0.0",
"ember-cli-dependency-checker": "^1.0.1",
"ember-cli-htmlbars": "0.7.9",
"ember-cli-htmlbars-inline-precompile": "^0.1.1",
"ember-cli-htmlbars-inline-precompile": "^0.2.0",
"ember-cli-ic-ajax": "0.2.1",
"ember-cli-inject-live-reload": "^1.3.0",
"ember-cli-qunit": "0.3.15",
"ember-cli-release": "0.2.3",
"ember-cli-uglify": "^1.0.1",
"ember-disable-prototype-extensions": "^1.0.0",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-qunit": "0.3.17",
"ember-cli-release": "0.2.5",
"ember-cli-uglify": "^1.2.0",
"ember-disable-prototype-extensions": "^1.0.1",
"ember-disable-proxy-controllers": "^1.0.0",
"ember-export-application-global": "^1.0.2",
"ember-export-application-global": "^1.0.3",
"ember-sinon": "0.2.1",
"ember-try": "0.0.6"
"ember-try": "0.0.7"
},
"keywords": [
"ember-addon",
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/metrics-adapters/google-analytics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ test('#trackPage returns the correct response shape', function(assert) {

assert.deepEqual(result, expectedResult, 'it sends the correct response shape');
});

test('#trackPage returns the correct response shape', function(assert) {
const adapter = this.subject({ config });
sandbox.stub(window, 'ga');
const result = adapter.trackPage();
const expectedResult = {
hitType: 'pageview'
};

assert.deepEqual(result, expectedResult, 'it sends the correct response shape');
});
10 changes: 10 additions & 0 deletions tests/unit/services/metrics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ test('#invoke invokes the named method on a single activated adapter', function(
assert.equal(MixpanelSpy.callCount, 0, 'it does not invoke other adapters');
});

test('#invoke invokes the named method on a single activated adapter with no arguments', function(assert) {
const service = this.subject({ metricsAdapters });
const GoogleAnalyticsStub = sandbox.stub(window, 'ga');
const GoogleAnalyticsSpy = sandbox.spy(get(service, '_adapters.GoogleAnalytics'), 'trackPage');
service.invoke('trackPage', 'GoogleAnalytics');

assert.ok(GoogleAnalyticsSpy.calledOnce, 'it invokes the track method on the adapter');
assert.ok(GoogleAnalyticsStub.calledOnce, 'it invoked the Google Analytics method');
});

test('it implements standard contracts', function(assert) {
const service = this.subject({ metricsAdapters });
sandbox.stub(window.mixpanel);
Expand Down

0 comments on commit d4d4701

Please sign in to comment.