Skip to content

Commit

Permalink
Merge pull request #122 from felixyz/integer-instead-of-fixnum-ruby24
Browse files Browse the repository at this point in the history
Avoid using Fixnum as type on all Rubys, Fixes #93
  • Loading branch information
d-Pixie authored Oct 30, 2017
2 parents 649582d + 2d5fd50 commit f1b36ab
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 1 addition & 2 deletions fortnox-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
spec.test_files = spec.files.grep(%r{^(spec)/})
spec.require_paths = ["lib"]

spec.required_ruby_version = ['> 2.2', '< 2.4'] # TODO: Gem breaks with Ruby 2.4 or higher. See issue #93.

spec.required_ruby_version = '> 2.2'
spec.add_dependency "httparty", "~> 0.14.0" # TODO: Temporary lockdown. See issue #103 for more info.
spec.add_dependency "dotenv", "~> 2.0"
spec.add_dependency "dry-struct", "~> 0.1"
Expand Down
2 changes: 1 addition & 1 deletion lib/fortnox/api/mappers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Mapper
end
end

Registry.register( :fixnum, Fortnox::API::Mapper::Identity )
Registry.register( :integer, Fortnox::API::Mapper::Identity )
Registry.register( :int, Fortnox::API::Mapper::Identity )
Registry.register( :float, Fortnox::API::Mapper::Identity )
Registry.register( :string, Fortnox::API::Mapper::Identity )
Expand Down
3 changes: 3 additions & 0 deletions lib/fortnox/api/mappers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def self.canonical_name_sym( *values )
values.first.class
end

# For Ruby < 2.4, make sure we don't pass Bignum and Fixnum around
klass = Integer if %w(Bignum Fixnum).include?(klass.to_s) # Stringify to avoid warnings on 2.4

klass.name.split('::').last.downcase.to_sym
end

Expand Down
6 changes: 6 additions & 0 deletions spec/fortnox/api/mappers/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
end
end

describe 'array with very large int (Bigint if Ruby <2.4)' do
include_examples 'identity mapper', :array do
let( :value ){ [(100**10)] }
end
end

describe 'advanced array' do
include_examples 'simple mapper', :array, [ "2016-01-01", "2016-01-02" ] do
let( :value ){ [ Date.new(2016, 1, 1), Date.new(2016, 1, 2) ] }
Expand Down

0 comments on commit f1b36ab

Please sign in to comment.