Created
January 10, 2012 09:54
-
-
Save al6x/1588214 to your computer and use it in GitHub Desktop.
Ruby vs NodeJS vs NodeJS + Async vs NodeJS + Fibers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'driver/spec_helper' | |
describe "Collection" do | |
with_mongo | |
it "should by default update all matched by criteria (not first as default in mongo)" do | |
db.units.save name: 'Probe', race: 'Protoss', status: 'alive' | |
db.units.save name: 'Zealot', race: 'Protoss', status: 'alive' | |
# Update. | |
db.units.update({race: 'Protoss'}, :$set => {status: 'dead'}) | |
db.units.all.collect{|u| u['status']}.should == %w(dead dead) | |
# Delete. | |
db.units.delete race: 'Protoss' | |
db.units.count.should == 0 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Collection", -> | |
withMongo() | |
it.async "should by default update all matched by criteria (not just first as default in mongo)", -> | |
$db.collection 'units', (err, units) -> | |
# Create. | |
units.save name: 'Probe', race: 'Protoss', status: 'alive', (err) -> | |
units.save name: 'Zealot', race: 'Protoss', status: 'alive', (err) -> | |
# Update. | |
units.update {race: 'Protoss'}, $set: {status: 'dead'}, (err) -> | |
units.all (err, list) -> | |
list.map((u) -> u.status).should be: ['dead', 'dead'] | |
# Delete. | |
units.delete race: 'Protoss', (err) -> | |
units.count (err, v) -> | |
v.should be: 0 | |
it.next() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Collection", -> | |
withMongo() | |
it.async "should by default update all matched by criteria (not just first as default in mongo)", -> | |
async.flow | |
units: -> $db.collection 'units', @next | |
-> @units.save name: 'Probe', race: 'Protoss', status: 'alive', @next | |
-> @units.save name: 'Zealot', race: 'Protoss', status: 'alive', @next | |
-> @units.update {race: 'Protoss'}, $set: {status: 'dead'}, @next | |
-> @units.all (err, list) => | |
list.map((u) -> u.status).should be: ['dead', 'dead'] | |
@next err, list | |
-> @units.delete race: 'Protoss', @next | |
-> @units.count (err, v) => | |
v.should be: 0 | |
@next err, v | |
(err) -> | |
_(err).should be: null | |
it.next() | |
# Source of async | |
# https://github.com/alexeypetrushin/node_modules/blob/master/async-ext.coffee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Collection", -> | |
withMongoSync() | |
it.sync "should update all matched by criteria (not just first as default in mongo)", -> | |
units = $db.collection 'units' | |
units.save name: 'Probe', race: 'Protoss', status: 'alive' | |
units.save name: 'Zealot', race: 'Protoss', status: 'alive' | |
units.update {race: 'Protoss'}, $set: {status: 'dead'} | |
units.all().map((u) -> u.status).should be: ['dead', 'dead'] | |
units.delete race: 'Protoss' | |
units.count().should be: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the tool that allows You to write such compact code http://alexeypetrushin.github.com/synchronize