spec/mongoid/clients_spec.rb in mongoid-7.0.2 vs spec/mongoid/clients_spec.rb in mongoid-7.0.3

- old
+ new

@@ -206,10 +206,76 @@ klass.collection_name end end it_behaves_like "an overridden collection name at the class level" + + context 'when nesting #with calls' do + let(:instance_collection_name) do + Band.with(collection: "ignore") do |klass| + Band.with(collection: "artists") do |klass| + klass.new.collection_name + end + end + end + + let(:class_collection_name) do + Band.with(collection: "ignore") do |klass| + Band.with(collection: "artists") do |klass| + klass.collection_name + end + end + end + + it_behaves_like "an overridden collection name at the class level" + end + + context 'when outer #with call specifies the collection' do + use_spec_mongoid_config + + let(:instance_collection_name) do + Band.with(collection: "artists") do |klass| + Band.with(client: :reports) do |klass| + klass.new.collection_name + end + end + end + + let(:class_collection_name) do + Band.with(collection: "artists") do |klass| + Band.with(client: :reports) do |klass| + klass.collection_name + end + end + end + + it_behaves_like "an overridden collection name at the class level" + end + + context 'restores outer context in outer block' do + use_spec_mongoid_config + + let(:instance_collection_name) do + Band.with(collection: "artists") do |klass| + Band.with(collection: "scratch") do |klass| + # nothing + end + klass.new.collection_name + end + end + + let(:class_collection_name) do + Band.with(collection: "artists") do |klass| + Band.with(collection: "scratch") do |klass| + # nothing + end + klass.collection_name + end + end + + it_behaves_like "an overridden collection name at the class level" + end end context "when overriding store_in and persistence options" do let(:instance_collection_name) do @@ -425,11 +491,11 @@ context "when overriding using the client" do let(:client_name) { :alternative } before do - Mongoid.clients[client_name] = { database: database_id_alt, hosts: [ "#{HOST}:#{PORT}" ] } + Mongoid.clients[client_name] = { database: database_id_alt, hosts: SpecConfig.instance.addresses } end after do Mongoid.clients.delete(client_name) end @@ -550,23 +616,17 @@ }.to raise_error(Mongoid::Errors::NoClientConfig) end end context "when getting a client by name" do + use_spec_mongoid_config - let(:file) do - File.join(File.dirname(__FILE__), "..", "config", "mongoid.yml") - end - before do - described_class.clear - Mongoid.load!(file, :test) Band.store_in(client: :reports) end after do mongo_client.close - Mongoid::Config.reset Band.reset_storage_options! end let(:mongo_client) do Band.new.mongo_client