Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Allow overrides to be nil #318

Merged
merged 1 commit into from Apr 2, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fabrication/generator/base.rb
Expand Up @@ -76,7 +76,7 @@ def initialize(klass)
end

def method_missing(method_name, *args, &block)
_attributes[method_name] || super
_attributes.fetch(method_name) { super }
end

protected
Expand Down
9 changes: 8 additions & 1 deletion spec/fabrication/generator/base_spec.rb
Expand Up @@ -85,7 +85,7 @@
let(:schematic) do
Fabrication::Schematic::Definition.new('ClassWithInit') do
arg1 10
initialize_with { Struct.new(:arg1, :arg2).new(arg1, arg1 + 10) }
initialize_with { Struct.new(:arg1, :arg2).new(arg1, arg1.to_i + 10) }
end
end

Expand All @@ -104,6 +104,13 @@
end
end

context "with nil override" do
subject { schematic.fabricate(arg1: nil) }
it "saves the return value of the block as instance" do
expect(subject.arg1).to eq(nil)
expect(subject.arg2).to eq(10)
end
end
end
end

Expand Down