rents 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80078451936b7b124d53da3e679da08045b97c17
4
- data.tar.gz: 3327aec2aeb6a9bce13fbb763de34c4cc4cf0120
3
+ metadata.gz: ba844c2f33282b0f62eb32737e641fb0f76e2057
4
+ data.tar.gz: 7c9a893f91276ff429344bebda00947690c97005
5
5
  SHA512:
6
- metadata.gz: b6e3b784344370d89513ab35dd2fefae37a049b546528d2b8f73d0d982739ef35cebfba61c1a02ff6b6b86e2396a736a8de9ab18c5b18efde3ab38a5484c2044
7
- data.tar.gz: f2c6f2b880c6033a9b6722265ac5c6b5fac8dbf9dc4fed5793ef95dac43621fdd480e1ae204e6bea81222c0294313eeb23c287dbc1cf67550cce011381bba2d5
6
+ metadata.gz: 09825367acc551a0f2e12e6a289737563a4b4b9a230b2f5ffbd913e9e747c00df89d89d1654b473d84b8173f282a23a27c044010250cf2aff7236b0f2b544739
7
+ data.tar.gz: f0c9f052506ee89272d9da97b8570a72e3f861fa213a9034a25d2b3cc8e3f35535858f702a2dad12b0c125c7e123cbc76e9247f4ac3638b65ea3ef3eabaa766e
@@ -5,7 +5,8 @@ module Rents
5
5
  def self.to_operator_str(amount)
6
6
  # Check invalid entry
7
7
  return nil if amount.nil?
8
- amount = amount.to_s if amount.is_a?Integer
8
+ return amount.to_s if amount.is_a?Integer
9
+ return amount if amount.is_a?(String) && (amount.index('.').nil? || amount.index(',').nil?)
9
10
 
10
11
  # Convert from BigDecimal
11
12
  if amount.is_a?BigDecimal
data/lib/rents/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Rents
2
2
  MAJOR = 1
3
3
  MINOR = 0
4
- PATCH = 2
4
+ PATCH = 3
5
5
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
6
6
  end
data/lib/rents.rb CHANGED
@@ -86,7 +86,7 @@ module Rents
86
86
  @@enum = enum
87
87
  end
88
88
 
89
- def self.load_yml file_name
89
+ def self.load_yml(file_name)
90
90
  YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'rents/config/enums/' + file_name))
91
91
  end
92
92
  end
@@ -1,31 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rents::Currency do
4
- describe "Operator Format value" do
4
+ describe 'Operator Format value' do
5
5
  # setup it vars to have the conversion tested, value: 1999 (nineteen ninety nine)
6
6
  pt_br = '1.999,00'
7
7
  en_us = '1,999.00'
8
+ non_formatted = '199900'
9
+ non_formatted_with_cents = '199933'
8
10
 
9
11
  # Values expected
10
- operator_value = '199900'
12
+ cents_expected = '55'
13
+ non_cents_expected = '00'
14
+ operator_value = non_formatted
15
+ integer_value = non_formatted.to_i
11
16
  operator_expected_value = '199900'
12
- integer_value = '199900'.to_i
13
17
  decimal_value = BigDecimal.new '1999.00'
14
- decimal_expected_value = BigDecimal.new '1999.00'
15
18
  operator_with_cents = '300055' # R$ 3.000,55
16
- non_cents_expected = '00'
17
- cents_expected = '55'
19
+ decimal_expected_value = BigDecimal.new '1999.00'
20
+
21
+
22
+ # Float values
23
+ float_with_cents = 1000.55
24
+ float_without_cents = 1000.0
18
25
 
19
26
  # Values Converted to operator format
27
+ non_cents_received = Rents::Currency.get_cents operator_value
28
+ decimal_converted = Rents::Currency.to_decimal operator_value
29
+ cents_received = Rents::Currency.get_cents operator_with_cents
20
30
  pt_br_operator_converted = Rents::Currency.to_operator_str pt_br
21
31
  en_us_operator_converted = Rents::Currency.to_operator_str en_us
22
- decimal_converted = Rents::Currency.to_decimal operator_value
23
- big_decimal_converted = Rents::Currency.to_operator_str decimal_value
24
32
  integer_converted = Rents::Currency.to_operator_str integer_value
25
- cents_received = Rents::Currency.get_cents operator_with_cents
26
- non_cents_received = Rents::Currency.get_cents operator_value
27
- float_with_cents = 1000.55
28
- float_without_cents = 1000.0
33
+ big_decimal_converted = Rents::Currency.to_operator_str decimal_value
34
+ non_formatted_converted = Rents::Currency.to_operator_str non_formatted
35
+ non_formatted_with_cents_converted = Rents::Currency.to_operator_str non_formatted_with_cents
29
36
 
30
37
  context 'Decimal to Operator' do
31
38
  # Convert PT_BR
@@ -70,12 +77,29 @@ describe Rents::Currency do
70
77
  # Convert from the operator to BigDecimal instance, like rails does/need
71
78
  it 'should be the BigDecimal expected' do
72
79
  expect(decimal_converted).to be_a BigDecimal
73
- expect(decimal_converted).to be == decimal_expected_value
80
+ expect(decimal_converted).to be == decimal_expected_value.to_i
81
+ end
82
+ end
83
+
84
+ context 'Non-formatted value to operator' do
85
+ context 'without cents' do
86
+ it 'must be the same as received' do
87
+ expect(non_formatted_converted).to be == non_formatted
88
+ end
89
+
90
+ it 'cents must be the same' do
91
+ expect(Rents::Currency.get_cents(non_formatted_converted)).to be == Rents::Currency.get_cents(non_formatted)
92
+ end
74
93
  end
75
94
 
76
- # Convert operator with cents to float correctly
77
- it 'should convert with cents correctly' do
95
+ context 'with cents' do
96
+ it 'must be the same as received' do
97
+ expect(non_formatted_with_cents_converted).to be == non_formatted_with_cents
98
+ end
78
99
 
100
+ it 'cents must be the same' do
101
+ expect(Rents::Currency.get_cents(non_formatted_with_cents_converted)).to be == Rents::Currency.get_cents(non_formatted_with_cents)
102
+ end
79
103
  end
80
104
  end
81
105
 
@@ -19,7 +19,7 @@ describe Rents::Transaction do
19
19
  @api_status = Rents::Status.new
20
20
  @page_transaction = Rents::Transaction.new({
21
21
  card:{brand:'visa'},
22
- amount: Random.rand(99999),
22
+ amount: Random.rand(99999), # The last 2 numbers are the cents
23
23
  redirect_link: "#{@base_url}/api/redirect_receiver" # (* optional) used only for CieloPage
24
24
  })
25
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rents
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilton Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-24 00:00:00.000000000 Z
11
+ date: 2015-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -217,7 +217,6 @@ files:
217
217
  - LICENSE.txt
218
218
  - README.md
219
219
  - Rakefile
220
- - lib/ca-bundle.crt
221
220
  - lib/generators/rents/install_generator.rb
222
221
  - lib/generators/templates/rents.rb
223
222
  - lib/rents.rb