77 controller = GuidesController . new
88 test_guides = [ { title : "Test Guide" , path : "test" } ]
99 allow ( controller ) . to receive ( :collect_guides ) . and_return ( test_guides )
10-
10+
1111 # Simulate what the index action does
1212 controller . index
1313 expect ( controller . instance_variable_get ( :@guides ) ) . to eq ( test_guides )
1414 end
1515 end
16-
16+
1717 describe "#collect_guides" do
1818 it "collects and sorts guides from metadata files" do
1919 controller = GuidesController . new
20-
20+
2121 # Mock file system
2222 allow ( Dir ) . to receive ( :glob ) . and_return ( [
2323 "/path/zebra_guide/metadata.json" ,
2424 "/path/alpha_guide/metadata.json"
2525 ] )
26-
26+
2727 metadata = {
2828 "screenshots" => [ { "filename" => "test.png" , "caption" => "Test" } ] ,
2929 "updated_at" => "2024-01-15T10:00:00Z"
3030 }
3131 allow ( File ) . to receive ( :read ) . and_return ( metadata . to_json )
32-
32+
3333 # Mock Pathname operations - first path is zebra, second is alpha
3434 # But they should be sorted alphabetically after collection
3535 allow_any_instance_of ( Pathname ) . to receive ( :relative_path_from ) do |path |
3939 instance_double ( Pathname , dirname : instance_double ( Pathname , to_s : "alpha_guide" ) )
4040 end
4141 end
42-
42+
4343 guides = controller . send ( :collect_guides )
4444 expect ( guides . length ) . to eq ( 2 )
4545 # After sorting by title, alpha should come first
4646 expect ( guides . first [ :title ] ) . to eq ( "Alpha guide" )
4747 expect ( guides . last [ :title ] ) . to eq ( "Zebra guide" )
4848 end
49-
49+
5050 it "returns empty array when no guides exist" do
5151 controller = GuidesController . new
5252 allow ( Dir ) . to receive ( :glob ) . and_return ( [ ] )
53-
53+
5454 guides = controller . send ( :collect_guides )
5555 expect ( guides ) . to eq ( [ ] )
5656 end
5757 end
58-
58+
5959 describe "GET #show" do
6060 let ( :guide_path ) { "test_guide" }
61-
61+
6262 before do
6363 # Skip n_plus_one_detection and stub render/redirect to avoid template rendering issues
6464 allow ( controller ) . to receive ( :n_plus_one_detection ) . and_yield
6565 allow ( controller ) . to receive ( :render )
6666 allow ( controller ) . to receive ( :redirect_to )
6767 end
68-
68+
6969 context "when metadata file exists" do
7070 let ( :metadata ) do
7171 {
7272 "screenshots" => [ { "filename" => "test.png" , "caption" => "Test" } ] ,
7373 "updated_at" => "2024-01-15T10:00:00Z"
7474 }
7575 end
76-
76+
7777 before do
7878 metadata_file = instance_double ( Pathname )
7979 allow ( metadata_file ) . to receive ( :exist? ) . and_return ( true )
8282 instance_double ( Pathname , join : metadata_file )
8383 )
8484 end
85-
85+
8686 it "assigns guide data when metadata exists" do
87- get :show , params : { path : guide_path }
87+ get :show , params : { path : guide_path }
8888 expect ( assigns ( :guide_data ) ) . to eq ( metadata )
8989 end
90-
90+
9191 it "assigns guide path" do
92- get :show , params : { path : guide_path }
92+ get :show , params : { path : guide_path }
9393 expect ( assigns ( :guide_path ) ) . to eq ( guide_path )
9494 end
95-
95+
9696 it "assigns humanized guide title" do
97- get :show , params : { path : guide_path }
97+ get :show , params : { path : guide_path }
9898 expect ( assigns ( :guide_title ) ) . to eq ( "Test guide" )
9999 end
100100 end
101-
101+
102102 context "when metadata file does not exist" do
103103 before do
104104 metadata_file = instance_double ( Pathname )
109109 # Don't stub redirect_to for these tests
110110 allow ( controller ) . to receive ( :render )
111111 end
112-
112+
113113 it "redirects to guides path when metadata doesn't exist" do
114114 allow ( controller ) . to receive ( :redirect_to ) . and_call_original
115- get :show , params : { path : guide_path }
115+ get :show , params : { path : guide_path }
116116 expect ( response ) . to redirect_to ( guides_path )
117117 end
118-
118+
119119 it "sets flash alert when guide not found" do
120120 allow ( controller ) . to receive ( :redirect_to ) . and_call_original
121- get :show , params : { path : guide_path }
121+ get :show , params : { path : guide_path }
122122 expect ( flash [ :alert ] ) . to eq ( I18n . t ( "guides.messages.not_found" ) )
123123 end
124124 end
125125 end
126-
126+
127127 describe "private methods" do
128128 describe "#guide_screenshots_root" do
129129 it "returns the correct path" do
132132 expect ( controller . send ( :guide_screenshots_root ) ) . to eq ( expected_path )
133133 end
134134 end
135-
135+
136136 describe "#humanize_guide_title" do
137137 it "removes _spec suffix and humanizes" do
138138 controller = GuidesController . new
139139 expect ( controller . send ( :humanize_guide_title , "test_workflow_spec" ) ) . to eq ( "Test workflow" )
140140 end
141-
141+
142142 it "handles nested paths" do
143143 controller = GuidesController . new
144144 expect ( controller . send ( :humanize_guide_title , "features/admin/user_management" ) ) . to eq ( "User management" )
145145 end
146146 end
147147 end
148- end
148+ end
0 commit comments