mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
doc.is_outdated: split on [-.], add unit tests
This commit is contained in:
parent
a2b73d81bc
commit
c10516cc62
2 changed files with 16 additions and 2 deletions
|
@ -196,8 +196,8 @@ module Docs
|
|||
# 1.1 -> 1.2 = outdated
|
||||
# 1.1.1 -> 1.1.2 = not outdated
|
||||
def is_outdated(scraper_version, latest_version)
|
||||
scraper_parts = scraper_version.to_s.split(/\./).map(&:to_i)
|
||||
latest_parts = latest_version.to_s.split(/\./).map(&:to_i)
|
||||
scraper_parts = scraper_version.to_s.split(/[-.]/).map(&:to_i)
|
||||
latest_parts = latest_version.to_s.split(/[-.]/).map(&:to_i)
|
||||
|
||||
# Only check the first two parts, the third part is for patch updates
|
||||
[0, 1].each do |i|
|
||||
|
|
|
@ -387,5 +387,19 @@ class DocsDocTest < MiniTest::Spec
|
|||
assert_equal ['https://4'], version.links
|
||||
end
|
||||
end
|
||||
|
||||
it "compares versions" do
|
||||
instance = doc.versions.first.new
|
||||
assert !instance.is_outdated('1', '1')
|
||||
assert !instance.is_outdated('1.2', '1.2')
|
||||
assert !instance.is_outdated('1.2.2', '1.2.2')
|
||||
assert !instance.is_outdated('1.2.2', '1.2.3')
|
||||
assert instance.is_outdated('1', '2')
|
||||
assert instance.is_outdated('1.2', '1.3')
|
||||
assert instance.is_outdated('9', '10')
|
||||
assert instance.is_outdated('99', '101')
|
||||
assert !instance.is_outdated('2006-01-02', '2006-01-03')
|
||||
assert instance.is_outdated('2006-01-02', '2006-02-03')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue