|
| 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 |
0 commit comments