mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
REFACTOR: Remove Discourse.Model
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const GENERAL_ATTRIBUTES = [
|
const GENERAL_ATTRIBUTES = [
|
||||||
"updated_at",
|
"updated_at",
|
||||||
@ -6,7 +7,7 @@ const GENERAL_ATTRIBUTES = [
|
|||||||
"release_notes_link"
|
"release_notes_link"
|
||||||
];
|
];
|
||||||
|
|
||||||
const AdminDashboard = Discourse.Model.extend({});
|
const AdminDashboard = EmberObject.extend({});
|
||||||
|
|
||||||
AdminDashboard.reopenClass({
|
AdminDashboard.reopenClass({
|
||||||
fetch() {
|
fetch() {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import { not } from "@ember/object/computed";
|
import { not } from "@ember/object/computed";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
export default Discourse.Model.extend({
|
export default EmberObject.extend({
|
||||||
restoreDisabled: not("restoreEnabled"),
|
restoreDisabled: not("restoreEnabled"),
|
||||||
|
|
||||||
@discourseComputed("allowRestore", "isOperationRunning")
|
@discourseComputed("allowRestore", "isOperationRunning")
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { extractError } from "discourse/lib/ajax-error";
|
import { extractError } from "discourse/lib/ajax-error";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const Backup = Discourse.Model.extend({
|
const Backup = EmberObject.extend({
|
||||||
destroy() {
|
destroy() {
|
||||||
return ajax("/admin/backups/" + this.filename, { type: "DELETE" });
|
return ajax("/admin/backups/" + this.filename, { type: "DELETE" });
|
||||||
},
|
},
|
||||||
|
@ -4,8 +4,9 @@ import {
|
|||||||
on
|
on
|
||||||
} from "discourse-common/utils/decorators";
|
} from "discourse-common/utils/decorators";
|
||||||
import { propertyNotEqual } from "discourse/lib/computed";
|
import { propertyNotEqual } from "discourse/lib/computed";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const ColorSchemeColor = Discourse.Model.extend({
|
const ColorSchemeColor = EmberObject.extend({
|
||||||
@on("init")
|
@on("init")
|
||||||
startTrackingChanges() {
|
startTrackingChanges() {
|
||||||
this.set("originals", { hex: this.hex || "FFFFFF" });
|
this.set("originals", { hex: this.hex || "FFFFFF" });
|
||||||
|
@ -2,8 +2,9 @@ import discourseComputed from "discourse-common/utils/decorators";
|
|||||||
import { not } from "@ember/object/computed";
|
import { not } from "@ember/object/computed";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import ColorSchemeColor from "admin/models/color-scheme-color";
|
import ColorSchemeColor from "admin/models/color-scheme-color";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const ColorScheme = Discourse.Model.extend(Ember.Copyable, {
|
const ColorScheme = EmberObject.extend(Ember.Copyable, {
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import AdminUser from "admin/models/admin-user";
|
import AdminUser from "admin/models/admin-user";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const EmailLog = Discourse.Model.extend({});
|
const EmailLog = EmberObject.extend({});
|
||||||
|
|
||||||
EmailLog.reopenClass({
|
EmailLog.reopenClass({
|
||||||
create(attrs) {
|
create(attrs) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
const EmailPreview = Discourse.Model.extend({});
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
|
const EmailPreview = EmberObject.extend({});
|
||||||
|
|
||||||
export function oneWeekAgo() {
|
export function oneWeekAgo() {
|
||||||
return moment()
|
return moment()
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
const EmailSettings = Discourse.Model.extend({});
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
|
const EmailSettings = EmberObject.extend({});
|
||||||
|
|
||||||
EmailSettings.reopenClass({
|
EmailSettings.reopenClass({
|
||||||
find: function() {
|
find: function() {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import AdminUser from "admin/models/admin-user";
|
import AdminUser from "admin/models/admin-user";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const IncomingEmail = Discourse.Model.extend({});
|
const IncomingEmail = EmberObject.extend({});
|
||||||
|
|
||||||
IncomingEmail.reopenClass({
|
IncomingEmail.reopenClass({
|
||||||
create(attrs) {
|
create(attrs) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
const Permalink = Discourse.Model.extend({
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
|
const Permalink = EmberObject.extend({
|
||||||
save: function() {
|
save: function() {
|
||||||
return ajax("/admin/permalinks.json", {
|
return ajax("/admin/permalinks.json", {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
@ -17,7 +17,7 @@ import { renderAvatar } from "discourse/helpers/user-avatar";
|
|||||||
// and you want to ensure cache is reset
|
// and you want to ensure cache is reset
|
||||||
export const SCHEMA_VERSION = 4;
|
export const SCHEMA_VERSION = 4;
|
||||||
|
|
||||||
const Report = Discourse.Model.extend({
|
const Report = EmberObject.extend({
|
||||||
average: false,
|
average: false,
|
||||||
percent: false,
|
percent: false,
|
||||||
higher_is_better: true,
|
higher_is_better: true,
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const ScreenedEmail = Discourse.Model.extend({
|
const ScreenedEmail = EmberObject.extend({
|
||||||
@discourseComputed("action")
|
@discourseComputed("action")
|
||||||
actionName(action) {
|
actionName(action) {
|
||||||
return I18n.t("admin.logs.screened_actions." + action);
|
return I18n.t("admin.logs.screened_actions." + action);
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import { equal } from "@ember/object/computed";
|
import { equal } from "@ember/object/computed";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const ScreenedIpAddress = Discourse.Model.extend({
|
const ScreenedIpAddress = EmberObject.extend({
|
||||||
@discourseComputed("action_name")
|
@discourseComputed("action_name")
|
||||||
actionName(actionName) {
|
actionName(actionName) {
|
||||||
return I18n.t(`admin.logs.screened_ips.actions.${actionName}`);
|
return I18n.t(`admin.logs.screened_ips.actions.${actionName}`);
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const ScreenedUrl = Discourse.Model.extend({
|
const ScreenedUrl = EmberObject.extend({
|
||||||
@discourseComputed("action")
|
@discourseComputed("action")
|
||||||
actionName(action) {
|
actionName(action) {
|
||||||
return I18n.t("admin.logs.screened_actions." + action);
|
return I18n.t("admin.logs.screened_actions." + action);
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import Setting from "admin/mixins/setting-object";
|
import Setting from "admin/mixins/setting-object";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const SiteSetting = Discourse.Model.extend(Setting, {});
|
const SiteSetting = EmberObject.extend(Setting, {});
|
||||||
|
|
||||||
SiteSetting.reopenClass({
|
SiteSetting.reopenClass({
|
||||||
findAll() {
|
findAll() {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
import Setting from "admin/mixins/setting-object";
|
import Setting from "admin/mixins/setting-object";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
export default Discourse.Model.extend(Setting, {});
|
export default EmberObject.extend(Setting, {});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
export default Discourse.Model.extend({
|
export default EmberObject.extend({
|
||||||
@discourseComputed("days_visited", "time_period")
|
@discourseComputed("days_visited", "time_period")
|
||||||
days_visited_percent(daysVisited, timePeriod) {
|
days_visited_percent(daysVisited, timePeriod) {
|
||||||
return Math.round((daysVisited * 100) / timePeriod);
|
return Math.round((daysVisited * 100) / timePeriod);
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const VersionCheck = Discourse.Model.extend({
|
const VersionCheck = EmberObject.extend({
|
||||||
@discourseComputed("updated_at")
|
@discourseComputed("updated_at")
|
||||||
noCheckPerformed(updatedAt) {
|
noCheckPerformed(updatedAt) {
|
||||||
return updatedAt === null;
|
return updatedAt === null;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import EmberObject from "@ember/object";
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const WatchedWord = Discourse.Model.extend({
|
const WatchedWord = EmberObject.extend({
|
||||||
save() {
|
save() {
|
||||||
return ajax(
|
return ajax(
|
||||||
"/admin/logs/watched_words" + (this.id ? "/" + this.id : "") + ".json",
|
"/admin/logs/watched_words" + (this.id ? "/" + this.id : "") + ".json",
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
//= require ./discourse/lib/show-modal
|
//= require ./discourse/lib/show-modal
|
||||||
//= require ./discourse/mixins/scrolling
|
//= require ./discourse/mixins/scrolling
|
||||||
//= require ./discourse/lib/ajax-error
|
//= require ./discourse/lib/ajax-error
|
||||||
//= require ./discourse/models/model
|
|
||||||
//= require ./discourse/models/result-set
|
//= require ./discourse/models/result-set
|
||||||
//= require ./discourse/models/store
|
//= require ./discourse/models/store
|
||||||
//= require ./discourse/models/action-summary
|
//= require ./discourse/models/action-summary
|
||||||
|
@ -6,6 +6,8 @@ import {
|
|||||||
} from "discourse-common/utils/decorators";
|
} from "discourse-common/utils/decorators";
|
||||||
import computed from "@ember/object/computed";
|
import computed from "@ember/object/computed";
|
||||||
import FocusEvent from "discourse-common/mixins/focus-event";
|
import FocusEvent from "discourse-common/mixins/focus-event";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
import deprecated from "discourse-common/lib/deprecated";
|
||||||
|
|
||||||
const _pluginCallbacks = [];
|
const _pluginCallbacks = [];
|
||||||
|
|
||||||
@ -206,4 +208,14 @@ const Discourse = Ember.Application.extend(FocusEvent, {
|
|||||||
})
|
})
|
||||||
}).create();
|
}).create();
|
||||||
|
|
||||||
|
Object.defineProperty(Discourse, "Model", {
|
||||||
|
get() {
|
||||||
|
deprecated("Use an `@ember/object` instead of Discourse.Model", {
|
||||||
|
since: "2.4.0",
|
||||||
|
dropFrom: "2.5.0"
|
||||||
|
});
|
||||||
|
return EmberObject;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default Discourse;
|
export default Discourse;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
const Draft = Discourse.Model.extend();
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
|
const Draft = EmberObject.extend();
|
||||||
|
|
||||||
Draft.reopenClass({
|
Draft.reopenClass({
|
||||||
clear(key, sequence) {
|
clear(key, sequence) {
|
||||||
|
@ -1,4 +1,2 @@
|
|||||||
import Model from "discourse/models/model";
|
import EmberObject from "@ember/object";
|
||||||
|
export default EmberObject.extend();
|
||||||
// A trivial model we use to handle input validation
|
|
||||||
export default Model.extend();
|
|
||||||
|
@ -4,7 +4,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
|||||||
import { userPath } from "discourse/lib/url";
|
import { userPath } from "discourse/lib/url";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
|
|
||||||
const Invite = Discourse.Model.extend({
|
const Invite = EmberObject.extend({
|
||||||
rescind() {
|
rescind() {
|
||||||
ajax("/invites", {
|
ajax("/invites", {
|
||||||
type: "DELETE",
|
type: "DELETE",
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
const LivePostCounts = Discourse.Model.extend({});
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
|
const LivePostCounts = EmberObject.extend({});
|
||||||
|
|
||||||
LivePostCounts.reopenClass({
|
LivePostCounts.reopenClass({
|
||||||
find() {
|
find() {
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
import { isEmpty } from "@ember/utils";
|
|
||||||
import EmberObject from "@ember/object";
|
|
||||||
const Model = EmberObject.extend();
|
|
||||||
|
|
||||||
Model.reopenClass({
|
|
||||||
extractByKey(collection, klass) {
|
|
||||||
const retval = {};
|
|
||||||
if (isEmpty(collection)) {
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
collection.forEach(function(item) {
|
|
||||||
retval[item.id] = klass.create(item);
|
|
||||||
});
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Model;
|
|
@ -2,8 +2,9 @@ import discourseComputed from "discourse-common/utils/decorators";
|
|||||||
import { toTitleCase } from "discourse/lib/formatter";
|
import { toTitleCase } from "discourse/lib/formatter";
|
||||||
import { emojiUnescape } from "discourse/lib/text";
|
import { emojiUnescape } from "discourse/lib/text";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const NavItem = Discourse.Model.extend({
|
const NavItem = EmberObject.extend({
|
||||||
@discourseComputed("categoryName", "name")
|
@discourseComputed("categoryName", "name")
|
||||||
title(categoryName, name) {
|
title(categoryName, name) {
|
||||||
const extra = {};
|
const extra = {};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const PermissionType = Discourse.Model.extend({
|
const PermissionType = EmberObject.extend({
|
||||||
@discourseComputed("id")
|
@discourseComputed("id")
|
||||||
description(id) {
|
description(id) {
|
||||||
var key = "";
|
var key = "";
|
||||||
|
@ -2,11 +2,24 @@ import { notEmpty } from "@ember/object/computed";
|
|||||||
import EmberObject from "@ember/object";
|
import EmberObject from "@ember/object";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import RestModel from "discourse/models/rest";
|
import RestModel from "discourse/models/rest";
|
||||||
import Model from "discourse/models/model";
|
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "discourse-common/lib/get-owner";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
import Session from "discourse/models/session";
|
import Session from "discourse/models/session";
|
||||||
|
import { isEmpty } from "@ember/utils";
|
||||||
|
import User from "discourse/models/user";
|
||||||
|
|
||||||
|
function extractByKey(collection, klass) {
|
||||||
|
const retval = {};
|
||||||
|
if (isEmpty(collection)) {
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.forEach(function(item) {
|
||||||
|
retval[item.id] = klass.create(item);
|
||||||
|
});
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
// Whether to show the category badge in topic lists
|
// Whether to show the category badge in topic lists
|
||||||
function displayCategoryInList(site, category) {
|
function displayCategoryInList(site, category) {
|
||||||
@ -139,8 +152,8 @@ TopicList.reopenClass({
|
|||||||
// Stitch together our side loaded data
|
// Stitch together our side loaded data
|
||||||
|
|
||||||
const categories = Category.list(),
|
const categories = Category.list(),
|
||||||
users = Model.extractByKey(result.users, Discourse.User),
|
users = extractByKey(result.users, User),
|
||||||
groups = Model.extractByKey(result.primary_groups, EmberObject);
|
groups = extractByKey(result.primary_groups, EmberObject);
|
||||||
|
|
||||||
return result.topic_list[listKey].map(t => {
|
return result.topic_list[listKey].map(t => {
|
||||||
t.category = categories.findBy("id", t.category_id);
|
t.category = categories.findBy("id", t.category_id);
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
import { defaultHomepage } from "discourse/lib/utilities";
|
import { defaultHomepage } from "discourse/lib/utilities";
|
||||||
import PreloadStore from "preload-store";
|
import PreloadStore from "preload-store";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
function isNew(topic) {
|
function isNew(topic) {
|
||||||
return (
|
return (
|
||||||
@ -25,7 +26,7 @@ function isUnread(topic) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TopicTrackingState = Discourse.Model.extend({
|
const TopicTrackingState = EmberObject.extend({
|
||||||
messageCount: 0,
|
messageCount: 0,
|
||||||
|
|
||||||
@on("init")
|
@on("init")
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
/**
|
import EmberObject from "@ember/object";
|
||||||
A data model representing a group of UserActions
|
|
||||||
**/
|
export default EmberObject.extend({
|
||||||
export default Discourse.Model.extend({
|
push(item) {
|
||||||
push: function(item) {
|
|
||||||
if (!this.items) {
|
if (!this.items) {
|
||||||
this.items = [];
|
this.items = [];
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,9 @@ import { ajax } from "discourse/lib/ajax";
|
|||||||
import Badge from "discourse/models/badge";
|
import Badge from "discourse/models/badge";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import Topic from "discourse/models/topic";
|
import Topic from "discourse/models/topic";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
const UserBadge = Discourse.Model.extend({
|
const UserBadge = EmberObject.extend({
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
postUrl: function() {
|
postUrl: function() {
|
||||||
if (this.topic_title) {
|
if (this.topic_title) {
|
||||||
|
@ -3,8 +3,9 @@ import { ajax } from "discourse/lib/ajax";
|
|||||||
import { url } from "discourse/lib/computed";
|
import { url } from "discourse/lib/computed";
|
||||||
import UserAction from "discourse/models/user-action";
|
import UserAction from "discourse/models/user-action";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
|
import EmberObject from "@ember/object";
|
||||||
|
|
||||||
export default Discourse.Model.extend({
|
export default EmberObject.extend({
|
||||||
loaded: false,
|
loaded: false,
|
||||||
|
|
||||||
@on("init")
|
@on("init")
|
||||||
|
@ -89,7 +89,6 @@ JS
|
|||||||
"discourse/routes/discourse",
|
"discourse/routes/discourse",
|
||||||
"discourse/models/site",
|
"discourse/models/site",
|
||||||
"discourse/models/user",
|
"discourse/models/user",
|
||||||
"discourse/models/model"
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
import EmberObject from "@ember/object";
|
|
||||||
import Model from "discourse/models/model";
|
|
||||||
|
|
||||||
QUnit.module("model:discourse");
|
|
||||||
|
|
||||||
QUnit.test(
|
|
||||||
"extractByKey: converts a list of hashes into a hash of instances of specified class, indexed by their ids",
|
|
||||||
assert => {
|
|
||||||
var firstObject = { id: "id_1", foo: "foo_1" };
|
|
||||||
var secondObject = { id: "id_2", foo: "foo_2" };
|
|
||||||
|
|
||||||
var actual = Model.extractByKey([firstObject, secondObject], EmberObject);
|
|
||||||
var expected = {
|
|
||||||
id_1: EmberObject.create(firstObject),
|
|
||||||
id_2: EmberObject.create(secondObject)
|
|
||||||
};
|
|
||||||
|
|
||||||
assert.ok(_.isEqual(actual, expected));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
QUnit.test(
|
|
||||||
"extractByKey: returns an empty hash if there isn't anything to convert",
|
|
||||||
assert => {
|
|
||||||
assert.deepEqual(
|
|
||||||
Model.extractByKey(),
|
|
||||||
{},
|
|
||||||
"when called without parameters"
|
|
||||||
);
|
|
||||||
assert.deepEqual(
|
|
||||||
Model.extractByKey([]),
|
|
||||||
{},
|
|
||||||
"when called with an empty array"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
Reference in New Issue
Block a user