Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Allow string write concern keys
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Sep 24, 2013
1 parent a8d59c9 commit 393e7fa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/moped/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ def logout
# Setup validation of allowed write concern options.
#
# @since 2.0.0
option(:write).allow(w: Optionable.any(Integer))
option(:write).allow(w: Optionable.any(String))
option(:write).allow(j: true)
option(:write).allow(j: false)
option(:write).allow(fsync: true)
option(:write).allow(fsync: false)
option(:write).allow({ w: Optionable.any(Integer) }, { "w" => Optionable.any(Integer) })
option(:write).allow({ w: Optionable.any(String) }, { "w" => Optionable.any(String) })
option(:write).allow({ j: true }, { "j" => true })
option(:write).allow({ j: false }, { "j" => false })
option(:write).allow({ fsync: true }, { "fsync" => true })
option(:write).allow({ fsync: false }, { "fsync" => false })

# Setup validation of allowed read preference options.
#
Expand Down
3 changes: 2 additions & 1 deletion lib/moped/write_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module WriteConcern
#
# @since 2.0.0
def get(value)
if value[:w] == 0 || value[:w] == -1
propagate = value[:w] || value["w"]
if propagate == 0 || propagate == -1
Unverified.new
else
Propagate.new(value)
Expand Down
22 changes: 18 additions & 4 deletions spec/moped/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,26 @@

context "when a write option is provided" do

let(:unverified) do
described_class.new([ "127.0.0.1:27017" ], write: { w: 0 })
context "when the option is a symbol" do

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

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

it "returns the corresponding write concern" do
expect(unverified.write_concern).to be_a(Moped::WriteConcern::Unverified)
context "when the option is a string" do

let(:unverified) do
described_class.new([ "127.0.0.1:27017" ], write: { "w" => 0 })
end

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

Expand Down
2 changes: 1 addition & 1 deletion spec/moped/write_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
context "when provided -1" do

let(:concern) do
described_class.get(w: -1)
described_class.get("w" => -1)
end

it "returns an unverified write concern" do
Expand Down

0 comments on commit 393e7fa

Please sign in to comment.