Skip to content

Instantly share code, notes, and snippets.

@osiro
Created September 14, 2012 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osiro/3720305 to your computer and use it in GitHub Desktop.
Save osiro/3720305 to your computer and use it in GitHub Desktop.
Venue Model Spec
describe 'Venue', ->
describe '#findByIds', ->
beforeEach =>
@venue1 = Factory.create 'Venue', attributes: -> {id: 1}
@venue2 = Factory.create 'Venue', attributes: -> {id: 2}
@venue3 = Factory.create 'Venue', attributes: -> {id: 3}
afterEach =>
Venue.destroyAll()
it "should return the correct venues", =>
for venue in Venue.findByIds([1,2])
expect(venue.id).not.toEqual(@venue3.id)
describe '#nameSort', ->
beforeEach =>
@venue1 = Factory.create 'Venue', attributes: -> {name: 'a'}
@venue2 = Factory.create 'Venue', attributes: -> {name: 'b'}
it "should return -1", =>
expect(Venue.nameSort(@venue1, @venue2)).toEqual(-1)
it "should return 0", =>
expect(Venue.nameSort(@venue1, @venue1)).toEqual(0)
it "should return 0", =>
expect(Venue.nameSort(@venue2, @venue1)).toEqual(1)
afterEach =>
Venue.destroyAll()
describe '#capacitySort', ->
beforeEach =>
@venue1 = Factory.create 'Venue', attributes: -> {capacity: { overall: { live: 10 } } }
@venue2 = Factory.create 'Venue', attributes: -> {capacity: { overall: { live: 20 } } }
it "should return 10", =>
expect(Venue.capacitySort(@venue1, @venue2)).toEqual(10)
afterEach =>
Venue.destroyAll()
describe '.statsFor', ->
beforeEach =>
@venue = Factory.create 'Venue', attributes: -> { capacity: {
female: { monday: '10' },
male: { tuesday: '20' },
overall:{ wednesday: '30' },
} }
it 'should return 10', =>
expect(@venue.statsFor('female', 'monday')).toEqual('10')
it 'should return 20', =>
expect(@venue.statsFor('male', 'tuesday')).toEqual('20')
it 'should return 30', =>
expect(@venue.statsFor('overall', 'wednesday')).toEqual('30')
afterEach =>
Venue.destroyAll()
describe '#distanceSort', ->
beforeEach =>
@venue1 = Factory.create 'Venue', attributes: -> {distance: '1'}
@venue2 = Factory.create 'Venue', attributes: -> {distance: '2'}
it "should return -1", =>
expect(Venue.distanceSort(@venue1, @venue2)).toEqual(-1)
afterEach =>
Venue.destroyAll()
describe '#calculateDistanceFromCurrentLocation', ->
beforeEach =>
@venue = Factory.create 'Venue', attributes: -> {distance: null, latitude: '-31.933', longitude: '115.833'}
it 'should update distance', =>
Venue.calculateDistanceFromCurrentLocation([@venue])
expect(@venue.distance).not.toEqual(null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment