-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from imdrasil/feature/add-big-decimal-support
Add BigDecimal support
- Loading branch information
Showing
30 changed files
with
291 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "../spec_helper" | ||
|
||
describe Jennifer::Model::BigDecimalConverter do | ||
described_class = Jennifer::Model::BigDecimalConverter(PG::Numeric) | ||
|
||
describe "#from_db" do | ||
postgres_only do | ||
it "reads numeric from result set" do | ||
ballance = PG::Numeric.new(2i16, 0i16, 0i16, 3i16, [1234i16, 6800i16]) | ||
executed = false | ||
Factory.create_contact(ballance: ballance) | ||
Contact.all.select([Contact._ballance]).each_result_set do |rs| | ||
described_class.from_db(rs, {name: "ballance", scale: 2, null: false}).should eq(BigDecimal.new(123468, 2)) | ||
executed = true | ||
end | ||
executed.should be_true | ||
end | ||
end | ||
|
||
it "reads nil from result set" do | ||
executed = false | ||
Factory.create_contact(ballance: nil) | ||
Contact.all.select([Contact._ballance]).each_result_set do |rs| | ||
described_class.from_db(rs, {name: "ballance", scale: 2, null: true}).should be_nil | ||
executed = true | ||
end | ||
executed.should be_true | ||
end | ||
end | ||
|
||
describe "#to_db" do | ||
postgres_only do | ||
it "writes value to a result set" do | ||
balance = described_class.to_db(BigDecimal.new(123468, 2), {name: "ballance", scale: 2}) | ||
Query["contacts"].insert(%w(name age ballance), [["test", 1, balance]]) | ||
Contact.all.last!.ballance.should eq(PG::Numeric.new(2i16, 0i16, 0i16, 2i16, [1234i16, 6800i16])) | ||
end | ||
end | ||
end | ||
|
||
describe "#from_hash" do | ||
postgres_only do | ||
it "converts numeric" do | ||
balance = PG::Numeric.new(2i16, 0i16, 0i16, 2i16, [1234i16, 6800i16]) | ||
described_class.from_hash({ "ballance" => balance }, "ballance", {name: "ballance", scale: 2}) | ||
.should eq(BigDecimal.new(123468, 2)) | ||
end | ||
end | ||
|
||
it "accepts nil value" do | ||
described_class.from_hash({ "ballance" => nil }, "ballance", {name: "ballance", scale: 2}).should be_nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "../spec_helper" | ||
|
||
describe Jennifer::Model::Coercer do | ||
described_class = Jennifer::Model::Coercer | ||
|
||
describe BigDecimal do | ||
it { described_class.coerce("123.12", BigDecimal?).should eq(BigDecimal.new(12312, 2)) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.