ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [36/50] [abbrv] ambari git commit: AMBARI-13939. Implement Em.computed macros (onechiporenko)
Date Wed, 18 Nov 2015 16:51:32 GMT
AMBARI-13939. Implement Em.computed macros (onechiporenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/15ffc016
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/15ffc016
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/15ffc016

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 15ffc016c0beafd59c0db3208042c9a367d43230
Parents: 6db7de9
Author: Oleg Nechiporenko <onechiporenko@apache.org>
Authored: Wed Nov 18 12:22:05 2015 +0200
Committer: Oleg Nechiporenko <onechiporenko@apache.org>
Committed: Wed Nov 18 12:22:05 2015 +0200

----------------------------------------------------------------------
 ambari-web/app/app.js                        |   1 +
 ambari-web/app/assets/test/tests.js          |   1 +
 ambari-web/app/utils/ember_computed.js       | 462 ++++++++++++++++++
 ambari-web/app/utils/ember_reopen.js         |  32 +-
 ambari-web/test/utils/ember_computed_test.js | 551 ++++++++++++++++++++++
 5 files changed, 1016 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/15ffc016/ambari-web/app/app.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/app.js b/ambari-web/app/app.js
index 12b25b9..dd9570c 100644
--- a/ambari-web/app/app.js
+++ b/ambari-web/app/app.js
@@ -18,6 +18,7 @@
 
 // Application bootstrapper
 require('utils/ember_reopen');
+require('utils/ember_computed');
 var stringUtils = require('utils/string_utils');
 
 module.exports = Em.Application.create({

http://git-wip-us.apache.org/repos/asf/ambari/blob/15ffc016/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index a9edd19..2155ce5 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -166,6 +166,7 @@ var files = [
   'test/utils/data_manipulation_test',
   'test/utils/config_test',
   'test/utils/db_test',
+  'test/utils/ember_computed_test',
   'test/utils/ember_reopen_test',
   'test/utils/form_field_test',
   'test/utils/host_progress_popup_test',

http://git-wip-us.apache.org/repos/asf/ambari/blob/15ffc016/ambari-web/app/utils/ember_computed.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ember_computed.js b/ambari-web/app/utils/ember_computed.js
new file mode 100644
index 0000000..d79c997
--- /dev/null
+++ b/ambari-web/app/utils/ember_computed.js
@@ -0,0 +1,462 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var computed = Em.computed;
+var get = Em.get;
+var makeArray = Em.makeArray;
+
+var dataUtils = require('utils/data_manipulation');
+
+function getProperties(self, propertyNames) {
+  var ret = {};
+  for (var i = 0; i < propertyNames.length; i++) {
+    ret[propertyNames[i]] = get(self, propertyNames[i]);
+  }
+  return ret;
+}
+
+function generateComputedWithProperties(macro) {
+  return function () {
+    var properties = [].slice.call(arguments);
+    var computedFunc = computed(function () {
+      return macro.apply(this, [getProperties(this, properties)]);
+    });
+
+    return computedFunc.property.apply(computedFunc, properties);
+  };
+}
+
+/**
+ *
+ * A computed property that returns true if the provided dependent property
+ * is equal to the given value.
+ * Example*
+ * ```javascript
+ * var Hamster = Ember.Object.extend({
+ *    napTime: Ember.computed.equal('state', 'sleepy')
+ *  });
+ * var hamster = Hamster.create();
+ * hamster.get('napTime'); // false
+ * hamster.set('state', 'sleepy');
+ * hamster.get('napTime'); // true
+ * hamster.set('state', 'hungry');
+ * hamster.get('napTime'); // false
+ * ```
+ * @method equal
+ * @param {String} dependentKey
+ * @param {String|Number|Object} value
+ * @return {Ember.ComputedProperty} computed property which returns true if
+ * the original value for property is equal to the given value.
+ * @public
+ */
+computed.equal = function (dependentKey, value) {
+  return computed(dependentKey, function () {
+    return get(this, dependentKey) === value;
+  }).cacheable();
+};
+
+/**
+ * A computed property that returns true if the provided dependent property is not equal
to the given value
+ *
+ * @method notEqual
+ * @param {string} dependentKey
+ * @param {*} value
+ * @returns {Ember.ComputedProperty}
+ */
+computed.notEqual = function (dependentKey, value) {
+  return computed(dependentKey, function () {
+    return get(this, dependentKey) !== value;
+  });
+};
+
+/**
+ * A computed property that returns true if provided dependent properties are equal to the
each other
+ *
+ * @method equalProperties
+ * @param {string} dependentKey1
+ * @param {string} dependentKey2
+ * @returns {Ember.ComputedProperty}
+ */
+computed.equalProperties = function (dependentKey1, dependentKey2) {
+  return computed(dependentKey1, dependentKey2, function () {
+    return get(this, dependentKey1) === get(this, dependentKey2);
+  });
+};
+
+/**
+ * A computed property that returns true if provided dependent properties are not equal to
the each other
+ *
+ * @method notEqualProperties
+ * @param {string} dependentKey1
+ * @param {string} dependentKey2
+ * @returns {Ember.ComputedProperty}
+ */
+computed.notEqualProperties = function (dependentKey1, dependentKey2) {
+  return computed(dependentKey1, dependentKey2, function () {
+    return get(this, dependentKey1) !== get(this, dependentKey2);
+  });
+};
+
+/**
+ * A computed property that returns grouped collection's items by propertyName-value
+ *
+ * @method groupBy
+ * @param {string} collectionKey
+ * @param {string} propertyName
+ * @returns {Ember.ComputedProperty}
+ */
+computed.groupBy = function (collectionKey, propertyName) {
+  return computed(collectionKey + '.@each.' + propertyName, function () {
+    var collection = get(this, collectionKey);
+    return dataUtils.groupPropertyValues(collection, propertyName);
+  });
+};
+
+/**
+ * A computed property that returns filtered collection by propertyName values-list
+ * Wrapper to filterProperty-method that allows using list of values to filter
+ *
+ * @method filterByMany
+ * @param {string} collectionKey
+ * @param {string} propertyName
+ * @param {array} valuesToFilter
+ * @returns {Ember.ComputedProperty}
+ */
+computed.filterByMany = function (collectionKey, propertyName, valuesToFilter) {
+  return computed(collectionKey + '.@each.' + propertyName, function () {
+    var collection = get(this, collectionKey);
+    return dataUtils.filterPropertyValues(collection, propertyName, makeArray(valuesToFilter));
+  });
+};
+
+/**
+ * A computed property that returns collection without elements with value that is in <code>valuesToReject</code>
+ * Exclude objects from <code>collection</code> if its <code>key</code>
exist in <code>valuesToReject</code>
+ *
+ * @method rejectMany
+ * @param {string} collectionKey
+ * @param {string} propertyName
+ * @param {array} valuesToReject
+ * @returns {Ember.ComputedProperty}
+ */
+computed.rejectMany = function (collectionKey, propertyName, valuesToReject) {
+  return computed(collectionKey + '.@each.' + propertyName, function () {
+    var collection = get(this, collectionKey);
+    return dataUtils.rejectPropertyValues(collection, propertyName, makeArray(valuesToReject));
+  });
+};
+
+/**
+ * A computed property that returns trueValue if dependent value is true and falseValue otherwise
+ *
+ * @method ifThenElse
+ * @param {string} dependentKey
+ * @param {*} trueValue
+ * @param {*} falseValue
+ * @returns {Ember.ComputedProperty}
+ */
+computed.ifThenElse = function (dependentKey, trueValue, falseValue) {
+  return computed(dependentKey, function () {
+    return get(this, dependentKey) ? trueValue : falseValue;
+  });
+};
+
+/**
+ * A computed property that is equal to the logical 'and'
+ * Takes any number of arguments
+ * Returns true if all of them are truly, false - otherwise
+ *
+ * @method and
+ * @returns {Ember.ComputedProperty}
+ */
+computed.and = generateComputedWithProperties(function (properties) {
+  var value;
+  for (var key in properties) {
+    value = properties[key];
+    if (properties.hasOwnProperty(key) && !value) {
+      return false;
+    }
+  }
+  return value;
+});
+
+/**
+ * A computed property that is equal to the logical 'or'
+ * Takes any number of arguments
+ * Returns true if at least one of them is truly, false - otherwise
+ *
+ * @method or
+ * @returns {Ember.ComputedProperty}
+ */
+computed.or = generateComputedWithProperties(function (properties) {
+  var value;
+  for (var key in properties) {
+    value = properties[key];
+    if (properties.hasOwnProperty(key) && value) {
+      return value;
+    }
+  }
+  return value;
+});
+
+/**
+ * A computed property that returns sum on the dependent properties values
+ * Takes any number of arguments
+ *
+ * @method sumProperties
+ * @returns {Ember.ComputedProperty}
+ */
+computed.sumProperties = generateComputedWithProperties(function (properties) {
+  var sum = 0;
+  for (var key in properties) {
+    if (properties.hasOwnProperty(key)) {
+      sum += properties[key];
+    }
+  }
+  return sum;
+});
+
+/**
+ * A computed property that returns true if dependent value is greater or equal to the needed
value
+ *
+ * @method gte
+ * @param {string} dependentKey
+ * @param {*} value
+ * @returns {Ember.ComputedProperty}
+ */
+computed.gte = function (dependentKey, value) {
+  return computed(dependentKey, function () {
+    return get(this, dependentKey) >= value;
+  });
+};
+
+/**
+ * A computed property that returns true if first dependent property is greater or equal
to the second dependent property
+ *
+ * @method gteProperties
+ * @param {string} dependentKey1
+ * @param {string} dependentKey2
+ * @returns {Ember.ComputedProperty}
+ */
+computed.gteProperties = function (dependentKey1, dependentKey2) {
+  return computed(dependentKey1, dependentKey2, function () {
+    return get(this, dependentKey1) >= get(this, dependentKey2);
+  });
+};
+
+/**
+ * A computed property that returns true if dependent property is less or equal to the needed
value
+ *
+ * @method lte
+ * @param {string} dependentKey
+ * @param {*} value
+ * @returns {Ember.ComputedProperty}
+ */
+computed.lte = function (dependentKey, value) {
+  return computed(dependentKey, function () {
+    return get(this, dependentKey) <= value;
+  });
+};
+
+/**
+ * A computed property that returns true if first dependent property is less or equal to
the second dependent property
+ *
+ * @method lteProperties
+ * @param {string} dependentKey1
+ * @param {string} dependentKey2
+ * @returns {Ember.ComputedProperty}
+ */
+computed.lteProperties = function (dependentKey1, dependentKey2) {
+  return computed(dependentKey1, dependentKey2, function () {
+    return get(this, dependentKey1) <= get(this, dependentKey2);
+  });
+};
+
+/**
+ * A computed property that returns true if dependent value is greater than the needed value
+ *
+ * @method gt
+ * @param {string} dependentKey
+ * @param {*} value
+ * @returns {Ember.ComputedProperty}
+ */
+computed.gt = function (dependentKey, value) {
+  return computed(dependentKey, function () {
+    return get(this, dependentKey) > value;
+  });
+};
+
+/**
+ * A computed property that returns true if first dependent property is greater than the
second dependent property
+ *
+ * @method gtProperties
+ * @param {string} dependentKey1
+ * @param {string} dependentKey2
+ * @returns {Ember.ComputedProperty}
+ */
+computed.gtProperties = function (dependentKey1, dependentKey2) {
+  return computed(dependentKey1, dependentKey2, function () {
+    return get(this, dependentKey1) > get(this, dependentKey2);
+  });
+};
+
+/**
+ * A computed property that returns true if dependent value is less than the needed value
+ *
+ * @method lt
+ * @param {string} dependentKey
+ * @param {*} value
+ * @returns {Ember.ComputedProperty}
+ */
+computed.lt = function (dependentKey, value) {
+  return computed(dependentKey, function () {
+    return get(this, dependentKey) < value;
+  });
+};
+
+/**
+ * A computed property that returns true if first dependent property is less than the second
dependent property
+ *
+ * @method gtProperties
+ * @param {string} dependentKey1
+ * @param {string} dependentKey2
+ * @returns {Ember.ComputedProperty}
+ */
+computed.ltProperties = function (dependentKey1, dependentKey2) {
+  return computed(dependentKey1, dependentKey2, function () {
+    return get(this, dependentKey1) < get(this, dependentKey2);
+  });
+};
+
+/**
+ * A computed property that returns true if dependent property is match to the needed regular
expression
+ *
+ * @method match
+ * @param {string} dependentKey
+ * @param {RegExp} regexp
+ * @returns {Ember.ComputedProperty}
+ */
+computed.match = function (dependentKey, regexp) {
+  return computed(dependentKey, function () {
+    var value = get(this, dependentKey);
+    return regexp.test(value);
+  });
+};
+
+/**
+ * A computed property that returns true of some collection's item has property with needed
value
+ *
+ * @method someBy
+ * @param {string} collectionKey
+ * @param {string} propertyName
+ * @param {*} neededValue
+ * @returns {Ember.ComputedProperty}
+ */
+computed.someBy = function (collectionKey, propertyName, neededValue) {
+  return computed(collectionKey + '.@each.' + propertyName, function () {
+    return get(this, collectionKey).someProperty(propertyName, neededValue);
+  });
+};
+
+/**
+ * A computed property that returns true of all collection's items have property with needed
value
+ *
+ * @method everyBy
+ * @param {string} collectionKey
+ * @param {string} propertyName
+ * @param {*} neededValue
+ * @returns {Ember.ComputedProperty}
+ */
+computed.everyBy = function (collectionKey, propertyName, neededValue) {
+  return computed(collectionKey + '.@each.' + propertyName, function () {
+    return get(this, collectionKey).everyProperty(propertyName, neededValue);
+  });
+};
+
+/**
+ * A computed property that returns array with values of named property on all items in the
collection
+ *
+ * @method mapBy
+ * @param {string} collectionKey
+ * @param {string} propertyName
+ * @returns {Ember.ComputedProperty}
+ */
+computed.mapBy = function (collectionKey, propertyName) {
+  return computed(collectionKey + '.@each.' + propertyName, function () {
+    return get(this, collectionKey).mapProperty(propertyName);
+  });
+};
+
+/**
+ * A computed property that returns array with collection's items that have needed property
value
+ *
+ * @method filterBy
+ * @param {string} collectionKey
+ * @param {string} propertyName
+ * @param {*} neededValue
+ * @returns {Ember.ComputedProperty}
+ */
+computed.filterBy = function (collectionKey, propertyName, neededValue) {
+  return computed(collectionKey + '.@each.' + propertyName, function () {
+    return get(this, collectionKey).filterProperty(propertyName, neededValue);
+  });
+};
+
+/**
+ * A computed property that returns first collection's item that has needed property value
+ *
+ * @method findBy
+ * @param {string} collectionKey
+ * @param {string} propertyName
+ * @param {*} neededValue
+ * @returns {Ember.ComputedProperty}
+ */
+computed.findBy = function (collectionKey, propertyName, neededValue) {
+  return computed(collectionKey + '.@each.' + propertyName, function () {
+    return get(this, collectionKey).findProperty(propertyName, neededValue);
+  });
+};
+
+/**
+ * A computed property that returns value equal to the dependent
+ * Should be used as 'short-name' for deeply-nested values
+ *
+ * @method alias
+ * @param {string} dependentKey
+ * @returns {Ember.ComputedProperty}
+ */
+computed.alias = function (dependentKey) {
+  return computed(dependentKey, function () {
+    return get(this, dependentKey);
+  })
+};
+
+/**
+ * A computed property that returns true if dependent property exists in the needed values
+ *
+ * @method existsIn
+ * @param {string} dependentKey
+ * @param {array} neededValues
+ * @returns {Ember.ComputedProperty}
+ */
+computed.existsIn = function (dependentKey, neededValues) {
+  return computed(dependentKey, function () {
+    var value = get(this, dependentKey);
+    return makeArray(neededValues).contains(value);
+  })
+};
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/15ffc016/ambari-web/app/utils/ember_reopen.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ember_reopen.js b/ambari-web/app/utils/ember_reopen.js
index 4f3f1dd..bf14b6b 100644
--- a/ambari-web/app/utils/ember_reopen.js
+++ b/ambari-web/app/utils/ember_reopen.js
@@ -216,34 +216,4 @@ Em.View.reopen({
 
 Ember.TextArea.reopen({
   attributeBindings: ['readonly']
-});
-
-/**
- *
- * A computed property that returns true if the provided dependent property
- * is equal to the given value.
- * Example*
- * ```javascript
- * var Hamster = Ember.Object.extend({
- *    napTime: Ember.computed.equal('state', 'sleepy')
- *  });
- * var hamster = Hamster.create();
- * hamster.get('napTime'); // false
- * hamster.set('state', 'sleepy');
- * hamster.get('napTime'); // true
- * hamster.set('state', 'hungry');
- * hamster.get('napTime'); // false
- * ```
- * @method equal
- * @for Ember.computed
- * @param {String} dependentKey
- * @param {String|Number|Object} value
- * @return {Ember.ComputedProperty} computed property which returns true if
- * the original value for property is equal to the given value.
- * @public
- */
-Ember.computed.equal = function(dependentKey, value) {
-  return Ember.computed(dependentKey, function(key) {
-    return Ember.get(this, dependentKey) === value;
-  }).cacheable();
-};
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/15ffc016/ambari-web/test/utils/ember_computed_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/ember_computed_test.js b/ambari-web/test/utils/ember_computed_test.js
new file mode 100644
index 0000000..0d8bb8e
--- /dev/null
+++ b/ambari-web/test/utils/ember_computed_test.js
@@ -0,0 +1,551 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+require('utils/ember_computed');
+
+describe('Ember.computed macros', function () {
+
+  describe('#notEqual', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: '123',
+        prop2: Em.computed.notEqual('prop1', '123')
+      });
+    });
+
+    it('`false` if values are equal', function () {
+      expect(this.obj.get('prop2')).to.be.false;
+    });
+
+    it('`true` if values are not equal', function () {
+      this.obj.set('prop1', '321');
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+  });
+
+  describe('#equalProperties', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: '123',
+        prop2: '123',
+        prop3: Em.computed.equalProperties('prop1', 'prop2')
+      });
+    });
+
+    it('`true` if values are equal', function () {
+      expect(this.obj.get('prop3')).to.be.true;
+    });
+
+    it('`false` if values are not equal', function () {
+      this.obj.set('prop1', '321');
+      expect(this.obj.get('prop3')).to.be.false;
+    });
+
+  });
+
+  describe('#notEqualProperties', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: '123',
+        prop2: '123',
+        prop3: Em.computed.notEqualProperties('prop1', 'prop2')
+      });
+    });
+
+    it('`false` if values are equal', function () {
+      expect(this.obj.get('prop3')).to.be.false;
+    });
+
+    it('`true` if values are not equal', function () {
+      this.obj.set('prop1', '321');
+      expect(this.obj.get('prop3')).to.be.true;
+    });
+
+  });
+
+  describe('#ifThenElse', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: true,
+        prop2: Em.computed.ifThenElse('prop1', '1', '0')
+      });
+    });
+
+    it('`1` if `prop1` is true', function () {
+      expect(this.obj.get('prop2')).to.equal('1');
+    });
+
+    it('`0` if `prop1` is false', function () {
+      this.obj.set('prop1', false);
+      expect(this.obj.get('prop2')).to.equal('0');
+    });
+
+  });
+
+  describe('#and', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: true,
+        prop2: true,
+        prop3: true,
+        prop4: Em.computed.and('prop1', 'prop2', 'prop3')
+      });
+    });
+
+    it('`true` if all dependent properties are true', function () {
+      expect(this.obj.get('prop4')).to.be.true;
+    });
+
+    it('`false` if at elast one dependent property is false', function () {
+      this.obj.set('prop2', false);
+      expect(this.obj.get('prop4')).to.be.false;
+    });
+
+  });
+
+  describe('#or', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: false,
+        prop2: false,
+        prop3: false,
+        prop4: Em.computed.or('prop1', 'prop2', 'prop3')
+      });
+    });
+
+    it('`false` if all dependent properties are false', function () {
+      expect(this.obj.get('prop4')).to.be.false;
+    });
+
+    it('`true` if at elast one dependent property is true', function () {
+      this.obj.set('prop2', true);
+      expect(this.obj.get('prop4')).to.be.true;
+    });
+
+  });
+
+  describe('#sumProperties', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: 1,
+        prop2: 2,
+        prop3: 3,
+        prop4: Em.computed.sumProperties('prop1', 'prop2', 'prop3')
+      });
+    });
+
+    it('should be sum of dependent values', function () {
+      expect(this.obj.get('prop4')).to.equal(6);
+    });
+
+    it('should be updated if some dependent vlaue is changed', function () {
+      this.obj.set('prop1', 4);
+      expect(this.obj.get('prop4')).to.equal(9);
+    });
+
+  });
+
+  describe('#gte', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: 2,
+        prop2: Em.computed.gte('prop1', 3)
+      });
+    });
+
+    it('`false` if value is less than needed', function () {
+      expect(this.obj.get('prop2')).to.be.false;
+    });
+
+    it('`true` if value is equal to the needed', function () {
+      this.obj.set('prop1', 3);
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+    it('`true` if value is greater than needed', function () {
+      this.obj.set('prop1', 4);
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+  });
+
+  describe('#gteProperties', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: 2,
+        prop2: 3,
+        prop3: Em.computed.gteProperties('prop1', 'prop2')
+      });
+    });
+
+    it('`false` if value is less than needed', function () {
+      expect(this.obj.get('prop3')).to.be.false;
+    });
+
+    it('`true` if value is equal to the needed', function () {
+      this.obj.set('prop1', 3);
+      expect(this.obj.get('prop3')).to.be.true;
+    });
+
+    it('`true` if value is greater than needed', function () {
+      this.obj.set('prop1', 4);
+      expect(this.obj.get('prop3')).to.be.true;
+    });
+
+  });
+
+  describe('#lte', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: 2,
+        prop2: Em.computed.lte('prop1', 1)
+      });
+    });
+
+    it('`false` if value is greater  than needed', function () {
+      expect(this.obj.get('prop2')).to.be.false;
+    });
+
+    it('`true` if value is equal to the needed', function () {
+      this.obj.set('prop1', 1);
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+    it('`true` if value is less than needed', function () {
+      this.obj.set('prop1', 0);
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+  });
+
+  describe('#lteProperties', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: 2,
+        prop2: 1,
+        prop3: Em.computed.lteProperties('prop1', 'prop2')
+      });
+    });
+
+    it('`false` if d1 is greater than d2', function () {
+      expect(this.obj.get('prop3')).to.be.false;
+    });
+
+    it('`true` if d1 is equal to the d2', function () {
+      this.obj.set('prop1', 1);
+      expect(this.obj.get('prop3')).to.be.true;
+    });
+
+    it('`true` if d1 is less than d2', function () {
+      this.obj.set('prop1', 0);
+      expect(this.obj.get('prop3')).to.be.true;
+    });
+
+  });
+
+  describe('#gt', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: 2,
+        prop2: Em.computed.gt('prop1', 3)
+      });
+    });
+
+    it('`false` if value is less than needed', function () {
+      expect(this.obj.get('prop2')).to.be.false;
+    });
+
+    it('`false` if value is equal to the needed', function () {
+      this.obj.set('prop1', 3);
+      expect(this.obj.get('prop2')).to.be.false;
+    });
+
+    it('`true` if value is greater than needed', function () {
+      this.obj.set('prop1', 4);
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+  });
+
+  describe('#gtProperties', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: 2,
+        prop2: 3,
+        prop3: Em.computed.gtProperties('prop1', 'prop2')
+      });
+    });
+
+    it('`false` if value is less than needed', function () {
+      expect(this.obj.get('prop3')).to.be.false;
+    });
+
+    it('`false` if value is equal to the needed', function () {
+      this.obj.set('prop1', 3);
+      expect(this.obj.get('prop3')).to.be.false;
+    });
+
+    it('`true` if value is greater than needed', function () {
+      this.obj.set('prop1', 4);
+      expect(this.obj.get('prop3')).to.be.true;
+    });
+
+  });
+
+  describe('#lt', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: 2,
+        prop2: Em.computed.lt('prop1', 1)
+      });
+    });
+
+    it('`false` if value is greater  than needed', function () {
+      expect(this.obj.get('prop2')).to.be.false;
+    });
+
+    it('`false` if value is equal to the needed', function () {
+      this.obj.set('prop1', 1);
+      expect(this.obj.get('prop2')).to.be.false;
+    });
+
+    it('`true` if value is less than needed', function () {
+      this.obj.set('prop1', 0);
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+  });
+
+  describe('#ltProperties', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: 2,
+        prop2: 1,
+        prop3: Em.computed.ltProperties('prop1', 'prop2')
+      });
+    });
+
+    it('`false` if d1 is greater than d2', function () {
+      expect(this.obj.get('prop3')).to.be.false;
+    });
+
+    it('`false` if d1 is equal to the d2', function () {
+      this.obj.set('prop1', 1);
+      expect(this.obj.get('prop3')).to.be.false;
+    });
+
+    it('`true` if d1 is less than d2', function () {
+      this.obj.set('prop1', 0);
+      expect(this.obj.get('prop3')).to.be.true;
+    });
+
+  });
+
+  describe('#match', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: 'abc',
+        prop2: Em.computed.match('prop1', /^ab/)
+      })
+    });
+
+    it('`true` if value match regexp', function () {
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+    it('`true` if value match regexp (2)', function () {
+      this.obj.set('prop1', 'abaaa');
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+    it('`false` if value doesn\'t match regexp', function () {
+      this.obj.set('prop1', '!!!!');
+      expect(this.obj.get('prop2')).to.be.false;
+    });
+
+  });
+
+  describe('#someBy', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: [{a: 1}, {a: 2}, {a: 3}],
+        prop2: Em.computed.someBy('prop1', 'a', 2)
+      });
+    });
+
+    it('`true` if some collection item has needed property value', function () {
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+    it('`false` if on one collection item doesn\'t have needed property value', function
() {
+      this.obj.set('prop1.1.a', 3);
+      expect(this.obj.get('prop2')).to.be.false;
+    });
+
+  });
+
+  describe('#everyBy', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: [{a: 2}, {a: 2}, {a: 2}],
+        prop2: Em.computed.everyBy('prop1', 'a', 2)
+      });
+    });
+
+    it('`true` if all collection items have needed property value', function () {
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+    it('`false` if at least one collection item doesn\'t have needed property value', function
() {
+      this.obj.set('prop1.1.a', 3);
+      expect(this.obj.get('prop2')).to.be.false;
+    });
+
+  });
+
+  describe('#mapBy', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: [{a: 1}, {a: 2}, {a: 3}],
+        prop2: Em.computed.mapBy('prop1', 'a')
+      });
+    });
+
+    it('should map dependent property', function () {
+      expect(this.obj.get('prop2')).to.eql([1, 2, 3]);
+    });
+
+    it('should map dependent property (2)', function () {
+      this.obj.get('prop1').push({a: 4});
+      expect(this.obj.get('prop2')).to.eql([1, 2, 3, 4]);
+    });
+
+  });
+
+  describe('#filterBy', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: [{a: 2}, {a: 2}, {a: 3}],
+        prop2: Em.computed.filterBy('prop1', 'a', 2)
+      });
+    });
+
+    it('should filter dependent property', function () {
+      expect(this.obj.get('prop2')).to.eql([{a: 2}, {a: 2}]);
+    });
+
+    it('should filter dependent property (2)', function () {
+      this.obj.get('prop1').pushObject({a: 2});
+      expect(this.obj.get('prop2')).to.eql([{a: 2}, {a: 2}, {a: 2}]);
+    });
+
+  });
+
+  describe('#findBy', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: [{b: 1, a: 2}, {b: 2, a: 2}, {a: 3}],
+        prop2: Em.computed.findBy('prop1', 'a', 2)
+      });
+    });
+
+    it('should filter dependent property', function () {
+      expect(this.obj.get('prop2')).to.eql({b:1, a: 2});
+    });
+
+    it('should filter dependent property (2)', function () {
+      this.obj.get('prop1').pushObject({b: 3, a: 2});
+      expect(this.obj.get('prop2')).to.eql({b: 1, a: 2});
+    });
+
+  });
+
+  describe('#alias', function() {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: {
+          a: {
+            b: {
+              c: 1
+            }
+          }
+        },
+        prop2: Em.computed.alias('prop1.a.b.c')
+      })
+    });
+
+    it('should be equal to dependent property', function () {
+      expect(this.obj.get('prop2')).to.equal(1);
+    });
+
+    it('should be equal to dependent property (2)', function () {
+      this.obj.set('prop1.a.b.c', 2);
+      expect(this.obj.get('prop2')).to.equal(2);
+    });
+
+  });
+
+  describe('#existsIn', function () {
+
+    beforeEach(function () {
+      this.obj = Em.Object.create({
+        prop1: 'v1',
+        prop2: Em.computed.existsIn('prop1', ['v1', 'v2'])
+      });
+    });
+
+    it('`true` if dependent value is in the array', function () {
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+    it('`true` if dependent value is in the array (2)', function () {
+      this.obj.set('prop1', 'v2');
+      expect(this.obj.get('prop2')).to.be.true;
+    });
+
+    it('`false` if dependent value is not in the array', function () {
+      this.obj.set('prop1', 'v3');
+      expect(this.obj.get('prop2')).to.be.false;
+    });
+
+  });
+
+});
\ No newline at end of file


Mime
View raw message