From 79ec817bdcd487f00ce779c0ce0b9ffd6b2017fd Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 24 Oct 2014 22:31:57 -0500 Subject: [PATCH 1/2] Add tests for filesize: metatag searches. --- test/unit/post_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index a15a73e2b..ceb51e192 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -1290,6 +1290,19 @@ class PostTest < ActiveSupport::TestCase assert_equal(post3.id, relation.first.id) end + should "return posts for a filesize search" do + post = FactoryGirl.create(:post, :file_size => 1.megabyte) + assert_equal(1, Post.tag_match("filesize:1mb").count) + assert_equal(1, Post.tag_match("filesize:1000kb").count) + assert_equal(1, Post.tag_match("filesize:1048576b").count) + end + + should "not perform fuzzy matching for an exact filesize search" do + post = FactoryGirl.create(:post, :file_size => 1.megabyte) + assert_equal(0, Post.tag_match("filesize:1048000b").count) + assert_equal(0, Post.tag_match("filesize:1048000").count) + end + should "fail for more than 6 tags" do post1 = FactoryGirl.create(:post, :rating => "s") From 9cc41de258d74c1b23877883642b65e36180bb0f Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 13 Oct 2014 21:48:34 -0500 Subject: [PATCH 2/2] Don't fudge filesize in filesize:1234b searches. --- app/models/tag.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index ed8cd9d2e..780c9b700 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -320,7 +320,10 @@ class Tag < ActiveRecord::Base def parse_helper_fudged(range, type) result = parse_helper(range, type) - if result[0] == :eq + # Don't fudge the filesize when searching filesize:123b or filesize:123. + if result[0] == :eq && type == :filesize && range !~ /[km]b?\Z/i + result + elsif result[0] == :eq new_min = (result[1] * 0.95).to_i new_max = (result[1] * 1.05).to_i [:between, new_min, new_max]