Skip to content

Commit

Permalink
Add support for single digit version strings, closes shakacode#489
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Davies committed Jul 27, 2016
1 parent 8ca86ed commit 496b2b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/react_on_rails/version_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module ReactOnRails
# against each otherat runtime.
class VersionChecker
attr_reader :node_package_version, :logger
MAJOR_VERSION_REGEX = /(\d+)\.?/

def self.build
new(NodePackageVersion.build, Rails.logger)
Expand Down Expand Up @@ -38,7 +39,7 @@ def gem_version
end

def gem_major_version
gem_version.match(/(\d+)\./)[1]
gem_version.match(MAJOR_VERSION_REGEX)[1]
end

class NodePackageVersion
Expand Down Expand Up @@ -66,7 +67,7 @@ def relative_path?

def major
return if relative_path?
raw.match(/(\d+)\./)[1]
raw.match(MAJOR_VERSION_REGEX)[1]
end

private
Expand Down
18 changes: 18 additions & 0 deletions spec/react_on_rails/version_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ module ReactOnRails
expect(logger.message).to be_nil
end
end

context "when package json uses a one-digit version string" do
let(:node_package_version) do
double_package_version(raw: '^6', major: '6')
end

it 'does not log a warning' do
stub_gem_version("6")
check_version(node_package_version, logger)
expect(logger.message).to be_nil
end

it 'logs a warning' do
stub_gem_version("5")
check_version(node_package_version, logger)
expect(logger.message).to be_present
end
end
end

def double_package_version(raw: nil, major: nil, relative_path: false)
Expand Down

0 comments on commit 496b2b3

Please sign in to comment.