Skip to content

Commit

Permalink
specs for extra writeconcern options [mongoid#307]
Browse files Browse the repository at this point in the history
  • Loading branch information
leemhenson committed Feb 27, 2015
1 parent 9781a5b commit 06113d8
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/moped/write_concern/propagate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(options)
def normalize(options)
opts = {}
options.each do |key, value|
opts[key] = value.is_a?(Symbol) ? value.to_s : value
opts[key.to_sym] = value.is_a?(Symbol) ? value.to_s : value
end
opts
end
Expand Down
104 changes: 104 additions & 0 deletions spec/moped/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,29 @@
expect(unverified.write_concern).to be_a(Moped::WriteConcern::Unverified)
end
end

context "when the value is an integer" do

let(:verified) do
described_class.new([ "127.0.0.1:27017" ], write: { w: 1 })
end

it "returns the corresponding write concern" do
expect(verified.write_concern).to be_a(Moped::WriteConcern::Propagate)
end
end

context "when the value is an string" do

let(:verified) do
described_class.new([ "127.0.0.1:27017" ], write: { w: "majority" })
end

it "returns the corresponding write concern" do
expect(verified.write_concern).to be_a(Moped::WriteConcern::Propagate)
expect(verified.write_concern.operation[:w]).to eq('majority')
end
end
end

context "when no write option is provided" do
Expand All @@ -327,6 +350,87 @@
expect(propagate.write_concern).to be_a(Moped::WriteConcern::Propagate)
end
end

context "when a timeout option is provided" do

context "when the option is a symbol" do

let(:verified) do
described_class.new([ "127.0.0.1:27017" ], write: { wtimeout: 10000 })
end

it "returns the corresponding write concern" do
expect(verified.write_concern).to be_a(Moped::WriteConcern::Propagate)
expect(verified.write_concern.operation[:wtimeout]).to eq(10000)
end
end

context "when the option is a string" do

let(:verified) do
described_class.new([ "127.0.0.1:27017" ], write: { 'wtimeout' => 10000 })
end

it "returns the corresponding write concern" do
expect(verified.write_concern).to be_a(Moped::WriteConcern::Propagate)
expect(verified.write_concern.operation[:wtimeout]).to eq(10000)
end
end
end

context "when a journal option is provided" do

context "when the option is a symbol" do

let(:verified) do
described_class.new([ "127.0.0.1:27017" ], write: { j: true })
end

it "returns the corresponding write concern" do
expect(verified.write_concern).to be_a(Moped::WriteConcern::Propagate)
expect(verified.write_concern.operation[:j]).to eq(true)
end
end

context "when the option is a string" do

let(:verified) do
described_class.new([ "127.0.0.1:27017" ], write: { 'j' => true })
end

it "returns the corresponding write concern" do
expect(verified.write_concern).to be_a(Moped::WriteConcern::Propagate)
expect(verified.write_concern.operation[:j]).to eq(true)
end
end
end

context "when an fsync option is provided" do

context "when the option is a symbol" do

let(:verified) do
described_class.new([ "127.0.0.1:27017" ], write: { fsync: true })
end

it "returns the corresponding write concern" do
expect(verified.write_concern).to be_a(Moped::WriteConcern::Propagate)
expect(verified.write_concern.operation[:fsync]).to eq(true)
end
end

context "when the option is a string" do

let(:verified) do
described_class.new([ "127.0.0.1:27017" ], write: { 'fsync' => true })
end

it "returns the corresponding write concern" do
expect(verified.write_concern).to be_a(Moped::WriteConcern::Propagate)
expect(verified.write_concern.operation[:fsync]).to eq(true)
end
end
end
end

context "when attempting to connect to a node that does not exist" do
Expand Down

0 comments on commit 06113d8

Please sign in to comment.