Skip to content

Commit 0fc10be

Browse files
authored
Make positional arguments optional for set_cookie_item action (#23)
This pull request updates the stream helper for the `set_cookie_item` action. It makes the positional arguments optional in order to just allow to specify them as keyword arguments. this action was implemented in marcoroth/turbo_power#32
1 parent 53da112 commit 0fc10be

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/turbo_power/stream_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ def set_cookie(cookie, **attributes)
153153
custom_action :set_cookie, attributes: attributes.merge(cookie: cookie)
154154
end
155155

156-
def set_cookie_item(key, value, **attributes)
157-
custom_action :set_cookie_item, attributes: attributes.merge(key: key, value: value)
156+
def set_cookie_item(key = nil, value = nil, **attributes)
157+
custom_action :set_cookie_item, attributes: { key: key, value: value }.merge(attributes)
158158
end
159159

160160
def set_focus(target, **attributes)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
module TurboPower
6+
module StreamHelper
7+
class SetCookieItemTest < StreamHelperTestCase
8+
test "set_cookie_item" do
9+
stream = %(<turbo-stream key="my-key" value="my-value" action="set_cookie_item"><template></template></turbo-stream>)
10+
11+
assert_dom_equal stream, turbo_stream.set_cookie_item("my-key", "my-value")
12+
end
13+
14+
test "set_cookie_item with kwargs" do
15+
stream = %(<turbo-stream key="my-key" value="my-value" action="set_cookie_item"><template></template></turbo-stream>)
16+
17+
assert_dom_equal stream, turbo_stream.set_cookie_item(key: "my-key", value: "my-value")
18+
end
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)