Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/issue-114-backend' into issue-5185
Browse files Browse the repository at this point in the history
  • Loading branch information
CarolineDenis committed Oct 14, 2024
2 parents 3a6805c + dc4ae07 commit a99d6cc
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 117 deletions.
14 changes: 7 additions & 7 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ DATABASE_PORT=3306
MYSQL_ROOT_PASSWORD=password
DATABASE_NAME=specify

# When running Specify 7 for the first time or during updates that
# require migrations, ensure that the MASTER_NAME and MASTER_PASSWORD
# are set to the root username and password. This will ensure proper
# execution of Django migrations during the initial setup.
# After launching Specify and verifying the update is complete, you can
# When running Specify 7 for the first time or during updates that
# require migrations, ensure that the MASTER_NAME and MASTER_PASSWORD
# are set to the root username and password. This will ensure proper
# execution of Django migrations during the ixnitial setup.
# After launching Specify and verifying the update is complete, you can
# safely replace these credentials with the master SQL user name and password.
MASTER_NAME=root
MASTER_PASSWORD=password
Expand Down Expand Up @@ -36,7 +36,7 @@ CELERY_RESULT_BACKEND=redis://redis/1
LOG_LEVEL=WARNING

# Set this variable to `true` to run Specify 7 in debug mode. This
# should only be used during development and troubleshooting and not
# during general use. Django applications leak memory when operated
# should only be used during development and troubleshooting and not
# during general use. Django applications leak memory when operated
# continuously in debug mode.
SP7_DEBUG=true
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ describe('Independent Collection', () => {
);

await collection.fetch();
const totalCount = collection._totalCount ?? 0;
expect(collection).toHaveLength(totalCount);
// eslint-disable-next-line jest/prefer-to-have-length
expect(collection.length).toBe(collection._totalCount);
});

test('specified offset', async () => {
Expand Down Expand Up @@ -408,6 +408,24 @@ describe('Independent Collection', () => {
expect(collection.removed).toStrictEqual(new Set());
});

test('success options respected', async () => {
const accession = new tables.Accession.Resource();

expect(accession.isNew()).toBe(true);

const collection = new tables.CollectionObject.IndependentCollection({
related: accession,
field: tables.CollectionObject.strictGetRelationship('accession'),
}) as Collection<CollectionObject>;

await collection.fetch({
success: (collection) => {
collection.add(new tables.CollectionObject.Resource());
},
} as CollectionFetchFilters<AnySchema>);
expect(collection.models).toHaveLength(1);
});

overrideAjax('/api/specify/collectionobject/200/', {
id: 200,
resource_uri: getResourceApiUrl('CollectionObject', 200),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ function notSupported() {
throw new Error('method is not supported');
}

async function fakeFetch() {
async function fakeFetch(rawOptions) {
const options = {
...rawOptions,
};
if (typeof options.success === 'function')
options.success.call(options.context, this, undefined, options);
return this;
}

async function lazyFetch(options) {
assert(this instanceof LazyCollection);
if (this._fetch) return this._fetch;
if (this.related?.isNew()) return this;
if (this.related?.isNew()) return fakeFetch.call(this, options);

this._neverFetched = false;

Expand Down Expand Up @@ -119,7 +124,9 @@ export const DependentCollection = Base.extend({
getFetchOffset() {
return 0;
},
fetch: fakeFetch,
async fetch(options) {
return fakeFetch.call(this, options);
},
sync: notSupported,
create: notSupported,
});
Expand Down Expand Up @@ -258,7 +265,7 @@ export const IndependentCollection = LazyCollection.extend({
},
async fetch(options) {
// If the related is being fetched, don't try and fetch the collection
if (this.related._fetch !== null) return this;
if (this.related._fetch !== null) return fakeFetch.call(this, options);

this.filters[this.field.name.toLowerCase()] = this.related.id;

Expand Down
Loading

0 comments on commit a99d6cc

Please sign in to comment.