diff --git a/app/logical/post_sets/intro.rb b/app/logical/post_sets/intro.rb new file mode 100644 index 000000000..b972e616e --- /dev/null +++ b/app/logical/post_sets/intro.rb @@ -0,0 +1,15 @@ +module PostSets + class Intro < PostSets::Post + def initialize(tags) + super(tags) + end + + def posts + @posts ||= begin + temp = ::Post.tag_match("#{tag_string} fav_count:>3").paginate(page, :search_count => nil, :limit => 6) + temp.all + temp + end + end + end +end diff --git a/app/presenters/intro_presenter.rb b/app/presenters/intro_presenter.rb index b68d83642..14844c138 100644 --- a/app/presenters/intro_presenter.rb +++ b/app/presenters/intro_presenter.rb @@ -5,7 +5,7 @@ class IntroPresenter def each popular_tags.each do |tag| - yield(tag, PostSets::Post.new(tag, 1, 6)) + yield(tag, PostSets::Intro.new(tag)) end end end diff --git a/test/unit/post_sets/intro_test.rb b/test/unit/post_sets/intro_test.rb new file mode 100644 index 000000000..f6f0f55ac --- /dev/null +++ b/test/unit/post_sets/intro_test.rb @@ -0,0 +1,42 @@ +require 'test_helper' +require "danbooru/paginator/pagination_error" + +module PostSets + class IntroTest < ActiveSupport::TestCase + context "In all cases" do + setup do + @user = FactoryGirl.create(:user) + CurrentUser.user = @user + CurrentUser.ip_addr = "127.0.0.1" + MEMCACHE.flush_all + + @post_1 = FactoryGirl.create(:post, :tag_string => "a") + @post_2 = FactoryGirl.create(:post, :tag_string => "b") + @post_3 = FactoryGirl.create(:post, :tag_string => "c") + end + + teardown do + CurrentUser.user = nil + CurrentUser.ip_addr = nil + end + + context "a set for the 'a' tag query" do + setup do + @post_4 = FactoryGirl.create(:post, :tag_string => "a") + @post_5 = FactoryGirl.create(:post, :tag_string => "a") + end + + context "with no page" do + setup do + @set = PostSets::Intro.new("a") + ::Post.stubs(:records_per_page).returns(1) + end + + should "return the first element" do + assert_equal(@post_5.id, @set.posts.first.id) + end + end + end + end + end +end