Skip to content

Commit 368d241

Browse files
committed
Add a SetHeader response mutator
1 parent 17a638a commit 368d241

File tree

5 files changed

+79
-2
lines changed

5 files changed

+79
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [0.0.19] - 2025-03-31
2+
3+
- Add SetHeader response mutator
4+
- Use / instead of :: for paths
5+
16
## [0.0.18] - 2025-03-29
27

38
- Implement SetInputsFromHeader request mutator and MoveAttributeToHeader response mutator

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
foobara-http-command-connector (0.0.18)
4+
foobara-http-command-connector (0.0.19)
55
foobara (~> 0.0.88)
66

77
GEM
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
RSpec.describe Foobara::CommandConnectors::Http::SetHeader do
2+
let(:command_class) do
3+
stub_class(:SomeCommand, Foobara::Command) do
4+
result foo: :string, bar: :string
5+
6+
def execute
7+
{ foo: "foo value", bar: "bar value" }
8+
end
9+
end
10+
end
11+
12+
let(:response_mutator) do
13+
described_class.for(:baz_header, "bazvalue")
14+
end
15+
16+
let(:command_connector) { Foobara::CommandConnectors::Http.new }
17+
let(:response) { command_connector.run(path: "/run/#{command_class.full_command_name}") }
18+
19+
before do
20+
command_connector.connect(command_class, response_mutators: response_mutator)
21+
end
22+
23+
it "moves the attribute to a header" do
24+
expect(response.status).to eq(200)
25+
26+
expect(JSON.parse(response.body)).to eq("foo" => "foo value", "bar" => "bar value")
27+
expect(response.headers["baz_header"]).to eq("bazvalue")
28+
end
29+
30+
it "does not change the result type" do
31+
result_type = command_class.result_type
32+
expect(response_mutator.instance.result_type_from(result_type)).to be(result_type)
33+
end
34+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module Foobara
2+
module CommandConnectors
3+
class Http < CommandConnector
4+
class SetHeader < ResponseMutator
5+
class << self
6+
attr_accessor :header_name, :header_value
7+
8+
def for(header_name, header_value)
9+
subclass = Class.new(self)
10+
11+
subclass.header_name = header_name
12+
subclass.header_value = header_value
13+
14+
subclass
15+
end
16+
end
17+
18+
attr_writer :header_name, :header_value
19+
20+
def result_type_from(result_type)
21+
result_type
22+
end
23+
24+
def mutate(response)
25+
response.add_header(header_name.to_s, header_value)
26+
end
27+
28+
def header_name
29+
@header_name ||= self.class.header_name
30+
end
31+
32+
def header_value
33+
@header_value ||= self.class.header_value
34+
end
35+
end
36+
end
37+
end
38+
end

version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Foobara
22
module HttpCommandConnector
3-
VERSION = "0.0.18".freeze
3+
VERSION = "0.0.19".freeze
44

55
local_ruby_version = File.read("#{__dir__}/.ruby-version").chomp
66
local_ruby_version_minor = local_ruby_version[/\A(\d+\.\d+)\.\d+\z/, 1]

0 commit comments

Comments
 (0)