Skip to content

Commit

Permalink
Merge pull request #229 from mavenlink/revert-223-ox-3256-wrap-brains…
Browse files Browse the repository at this point in the history
…tem-js

Revert "Ox 3256 wrap brainstem js"
  • Loading branch information
guanw88 authored Aug 30, 2024
2 parents 8115f35 + d9fc249 commit 4da0aac
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 186 deletions.
34 changes: 17 additions & 17 deletions spec/collection-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ = require 'jquery'
{ keys: underscoreKeys, clone, extend, pluck, underscore } = require '../src/utility-functions'
_ = require 'underscore'
Backbone = require 'backbone'
Backbone.$ = $ # TODO remove after upgrading to backbone 1.2+

Expand Down Expand Up @@ -60,7 +60,7 @@ describe 'Collection', ->
cacheKey : 1
bogus : 1
stuff : 1
keys = underscoreKeys(Collection.pickFetchOptions(sampleOptions))
keys = _.keys(Collection.pickFetchOptions(sampleOptions))

it 'returns an array with picked option keys', ->
for key of sampleOptions
Expand Down Expand Up @@ -176,11 +176,11 @@ describe 'Collection', ->
collection.fetch(options)

for key of options
expect(underscoreKeys(loadObjectSpy.calls.mostRecent().args[1])).toContain key
expect(_.keys(loadObjectSpy.calls.mostRecent().args[1])).toContain key
expect(loadObjectSpy.calls.mostRecent().args[1][key]).toEqual options[key]

it 'does not modify `firstFetchOptions`', ->
firstFetchOptions = clone collection.firstFetchOptions
firstFetchOptions = _.clone collection.firstFetchOptions

collection.fetch(bla: 'bla')

Expand Down Expand Up @@ -239,12 +239,12 @@ describe 'Collection', ->
spyOn(Collection.prototype, 'update')

it 'is true when silent is true', ->
collection.fetch(extend(options, silent: true))
collection.fetch(_.extend(options, silent: true))
expectation.respond()
expect(Collection.prototype.update).toHaveBeenCalledWith(jasmine.any(Array), silent: true)

it 'is false when silent is false', ->
collection.fetch(extend(options, silent: false))
collection.fetch(_.extend(options, silent: false))
expectation.respond()
expect(Collection.prototype.update).toHaveBeenCalledWith(jasmine.any(Array), silent: false)

Expand All @@ -258,7 +258,7 @@ describe 'Collection', ->
expectation.respond()

objects = collection.set.calls.mostRecent().args[0]
expect(pluck(objects, 'id')).toEqual(pluck(posts, 'id'))
expect(_.pluck(objects, 'id')).toEqual(_.pluck(posts, 'id'))
expect(object).toEqual(jasmine.any Post) for object in objects

context 'add option is set to true', ->
Expand All @@ -271,7 +271,7 @@ describe 'Collection', ->
expectation.respond()

objects = collection.add.calls.mostRecent().args[0]
expect(pluck(objects, 'id')).toEqual(pluck(posts, 'id'))
expect(_.pluck(objects, 'id')).toEqual(_.pluck(posts, 'id'))
expect(object).toEqual(jasmine.any Post) for object in objects

context 'reset option is set to true', ->
Expand All @@ -284,7 +284,7 @@ describe 'Collection', ->
expectation.respond()

objects = collection.reset.calls.mostRecent().args[0]
expect(pluck(objects, 'id')).toEqual(pluck(posts, 'id'))
expect(_.pluck(objects, 'id')).toEqual(_.pluck(posts, 'id'))
expect(object).toEqual(jasmine.any Post) for object in objects

context 'collection is fetched again with different options', ->
Expand All @@ -307,7 +307,7 @@ describe 'Collection', ->

it 'returns only the second set of results', ->
objects = collection.set.calls.mostRecent().args[0]
expect(pluck(objects, 'id')).toEqual(pluck(secondPosts, 'id'))
expect(_.pluck(objects, 'id')).toEqual(_.pluck(secondPosts, 'id'))
expect(object).toEqual(jasmine.any Post) for object in objects

it 'updates `lastFetchOptions` on the collection instance', ->
Expand Down Expand Up @@ -343,7 +343,7 @@ describe 'Collection', ->
respondWith(server, '/api/posts?per_page=5&page=1', resultsFrom: 'posts', data: { posts: posts1 })

promise = collection.fetch()
methods = underscoreKeys(promise)
methods = _.keys(promise)

for method in ['reject', 'resolve', 'rejectWith', 'resolveWith']
expect(methods).not.toContain(method)
Expand All @@ -365,7 +365,7 @@ describe 'Collection', ->
collection.fetch()
server.respond()

expect(collection.pluck('id')).toEqual(underscore(posts1).pluck('id'))
expect(collection.pluck('id')).toEqual(_(posts1).pluck('id'))

