This commit is contained in:
r888888888
2013-04-23 15:58:01 -07:00
parent db69d45632
commit 1ccb33a898
3 changed files with 28 additions and 14 deletions

View File

@@ -120,7 +120,7 @@ class PostQueryBuilder
relation = add_range_relation(q[:fav_count], "posts.fav_count", relation)
relation = add_range_relation(q[:filesize], "posts.file_size", relation)
relation = add_range_relation(q[:date], "posts.created_at", relation)
relation = add_range_relation(q[:age], "extract(epoch from (posts.created_at - CURRENT_TIMESTAMP))", relation)
relation = add_range_relation(q[:age], "posts.created_at", relation)
relation = add_range_relation(q[:general_tag_count], "posts.tag_count_general", relation)
relation = add_range_relation(q[:artist_tag_count], "posts.tag_count_artist", relation)
relation = add_range_relation(q[:copyright_tag_count], "posts.tag_count_copyright", relation)

View File

@@ -195,27 +195,25 @@ class Tag < ActiveRecord::Base
size = $1.to_i
unit = $2
conversion_factor = case unit
case unit
when /^s/i
1.second
size.seconds.ago
when /^mi/i
1.minute
size.minutes.ago
when /^h/i
1.hour
size.hours.ago
when /^d/i
1.day
size.days.ago
when /^w/i
1.week
size.weeks.ago
when /^mo/i
1.month
size.months.ago
when /^y/i
1.year
size.years.ago
else
1.second
size.seconds.ago
end
(size * conversion_factor).to_i
when :filesize
object =~ /\A(\d+(?:\.\d*)?|\d*\.\d+)([kKmM]?)[bB]?\Z/

View File

@@ -839,12 +839,28 @@ class PostTest < ActiveSupport::TestCase
end
context "Searching:" do
should "return posts for the age:<1m tag" do
should "return posts for the age:>1m tag" do
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
count = Post.tag_match("age:<1m").count
count = Post.tag_match("age:>1m").count
assert_equal(1, count)
end
should "return posts for the age:>1m tag when the user is in Pacific time zone" do
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
Time.zone = "Pacific Time (US & Canada)"
count = Post.tag_match("age:>1m").count
assert_equal(1, count)
Time.zone = "Eastern Time (US & Canada)"
end
should "return posts for the age:>1m tag when the user is in Tokyo time zone" do
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
Time.zone = "Asia/Tokyo"
count = Post.tag_match("age:>1m").count
assert_equal(1, count)
Time.zone = "Eastern Time (US & Canada)"
end
should "return posts for the ' tag" do
post1 = FactoryGirl.create(:post, :tag_string => "'")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")