1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00
Commit graph

2 commits

Author SHA1 Message Date
Lucas Mazza
23728c765e
Update country_select dependency on 5-0-stable Gemfile. 2016-08-12 17:02:06 -03:00
Olivier Lacan
2b5d4176d9
Simplify check for decimal_or_float?
This simplification should make it compatible with Rails 5's new
Attributes API without requiring a major refactor of the FormBuilder class.

The motivation for this commit originated in #1342.

@rafaelfranca mentioned that we should be using the new type_for_attribute interface
to determine the precise type of a column instead. At first I used the interface directly like
this:

      def decimal_or_float?
        if object.respond_to?(:type_for_attribute)
          type = object.type_for_attribute(column.name.to_s).type
          type == :float || :decimal
        else
          column.number? && column.type != :integer
        end
      end

I then realized that we're already asking the column object directly for the type, so
why not simple check for the two types we care about and implement the method in a much
more straightforward *and* backward-compatible way? I ended up with this:

      def decimal_or_float?
        column.type == :float || :decimal
      end

I could be missing something obvious but this is green in my Rails 5.0.0 app. The tests mock out the now removed number? ActiveModel method
so I had to remove that:
method: 1c389f6559/test/support/models.rb (L3-L8)
2016-08-12 16:38:42 -03:00