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

Schema cleaner fix #15

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/datacaster/context_nodes/structure_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def create_runtime(parent)
def transform_result(result)
return result unless result.valid?
result = cast_success(result)
if @runtime.instance_variable_get(:@parent).respond_to?(:checked_schema=)
@runtime.instance_variable_get(:@parent).checked_schema = @runtime.checked_schema
parent_runtime = @runtime.instance_variable_get(:@parent)
if parent_runtime.respond_to?(:checked_schema!)
parent_runtime.checked_schema!(@runtime.checked_schema)
end
result
end
Expand Down
4 changes: 4 additions & 0 deletions lib/datacaster/runtimes/structure_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def will_check!
@should_check_stack[-1] = true
end

def checked_schema!(schema)
@pointer_stack[-1].merge!(schema)
end

def ignore_checks!(&block)
@ignore = true
result = yield
Expand Down
2 changes: 1 addition & 1 deletion lib/datacaster/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Datacaster
VERSION = "3.2.1"
VERSION = "3.2.2"
end
26 changes: 24 additions & 2 deletions spec/datacaster_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1542,12 +1542,34 @@ def amount
describe "cleaning nested schemas" do
it "doesn't complain on keys checked in nested contex node" do
schema = Datacaster.schema do
Datacaster.schema do
schema(
hash_schema(a: integer, b: integer)
end & hash_schema(b: integer)
) & hash_schema(b: integer)
end

expect(schema.(a: 1, b: 2).to_dry_result).to eq Success(a: 1, b: 2)
end

it "doesn't complain on nested keys in nested context node" do
caster = Datacaster.schema do
nested = schema(
hash_schema(a: integer, b: integer)
)

hash_schema(nested: nested)
end

expect(caster.(nested: {a: 1, b: 2}).to_dry_result).to eq Success(nested: {a: 1, b: 2})
end

it "doesn't complain on keys in deeply nested strict schemas" do
schema = Datacaster.schema do
hash_schema(
test: schema(hash_schema(a: integer, b: integer))
)
end

expect(schema.(test: {a: 1, b: 2}).to_dry_result).to eq Success(test: {a: 1, b: 2})
end
end
end