Sha256: 41586cd1c37f378d1c80b813b5e6348aa3fd37a76078ba99a0b66f1ca3fac220

Contents?: true

Size: 1.89 KB

Versions: 5

Compression:

Stored size: 1.89 KB

Contents

require File.expand_path('../test_helper', __FILE__)

module Propono
  class QueueSubscriptionTest < Minitest::Test
    def test_create_topic
      topic_id = 'foobar'
      topic = Topic.new(topic_id)
      TopicCreator.expects(:find_or_create).with(topic_id).returns(topic)
      QueueSubscription.create(topic_id)
    end

    def test_sqs_create_is_called
      topic_id = "Foobar"
      subscription = QueueSubscription.new(topic_id)

      TopicCreator.stubs(find_or_create: Topic.new("1123"))

      sqs = mock()
      sqs.expects(:create_queue).with(subscription.send(:queue_name)).returns(mock(body: {'QueueUrl' => Fog::AWS::SQS::Mock::QueueUrl}))
      QueueCreator.any_instance.stubs(sqs: sqs)

      subscription.create
    end

    def test_subscription_queue_name
      config.application_name = "MyApp"

      topic_id = "Foobar"
      subscription = QueueSubscription.new(topic_id)

      assert_equal subscription.send(:queue_name), "MyApp-Foobar"
    end

    def test_subscription_queue_name_with_spaces
      config.application_name = "My App"

      topic_id = "Foobar"
      subscription = QueueSubscription.new(topic_id)

      assert_equal subscription.send(:queue_name), "My_App-Foobar"
    end

    def test_create_calls_create
      arn = "arn123"

      TopicCreator.stubs(find_or_create: Topic.new(arn))
      QueueCreator.stubs(find_or_create: Queue.new(Fog::AWS::SQS::Mock::QueueUrl))

      sns = mock()
      sns.expects(:subscribe).with(arn, Fog::AWS::SQS::Mock::QueueArn, 'sqs')
      subscription = QueueSubscription.new("Some topic")
      subscription.stubs(sns: sns)
      subscription.create
    end

    def test_create_saves_queue
      queue = Queue.new(Fog::AWS::SQS::Mock::QueueUrl)

      QueueCreator.expects(:find_or_create).returns(queue)
      subscription = QueueSubscription.new("Some Topic")
      subscription.create
      assert_equal queue, subscription.queue
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
propono-0.5.4 test/queue_subscription_test.rb
propono-0.5.3 test/queue_subscription_test.rb
propono-0.5.2 test/queue_subscription_test.rb
propono-0.5.1 test/queue_subscription_test.rb
propono-0.5.0 test/queue_subscription_test.rb