File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed
spec/unit/views/components Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -256,9 +256,9 @@ def selectable_column(**options)
256
256
end
257
257
258
258
# Display a column for the id
259
- def id_column
259
+ def id_column ( sortable : resource_class . primary_key )
260
260
raise "#{ resource_class . name } has no primary_key!" unless resource_class . primary_key
261
- column ( resource_class . human_attribute_name ( resource_class . primary_key ) , sortable : resource_class . primary_key ) do |resource |
261
+ column ( resource_class . human_attribute_name ( resource_class . primary_key ) , sortable : sortable ) do |resource |
262
262
if controller . action_methods . include? ( "show" )
263
263
link_to resource . id , resource_path ( resource )
264
264
elsif controller . action_methods . include? ( "edit" )
Original file line number Diff line number Diff line change 15
15
let ( :assigns ) do
16
16
{
17
17
collection : collection ,
18
- active_admin_config : active_admin_config
18
+ active_admin_config : active_admin_config ,
19
+ resource_class : User ,
19
20
}
20
21
end
21
22
let ( :helpers ) { mock_action_view }
43
44
end
44
45
end
45
46
end
47
+
48
+ context "when creating an id column" do
49
+ before { allow ( helpers ) . to receive ( :url_target ) { 'routing_stub' } }
50
+
51
+ def build_index_table ( &block )
52
+ render_arbre_component assigns , helpers do
53
+ insert_tag ( ActiveAdmin ::Views ::IndexAsTable ::IndexTableFor , collection , { sortable : true } ) do
54
+ instance_exec ( &block )
55
+ end
56
+ end
57
+ end
58
+
59
+ it "is sortable by default" do
60
+ table = build_index_table { id_column }
61
+ header = table . find_by_tag ( "th" ) . first
62
+ expect ( header . attributes ) . to include ( "data-sortable" : "" )
63
+ end
64
+
65
+ it "supports sortable: false" do
66
+ table = build_index_table { id_column sortable : false }
67
+ header = table . find_by_tag ( "th" ) . first
68
+ expect ( header . attributes ) . not_to include ( "data-sortable" : "" )
69
+ end
70
+
71
+ it "supports sortable column names" do
72
+ table = build_index_table { id_column sortable : :created_at }
73
+ header = table . find_by_tag ( "th" ) . first
74
+ expect ( header . attributes ) . to include ( "data-sortable" : "" )
75
+ end
76
+ end
46
77
end
47
78
end
You can’t perform that action at this time.
0 commit comments