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

WIP - Add for rescue it is possible to add attributes that do not exist in the model #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
croods (0.3.2)
croods (0.3.3)
api-pagination (= 4.8.2)
committee (= 3.3.0)
devise_token_auth (= 1.1.3)
Expand Down
4 changes: 3 additions & 1 deletion lib/croods/controller/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ def identifier
params[resource.identifier]
end

def member_params
def member_params # rubocop:disable Metrics/AbcSize
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about we disable this for the project?
these ad-hoc rubocop disable reduce legibility and don't help with keeping the code standards (one of rubocop main purposes).

params
.permit(resource.request_attributes.keys)
.merge(
params
.require(resource.resource_name)
.permit!
)
rescue StandardError
params.permit(resource.request_attributes.keys)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a solution that prevents the error from happening instead of rescuing. Please give instructions on how to reproduce the issue and let's find another way to solve the problem in the current project that needs this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created the Issue: #55.

end

def new_member
Expand Down
11 changes: 11 additions & 0 deletions spec/todos/tasks/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@
it { is_expected.to have_http_status(:ok) }
end

context 'when we add an attribute that does not exist in the model' do
let(:params) { { foobaz: 'foobar' } }

before do
put "/tasks/#{task.id}", params: params.to_json
end

it { is_expected.to have_http_status(:ok) }
# it { expect(response.body).to eq_json(error) }
end

context 'when task is from another organization' do
let(:id) { another_user_task.id }

Expand Down
1 change: 1 addition & 0 deletions todos/app/resources/tasks/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Resource < ApplicationResource

request do
skip_attribute :finished
add_attribute :foobaz, :string, null: true
end

add_action :finish, method: :put do
Expand Down
1 change: 1 addition & 0 deletions todos/app/resources/tasks/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Update < Croods::Service
about :task

def execute
params.delete(:foobaz)
task.update!(params)

task.list.update!(
Expand Down