it 'responds to requests with custom params', ->
paramsOnDoneSpy = jasmine.createSpy('paramsOnDoneSpy')
Expand All @@ -387,8 +387,8 @@ describe 'Collection', ->
it 'returns data from storage manager cache', ->
collection.fetch()

expect(collection.pluck 'id').toEqual(pluck posts1, 'id')
expect(collection.pluck 'id').not.toEqual(pluck posts2, 'id')
expect(collection.pluck 'id').toEqual(_.pluck posts1, 'id')
expect(collection.pluck 'id').not.toEqual(_.pluck posts2, 'id')

context 'different options are provided', ->
beforeEach ->
Expand All @@ -397,8 +397,8 @@ describe 'Collection', ->
server.respond()

it 'updates collection with new data', ->
expect(collection.pluck 'id').not.toEqual(pluck posts1, 'id')
expect(collection.pluck 'id').toEqual(pluck posts2, 'id')
expect(collection.pluck 'id').not.toEqual(_.pluck posts1, 'id')
expect(collection.pluck 'id').toEqual(_.pluck posts2, 'id')

describe '#refresh', ->
beforeEach ->
Expand Down Expand Up @@ -931,7 +931,7 @@ describe 'Collection', ->
spyOn(model, 'toServerJSON').and.callThrough() for model in collection.models

it 'returns model contents serialized using model server json', ->
expect(underscore(collection.toServerJSON()).pluck('id')).toEqual(collection.pluck('id'))
expect(_(collection.toServerJSON()).pluck('id')).toEqual(collection.pluck('id'))

it 'passes method to model method calls', ->
collection.toServerJSON('update')
Expand Down
6 changes: 3 additions & 3 deletions spec/helpers/builders.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ = require 'jquery'
{ isArray, map } = require '../../src/utility-functions'
_ = require 'underscore'
inflection = require 'inflection'

StorageManager = require '../../src/storage-manager'
Expand Down Expand Up @@ -46,8 +46,8 @@ spec.defineBuilders = ->
attrName == 'id' || attrName.match(/_id$/) || (attrName.match(/_ids$/))

arrayPreservedToString = (value) ->
if isArray(value)
map(value, (v) -> arrayPreservedToString(v))
if _.isArray(value)
_.map(value, (v) -> arrayPreservedToString(v))
else if value? && !$.isPlainObject(value)
String(value)
else
Expand Down
8 changes: 4 additions & 4 deletions spec/helpers/spec-helper.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ = require 'jquery'
{ underscore } = require '../../src/utility-functions'
_ = require 'underscore'
Backbone = require 'backbone'
Backbone.$ = $ # TODO remove after upgrading to backbone 1.2+

Expand All @@ -16,7 +16,7 @@ Users = require './models/users'


window.resultsArray = (key, models) ->
underscore(models).map (model) -> { key: key, id: model.get("id") }
_(models).map (model) -> { key: key, id: model.get("id") }

window.resultsObject = (models) ->
results = {}
Expand All @@ -25,10 +25,10 @@ window.resultsObject = (models) ->
results

window.convertTopLevelKeysToObjects = (data) ->
for key in underscore(data).keys()
for key in _(data).keys()
continue if key in ["count", "results"]
if data[key] instanceof Array
data[key] = underscore(data[key]).reduce(((memo, item) -> memo[item.id] = item; memo ), {})
data[key] = _(data[key]).reduce(((memo, item) -> memo[item.id] = item; memo ), {})

window.respondWith = (server, url, options) ->
if options.resultsFrom?
Expand Down
10 changes: 5 additions & 5 deletions spec/loaders/abstract-loader-shared-behavior.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ extend } = require '../../src/utility-functions'
_ = require 'underscore'
$ = require 'jquery'
Backbone = require 'backbone'
Backbone.$ = $ # TODO remove after upgrading to backbone 1.2+
Expand Down Expand Up @@ -26,7 +26,7 @@ registerSharedBehavior "AbstractLoaderSharedBehavior", (sharedContext) ->
defaults =
storageManager: storageManager

loader = new loaderClass(extend {}, defaults, opts)
loader = new loaderClass(_.extend {}, defaults, opts)
loader._getCollectionName = -> 'tasks'
loader._createObjects = ->
@internalObject = bar: 'foo'
Expand Down Expand Up @@ -243,7 +243,7 @@ registerSharedBehavior "AbstractLoaderSharedBehavior", (sharedContext) ->
expect(loadOptions.cache).toEqual false

it 'sets cache to false if search is present', ->
opts = extend opts, cache: true, search: 'term'
opts = _.extend opts, cache: true, search: 'term'

loadOptions = loader._parseLoadOptions(opts)
expect(loadOptions.cache).toEqual false
Expand All @@ -265,7 +265,7 @@ registerSharedBehavior "AbstractLoaderSharedBehavior", (sharedContext) ->
only: [3, 1, 2]
search: 'foobar'

