From 961982abbfccc0378127f6482e7dbe8f8e618992 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Sun, 19 Oct 2014 10:11:28 +0100 Subject: [PATCH 1/3] Converting to new style ember addon with all passing tests --- .bowerrc | 3 +- .editorconfig | 33 ++ .ember-cli | 9 + .gitignore | 8 +- .jshintrc | 18 +- .travis.yml | 16 + Brocfile.js | 105 ++---- README.md | 36 ++- addon/.gitkeep | 0 addon/egc.js | 16 + {lib => addon}/egc/authorization.js | 5 +- {lib => addon}/egc/drive.js | 4 +- {lib => addon}/egc/drive/files.js | 15 +- {lib => addon}/egc/drive/uploadFile.js | 6 +- {lib => addon}/egc/ready.js | 2 + {lib => addon}/egc/utils.js | 2 + app/.gitkeep | 0 bower.json | 24 +- config/environment.js | 5 + dist/index.js | 302 ------------------ index.js | 5 + lib/egc.js | 15 - package.json | 31 +- testem.json | 8 +- tests/dummy/.jshintrc | 33 ++ tests/dummy/app/app.js | 16 + tests/dummy/app/components/.gitkeep | 0 tests/dummy/app/controllers/.gitkeep | 0 tests/dummy/app/helpers/.gitkeep | 0 tests/dummy/app/index.html | 21 ++ tests/dummy/app/models/.gitkeep | 0 tests/dummy/app/router.js | 11 + tests/dummy/app/routes/.gitkeep | 0 tests/dummy/app/styles/.gitkeep | 0 tests/dummy/app/styles/app.css | 3 + tests/dummy/app/templates/.gitkeep | 0 tests/dummy/app/templates/application.hbs | 3 + tests/dummy/app/templates/components/.gitkeep | 0 tests/dummy/app/views/.gitkeep | 0 tests/dummy/config/environment.js | 47 +++ tests/dummy/public/.gitkeep | 0 tests/dummy/public/crossdomain.xml | 15 + tests/dummy/public/robots.txt | 3 + tests/helpers/resolver.js | 4 +- tests/helpers/start-app.js | 25 ++ tests/index.html | 43 ++- tests/test-helper.js | 37 +++ tests/unit/.gitkeep | 0 tests/{ => unit}/egc-test.js | 4 +- tests/{ => unit}/egc/authorization-test.js | 5 +- tests/{ => unit}/egc/drive-test.js | 5 +- tests/{ => unit}/egc/drive/files-test.js | 5 +- tests/{ => unit}/egc/drive/uploadFile-test.js | 7 +- tests/{ => unit}/egc/ready-test.js | 4 +- vendor/.gitkeep | 0 55 files changed, 480 insertions(+), 479 deletions(-) create mode 100644 .editorconfig create mode 100644 .ember-cli create mode 100644 .travis.yml create mode 100644 addon/.gitkeep create mode 100644 addon/egc.js rename {lib => addon}/egc/authorization.js (93%) rename {lib => addon}/egc/drive.js (81%) rename {lib => addon}/egc/drive/files.js (85%) rename {lib => addon}/egc/drive/uploadFile.js (95%) rename {lib => addon}/egc/ready.js (95%) rename {lib => addon}/egc/utils.js (90%) create mode 100644 app/.gitkeep create mode 100644 config/environment.js delete mode 100644 dist/index.js create mode 100644 index.js delete mode 100644 lib/egc.js create mode 100644 tests/dummy/.jshintrc create mode 100644 tests/dummy/app/app.js create mode 100644 tests/dummy/app/components/.gitkeep create mode 100644 tests/dummy/app/controllers/.gitkeep create mode 100644 tests/dummy/app/helpers/.gitkeep create mode 100644 tests/dummy/app/index.html create mode 100644 tests/dummy/app/models/.gitkeep create mode 100644 tests/dummy/app/router.js create mode 100644 tests/dummy/app/routes/.gitkeep create mode 100644 tests/dummy/app/styles/.gitkeep create mode 100644 tests/dummy/app/styles/app.css create mode 100644 tests/dummy/app/templates/.gitkeep create mode 100644 tests/dummy/app/templates/application.hbs create mode 100644 tests/dummy/app/templates/components/.gitkeep create mode 100644 tests/dummy/app/views/.gitkeep create mode 100644 tests/dummy/config/environment.js create mode 100644 tests/dummy/public/.gitkeep create mode 100644 tests/dummy/public/crossdomain.xml create mode 100644 tests/dummy/public/robots.txt create mode 100644 tests/helpers/start-app.js create mode 100644 tests/test-helper.js create mode 100644 tests/unit/.gitkeep rename tests/{ => unit}/egc-test.js (63%) rename tests/{ => unit}/egc/authorization-test.js (96%) rename tests/{ => unit}/egc/drive-test.js (89%) rename tests/{ => unit}/egc/drive/files-test.js (98%) rename tests/{ => unit}/egc/drive/uploadFile-test.js (96%) rename tests/{ => unit}/egc/ready-test.js (91%) create mode 100644 vendor/.gitkeep diff --git a/.bowerrc b/.bowerrc index 6866ac2..959e169 100644 --- a/.bowerrc +++ b/.bowerrc @@ -1,3 +1,4 @@ { - "directory": "vendor" + "directory": "bower_components", + "analytics": false } diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5d5dea4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,33 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +[*.js] +indent_style = space +indent_size = 2 + +[*.hbs] +indent_style = space +indent_size = 2 + +[*.css] +indent_style = space +indent_size = 2 + +[*.html] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/.ember-cli b/.ember-cli new file mode 100644 index 0000000..ee64cfe --- /dev/null +++ b/.ember-cli @@ -0,0 +1,9 @@ +{ + /** + Ember CLI sends analytics information by default. The data is completely + anonymous, but there are times when you might want to disable this behavior. + + Setting `disableAnalytics` to true will prevent any data from being sent. + */ + "disableAnalytics": false +} diff --git a/.gitignore b/.gitignore index ab023e3..86fceae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,17 @@ # See http://help.github.com/ignore-files/ for more about ignoring files. # compiled output +/dist /tmp # dependencies /node_modules -/vendor/* +/bower_components # misc /.sass-cache /connect.lock -/libpeerconnection.log -.DS_Store -Thumbs.db /coverage/* +/libpeerconnection.log npm-debug.log +testem.log diff --git a/.jshintrc b/.jshintrc index 5724f48..f75233a 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,22 +1,14 @@ { "predef": { - "document": true, "window": true, - "location": true, - "setTimeout": true, - "Ember": true, - "Em": true, - "DS": true, - "$": true, - "ENV": true, - "module": true + "console": true, + "gapi": true }, - "node" : false, - "browser" : false, + "browser" : true, "boss" : true, - "curly": false, + "curly": true, "debug": false, - "devel": false, + "devel": true, "eqeqeq": true, "evil": true, "forin": false, diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..df6253d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +--- +language: node_js + +sudo: false + +cache: + directories: + - node_modules + +install: + - npm install -g bower + - npm install + - bower install + +script: + - npm test diff --git a/Brocfile.js b/Brocfile.js index b55ec4b..8c25bfe 100644 --- a/Brocfile.js +++ b/Brocfile.js @@ -1,85 +1,20 @@ -/* global require, process */ -'use strict'; - -var name = require('./package.json').name; -var path = require('path'); -var env = process.env.EMBER_ENV; -var dist = env === 'dist'; - -var pickFiles = require('broccoli-static-compiler'); -var compileES6 = require('broccoli-es6-concatenator'); -var findBowerTrees = require('broccoli-bower'); -var mergeTrees = require('broccoli-merge-trees'); - -var lib = pickFiles('lib', { - srcDir: '/', - destDir: name -}); - -if (dist) { - var loader = pickFiles('vendor', { - srcDir: '/loader', - files: ['loader.js'], - destDir: '/loader' - }); - - var scripts = mergeTrees([lib, loader], { overwrite: true }); - - var es6 = compileES6(scripts, { - loaderFile: 'loader/loader.js', - inputFiles: [name + '/**/*.js'], - outputFile: '/index.js', - wrapInEval: false - }); - - return module.exports = es6; -} - -var index = pickFiles('tests', { - srcDir: '/', - files: ['index.html'], - destDir: '/' -}); - -var tests = pickFiles('tests', { - srcDir: '/', - destDir: name + '/tests' -}); - -var sourceFiles = [lib, tests, 'vendor'].concat(findBowerTrees()); -var scripts = mergeTrees(sourceFiles, { overwrite: true }); - -var ignoredModules = [ - 'ember', - 'ember/resolver', - 'ic-ajax' -]; - -var legacyFilesToAppend = [ - 'jquery.js', - 'handlebars.js', - 'ember.js', - 'ic-ajax/dist/named-amd/main.js', - 'ember-data.js', - 'app-shims.js', - 'ember-resolver.js' - ]; - -var qunit = require('broctree-qunit'); - -var testem = pickFiles('tests', { - files: ['testem.js'], - srcDir: 'helpers', - destDir: '/' -}); - -var es6 = compileES6(scripts, { - loaderFile: 'loader/loader.js', - ignoredModules: ignoredModules, - inputFiles: [name + '/**/*.js'], - wrapInEval: true, - outputFile: '/index.js', - legacyFilesToAppend: legacyFilesToAppend -}); - -return module.exports = mergeTrees([index, es6, qunit, testem], { overwrite: true}); +/* global require, module */ + +var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); + +var app = new EmberAddon(); + +// Use `app.import` to add additional libraries to the generated +// output files. +// +// If you need to use different assets in different +// environments, specify an object as the first parameter. That +// object's keys should be the environment name and the values +// should be the asset to use in that environment. +// +// If the library that you are including contains AMD or ES6 +// modules that you would like to import into your application +// please specify an object with the list of modules as keys +// along with the exports of each module as its value. + +module.exports = app.toTree(); diff --git a/README.md b/README.md index 93e241f..46ed31e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,13 @@ -# Work In Progress +# Ember-google-api-client - Work In Progress + +# Installation + +**note: this has not been published yet** +``` +npm install --save-dev ember-google-api-client +``` + +# Usage ## Initialization @@ -70,3 +79,28 @@ egc.update(file) ```javascript egc.destroy(file.id); ``` + +# Collaboration +This section outlines the details of collaborating on this Ember addon. + +## Installation + +* `git clone` this repository +* `npm install` +* `bower install` + +## Running + +* `ember server` +* Visit your app at http://localhost:4200. + +## Running Tests + +* `ember test` +* `ember test --server` + +## Building + +* `ember build` + +For more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/). diff --git a/addon/.gitkeep b/addon/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/addon/egc.js b/addon/egc.js new file mode 100644 index 0000000..9f5836f --- /dev/null +++ b/addon/egc.js @@ -0,0 +1,16 @@ +import Em from 'ember'; +import ReadyMixin from './egc/ready'; +import AuthorizationMixin from './egc/authorization'; +import DriveMixin from './egc/drive'; + +var EGC = Em.Object.extend( + ReadyMixin, + AuthorizationMixin, + DriveMixin, { + + DEBUG: true, + getScript: Em.$.getScript +}); + +Em.EGC = EGC; +export default EGC; diff --git a/lib/egc/authorization.js b/addon/egc/authorization.js similarity index 93% rename from lib/egc/authorization.js rename to addon/egc/authorization.js index 54e03da..a0e98e2 100644 --- a/lib/egc/authorization.js +++ b/addon/egc/authorization.js @@ -1,7 +1,8 @@ // TODO - _gapi put in for testing needs to // handle Em.run.next(). Get rid of it. +/*global gapi*/ -var Promise = Em.RSVP.Promise; +import Em from 'ember'; export default Em.Mixin.create(Em.PromiseProxyMixin, { apiKey: null, @@ -20,7 +21,7 @@ export default Em.Mixin.create(Em.PromiseProxyMixin, { }, setPromise: function() { - var promise = new Promise(function(resolve, reject) { + var promise = new Em.RSVP.Promise(function(resolve, reject) { this.addObserver('authorized', function() { var authorized = this.get('authorized'); if (authorized) { resolve(); } diff --git a/lib/egc/drive.js b/addon/egc/drive.js similarity index 81% rename from lib/egc/drive.js rename to addon/egc/drive.js index 30e913c..c18d067 100644 --- a/lib/egc/drive.js +++ b/addon/egc/drive.js @@ -1,4 +1,6 @@ -import FilesMixin from 'egc/egc/drive/files'; +/*global gapi*/ +import Em from 'ember'; +import FilesMixin from './drive/files'; export default Em.Mixin.create( FilesMixin, { diff --git a/lib/egc/drive/files.js b/addon/egc/drive/files.js similarity index 85% rename from lib/egc/drive/files.js rename to addon/egc/drive/files.js index f98f375..402f4a8 100644 --- a/lib/egc/drive/files.js +++ b/addon/egc/drive/files.js @@ -1,8 +1,10 @@ -import { handleGapiResponse } from 'egc/egc/utils'; -import uploadFile from 'egc/egc/drive/uploadFile'; +/*global gapi*/ -var Promise = Em.RSVP.Promise, - a_slice = Array.prototype.slice; +import Em from 'ember'; +import { handleGapiResponse } from '../utils'; +import uploadFile from './uploadFile'; + +var a_slice = Array.prototype.slice; function extractItems(res) { if (res.items) { return res.items; } @@ -15,7 +17,6 @@ export default Em.Mixin.create({ driveVersion: 'v2', // also in DriveMixin find: function(args) { - var self = this; if (!args) { return this.request('list').then(extractItems); @@ -54,7 +55,7 @@ export default Em.Mixin.create({ var path = '/drive/' + this.get('driveVersion') + '/files/' + id, DEBUG = this.get('DEBUG'); - return new Promise(function(resolve, reject) { + return new Em.RSVP.Promise(function(resolve, reject) { gapi.client.request({ path: path, method: 'DELETE' }) .execute(handleGapiResponse(resolve, reject, DEBUG)); }); @@ -66,7 +67,7 @@ export default Em.Mixin.create({ rest = args.slice(1), DEBUG = this.get('DEBUG'); - return new Promise(function(resolve, reject) { + return new Em.RSVP.Promise(function(resolve, reject) { if (DEBUG) { console.log('sending gapi request', args);} gapi.client.drive diff --git a/lib/egc/drive/uploadFile.js b/addon/egc/drive/uploadFile.js similarity index 95% rename from lib/egc/drive/uploadFile.js rename to addon/egc/drive/uploadFile.js index a5e15ef..84f3a01 100644 --- a/lib/egc/drive/uploadFile.js +++ b/addon/egc/drive/uploadFile.js @@ -1,4 +1,6 @@ -import { handleGapiResponse } from 'egc/egc/utils'; +/*global gapi*/ +import Em from 'ember'; +import { handleGapiResponse } from '../utils'; var boundary = 'foo_bar_baz', delimiter = "\r\n--" + boundary + "\r\n", @@ -62,6 +64,6 @@ function uploadFile(file, opts) { gapi.client.request(params) .execute(handleGapiResponse(resolve, reject, (opts && opts.DEBUG))); }); -}; +} export default uploadFile; diff --git a/lib/egc/ready.js b/addon/egc/ready.js similarity index 95% rename from lib/egc/ready.js rename to addon/egc/ready.js index c086778..e987523 100644 --- a/lib/egc/ready.js +++ b/addon/egc/ready.js @@ -1,3 +1,5 @@ +import Em from 'ember'; + export default Em.Mixin.create({ gapiSourceUrl: 'https://apis.google.com/js/client.js?onload=gapiReady', getScript: null, // ie. $.getScript if using jQuery diff --git a/lib/egc/utils.js b/addon/egc/utils.js similarity index 90% rename from lib/egc/utils.js rename to addon/egc/utils.js index 79322bf..8f7b844 100644 --- a/lib/egc/utils.js +++ b/addon/egc/utils.js @@ -1,3 +1,5 @@ +import Em from 'ember'; + export function handleGapiResponse(resolve, reject, DEBUG) { return function(res) { if (DEBUG) { console.log('gapi response', res); } diff --git a/app/.gitkeep b/app/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/bower.json b/bower.json index 745915b..2f72354 100644 --- a/bower.json +++ b/bower.json @@ -1,15 +1,17 @@ { - "name": "egc", + "name": "ember-google-api-client", "dependencies": { "handlebars": "~1.3.0", - "jquery": "~1.9.1", - "qunit": "~1.12.0", - "ember-qunit": "~0.1.5", - "ember": "1.5.0", - "ember-data": "1.0.0-beta.7", - "ember-resolver": "stefanpenner/ember-jj-abrams-resolver#master", - "ic-ajax": "~1.x", - "loader": "stefanpenner/loader.js#1.0.0", - "ember-cli-shims": "stefanpenner/ember-cli-shims#0.0.1" + "jquery": "^1.11.1", + "ember": "1.7.0", + "ember-data": "1.0.0-beta.10", + "ember-resolver": "~0.1.7", + "loader.js": "stefanpenner/loader.js#1.0.1", + "ember-cli-shims": "stefanpenner/ember-cli-shims#0.0.3", + "ember-cli-test-loader": "rwjblue/ember-cli-test-loader#0.0.4", + "ember-load-initializers": "stefanpenner/ember-load-initializers#0.0.2", + "ember-qunit": "0.1.8", + "ember-qunit-notifications": "0.0.4", + "qunit": "~1.15.0" } -} +} \ No newline at end of file diff --git a/config/environment.js b/config/environment.js new file mode 100644 index 0000000..0dfaed4 --- /dev/null +++ b/config/environment.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function(/* environment, appConfig */) { + return { }; +}; diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5a3d11a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,302 +0,0 @@ -define("egc/egc", - ["egc/egc/ready","egc/egc/authorization","egc/egc/drive","exports"], - function(__dependency1__, __dependency2__, __dependency3__, __exports__) { - "use strict"; - var ReadyMixin = __dependency1__["default"]; - var AuthorizationMixin = __dependency2__["default"]; - var DriveMixin = __dependency3__["default"]; - - var EGC = Em.Object.extend( - ReadyMixin, - AuthorizationMixin, - DriveMixin, { - - DEBUG: true, - getScript: $.getScript - }); - - Ember.EGC = EGC; - __exports__["default"] = EGC; - });define("egc/egc/ready", - ["exports"], - function(__exports__) { - "use strict"; - __exports__["default"] = Em.Mixin.create({ - gapiSourceUrl: 'https://apis.google.com/js/client.js?onload=gapiReady', - getScript: null, // ie. $.getScript if using jQuery - gapiReady: false, - - init: function() { - this._super(); - if (window.gapi) { return this.setReady(); } - window.gapiReady = this.setReady.bind(this); - }, - - setReady: function() { - this.set('gapiReady', true); - }, - - fetchGapi: function() { - var getScript = this.get('getScript'); - if (getScript) { getScript(this.get('gapiSourceUrl')); } - }.observes('getScript', 'gapiSourceUrl').on('init') - }); - });define("egc/egc/authorization", - ["exports"], - function(__exports__) { - "use strict"; - // TODO - _gapi put in for testing needs to - // handle Em.run.next(). Get rid of it. - - var Promise = Em.RSVP.Promise; - - __exports__["default"] = Em.Mixin.create(Em.PromiseProxyMixin, { - apiKey: null, - clientId: null, - scope: null, - - gapiReady: false, - apiKeySetOnGapi: false, - authorized: null, - accessToken: null, - _gapi: null, - - init: function() { - this._super(); - this.setPromise(); - }, - - setPromise: function() { - var promise = new Promise(function(resolve, reject) { - this.addObserver('authorized', function() { - var authorized = this.get('authorized'); - if (authorized) { resolve(); } - if (authorized === false) { reject(); } - }); - }.bind(this)); - - this.set('promise', promise); - }, - - setApiKey: function() { - if (!this.get('gapiReady')) { return; } - - var apiKey = this.get('apiKey'); - if (!apiKey) { return; } - - gapi.client.setApiKey(apiKey); - this.setProperties({ _gapi: gapi, apiKeySetOnGapi: true }); - Em.run.next(this, function() { this.authorize(true); }); - }.observes('gapiReady').on('init'), - - authorize: function(now) { - this.get('_gapi').auth.authorize({ - client_id: this.get('clientId'), - scope: this.get('scope'), - immediate: now - }, this.handlAuthResult.bind(this)); - - this.setPromise(); - return this; - }, - - handlAuthResult: function(res) { - if (res && res.access_token) { return this.set('authorized', true); } - this.set('authorized', false); - }, - - setAccessToken: function() { - if (!this.get('authorized')) { return; } - - this.set('accessToken', gapi.auth.getToken().access_token); - }.observes('authorized'), - - }); - });define("egc/egc/drive", - ["egc/egc/drive/files","exports"], - function(__dependency1__, __exports__) { - "use strict"; - var FilesMixin = __dependency1__["default"]; - - __exports__["default"] = Em.Mixin.create( - FilesMixin, { - - driveVersion: 'v2', - apiKeySetOnGapi: false, - driveReady: false, - - loadDrive: function() { - if (!this.get('apiKeySetOnGapi')) { return; } - - gapi.client.load('drive', this.get('driveVersion'), function() { - this.set('driveReady', true); - }.bind(this)); - }.observes('apiKeySetOnGapi') - - }); - });define("egc/egc/drive/files", - ["egc/egc/utils","egc/egc/drive/uploadFile","exports"], - function(__dependency1__, __dependency2__, __exports__) { - "use strict"; - var handleGapiResponse = __dependency1__.handleGapiResponse; - var uploadFile = __dependency2__["default"]; - - var Promise = Em.RSVP.Promise, - a_slice = Array.prototype.slice; - - function extractItems(res) { - if (res.items) { return res.items; } - return []; - } - - // assumes driveReady is true when requests are made - __exports__["default"] = Em.Mixin.create({ - DEBUG: false, - driveVersion: 'v2', // also in DriveMixin - - find: function(args) { - var self = this; - - if (!args) { - return this.request('list').then(extractItems); - } - - if (typeof args === 'string') { - return this.request('get', { fileId: args }); - } - - if (typeof args === 'object') { - return this.request('list', args).then(extractItems); - } - }, - - insert: function(file) { - if (file.content) { - var params = { - version: this.get('driveVersion'), - DEBUG: this.get('DEBUG') - }; - return uploadFile(file, params); - } - - if (file.id) { return this.patch(file); } - return this.request('insert', { resource: file }); - }, - - update: Em.aliasMethod('insert'), - - patch: function(file) { - return this.request('patch', { fileId: file.id, resource: file }); - }, - - // Google's gapi client sends a POST request instead of DELETE - destroy: function(id) { - var path = '/drive/' + this.get('driveVersion') + '/files/' + id, - DEBUG = this.get('DEBUG'); - - return new Promise(function(resolve, reject) { - gapi.client.request({ path: path, method: 'DELETE' }) - .execute(handleGapiResponse(resolve, reject, DEBUG)); - }); - }, - - request: function() { - var args = a_slice.call(arguments), - method = args[0], - rest = args.slice(1), - DEBUG = this.get('DEBUG'); - - return new Promise(function(resolve, reject) { - if (DEBUG) { console.log('sending gapi request', args);} - - gapi.client.drive - .files[method].apply(null, rest) - .execute(handleGapiResponse(resolve, reject, DEBUG)); - }); - } - }); - });define("egc/egc/utils", - ["exports"], - function(__exports__) { - "use strict"; - function handleGapiResponse(resolve, reject, DEBUG) { - return function(res) { - if (DEBUG) { console.log('gapi response', res); } - if (res && res.error) { return Em.run(null, reject, res); } - Em.run(null, resolve, res); - }; - } - - __exports__.handleGapiResponse = handleGapiResponse; - });define("egc/egc/drive/uploadFile", - ["egc/egc/utils","exports"], - function(__dependency1__, __exports__) { - "use strict"; - var handleGapiResponse = __dependency1__.handleGapiResponse; - - var boundary = 'foo_bar_baz', - delimiter = "\r\n--" + boundary + "\r\n", - closeDelimeter = "\r\n--" + boundary + "--"; - - function createRequestBody(file) { - var specFile = Em.copy(file); - delete specFile.content; - - return delimiter + - 'Content-Type: application/json\r\n\r\n' + - JSON.stringify(specFile) + - delimiter + - 'Content-Type: ' + file.mimeType + '\r\n\r\n' + - file.content + - closeDelimeter; - } - - function uploadFile(file, opts) { - var version = 'v2', uploadPath, params; - - if (!file) { throw new Error('A file resource is required.'); } - if (opts && opts.version) { version = opts.version; } - uploadPath = '/upload/drive/' + version + '/files'; - - params = { - path: uploadPath, - method: 'POST', - params: { uploadType: 'multipart' }, - headers: { - 'Content-Type': 'multipart/related; boundary="' + boundary + '"' - } - }; - - if (opts) { - if (opts.uploadType) { params.params.uploadType = opts.uploadType; } - if (opts.contentType) { params.headers['Content-Type'] = opts.contentType; } - if (opts.contentLength) { params.headers['Content-Length'] = opts.contentLength; } - if (opts.uploadType === 'media') { - if (file.mimeType) { - params.headers['Content-Type'] = file.mimeType; - } - - if (file.content) { - params.body = file.content; - params.headers['Content-Length'] = file.content.length; - } - } - } - - if (file.id) { - params.path += '/' + file.id; - params.method = 'PUT'; - } - - if (params.params.uploadType === 'multipart') { - params.body = createRequestBody(file); - } - - return new Em.RSVP.Promise(function(resolve, reject) { - gapi.client.request(params) - .execute(handleGapiResponse(resolve, reject, (opts && opts.DEBUG))); - }); - }; - - __exports__["default"] = uploadFile; - }); diff --git a/index.js b/index.js new file mode 100644 index 0000000..293df5f --- /dev/null +++ b/index.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = { + name: 'ember-google-api-client' +}; diff --git a/lib/egc.js b/lib/egc.js deleted file mode 100644 index df0e09c..0000000 --- a/lib/egc.js +++ /dev/null @@ -1,15 +0,0 @@ -import ReadyMixin from 'egc/egc/ready'; -import AuthorizationMixin from 'egc/egc/authorization'; -import DriveMixin from 'egc/egc/drive'; - -var EGC = Em.Object.extend( - ReadyMixin, - AuthorizationMixin, - DriveMixin, { - - DEBUG: true, - getScript: $.getScript -}); - -Ember.EGC = EGC; -export default EGC; diff --git a/package.json b/package.json index fe4178b..2cb5b21 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,39 @@ { - "name": "egc", + "name": "ember-google-api-client", "version": "0.0.0", - "private": true, "directories": { - "test": "test" + "doc": "doc", + "test": "tests" }, "scripts": { "start": "ember server", "build": "ember build", "test": "ember test" }, + "repository": "https://github.com/stefanpenner/ember-cli", "engines": { "node": ">= 0.10.0" }, "author": "", "license": "MIT", "devDependencies": { - "ember-cli" : "0.0.23", - "broccoli-template": "~0.1.1", - "broccoli-static-compiler": "0.1.4", - "broccoli-es6-concatenator": "0.1.4", - "broccoli-bower": "^0.2.0", - "broctree-qunit": "git://github.com/monocle/broctree-qunit" + "body-parser": "^1.2.0", + "broccoli-asset-rev": "0.3.1", + "broccoli-ember-hbs-template-compiler": "^1.6.1", + "ember-cli": "0.1.2", + "ember-cli-content-security-policy": "0.3.0", + "ember-export-application-global": "^1.0.0", + "ember-cli-ic-ajax": "0.1.1", + "ember-cli-inject-live-reload": "^1.3.0", + "ember-cli-qunit": "0.1.0", + "ember-data": "1.0.0-beta.10", + "express": "^4.8.5", + "glob": "^4.0.5" + }, + "keywords": [ + "ember-addon" + ], + "ember-addon": { + "configPath": "tests/dummy/config" } } diff --git a/testem.json b/testem.json index 0fb2f1e..eff93f9 100644 --- a/testem.json +++ b/testem.json @@ -1,5 +1,11 @@ { "framework": "qunit", "test_page": "tests/index.html", - "launch_in_ci": ["PhantomJS", "Chrome"] + "launch_in_ci": [ + "PhantomJS" + ], + "launch_in_dev": [ + "PhantomJS", + "Chrome" + ] } diff --git a/tests/dummy/.jshintrc b/tests/dummy/.jshintrc new file mode 100644 index 0000000..f01a192 --- /dev/null +++ b/tests/dummy/.jshintrc @@ -0,0 +1,33 @@ +{ + "predef": [ + "document", + "window", + "-Promise", + "gapi" + ], + "browser" : true, + "boss" : true, + "curly": true, + "debug": false, + "devel": true, + "eqeqeq": true, + "evil": true, + "forin": false, + "immed": false, + "laxbreak": false, + "newcap": true, + "noarg": true, + "noempty": false, + "nonew": false, + "nomen": false, + "onevar": false, + "plusplus": false, + "regexp": false, + "undef": true, + "sub": true, + "strict": false, + "white": false, + "eqnull": true, + "esnext": true, + "unused": true +} diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js new file mode 100644 index 0000000..757df38 --- /dev/null +++ b/tests/dummy/app/app.js @@ -0,0 +1,16 @@ +import Ember from 'ember'; +import Resolver from 'ember/resolver'; +import loadInitializers from 'ember/load-initializers'; +import config from './config/environment'; + +Ember.MODEL_FACTORY_INJECTIONS = true; + +var App = Ember.Application.extend({ + modulePrefix: config.modulePrefix, + podModulePrefix: config.podModulePrefix, + Resolver: Resolver +}); + +loadInitializers(App, config.modulePrefix); + +export default App; diff --git a/tests/dummy/app/components/.gitkeep b/tests/dummy/app/components/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/controllers/.gitkeep b/tests/dummy/app/controllers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/helpers/.gitkeep b/tests/dummy/app/helpers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/index.html b/tests/dummy/app/index.html new file mode 100644 index 0000000..b7d8600 --- /dev/null +++ b/tests/dummy/app/index.html @@ -0,0 +1,21 @@ + + + + + + Dummy + + + + {{content-for 'head'}} + + + + + + {{content-for 'body'}} + + + + + diff --git a/tests/dummy/app/models/.gitkeep b/tests/dummy/app/models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js new file mode 100644 index 0000000..cef554b --- /dev/null +++ b/tests/dummy/app/router.js @@ -0,0 +1,11 @@ +import Ember from 'ember'; +import config from './config/environment'; + +var Router = Ember.Router.extend({ + location: config.locationType +}); + +Router.map(function() { +}); + +export default Router; diff --git a/tests/dummy/app/routes/.gitkeep b/tests/dummy/app/routes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/styles/.gitkeep b/tests/dummy/app/styles/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/styles/app.css b/tests/dummy/app/styles/app.css new file mode 100644 index 0000000..9adb5ad --- /dev/null +++ b/tests/dummy/app/styles/app.css @@ -0,0 +1,3 @@ +html, body { + margin: 20px; +} diff --git a/tests/dummy/app/templates/.gitkeep b/tests/dummy/app/templates/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs new file mode 100644 index 0000000..d08c11f --- /dev/null +++ b/tests/dummy/app/templates/application.hbs @@ -0,0 +1,3 @@ +

