Skip to content

Commit 489f5db

Browse files
committed
Fix form_with arguments
1 parent b731919 commit 489f5db

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

app/helpers/strata/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def strata_form_with(model: false, scope: nil, url: nil, format: nil, **options,
99
options[:builder] = Strata::FormBuilder
1010
args = { scope: scope, url: url, format: format, **options }
1111
args[:model] = model if model
12-
form_with args, &block
12+
form_with(**args, &block)
1313
end
1414
end
1515
end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Strata::ApplicationHelper, type: :helper do
4+
describe '#strata_form_with' do
5+
it 'sets the builder, forwards options, includes :model when provided, and yields the block' do
6+
dummy_model = double('Model')
7+
8+
expect(helper).to receive(:form_with) do |**args, &blk|
9+
expect(args[:builder]).to eq(Strata::FormBuilder)
10+
expect(args[:scope]).to eq(:user)
11+
expect(args[:url]).to eq('/submit')
12+
expect(args[:format]).to eq(:json)
13+
14+
# forwards arbitrary options
15+
expect(args[:local]).to eq(true)
16+
expect(args[:method]).to eq(:patch)
17+
expect(args[:data]).to eq({ foo: 'bar' })
18+
19+
# includes model when provided
20+
expect(args[:model]).to eq(dummy_model)
21+
22+
expect(blk).to be_a(Proc)
23+
:result
24+
end
25+
26+
result = helper.strata_form_with(
27+
model: dummy_model,
28+
scope: :user,
29+
url: '/submit',
30+
format: :json,
31+
local: true,
32+
method: :patch,
33+
data: { foo: 'bar' }
34+
) { :yielded }
35+
36+
expect(result).to eq(:result)
37+
end
38+
39+
it 'omits :model when model is falsey' do
40+
expect(helper).to receive(:form_with) do |**args, &blk|
41+
expect(args).not_to have_key(:model)
42+
:no_model
43+
end
44+
45+
result = helper.strata_form_with(scope: :user) { :yielded }
46+
expect(result).to eq(:no_model)
47+
end
48+
end
49+
end
50+
51+

0 commit comments

Comments
 (0)