binda
binda copied to clipboard
Binda::Radio and Binda::Checkbox shouldn't be subclasses of Binda::Selection
Expected behavior
Assuming I have a select field, a radio and a checkbox, I expect the following lines to return 1.
Binda::Selection.all.length
# => 1
Binda::Radio.all.length
# => 1
Binda::Checkbox.all.length
# => 1
Actual behavior
Unfortunately Binda::Selection.all
returns all fields (select field, a radio and a checkbox).
Binda::Selection.all.length
# => 3
System configuration
Binda version: 0.1.3
Rails version: 5.1.4
There is another major issue with Binda::Radio
being a subclass of Binda::Selection
: the fact that it has a has_many :choices
rather than has_one :choice
!
The best way to refactor this portion of code is to extract all methods from Binda::Selection
and place them in a concern the same way happens for Binda::FieldableAssociation
.
The Binda::Radio
can inherit all methods from the concern without being a subclass of Binda::Selection
.