Welcome to Ember.js

+ +{{outlet}} diff --git a/tests/dummy/app/templates/components/.gitkeep b/tests/dummy/app/templates/components/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/app/views/.gitkeep b/tests/dummy/app/views/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js new file mode 100644 index 0000000..bc0d538 --- /dev/null +++ b/tests/dummy/config/environment.js @@ -0,0 +1,47 @@ +/* jshint node: true */ + +module.exports = function(environment) { + var ENV = { + modulePrefix: 'dummy', + environment: environment, + baseURL: '/', + locationType: 'auto', + EmberENV: { + FEATURES: { + // Here you can enable experimental features on an ember canary build + // e.g. 'with-controller': true + } + }, + + APP: { + // Here you can pass flags/options to your application instance + // when it is created + } + }; + + if (environment === 'development') { + // ENV.APP.LOG_RESOLVER = true; + ENV.APP.LOG_ACTIVE_GENERATION = true; + // ENV.APP.LOG_TRANSITIONS = true; + // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; + ENV.APP.LOG_VIEW_LOOKUPS = true; + } + + if (environment === 'test') { + // Testem prefers this... + ENV.baseURL = '/'; + ENV.locationType = 'auto'; + + // keep test console output quieter + ENV.APP.LOG_ACTIVE_GENERATION = false; + ENV.APP.LOG_VIEW_LOOKUPS = false; + + ENV.APP.rootElement = '#ember-testing'; + } + + if (environment === 'production') { + + } + + return ENV; +}; diff --git a/tests/dummy/public/.gitkeep b/tests/dummy/public/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/dummy/public/crossdomain.xml b/tests/dummy/public/crossdomain.xml new file mode 100644 index 0000000..29a035d --- /dev/null +++ b/tests/dummy/public/crossdomain.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/tests/dummy/public/robots.txt b/tests/dummy/public/robots.txt new file mode 100644 index 0000000..ee2cc21 --- /dev/null +++ b/tests/dummy/public/robots.txt @@ -0,0 +1,3 @@ +# robotstxt.org/ + +User-agent: * diff --git a/tests/helpers/resolver.js b/tests/helpers/resolver.js index 53936bb..28f4ece 100644 --- a/tests/helpers/resolver.js +++ b/tests/helpers/resolver.js @@ -1,9 +1,11 @@ import Resolver from 'ember/resolver'; +import config from '../../config/environment'; var resolver = Resolver.create(); resolver.namespace = { - modulePrefix: 'egc' + modulePrefix: config.modulePrefix, + podModulePrefix: config.podModulePrefix }; export default resolver; diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js new file mode 100644 index 0000000..7cd4320 --- /dev/null +++ b/tests/helpers/start-app.js @@ -0,0 +1,25 @@ +import Ember from 'ember'; +import Application from '../../app'; +import Router from '../../router'; +import config from '../../config/environment'; + +export default function startApp(attrs) { + var App; + + var attributes = Ember.merge({}, config.APP); + attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; + + Router.reopen({ + location: 'none' + }); + + Ember.run(function() { + App = Application.create(attributes); + App.setupForTesting(); + App.injectTestHelpers(); + }); + + App.reset(); // this shouldn't be needed, i want to be able to "start an app at a specific URL" + + return App; +} diff --git a/tests/index.html b/tests/index.html index 47b0826..85990e1 100644 --- a/tests/index.html +++ b/tests/index.html @@ -2,19 +2,44 @@ - Egc Tests + + Dummy Tests + + - - - - + {{content-for 'head'}} + {{content-for 'test-head'}} + + + + +
- + + {{content-for 'body'}} + {{content-for 'test-body'}} + + + + + diff --git a/tests/test-helper.js b/tests/test-helper.js new file mode 100644 index 0000000..092f3ad --- /dev/null +++ b/tests/test-helper.js @@ -0,0 +1,37 @@ +import resolver from './helpers/resolver'; +import { + setResolver +} from 'ember-qunit'; + +setResolver(resolver); + +document.write('
'); + +QUnit.config.urlConfig.push({ id: 'nocontainer', label: 'Hide container'}); +var containerVisibility = QUnit.urlParams.nocontainer ? 'hidden' : 'visible'; +document.getElementById('ember-testing-container').style.visibility = containerVisibility; + +// Add Function bind polyfill to fix phantom tests +if (!Function.prototype.bind) { + Function.prototype.bind = function(oThis) { + if (typeof this !== 'function') { + // closest thing possible to the ECMAScript 5 + // internal IsCallable function + throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + FNOP = function() {}, + fBound = function() { + return fToBind.apply(this instanceof FNOP && oThis ? this + : oThis, + aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + FNOP.prototype = this.prototype; + fBound.prototype = new FNOP(); + + return fBound; + }; +} diff --git a/tests/unit/.gitkeep b/tests/unit/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/egc-test.js b/tests/unit/egc-test.js similarity index 63% rename from tests/egc-test.js rename to tests/unit/egc-test.js index 2cdada9..0bdc9d5 100644 --- a/tests/egc-test.js +++ b/tests/unit/egc-test.js @@ -1,4 +1,5 @@ -import _ from 'egc/egc'; +import Em from 'ember'; +import _ from 'ember-google-api-client/egc'; module("EGC", { setup: function() { @@ -9,4 +10,3 @@ module("EGC", { test("it lives in Ember's namespace", function() { ok(Em.EGC); }); - diff --git a/tests/egc/authorization-test.js b/tests/unit/egc/authorization-test.js similarity index 96% rename from tests/egc/authorization-test.js rename to tests/unit/egc/authorization-test.js index 6a1761e..2af6e74 100644 --- a/tests/egc/authorization-test.js +++ b/tests/unit/egc/authorization-test.js @@ -1,4 +1,5 @@ -import AuthorizationMixin from 'egc/egc/authorization'; +import Em from 'ember'; +import AuthorizationMixin from 'ember-google-api-client/egc/authorization'; var EGC = Em.Object.extend(AuthorizationMixin), egc, gapi; @@ -83,7 +84,7 @@ test("accessToken is not set if unauthorized", function() { createEgc(); egc.set('authorized', false); - ok(!egc.get('accessToken')) + ok(!egc.get('accessToken')); }); diff --git a/tests/egc/drive-test.js b/tests/unit/egc/drive-test.js similarity index 89% rename from tests/egc/drive-test.js rename to tests/unit/egc/drive-test.js index 1fea6b6..bfb29db 100644 --- a/tests/egc/drive-test.js +++ b/tests/unit/egc/drive-test.js @@ -1,4 +1,5 @@ -import DriveMixin from 'egc/egc/drive'; +import Em from 'ember'; +import DriveMixin from 'ember-google-api-client/egc/drive'; var EGC = Em.Object.extend(DriveMixin), egc, gapi; @@ -36,5 +37,3 @@ test("loads drive into gapi when apiKey has been set on gapi", function() { egc.set('apiKeySetOnGapi', true); }); - - diff --git a/tests/egc/drive/files-test.js b/tests/unit/egc/drive/files-test.js similarity index 98% rename from tests/egc/drive/files-test.js rename to tests/unit/egc/drive/files-test.js index 87afe25..ef1ddf8 100644 --- a/tests/egc/drive/files-test.js +++ b/tests/unit/egc/drive/files-test.js @@ -1,4 +1,5 @@ -import DriveFilesMixin from 'egc/egc/drive/files'; +import Em from 'ember'; +import DriveFilesMixin from 'ember-google-api-client/egc/drive/files'; var EGC = Em.Object.extend(DriveFilesMixin), egc, gapi; @@ -206,5 +207,3 @@ asyncTest("#destroy sends a gapi delete client request", function() { deepEqual(res, {}); }); }); - - diff --git a/tests/egc/drive/uploadFile-test.js b/tests/unit/egc/drive/uploadFile-test.js similarity index 96% rename from tests/egc/drive/uploadFile-test.js rename to tests/unit/egc/drive/uploadFile-test.js index 4aa5a62..4533102 100644 --- a/tests/egc/drive/uploadFile-test.js +++ b/tests/unit/egc/drive/uploadFile-test.js @@ -1,4 +1,5 @@ -import uploadFile from 'egc/egc/drive/uploadFile'; +import Em from 'ember'; +import uploadFile from 'ember-google-api-client/egc/drive/uploadFile'; var reqObj = { execute: Em.K }, gapi; @@ -119,7 +120,7 @@ asyncTest("response is resolved", function() { uploadFile(file).then(function(res) { start(); equal(res, file); - }) + }); }); asyncTest("error response is rejected", function() { @@ -134,5 +135,5 @@ asyncTest("error response is rejected", function() { uploadFile({}).catch(function(res) { start(); equal(res, resp); - }) + }); }); diff --git a/tests/egc/ready-test.js b/tests/unit/egc/ready-test.js similarity index 91% rename from tests/egc/ready-test.js rename to tests/unit/egc/ready-test.js index 0a71d32..a7f249c 100644 --- a/tests/egc/ready-test.js +++ b/tests/unit/egc/ready-test.js @@ -1,4 +1,5 @@ -import ReadyMixin from 'egc/egc/ready'; +import Em from 'ember'; +import ReadyMixin from 'ember-google-api-client/egc/ready'; var EGC = Em.Object.extend(ReadyMixin), egc; @@ -36,4 +37,3 @@ test("will call getScript with gapi source URL if window.gapi does not exist", f var getScript = function(url) { equal(url, egc.get('gapiSourceUrl')); }; EGC.create({getScript: getScript}); }); - diff --git a/vendor/.gitkeep b/vendor/.gitkeep new file mode 100644 index 0000000..e69de29 From 1e7e4e973ba3c81e6c70d3afcafed5f057db32ca Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Sun, 19 Oct 2014 10:14:23 +0100 Subject: [PATCH 2/3] updating stray dot files --- tests/.jshintrc | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/.jshintrc b/tests/.jshintrc index 4dcfd10..6ebf71a 100644 --- a/tests/.jshintrc +++ b/tests/.jshintrc @@ -4,14 +4,11 @@ "window", "location", "setTimeout", - "Ember", - "Em", "$", + "-Promise", "QUnit", "define", "console", - "require", - "requirejs", "equal", "notEqual", "notStrictEqual", @@ -27,6 +24,9 @@ "ok", "strictEqual", "module", + "moduleFor", + "moduleForComponent", + "moduleForModel", "process", "expect", "visit", @@ -34,16 +34,21 @@ "fillIn", "click", "keyEvent", + "triggerEvent", "find", + "findWithAssert", "wait", "DS", - "keyEvent", "isolatedContainer", - "startApp" + "startApp", + "andThen", + "currentURL", + "currentPath", + "currentRouteName" ], - "node" : false, - "browser" : false, - "boss" : true, + "node": false, + "browser": false, + "boss": true, "curly": false, "debug": false, "devel": false, From 557eab6b1fe83866c17f444dd4adb8cd97af4a86 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Sun, 19 Oct 2014 10:14:36 +0100 Subject: [PATCH 3/3] removing old unused test helpers --- tests/helpers/test-helper.js | 26 -------------------------- tests/helpers/test-loader.js | 6 ------ tests/helpers/testem.js | 1 - 3 files changed, 33 deletions(-) delete mode 100644 tests/helpers/test-helper.js delete mode 100644 tests/helpers/test-loader.js delete mode 100644 tests/helpers/testem.js diff --git a/tests/helpers/test-helper.js b/tests/helpers/test-helper.js deleted file mode 100644 index 14f4f61..0000000 --- a/tests/helpers/test-helper.js +++ /dev/null @@ -1,26 +0,0 @@ -Ember.testing = true; - -import resolver from './resolver'; -// require('ember-qunit').setResolver(resolver); - -function exists(selector) { - return !!find(selector).length; -} - -function getAssertionMessage(actual, expected, message) { - return message || QUnit.jsDump.parse(expected) + " expected but was " + QUnit.jsDump.parse(actual); -} - -function equal(actual, expected, message) { - message = getAssertionMessage(actual, expected, message); - QUnit.equal.call(this, actual, expected, message); -} - -function strictEqual(actual, expected, message) { - message = getAssertionMessage(actual, expected, message); - QUnit.strictEqual.call(this, actual, expected, message); -} - -window.exists = exists; -window.equal = equal; -window.strictEqual = strictEqual; diff --git a/tests/helpers/test-loader.js b/tests/helpers/test-loader.js deleted file mode 100644 index 1019220..0000000 --- a/tests/helpers/test-loader.js +++ /dev/null @@ -1,6 +0,0 @@ -// TODO: load based on params -Ember.keys(requirejs._eak_seen).filter(function(key) { - return (/\-test/).test(key); -}).forEach(function(moduleName) { - require(moduleName, null, null, true); -}); diff --git a/tests/helpers/testem.js b/tests/helpers/testem.js deleted file mode 100644 index ed53894..0000000 --- a/tests/helpers/testem.js +++ /dev/null @@ -1 +0,0 @@ -/* stub */