diff --git a/lib/trestle/resource/builder.rb b/lib/trestle/resource/builder.rb index 67a2daaf..07ed064b 100644 --- a/lib/trestle/resource/builder.rb +++ b/lib/trestle/resource/builder.rb @@ -43,9 +43,10 @@ def to_param(&block) admin.define_adapter_method(:to_param, &block) end - def params(&block) + def permitted_params(&block) admin.define_adapter_method(:permitted_params, &block) end + alias params permitted_params def decorator(decorator) admin.decorator = decorator diff --git a/spec/trestle/resource/builder_spec.rb b/spec/trestle/resource/builder_spec.rb index 167fed10..6332601e 100644 --- a/spec/trestle/resource/builder_spec.rb +++ b/spec/trestle/resource/builder_spec.rb @@ -203,8 +203,19 @@ def custom_method end end - describe "#params" do + describe "#permitted_params" do it "sets an explicit permitted_params block" do + Trestle::Resource::Builder.create(:tests) do + permitted_params do |params| + params.require(:test).permit(:name) + end + end + + params = ActionController::Parameters.new({ test: { name: "Test", ignored: 123 }}) + expect(::TestsAdmin.permitted_params(params)).to eq(ActionController::Parameters.new(name: "Test").permit!) + end + + it "is aliased as #params" do Trestle::Resource::Builder.create(:tests) do params do |params| params.require(:test).permit(:name)