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

[bug] association with if: <Symbol> finds a method from wrong blueprint #458

Closed
2 tasks done
kyori19 opened this issue Aug 27, 2024 · 1 comment · Fixed by #464
Closed
2 tasks done

[bug] association with if: <Symbol> finds a method from wrong blueprint #458

kyori19 opened this issue Aug 27, 2024 · 1 comment · Fixed by #464
Assignees
Labels
bug An issue with the system

Comments

@kyori19
Copy link

kyori19 commented Aug 27, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is this a regression?

  • Yes, this used to work before

Current Behavior

association :parent, blueprint: ParentBlueprint, if: :include_parent? in ChildBlueprint calls ParentBlueprint.include_parent?

Expected Behavior

association :parent, blueprint: ParentBlueprint, if: :include_parent? in ChildBlueprint should call ChildBlueprint.include_parent?

Steps To Reproduce

Use this script to reproduce the problem.

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/inline'
require 'json'

gemfile do
  source 'https://rubygems.org'

  # uncomment this to check previous behavior
  # gem 'blueprinter', '= 1.0.2'

  gem 'blueprinter', '= 1.1.0'
end

Parent = Struct.new(:name, keyword_init: true)
Child = Struct.new(:parent, :name, keyword_init: true)

class ParentBlueprint < Blueprinter::Base
  field :name
end

class ChildBlueprint < Blueprinter::Base
  def self.include_parent?(_, _, _)
    true
  end

  field :name
  association :parent, blueprint: ParentBlueprint, if: :include_parent?
end

parent = Parent.new(
  name: 'Parent',
)

child = Child.new(
  parent:,
  name: 'Child',
)

pp ChildBlueprint.render_as_hash(child)

Environment

- OS: Ubuntu 22.04
- Browser Name and version: N/A
- Ruby Version: ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-linux]

Anything else?

No response

@kyori19 kyori19 added the bug An issue with the system label Aug 27, 2024
@lessthanjacob
Copy link
Contributor

Apologies for the delay here @kyori19!

I was able to replicate via tests (it looks like there was also a substantial gap in test coverage here), and will prioritize a fix shortly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants