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 @@ -291,9 +291,9 @@ def index_column(start_value = 1)
291
291
end
292
292
293
293
# Display a column for the id
294
- def id_column
294
+ def id_column ( sortable : resource_class . primary_key )
295
295
raise "#{ resource_class . name } has no primary_key!" unless resource_class . primary_key
296
- column ( resource_class . human_attribute_name ( resource_class . primary_key ) , sortable : resource_class . primary_key ) do |resource |
296
+ column ( resource_class . human_attribute_name ( resource_class . primary_key ) , sortable : sortable ) do |resource |
297
297
if controller . action_methods . include? ( "show" )
298
298
link_to resource . id , resource_path ( resource ) , class : "resource_id_link"
299
299
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
8000
let ( :helpers ) { mock_action_view }
44
45
end
45
46
end
46
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 [ :class ] ) . to include ( "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 [ :class ] ) . not_to include ( "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 [ :class ] ) . to include ( "sortable" )
75
+ end
76
+ end
77
+
47
78
context "when creating an index column" do
48
79
let ( :base_collection ) do
49
80
posts = [
You can’t perform that action at this time.
0 commit comments