mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 21:25:24 +08:00
FEATURE: Can edit category/host relationships for embedding
This commit is contained in:
@ -39,13 +39,17 @@ const _moreWidgets = [
|
||||
{id: 224, name: 'Good Repellant'}
|
||||
];
|
||||
|
||||
const fruits = [{id: 1, name: 'apple', farmer_id: 1, category_id: 4},
|
||||
{id: 2, name: 'banana', farmer_id: 1, category_id: 3},
|
||||
{id: 3, name: 'grape', farmer_id: 2, category_id: 5}];
|
||||
const fruits = [{id: 1, name: 'apple', farmer_id: 1, color_ids: [1,2], category_id: 4},
|
||||
{id: 2, name: 'banana', farmer_id: 1, color_ids: [3], category_id: 3},
|
||||
{id: 3, name: 'grape', farmer_id: 2, color_ids: [2], category_id: 5}];
|
||||
|
||||
const farmers = [{id: 1, name: 'Old MacDonald'},
|
||||
{id: 2, name: 'Luke Skywalker'}];
|
||||
|
||||
const colors = [{id: 1, name: 'Red'},
|
||||
{id: 2, name: 'Green'},
|
||||
{id: 3, name: 'Yellow'}];
|
||||
|
||||
function loggedIn() {
|
||||
return !!Discourse.User.current();
|
||||
}
|
||||
@ -221,12 +225,11 @@ export default function() {
|
||||
|
||||
this.get('/fruits/:id', function() {
|
||||
const fruit = fruits[0];
|
||||
|
||||
return response({ __rest_serializer: "1", fruit, farmers: [farmers[0]] });
|
||||
return response({ __rest_serializer: "1", fruit, farmers, colors });
|
||||
});
|
||||
|
||||
this.get('/fruits', function() {
|
||||
return response({ __rest_serializer: "1", fruits, farmers });
|
||||
return response({ __rest_serializer: "1", fruits, farmers, colors });
|
||||
});
|
||||
|
||||
this.get('/widgets/:widget_id', function(request) {
|
||||
|
@ -106,19 +106,31 @@ test('destroyRecord when new', function(assert) {
|
||||
});
|
||||
|
||||
|
||||
test('find embedded', function() {
|
||||
test('find embedded', function(assert) {
|
||||
const store = createStore();
|
||||
return store.find('fruit', 1).then(function(f) {
|
||||
ok(f.get('farmer'), 'it has the embedded object');
|
||||
ok(f.get('category'), 'categories are found automatically');
|
||||
return store.find('fruit', 2).then(function(f) {
|
||||
assert.ok(f.get('farmer'), 'it has the embedded object');
|
||||
|
||||
const fruitCols = f.get('colors');
|
||||
assert.equal(fruitCols.length, 2);
|
||||
assert.equal(fruitCols[0].get('id'), 1);
|
||||
assert.equal(fruitCols[1].get('id'), 2);
|
||||
|
||||
assert.ok(f.get('category'), 'categories are found automatically');
|
||||
});
|
||||
});
|
||||
|
||||
test('findAll embedded', function() {
|
||||
test('findAll embedded', function(assert) {
|
||||
const store = createStore();
|
||||
return store.findAll('fruit').then(function(fruits) {
|
||||
equal(fruits.objectAt(0).get('farmer.name'), 'Old MacDonald');
|
||||
equal(fruits.objectAt(0).get('farmer'), fruits.objectAt(1).get('farmer'), 'points at the same object');
|
||||
equal(fruits.objectAt(2).get('farmer.name'), 'Luke Skywalker');
|
||||
assert.equal(fruits.objectAt(0).get('farmer.name'), 'Old MacDonald');
|
||||
assert.equal(fruits.objectAt(0).get('farmer'), fruits.objectAt(1).get('farmer'), 'points at the same object');
|
||||
|
||||
const fruitCols = fruits.objectAt(0).get('colors');
|
||||
assert.equal(fruitCols.length, 2);
|
||||
assert.equal(fruitCols[0].get('id'), 1);
|
||||
assert.equal(fruitCols[1].get('id'), 2);
|
||||
|
||||
assert.equal(fruits.objectAt(2).get('farmer.name'), 'Luke Skywalker');
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user