History

Merge pull request #1357 from simon04/is_outdated-dash

doc.is_outdated: split on [-.], add unit tests

Simon Legner committed 5 years ago

Commit 89d53622 parents a2b73d8 c10516c2 files · +16 −2Browse files

Unified · Split

2 files
  1. lib/docs/core/doc.rb +2 −2
  2. test/lib/docs/core/doc_test.rb +14 −0
lib/docs/core/doc.rb+2−2
@@ -196,8 +196,8 @@ module Docs · 195 unmodified lines
196 # 1.1 -> 1.2 = outdated196 # 1.1 -> 1.2 = outdated
197 # 1.1.1 -> 1.1.2 = not outdated197 # 1.1.1 -> 1.1.2 = not outdated
198 def is_outdated(scraper_version, latest_version)198 def is_outdated(scraper_version, latest_version)
199 scraper_parts = scraper_version.to_s.split(/\./).map(&:to_i)199 scraper_parts = scraper_version.to_s.split(/[-.]/).map(&:to_i)
200 latest_parts = latest_version.to_s.split(/\./).map(&:to_i)200 latest_parts = latest_version.to_s.split(/[-.]/).map(&:to_i)
201 201
202 # Only check the first two parts, the third part is for patch updates202 # Only check the first two parts, the third part is for patch updates
203 [0, 1].each do |i|203 [0, 1].each do |i|
test/lib/docs/core/doc_test.rb+14−0
@@ -387,5 +387,19 @@ class DocsDocTest < MiniTest::Spec · 386 unmodified lines
387 assert_equal ['https://4'], version.links387 assert_equal ['https://4'], version.links
388 end388 end
389 end389 end
390
391 it "compares versions" do
392 instance = doc.versions.first.new
393 assert !instance.is_outdated('1', '1')
394 assert !instance.is_outdated('1.2', '1.2')
395 assert !instance.is_outdated('1.2.2', '1.2.2')
396 assert !instance.is_outdated('1.2.2', '1.2.3')
397 assert instance.is_outdated('1', '2')
398 assert instance.is_outdated('1.2', '1.3')
399 assert instance.is_outdated('9', '10')
400 assert instance.is_outdated('99', '101')
401 assert !instance.is_outdated('2006-01-02', '2006-01-03')
402 assert instance.is_outdated('2006-01-02', '2006-02-03')
403 end
390 end404 end
391end405end