Skip to content

Commit

Permalink
Move custom_type inside test harness
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <[email protected]>
  • Loading branch information
Morriar committed Jul 12, 2023
1 parent 1a138c6 commit cac38c9
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions spec/tapioca/dsl/compilers/json_api_client_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,20 @@ def title=(title); end
end

describe "with custom type" do
let(:custom_type) do
Class.new do
class << self
def cast(value, default)
value
before do
add_ruby_file("custom_type.rb", <<~RB)
class CustomType
class << self
def cast(value, default)
value
end
end
end
end
end

before do
::JsonApiClient::Schema::TypeFactory.register({
custom_type: custom_type,
})
end
after do
types = ::JsonApiClient::Schema::TypeFactory.class_variable_get(:@@types)
types.delete(:custom_type)
::JsonApiClient::Schema::TypeFactory.register({
custom_type: CustomType,
})
RB
end

it "generates untyped properties for custom types" do
Expand Down Expand Up @@ -331,11 +326,13 @@ def name=(name); end
end

it "honours types that declare sorbet_type" do
def custom_type.sorbet_type
"Integer"
end

add_ruby_file("post.rb", <<~RUBY)
class CustomType
def self.sorbet_type
"Integer"
end
end
class Post < JsonApiClient::Resource
property :comment_count, type: :custom_type
property :tag_count, type: :custom_type, default: 0
Expand Down

0 comments on commit cac38c9

Please sign in to comment.