Sha256: fa2dc70b337f59ef6ea856648da93509a0c75d04b152cd694cd0b3d1dc77bf63
Contents?: true
Size: 1.62 KB
Versions: 4
Compression:
Stored size: 1.62 KB
Contents
require "spec_helper" describe Mongoid::Sessions::Options do describe "#with" do context "when passing some options" do let(:options) { { database: 'test' } } let!(:klass) do Band.with(options) end it "sets the options into the class" do expect(klass.persistence_options).to eq(options) end it "sets the options into the instance" do expect(klass.new.persistence_options).to eq(options) end it "doesnt set the options on class level" do expect(Band.new.persistence_options).to be_nil end context "when calling .collection method" do before do klass.collection end it "keeps the options" do expect(klass.persistence_options).to eq(options) end end end end describe ".with" do let(:options) { { database: 'test' } } let(:instance) do Band.new.with(options) end it "sets the options into" do expect(instance.persistence_options).to eq(options) end it "passes down the options to collection" do Moped::Session.any_instance.should_receive(:with).with(options).and_return({}) instance.collection end end describe "#persistence_options" do it "touches the thread local" do expect(Thread.current).to receive(:[]).with("[mongoid][Band]:persistence-options").and_return({foo: :bar}) expect(Band.persistence_options).to eq({foo: :bar}) end it "cannot force a value on thread local" do expect { Band.set_persistence_options(Band, {}) }.to raise_error(NoMethodError) end end end
Version data entries
4 entries across 4 versions & 3 rubygems