File tree 2 files changed +14
-3
lines changed
lib/rails_admin/config/fields/types
spec/rails_admin/config/fields/types
2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class Enum < RailsAdmin::Config::Fields::Base
21
21
end
22
22
23
23
register_instance_option :enum_method do
24
- @enum_method ||= bindings [ :object ] . class . respond_to? ( "#{ name } _enum" ) || ( bindings [ :object ] || abstract_model . model . new ) . respond_to? ( "#{ name } _enum" ) ? "#{ name } _enum" : name
24
+ @enum_method ||= bindings &.[] ( :object ) . class . respond_to? ( "#{ name } _enum" ) || ( bindings &.[] ( :object ) || abstract_model . model . new ) . respond_to? ( "#{ name } _enum" ) ? "#{ name } _enum" : name
25
25
end
26
26
27
27
register_instance_option :enum do
Original file line number Diff line number Diff line change 17
17
end
18
18
end
19
19
20
- it 'auto-detects enumeration' do
20
+ it 'auto-detects enumeration when bindings provide object ' do
21
21
is_expected . to be_a ( RailsAdmin ::Config ::Fields ::Types ::Enum )
22
22
is_expected . not_to be_multiple
23
23
expect ( subject . with ( object : Team . new ) . enum ) . to eq %w[ blue green red ]
24
24
end
25
+
26
+ it 'auto-detects enumeration when no bindings provided' do
27
+ is_expected . to be_a ( RailsAdmin ::Config ::Fields ::Types ::Enum )
28
+ is_expected . not_to be_multiple
29
+ expect ( subject . enum ) . to eq %w[ blue green red ]
30
+ end
25
31
end
26
32
27
33
describe "when class responds to '\# {method}_enum'" do
@@ -39,10 +45,15 @@ def color_enum
39
45
end
40
46
end
41
47
42
- it 'auto-detects enumeration' do
48
+ it 'auto-detects enumeration when bindings provide object ' do
43
49
is_expected . to be_a ( RailsAdmin ::Config ::Fields ::Types ::Enum )
44
50
expect ( subject . with ( object : Team . new ) . enum ) . to eq %w[ blue green red ]
45
51
end
52
+
53
+ it 'auto-detects enumeration when no bindings provided' do
54
+ is_expected . to be_a ( RailsAdmin ::Config ::Fields ::Types ::Enum )
55
+ expect ( subject . enum ) . to eq %w[ blue green red ]
56
+ end
46
57
end
47
58
48
59
describe 'the enum instance method' do
You can’t perform that action at this time.
0 commit comments