Skip to content

Problem with decorator and relationships #2

@j0an

Description

@j0an

Hi, i don't know how to describe this error, I will put some logs from the rails c console to describe the problem.

Project has_many Comment

> p = Project.first
 => #<Project id: 4620, token: "8e23d5d63b217fce08a5", .... >

> p.comments
 => #<ActiveRecord::Associations::CollectionProxy [#<Comment id: 148140, content: "...">, #<Comment id: 148141, content: "...">, ......

> p.decorate
 => #<ProjectDecorator:0x007fe9ca704250 @object=#<Project id: 4620, token: "8e23d5d63b217fce08a5", ...>, @options={}>

> p.decorate.comments
ArgumentError: wrong number of arguments (given 1, expected 0)

And the Comment model with decorator works fine

> c = Comment.first
 => #<Comment id: 1, content: "...">
> c = Comment.first.decorate
 => #<CommentDecorator:0x007fe9c88fd9c8 @object=#<Comment id: 1, content: "...">, @options={}>

tried with another models and happend the same

:012 > u = User.first
 => #<User id: 3029, email: "**@**">

:013 > u.decorate
 => #<UserDecorator:0x007fe9c9ec58c8 @object=#<User id: 3029, email: "**@**">, @options={}>

 :014 > u.projects
 => #<ActiveRecord::Associations::CollectionProxy [#<Project id: 4563, token: "3a145b635df0117cc3af">]>

 :015 > u.decorate.projects
ArgumentError: wrong number of arguments (given 1, expected 0)

 :016 > u.decorate.comments
ArgumentError: wrong number of arguments (given 1, expected 0)

Ruby and Rails versions

ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

rails -v
Rails 5.1.3

stack trace

Extracted from rspec results

      ArgumentError:
        wrong number of arguments (given 1, expected 0)
      # /Users/j0an/.rvm/gems/ruby-2.4.1@dashboard/gems/light-decorator-1.0.1/lib/light/decorator/concerns/associations/collection_proxy.rb:32:in block in override_scope'
      # ./app/policies/invoice_policy.rb:11:in resolve'
# /Users/j0an/.rvm/gems/ruby-2.4.1@dashboard/gems/pundit-1.1.0/lib/pundit.rb:90:in policy_scope!'
# /Users/j0an/.rvm/gems/ruby-2.4.1@dashboard/gems/pundit-1.1.0/lib/pundit.rb:284:in pundit_policy_scope'
# /Users/j0an/.rvm/gems/ruby-2.4.1@dashboard/gems/pundit-1.1.0/lib/pundit.rb:226:in policy_scope'
# ./app/controllers/payrolls_controller.rb:6:in index'
# /Users/j0an/.rvm/gems/ruby-2.4.1@dashboard/gems/rails-controller-testing-1.0.2/lib/rails/controller/testing/template_assertions.rb:61:in process'
# /Users/j0an/.rvm/gems/ruby-2.4.1@dashboard/gems/devise-4.3.0/lib/devise/test/controller_helpers.rb:33:in block in process'
# /Users/j0an/.rvm/gems/ruby-2.4.1@dashboard/gems/devise-4.3.0/lib/devise/test/controller_helpers.rb:100:in catch'
# /Users/j0an/.rvm/gems/ruby-2.4.1@dashboard/gems/devise-4.3.0/lib/devise/test/controller_helpers.rb:100:in _catch_warden'
# /Users/j0an/.rvm/gems/ruby-2.4.1@dashboard/gems/devise-4.3.0/lib/devise/test/controller_helpers.rb:33:in process'
# /Users/j0an/.rvm/gems/ruby-2.4.1@dashboard/gems/rails-controller-testing-1.0.2/lib/rails/controller/testing/integration.rb:12:in block (2 levels) in <module:Integration>'
# ./spec/controllers/payrolls_controller_spec.rb:32:in block (4 levels) in <top (required)>'

Is the any chance of a conflict with Pundit gem

Is there any way to check what's going on? do you need more information, let me know :D

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions