trigger_spec.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:1k
源码类别:

Ajax

开发平台:

Others

  1. require File.dirname(__FILE__) + '/../spec_helper'
  2. describe 'With the contents fixture' do
  3.   before(:each) do
  4.     @page = mock('fake_page')
  5.     @page.stub!(:id).and_return(1)
  6.     @page.stub!(:type).and_return('Page')
  7.     @page.stub!(:new_record?).and_return(false)
  8.     @page.stub!(:class).and_return(Page)
  9.     @page.stub!(:destroyed?).and_return(false)
  10.     Content.stub!(:find).and_return(@page)
  11.     @current_utime = 1
  12.     Time.stub!(:now).and_return { Time.at(@current_utime) }
  13.   end
  14.   def sleep(time_delta)
  15.     @current_utime += time_delta
  16.   end
  17.   it '.post_action should not fire immediately for future triggers' do
  18.     lambda do
  19.       Trigger.post_action(Time.now + 2, @page, 'tickle')
  20.       Trigger.count.should == 1
  21.       Trigger.fire
  22.       Trigger.count.should == 1
  23.     end.should_not raise_error
  24.     @page.should_receive(:tickle)
  25.     sleep 2
  26.     Trigger.fire
  27.     Trigger.count.should == 0
  28.   end
  29.   it '.post_action should fire immediately if the target time is <= now' do
  30.     @page.should_receive(:tickle)
  31.     Trigger.post_action(Time.now, @page, 'tickle')
  32.     Trigger.count.should == 0
  33.   end
  34. end