|
7 | 7 | expect(RubyDanfe::Helper.format_date(string)).to eq "18/10/2013 13:54:04" |
8 | 8 | end |
9 | 9 | end |
| 10 | + |
| 11 | + |
| 12 | + describe ".format_quantity" do |
| 13 | + context "with RubyDanfe.options.numerify_prod_qcom false" do |
| 14 | + before(:each) { |
| 15 | + RubyDanfe.options.numerify_prod_qcom = false |
| 16 | + } |
| 17 | + it "should replace last dot for comma" do |
| 18 | + expect(RubyDanfe::Helper.format_quantity("100.00")).to eq "100,00" |
| 19 | + end |
| 20 | + it "should replace all commas for dot except the last one" do |
| 21 | + expect(RubyDanfe::Helper.format_quantity("2,100.00")).to eq "2.100,00" |
| 22 | + end |
| 23 | + it "should do anything if there is no comma and dot" do |
| 24 | + expect(RubyDanfe::Helper.format_quantity("100")).to eq "100" |
| 25 | + end |
| 26 | + it "should keep decimals" do |
| 27 | + expect(RubyDanfe::Helper.format_quantity("1.665")).to eq "1,665" |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + context "with RubyDanfe.options.numerify_prod_qcom true" do |
| 32 | + context "with quantity_decimals = 4" do |
| 33 | + before(:each) { |
| 34 | + RubyDanfe.options.numerify_prod_qcom = true |
| 35 | + RubyDanfe.options.quantity_decimals = 4 |
| 36 | + } |
| 37 | + it "should format number to 4 decimal places" do |
| 38 | + expect(RubyDanfe::Helper.format_quantity("100.00")).to eq "100,0000" |
| 39 | + end |
| 40 | + it "should format number with thousand separator" do |
| 41 | + expect(RubyDanfe::Helper.format_quantity("8956100.00")).to eq "8.956.100,0000" |
| 42 | + end |
| 43 | + it "should format number without dot and comma" do |
| 44 | + expect(RubyDanfe::Helper.format_quantity("200")).to eq "200,0000" |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + context "with quantity_decimals = 3" do |
| 49 | + before(:each) { |
| 50 | + RubyDanfe.options.numerify_prod_qcom = true |
| 51 | + RubyDanfe.options.quantity_decimals = 3 |
| 52 | + } |
| 53 | + it "should format number to 4 decimal places" do |
| 54 | + expect(RubyDanfe::Helper.format_quantity("100.00")).to eq "100,000" |
| 55 | + end |
| 56 | + it "should format number with thousand separator" do |
| 57 | + expect(RubyDanfe::Helper.format_quantity("8956100.00")).to eq "8.956.100,000" |
| 58 | + end |
| 59 | + it "should format number without dot and comma" do |
| 60 | + expect(RubyDanfe::Helper.format_quantity("200")).to eq "200,000" |
| 61 | + end |
| 62 | + end |
| 63 | + end |
| 64 | + end |
10 | 65 | end |
0 commit comments