File tree Expand file tree Collapse file tree
lib/rails_admin/config/fields/types
rails_admin/config/fields/types Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- require 'rails_admin/config/fields/base '
1+ require 'rails_admin/config/fields/types/numeric '
22
33module RailsAdmin
44 module Config
55 module Fields
66 module Types
7- class Decimal < RailsAdmin ::Config ::Fields ::Base
7+ class Decimal < RailsAdmin ::Config ::Fields ::Types :: Numeric
88 # Register field type for the type loader
99 RailsAdmin ::Config ::Fields ::Types . register ( self )
10+
11+ register_instance_option :html_attributes do
12+ {
13+ required : required? ,
14+ step : "any" ,
15+ }
16+ end
1017 end
1118 end
1219 end
Original file line number Diff line number Diff line change 1- require 'rails_admin/config/fields/base '
1+ require 'rails_admin/config/fields/types/numeric '
22
33module RailsAdmin
44 module Config
55 module Fields
66 module Types
7- class Float < RailsAdmin ::Config ::Fields ::Base
7+ class Float < RailsAdmin ::Config ::Fields ::Types :: Numeric
88 # Register field type for the type loader
99 RailsAdmin ::Config ::Fields ::Types . register ( self )
10+
11+ register_instance_option :html_attributes do
12+ {
13+ required : required? ,
14+ step : "any" ,
15+ }
16+ end
1017 end
1118 end
1219 end
Original file line number Diff line number Diff line change 1- require 'rails_admin/config/fields/base '
1+ require 'rails_admin/config/fields/types/numeric '
22
33module RailsAdmin
44 module Config
55 module Fields
66 module Types
7- class Integer < RailsAdmin ::Config ::Fields ::Base
7+ class Integer < RailsAdmin ::Config ::Fields ::Types :: Numeric
88 # Register field type for the type loader
99 RailsAdmin ::Config ::Fields ::Types . register ( self )
1010
11- register_instance_option :view_helper do
12- :number_field
13- end
14-
1511 register_instance_option :sort_reverse? do
1612 serial?
1713 end
Original file line number Diff line number Diff line change 1+ require 'rails_admin/config/fields/base'
2+
3+ module RailsAdmin
4+ module Config
5+ module Fields
6+ module Types
7+ class Numeric < RailsAdmin ::Config ::Fields ::Base
8+ # Register field type for the type loader
9+ RailsAdmin ::Config ::Fields ::Types . register ( self )
10+
11+ register_instance_option :view_helper do
12+ :number_field
13+ end
14+ end
15+ end
16+ end
17+ end
18+ end
Original file line number Diff line number Diff line change 11require 'spec_helper'
22
33RSpec . describe RailsAdmin ::Config ::Fields ::Types ::Decimal do
4- it_behaves_like 'a generic field type' , :decimal_field , :decimal
4+ it_behaves_like 'a float-like field type' , :float_field
55end
Original file line number Diff line number Diff line change 11require 'spec_helper'
22
33RSpec . describe RailsAdmin ::Config ::Fields ::Types ::Float do
4- it_behaves_like 'a generic field type' , :float_field , :float
4+ it_behaves_like 'a float-like field type' , :float_field
55end
Original file line number Diff line number Diff line change 1+ require 'spec_helper'
2+
3+ RSpec . describe RailsAdmin ::Config ::Fields ::Types ::Numeric do
4+ it_behaves_like 'a generic field type' , :integer_field , :integer
5+
6+ subject do
7+ RailsAdmin . config ( 'FieldTest' ) . fields . detect do |f |
8+ f . name == :integer_field
9+ end . with ( object : FieldTest . new )
10+ end
11+
12+ describe '#view_helper' do
13+ it "uses the 'number' type input tag" do
14+ expect ( subject . view_helper ) . to eq ( :number_field )
15+ end
16+ end
17+ end
Original file line number Diff line number Diff line change 3434 expect ( subject ) . to be_a ( RailsAdmin ::Config ::Fields ::Types ::StringLike )
3535 end
3636end
37+
38+ RSpec . shared_examples 'a float-like field type' do |column_name |
39+ subject do
40+ RailsAdmin . config ( 'FieldTest' ) . fields . detect do |f |
41+ f . name == column_name
42+ end . with ( object : FieldTest . new )
43+ end
44+
45+ describe '#html_attributes' do
46+ it 'should contain a step attribute' do
47+ expect ( subject . html_attributes [ :step ] ) . to eq ( 'any' )
48+ end
49+
50+ it 'should contain a falsey required attribute' do
51+ expect ( subject . html_attributes [ :required ] ) . to be_falsey
52+ end
53+
54+ context 'when the field is required' do
55+ before do
56+ RailsAdmin . config FieldTest do
57+ field column_name , :float do
58+ required true
59+ end
60+ end
61+ end
62+
63+ it 'should contain a truthy required attribute' do
64+ expect ( subject . html_attributes [ :required ] ) . to be_truthy
65+ end
66+ end
67+ end
68+
69+ describe '#view_helper' do
70+ it "uses the 'number' type input tag" do
71+ expect ( subject . view_helper ) . to eq ( :number_field )
72+ end
73+ end
74+ end
You can’t perform that action at this time.
0 commit comments