doc.is_outdated: split on [-.], add unit tests
Unified · Split
| @@ -196,8 +196,8 @@ module Docs · 195 unmodified lines | ||
| 196 | 196 | # 1.1 -> 1.2 = outdated |
| 197 | 197 | # 1.1.1 -> 1.1.2 = not outdated |
| 198 | 198 | def is_outdated(scraper_version, latest_version) |
| 199 | − scraper_parts = scraper_version.to_s.split(/\./).map(&:to_i) | |
| 200 | − latest_parts = latest_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) | |
| 201 | 201 | |
| 202 | 202 | # Only check the first two parts, the third part is for patch updates |
| 203 | 203 | [0, 1].each do |i| |
| @@ -387,5 +387,19 @@ class DocsDocTest < MiniTest::Spec · 386 unmodified lines | ||
| 387 | 387 | assert_equal ['https://4'], version.links |
| 388 | 388 | end |
| 389 | 389 | 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 | 404 | end |
| 391 | 405 | end |