Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Created August 20, 2013 02:06
Show Gist options
  • Save arthurnn/6276351 to your computer and use it in GitHub Desktop.
Save arthurnn/6276351 to your computer and use it in GitHub Desktop.
# encoding: utf-8
require "spec_helper"
class Person
include Mongoid::Document
has_many :pets
field :name
end
class Pet
include Mongoid::Document
belongs_to :person
field :species
end
describe "ThreadSpec" do
context 'with two collections and many threads' do
let(:pet) { Pet.new }
let(:person) { Person.new }
before do
threads = (0...50).map do
Thread.new do
Pet.store_in collection: 'bands'
Person.store_in collection: 'artists'
end
end
threads.map(&:join)
end
after do
Pet.storage_options = nil
Person.storage_options = nil
end
it 'sets the right collection for Band' do
expect(Pet.collection.name).to eq('bands')
end
it 'sets the right collection for Artist' do
expect(Person.collection.name).to eq('artists')
end
end
end
@arthurnn
Copy link
Author

running on:

Arthurs-MacBook-Pro:echo arthurnn$ ruby -v
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_17-b02 [darwin-x86_64]

gems

  * carrierwave-mongoid (0.3.0)
  * mongoid (3.1.4)
  * mongoid-grid_fs (1.7.0)
  * moped (1.5.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment