Skip to content

Commit

Permalink
Test to ensure id sig is generated without id column
Browse files Browse the repository at this point in the history
In Active Record, the primary key column is always referenceable via
id attribute methods.
  • Loading branch information
gmcgibbon committed Sep 8, 2023
1 parent afdbf5e commit 3dfc8c2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spec/tapioca/dsl/compilers/active_record_columns_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,30 @@ def cost=(value); end

assert_includes(rbi_for(:Post), expected)
end

it "generates id accessors when primary key isn't id" do
add_ruby_file("schema.rb", <<~RUBY)
ActiveRecord::Migration.suppress_messages do
ActiveRecord::Schema.define do
create_table :posts, primary_key: :number do |t|
end
end
end
RUBY

add_ruby_file("post.rb", <<~RUBY)
class Post < ActiveRecord::Base
self.primary_key = :number
end
RUBY

expected = indented(<<~RBI, 4)
sig { returns(T.nilable(::Integer)) }
def id; end
RBI

assert_includes(rbi_for(:Post), expected)
end
end

describe "when StrongTypeGeneration is defined" do
Expand Down

0 comments on commit 3dfc8c2

Please sign in to comment.