Merge branch 'master' into gh-pages

This commit is contained in:
Rufus Pollock 2012-11-13 11:09:38 +00:00
commit d2046f2449
4 changed files with 47 additions and 2 deletions

View File

@ -21,6 +21,16 @@ Running the tests by opening `test/index.html` in your browser.
We welcome patches and pull requests and have a few guidelines.
General:
* Please do **not** build the dist files (e.g. dist/recline.js) when submitting
patches. dist files will get built automatically and if they are part of a
patch or pull request it makes them harder to review and more likely to
conflict.
* If possible have an issue to which the commits can relate. You can reference
an issue in the commits by just including #{issue-number} somewhere in the
commit message). Note if no issue exists suggest creating one.
For small bugfixes or enhancements:
* Please run the tests

View File

@ -495,7 +495,11 @@ my.Query = Backbone.Model.extend({
var ourfilter = JSON.parse(JSON.stringify(filter));
// not fully specified so use template and over-write
if (_.keys(filter).length <= 3) {
ourfilter = _.extend(this._filterTemplates[filter.type], ourfilter);
ourfilter = _.extend(
// crude deep copy
JSON.parse(JSON.stringify(this._filterTemplates[filter.type])),
ourfilter
);
}
var filters = this.get('filters');
filters.push(ourfilter);

View File

@ -320,6 +320,9 @@ test('Query.addFilter', function () {
};
deepEqual(query.get('filters')[0], exp);
query.addFilter({type: 'term', field: 'abc'});
deepEqual(query.get('filters')[0], exp);
query.addFilter({type: 'geo_distance', field: 'xyz'});
var exp = {
distance: 10,
@ -331,7 +334,7 @@ test('Query.addFilter', function () {
field: 'xyz',
type: 'geo_distance'
};
deepEqual(exp, query.get('filters')[1]);
deepEqual(exp, query.get('filters')[2]);
});
})(this.jQuery);

View File

@ -40,6 +40,7 @@ test('basics', function () {
$editForm.find('.filter-range input').first().val('2');
$editForm.find('.filter-range input').last().val('4');
$editForm.submit();
equal(dataset.queryState.attributes.filters[0].term, 'UK');
equal(dataset.queryState.attributes.filters[1].start, 2);
equal(dataset.records.length, 2);
@ -59,6 +60,33 @@ test('basics', function () {
view.remove();
});
test('add 2 filters of same type', function () {
var dataset = Fixture.getDataset();
var view = new recline.View.FilterEditor({
model: dataset
});
$('.fixtures').append(view.el);
// add 2 term filters
var $addForm = view.el.find('form.js-add');
view.el.find('.js-add-filter').click();
$addForm.find('select.fields').val('country');
$addForm.submit();
var $addForm = view.el.find('form.js-add');
view.el.find('.js-add-filter').click();
$addForm.find('select.fields').val('id');
$addForm.submit();
var fields = [];
view.el.find('form.js-edit .filter-term input').each(function(idx, item) {
fields.push($(item).attr('data-filter-field'));
});
deepEqual(fields, ['country', 'id']);
view.remove();
});
test('geo_distance', function () {
var dataset = Fixture.getDataset();
var view = new recline.View.FilterEditor({