Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Trestle::Builder#params to #permitted_params (aliasing old method) #481

Merged
merged 1 commit into from
Aug 30, 2024
Merged
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
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