[devdocsgjs/main: 1254/1867] doc.is_outdated: split on [-.], add unit tests
- From: Andy Holmes <andyholmes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devdocsgjs/main: 1254/1867] doc.is_outdated: split on [-.], add unit tests
- Date: Fri, 19 Nov 2021 23:47:51 +0000 (UTC)
commit c10516cc62f961ff83de75ee6143d21a79c8cbd5
Author: Simon Legner <Simon Legner gmail com>
Date: Thu Nov 19 22:05:50 2020 +0100
doc.is_outdated: split on [-.], add unit tests
lib/docs/core/doc.rb | 4 ++--
test/lib/docs/core/doc_test.rb | 14 ++++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/lib/docs/core/doc.rb b/lib/docs/core/doc.rb
index 94611208..3b67acb1 100644
--- a/lib/docs/core/doc.rb
+++ b/lib/docs/core/doc.rb
@@ -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|
diff --git a/test/lib/docs/core/doc_test.rb b/test/lib/docs/core/doc_test.rb
index fc28a2f6..c0ea718c 100644
--- a/test/lib/docs/core/doc_test.rb
+++ b/test/lib/docs/core/doc_test.rb
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]