binda icon indicating copy to clipboard operation
binda copied to clipboard

Binda::Radio and Binda::Checkbox shouldn't be subclasses of Binda::Selection

Open a-barbieri opened this issue 7 years ago • 1 comments

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

a-barbieri avatar Jan 29 '18 07:01 a-barbieri

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.

a-barbieri avatar Feb 05 '18 16:02 a-barbieri