Skip to content

Commit

Permalink
Rename Trestle::Builder#params to #permitted_params (aliasing old met…
Browse files Browse the repository at this point in the history
…hod)
  • Loading branch information
spohlenz committed Aug 30, 2024
1 parent 4c04ae7 commit b4cdec7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/trestle/resource/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion spec/trestle/resource/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b4cdec7

Please sign in to comment.