Merge pull request #2283 from evazion/fix-exact-filesize-search

Fix #2248: filesize metatag: exact match if unit is bytes
This commit is contained in:
Albert Yi
2014-10-26 16:32:22 -07:00
2 changed files with 17 additions and 1 deletions

View File

@@ -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]

View File

@@ -1328,6 +1328,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")