Changeset 32960 for lang

Show
Ignore:
Timestamp:
04/30/09 13:18:17 (5 years ago)
Author:
isaisstillalive
Message:
  • eachにて初期ページ推測を利用するように変更
Location:
lang/ruby/hatena_binding
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/hatena_binding/lib/hatena/haiku/entries.rb

    r32959 r32960  
    1414        executed_ids = Set.new 
    1515         
    16         super query do |entry| 
     16        page = @since ? guess_binary_search_range(query, @since) 
     17                      : 1 
     18         
     19        super query, page do |entry| 
    1720          id = entry["id"] 
    1821          next if executed_ids.include? id 
  • lang/ruby/hatena_binding/test/hatena/haiku/test_entries.rb

    r32959 r32960  
    141141  end 
    142142   
     143  # eachメソッドは、@sinceが設定されている場合、初期値を推測する 
     144  def test_each_should_guess_first_page 
     145    def @entries.page query, page, &block 
     146      $called_methods << [:page, [query, page]] 
     147      raise StopIteration 
     148    end 
     149    def @entries.guess_binary_search_range query, target 
     150      $called_methods << [:guess_binary_search_range, [query, target]] 
     151      100 
     152    end 
     153     
     154    @entries.instance_variable_set(:@since, (Time.local(2009, 4, 1).utc)) 
     155     
     156    @entries.each{} 
     157     
     158    assert_equal 2, $called_methods.size 
     159    assert_equal [:guess_binary_search_range, ["", Time.local(2009, 4, 1).utc]], $called_methods[0] 
     160    assert_equal [:page, ["", 100]], $called_methods[1] 
     161  end 
     162   
    143163  # _betweenメソッドは、@after, @beforeプロパティを変更した新しいEntriesを返す 
    144164  def test_between_should_return_after_and_before_properties_changed_new_entries