From 5c31eccc5f8acc0a55c181d72a85b57b22dd17a1 Mon Sep 17 00:00:00 2001 From: Grey Baker Date: Sat, 24 Oct 2015 19:09:35 +0100 Subject: [PATCH] Allow attributes to be set on queue creation --- lib/fake_sqs/actions/create_queue.rb | 9 ++++++++- spec/acceptance/queue_actions_spec.rb | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/fake_sqs/actions/create_queue.rb b/lib/fake_sqs/actions/create_queue.rb index 09cabaa..b4b69ba 100644 --- a/lib/fake_sqs/actions/create_queue.rb +++ b/lib/fake_sqs/actions/create_queue.rb @@ -10,7 +10,14 @@ def initialize(options = {}) def call(params) name = params.fetch("QueueName") - queue = @queues.create(name, params) + + # Extract any attributes into a simple hash structure + attributes = params.each_with_object({}) do |(key, value), attrs| + next unless key =~ /\AAttribute\.(\d+)\.Name\z/ + attrs[value] = params.fetch("Attribute.#{$1}.Value") + end + + queue = @queues.create(name, params.merge("Attributes" => attributes)) @responder.call :CreateQueue do |xml| xml.QueueUrl @server.url_for(queue.name) end diff --git a/spec/acceptance/queue_actions_spec.rb b/spec/acceptance/queue_actions_spec.rb index bc48025..c102581 100644 --- a/spec/acceptance/queue_actions_spec.rb +++ b/spec/acceptance/queue_actions_spec.rb @@ -8,10 +8,12 @@ end specify "CreateQueue" do - response = sqs.create_queue(queue_name: "test-create-queue") + response = sqs.create_queue(queue_name: "test-create-queue", + attributes: { "VisibilityTimeout" => "5" }) expect(response.queue_url).to eq "http://0.0.0.0:4568/test-create-queue" response2 = sqs.get_queue_attributes(queue_url: response.queue_url) expect(response2.attributes.fetch("QueueArn")).to match %r"arn:aws:sqs:us-east-1:.+:test-create-queue" + expect(response2.attributes.fetch("VisibilityTimeout")).to eq "5" end specify "GetQueueUrl" do