aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/cases/subscriber_test.rb
blob: 7100b02872f90e7e3a8e357d176c40e238ebbd55 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require "abstract_unit"
require "fixtures/person"
require "rails/subscriber/test_helper"
require "active_resource/railties/subscriber"

module SubscriberTest
  Rails::Subscriber.add(:active_resource, ActiveResource::Railties::Subscriber.new)

  def setup
    @matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person')
    ActiveResource::HttpMock.respond_to do |mock|
      mock.get "/people/1.xml", {}, @matz
    end

    super
  end

  def set_logger(logger)
    ActiveResource::Base.logger = logger
  end

  def test_request_notification
    matz = Person.find(1)
    wait
    assert_equal 2, @logger.logged(:info).size
    assert_equal "GET http://somewhere.else:80/people/1.xml", @logger.logged(:info)[0] 
    assert_match /\-\-\> 200 200 106/, @logger.logged(:info)[1]
  end

  class SyncSubscriberTest < ActiveSupport::TestCase
    include Rails::Subscriber::SyncTestHelper
    include SubscriberTest
  end

  class AsyncSubscriberTest < ActiveSupport::TestCase
    include Rails::Subscriber::AsyncTestHelper
    include SubscriberTest
  end
end