opts = extend(opts, myOpts)
opts = _.extend(opts, myOpts)
loadOptions = loader._parseLoadOptions(opts)
expect(loadOptions.cacheKey).toEqual 'myOrder|{"key1":"value1","key2":"value2","key3":{"value1":"a","value2":"b"}}|1,2,3|1|200|50|0|foobar'

Expand Down Expand Up @@ -462,7 +462,7 @@ registerSharedBehavior "AbstractLoaderSharedBehavior", (sharedContext) ->

beforeEach ->
loader = createLoader()
opts = extend defaultLoadOptions(),
opts = _.extend defaultLoadOptions(),
cache: false
headers:
'X-Feature-Name': 'a-feature'
Expand Down
12 changes: 6 additions & 6 deletions spec/loaders/collection-loader-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ = require 'jquery'
{ extend } = require '../../src/utility-functions'
_ = require 'underscore'
Backbone = require 'backbone'
Backbone.$ = $ # TODO remove after upgrading to backbone 1.2+
StorageManager = require '../../src/storage-manager'
Expand All @@ -25,7 +25,7 @@ describe 'Loaders CollectionLoader', ->
defaults =
storageManager: storageManager

loader = new loaderClass(extend {}, defaults, opts)
loader = new loaderClass(_.extend {}, defaults, opts)
loader

# It should keep the AbstractLoader behavior.
Expand Down Expand Up @@ -181,15 +181,15 @@ describe 'Loaders CollectionLoader', ->

context 'when the silent argument is true', ->
beforeEach ->
loader.setup(extend(opts, silent: true))
loader.setup(_.extend(opts, silent: true))
loader._updateStorageManagerFromResponse(fakeResponse)

it 'calls Collection#update with { silent: true }', ->
expect(Collection.prototype.update).toHaveBeenCalledWith(fakeResponse.tasks, silent: true)

context 'when the silent argument is false', ->
beforeEach ->
loader.setup(extend(opts, silent: false))
loader.setup(_.extend(opts, silent: false))
loader._updateStorageManagerFromResponse(fakeResponse)

it 'calls Collection#update with { silent: false }', ->
Expand All @@ -208,14 +208,14 @@ describe 'Loaders CollectionLoader', ->

describe 'cache option', ->
it 'updates the cache when true', ->
loader.setup(extend(opts, cache: true))
loader.setup(_.extend(opts, cache: true))
expect(loader.getCacheObject()).toBeUndefined()

loader._updateStorageManagerFromResponse(fakeResponse)
expect(loader.getCacheObject()).not.toBeUndefined()

it 'updates the cache when false', ->
loader.setup(extend(opts, cache: false))
loader.setup(_.extend(opts, cache: false))
expect(loader.getCacheObject()).toBeUndefined()

loader._updateStorageManagerFromResponse(fakeResponse)
Expand Down
4 changes: 2 additions & 2 deletions spec/loaders/model-loader-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ = require 'jquery'
{ extend } = require '../../src/utility-functions'
_ = require 'underscore'
Backbone = require 'backbone'
Backbone.$ = $ # TODO remove after upgrading to backbone 1.2+
StorageManager = require '../../src/storage-manager'
Expand All @@ -25,7 +25,7 @@ describe 'Loaders ModelLoader', ->
defaults =
storageManager: storageManager

loader = new loaderClass(extend {}, defaults, opts)
loader = new loaderClass(_.extend {}, defaults, opts)
loader

# It should keep the AbstractLoader behavior.
Expand Down
6 changes: 3 additions & 3 deletions spec/model-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ each, pluck } = require '../src/utility-functions'
_ = require 'underscore'
$ = require 'jquery'
Backbone = require 'backbone'
Backbone.$ = $ # TODO remove after upgrading to backbone 1.2+
Expand Down Expand Up @@ -386,7 +386,7 @@ describe 'Model', ->

usersIndex = tasksIndex = null

each storageManager.storage.calls.all(), (call, index) ->
_.each storageManager.storage.calls.all(), (call, index) ->
switch call.args[0]
when 'users' then usersIndex = index
when 'tasks' then tasksIndex = index
Expand Down Expand Up @@ -1052,7 +1052,7 @@ describe 'Model', ->
context 'when the deleted object is referenced in a has-many relationship', ->
it 'should remove the reference to the deleted object', ->
childTaskToDelete = buildAndCacheTask(id:103 , position: 3, updated_at: 845785, parent_task_id: 7)
survivingChildTaskIds = pluck(
survivingChildTaskIds = _.pluck(
[
buildAndCacheTask(id:77 , position: 2, updated_at: 995785, parent_task_id: 7)
buildAndCacheTask(id:99 , position: 1, updated_at: 635785, parent_task_id: 7)
Expand Down
Loading

0 comments on commit 4da0aac

Please sign in to comment.