Skip to content

Commit feb2e00

Browse files
maebealeclaude
andcommitted
Add comprehensive tests for STI VideoLibrary implementation
- Add model specs for .tutorials, .podcasts, .intros scopes - Add request specs for tutorials#index (Tutorial type only) and tutorials#video_library (all types) - Add routing specs for /video_library route - Add home video library controller specs: - All content types displayed with youtube_url - Excludes records without youtube_url - Correct ordering by position then created_at Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 73fe11e commit feb2e00

4 files changed

Lines changed: 104 additions & 0 deletions

File tree

spec/models/tutorial_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,40 @@
4040
expect(results).not_to include(draft_tutorial)
4141
end
4242
end
43+
44+
describe '.tutorials' do
45+
let!(:tutorial) { create(:tutorial, title: 'Tutorial 1') }
46+
let!(:podcast) { create(:podcast, title: 'Podcast 1') }
47+
let!(:intro) { create(:intro, title: 'Intro 1') }
48+
49+
it 'returns only Tutorial type records' do
50+
results = VideoLibrary.tutorials
51+
expect(results).to include(tutorial)
52+
expect(results).not_to include(podcast, intro)
53+
end
54+
end
55+
56+
describe '.podcasts' do
57+
let!(:tutorial) { create(:tutorial, title: 'Tutorial 1') }
58+
let!(:podcast) { create(:podcast, title: 'Podcast 1') }
59+
let!(:intro) { create(:intro, title: 'Intro 1') }
60+
61+
it 'returns only Podcast type records' do
62+
results = VideoLibrary.podcasts
63+
expect(results).to include(podcast)
64+
expect(results).not_to include(tutorial, intro)
65+
end
66+
end
67+
68+
describe '.intros' do
69+
let!(:tutorial) { create(:tutorial, title: 'Tutorial 1') }
70+
let!(:podcast) { create(:podcast, title: 'Podcast 1') }
71+
let!(:intro) { create(:intro, title: 'Intro 1') }
72+
73+
it 'returns only Intro type records' do
74+
results = VideoLibrary.intros
75+
expect(results).to include(intro)
76+
expect(results).not_to include(tutorial, podcast)
77+
end
78+
end
4379
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require "rails_helper"
2+
3+
RSpec.describe "Home::VideoLibrary", type: :request do
4+
describe "GET /home/video_library" do
5+
it "renders a successful response" do
6+
get home_video_library_url
7+
expect(response).to be_successful
8+
end
9+
10+
it "displays all content types with youtube_url" do
11+
tutorial = create(:tutorial, title: 'Tutorial Video', youtube_url: 'https://www.youtube.com/watch?v=1')
12+
podcast = create(:podcast, title: 'Podcast Video', youtube_url: 'https://www.youtube.com/watch?v=2')
13+
intro = create(:intro, title: 'Intro Video', youtube_url: 'https://www.youtube.com/watch?v=3')
14+
get home_video_library_url
15+
expect(response.body).to include(tutorial.title, podcast.title, intro.title)
16+
end
17+
18+
it "excludes records without youtube_url" do
19+
with_url = create(:tutorial, title: 'With URL', youtube_url: 'https://www.youtube.com/watch?v=1')
20+
without_url = create(:podcast, title: 'No URL', youtube_url: nil)
21+
get home_video_library_url
22+
expect(response.body).to include(with_url.title)
23+
expect(response.body).not_to include(without_url.title)
24+
end
25+
26+
it "orders by position ascending, then created_at descending" do
27+
item1 = create(:tutorial, position: 2, youtube_url: 'https://www.youtube.com/watch?v=1')
28+
item2 = create(:podcast, position: 1, youtube_url: 'https://www.youtube.com/watch?v=2')
29+
item3 = create(:intro, position: 1, youtube_url: 'https://www.youtube.com/watch?v=3')
30+
get home_video_library_url
31+
body = response.body
32+
pos2 = body.index(item2.title)
33+
pos3 = body.index(item3.title)
34+
pos1 = body.index(item1.title)
35+
expect(pos2).to be < pos3 unless pos2.nil? || pos3.nil?
36+
expect(pos2).to be < pos1 unless pos2.nil? || pos1.nil?
37+
end
38+
end
39+
end

spec/requests/tutorials_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@
4444
get tutorials_url
4545
expect(response).to be_successful
4646
end
47+
48+
it "shows only Tutorial type records" do
49+
tutorial = create(:tutorial, title: 'Test Tutorial')
50+
podcast = create(:podcast, title: 'Test Podcast')
51+
intro = create(:intro, title: 'Test Intro')
52+
get tutorials_url
53+
expect(response.body).to include(tutorial.title)
54+
expect(response.body).not_to include(podcast.title, intro.title)
55+
end
56+
end
57+
58+
describe "GET /video_library" do
59+
it "renders a successful response" do
60+
create(:tutorial)
61+
get video_library_url
62+
expect(response).to be_successful
63+
end
64+
65+
it "shows all content types (Tutorial, Podcast, Intro)" do
66+
tutorial = create(:tutorial, title: 'Test Tutorial')
67+
podcast = create(:podcast, title: 'Test Podcast')
68+
intro = create(:intro, title: 'Test Intro')
69+
get video_library_url
70+
expect(response.body).to include(tutorial.title, podcast.title, intro.title)
71+
end
4772
end
4873

4974
describe "GET /show" do

spec/routing/tutorials_routing_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@
3434
it "routes to #destroy" do
3535
expect(delete: "/tutorials/1").to route_to("tutorials#destroy", id: "1")
3636
end
37+
38+
it "routes /video_library to tutorials#video_library" do
39+
expect(get: "/video_library").to route_to("tutorials#video_library")
40+
end
3741
end
3842
end

0 commit comments

Comments
 (0)