Skip to content
This repository was archived by the owner on Jul 5, 2023. It is now read-only.
This repository was archived by the owner on Jul 5, 2023. It is now read-only.

Running tests raises a NameError for sigs receiving or returning an ActiveRecord_AssociationRelation #211

@franciscoj

Description

@franciscoj

Describe the bug:

When you declare a method which receives or returns an ActiveRecord_AssociationRelation of some sort, tests fail with:

     NameError:
       private constant #<Class:0x00007fa75c4e8d28>::ActiveRecord_AssociationRelation referenced

Steps to reproduce:

create a method which returns an association relation on a model

class Post < ApplicationRecord
  belongs_to :user

  scope :published ->() { where(published: true) }
end

class User < ApplicationRecord
  extend T::Sig

  has_many :posts

  sig { returns(Post::ActiveRecord_AssociationRelation) }
  def published_posts
    posts.published
  end
end

RSpec.describe User do
  describe '#published_posts' do
    it 'returns only the published posts' do
      user = User.create!
      published = user.posts.create(published: true)
      user.posts.create(published: false)

      expect(user.published_posts).to eq([published])
    end
  end
end

This would raise a NameError claming that Post::ActiveRecord_AssociationRelation is a private class.

Note as well that in my case the models are on a rails engine.

Expected behavior:

The test passes

Versions:

  • Ruby: 2.4
  • Rails: 5.2.3
  • Sorbet: Sorbet typechecker 0.4.4891 git 4c9a4534439483b46e869c7212007ad103923203 built on 2019-10-17 22:56:24 GMT debug_symbols=true
  • Sorbet-Rails: 0.5.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions