-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
## [Unreleased] | ||
|
||
## [0.1.1] - 2023-02-22 | ||
|
||
- Add support for inheritance | ||
|
||
## [0.1.0] - 2023-02-21 | ||
|
||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,61 @@ class TestTransactionType < ::Shale::Mapper | |
attribute :amount, TestAmountType | ||
end | ||
|
||
class TestClientDataType < ::Shale::Mapper | ||
include ::Shale::Builder | ||
|
||
attribute :first_name, ::Shale::Type::String | ||
attribute :last_name, ::Shale::Type::String | ||
attribute :email, ::Shale::Type::String | ||
end | ||
|
||
class TestEnhancedTransactionType < TestTransactionType | ||
attribute :client_data, TestClientDataType | ||
end | ||
|
||
context 'inheritance' do | ||
should 'correctly set up a class after inheriting' do | ||
mod_parent = TestTransactionType.builder_methods_module | ||
mod_child = TestEnhancedTransactionType.builder_methods_module | ||
assert mod_parent.is_a?(::Module) | ||
assert mod_child.is_a?(::Module) | ||
assert !mod_child.equal?(mod_parent) | ||
assert TestTransactionType.include?(mod_parent) | ||
assert !TestTransactionType.include?(mod_child) | ||
assert TestEnhancedTransactionType.include?(mod_child) | ||
assert TestEnhancedTransactionType.include?(mod_parent) | ||
assert_equal %i[amount], mod_parent.instance_methods | ||
assert_equal %i[client_data], mod_child.instance_methods | ||
end | ||
|
||
should 'correctly build an instance of a subclass' do | ||
obj = TestEnhancedTransactionType.build do |t| | ||
t.cvv_code = '321' | ||
t.amount do |a| | ||
a.value = 45.0 | ||
a.currency = 'USD' | ||
end | ||
t.client_data do |c| | ||
c.first_name = 'Dupa' | ||
c.last_name = 'Kret' | ||
c.email = '[email protected]' | ||
end | ||
end | ||
|
||
assert obj.is_a?(TestEnhancedTransactionType) | ||
assert_equal '321', obj.cvv_code | ||
assert obj.amount.is_a?(TestAmountType) | ||
assert_equal 45.0, obj.amount.value | ||
assert_equal 'USD', obj.amount.currency | ||
assert obj.client_data.is_a?(TestClientDataType) | ||
assert_equal 'Dupa', obj.client_data.first_name | ||
assert_equal 'Kret', obj.client_data.last_name | ||
assert_equal '[email protected]', obj.client_data.email | ||
end | ||
end | ||
|
||
|
||
should 'correctly set up a class after inheriting' do | ||
should 'correctly set up a class after including' do | ||
mod = TestTransactionType.builder_methods_module | ||
assert mod.is_a?(::Module) | ||
assert TestTransactionType.include?(mod) | ||
|