Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Integer/Float attributes accept many different types #223

Merged
merged 2 commits into from
Nov 12, 2019

Conversation

ghiculescu
Copy link
Contributor

Currently we are quite strict about what types can be passed to an attribute of type Integer/Float, but in reality Rails is quite accommodating. This PR allows more types to be passed in.

Fixes sorbet/sorbet-typed#163 (comment)

@codecov-io
Copy link

codecov-io commented Nov 11, 2019

Codecov Report

Merging #223 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #223      +/-   ##
==========================================
+ Coverage   96.14%   96.14%   +<.01%     
==========================================
  Files         138      138              
  Lines        2228     2233       +5     
==========================================
+ Hits         2142     2147       +5     
  Misses         86       86
Impacted Files Coverage Δ
...bet-rails/model_plugins/active_record_attribute.rb 95.52% <100%> (+0.36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c2fa85...2359609. Read the comment docs.

Currently we are quite strict about what types can be passed to an attribute of type `Integer`/`Float`, but in reality Rails is quite accommodating. This PR allows more types to be passed in.

Fixes sorbet/sorbet-typed#163 (comment)
@ghiculescu ghiculescu marked this pull request as ready for review November 11, 2019 23:41
Copy link
Contributor

@hdoan741 hdoan741 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the fix. I'm going on a PTO for 2 weeks so I might merge this PR early. I think we can have a bigger change to improve the code though.

@@ -131,15 +131,23 @@ def time_zone_aware_column?(column_def, cast_type)

sig { params(column_type: Object).returns(String) }
def value_type_for_attr_writer(column_type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should pass a column_def to this method and have a switcher based on active_record_type like active_record_type_to_sorbet_type

@hdoan741
Copy link
Contributor

Created an issue for code quality improvement.

@hdoan741 hdoan741 merged commit 8ef6518 into chanzuckerberg:master Nov 12, 2019
@ghiculescu ghiculescu deleted the integer_type_more_options branch November 12, 2019 17:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants