Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/superform/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ def title
end
end

def initialize(model, action: nil, method: nil, **attributes)
def initialize(model, action: nil, method: nil, namespace: nil, **attributes)
@model = model
@action = action
@method = method
@attributes = attributes
@namespace = Namespace.root(key, object: model, field_class: self.class::Field)
@namespace = Namespace.root(namespace || key, object: model, field_class: self.class::Field)
end

def around_template(&)
Expand Down
17 changes: 17 additions & 0 deletions spec/superform/rails/form_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
RSpec.describe Superform::Rails::Form do
let(:model) { double('MockModel', model_name: double(param_key: 'mock_model')) }

it 'creates a root namespace based on the active model' do
expect(Superform::Namespace).to receive(:root).with('mock_model', any_args)

described_class.new(model)
end

context 'override root namespace with an argument' do
it 'creates a root namespace based on the namespace argument' do
expect(Superform::Namespace).to receive(:root).with('user', any_args)

described_class.new(model, namespace: 'user')
end
end
end