Skip to content

Commit

Permalink
Merge pull request #25 from ksss/fix-spec
Browse files Browse the repository at this point in the history
Fix spec
  • Loading branch information
ksss authored Sep 2, 2024
2 parents 4c688a8 + 70b40cb commit 37c5d0c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
6 changes: 3 additions & 3 deletions lib/orthoses/active_record/relation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_relation(t)
expect = <<~RBS
class RelationTest::User::ActiveRecord_Relation < ::ActiveRecord::Relation
include RelationTest::User::GeneratedRelationMethods
include _ActiveRecord_Relation[RelationTest::User, untyped]
include _ActiveRecord_Relation[RelationTest::User, ::Integer]
include Enumerable[RelationTest::User]
end
RBS
Expand All @@ -45,7 +45,7 @@ class RelationTest::User::ActiveRecord_Relation < ::ActiveRecord::Relation

expect = <<~RBS
class RelationTest::User::ActiveRecord_Associations_CollectionProxy < ::ActiveRecord::Associations::CollectionProxy
include _ActiveRecord_Relation[RelationTest::User, untyped]
include _ActiveRecord_Relation[RelationTest::User, ::Integer]
end
RBS
actual = store["RelationTest::User::ActiveRecord_Associations_CollectionProxy"].to_rbs
Expand All @@ -55,7 +55,7 @@ class RelationTest::User::ActiveRecord_Associations_CollectionProxy < ::ActiveRe

expect = <<~RBS
class RelationTest::User < ::ActiveRecord::Base
extend _ActiveRecord_Relation_ClassMethods[RelationTest::User, RelationTest::User::ActiveRecord_Relation, untyped]
extend _ActiveRecord_Relation_ClassMethods[RelationTest::User, RelationTest::User::ActiveRecord_Relation, ::Integer]
end
RBS
actual = store["RelationTest::User"].to_rbs
Expand Down
7 changes: 7 additions & 0 deletions lib/orthoses/active_storage/attached/model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@

require "active_storage/attached"
require "active_storage/reflection"

ActiveRecord::Base.include(ActiveStorage::Attached::Model)
ActiveRecord::Base.include(ActiveStorage::Reflection::ActiveRecordExtensions)
ActiveRecord::Reflection.singleton_class.prepend(ActiveStorage::Reflection::ReflectionExtension)

if ActiveRecord.version >= Gem::Version.new("7.2")
class ::ActiveStorage::Blob
def self.validate_service_configuration(*); end
end
end

module ModelTest
LOADER = ->(){
class User < ActiveRecord::Base
Expand Down
58 changes: 38 additions & 20 deletions test/fake_schema.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
FakeColumn = Struct.new(:type, :name, :null, keyword_init: true)
def FakeColumn.columns_hash
{
"id" => FakeColumn.new(
name: :id,
null: false,
type: :integer,
),
"name" => FakeColumn.new(
name: :name,
null: false,
type: :string,
),
"confirmed" => FakeColumn.new(
name: :confirmed,
null: true,
type: :boolean,
),
}
end

module ::ActiveRecord
module AttributeMethods::PrimaryKey::ClassMethods
def get_primary_key(base_name)
Expand All @@ -6,29 +27,26 @@ def get_primary_key(base_name)
end

module ModelSchema::ClassMethods
FakeColumn = Struct.new(:type, :name, :null, keyword_init: true)

def load_schema
end

def columns_hash
{
id: FakeColumn.new(
name: :id,
null: false,
type: :integer,
),
name: FakeColumn.new(
name: :name,
null: false,
type: :string,
),
confirmed: FakeColumn.new(
name: :confirmed,
null: true,
type: :boolean,
),
}
FakeColumn.columns_hash
end

def attribute_types
FakeColumn.columns_hash
end
end
end

# for rails v7.2
module ActiveModel
module AttributeRegistration
module ClassMethods
def attribute_types
FakeColumn.columns_hash
end
end
end
end
end

0 comments on commit 37c5d0c

Please sign in to comment.