From 3cacad272654fa2ae4084a52300a4b4447333e97 Mon Sep 17 00:00:00 2001 From: Noelle Hemphill Date: Thu, 12 Oct 2023 15:53:08 -0600 Subject: [PATCH] test and mvc: wrote tests for the discover movies page and implemented via tdd the view needed Co-authored-by: Jorja Flemming --- app/controllers/discover_controller.rb | 1 - app/controllers/movies_controller.rb | 5 + app/views/discover/index.html.erb | 14 +- app/views/movies/index.html.erb | 1 + config/routes.rb | 1 + coverage/.last_run.json | 2 +- coverage/.resultset.json | 71 +++- coverage/index.html | 559 ++++++++++++++++++++++++- spec/features/discover/index_spec.rb | 30 ++ 9 files changed, 646 insertions(+), 38 deletions(-) create mode 100644 app/controllers/movies_controller.rb create mode 100644 app/views/movies/index.html.erb create mode 100644 spec/features/discover/index_spec.rb diff --git a/app/controllers/discover_controller.rb b/app/controllers/discover_controller.rb index 5074a7b39..d5044c400 100644 --- a/app/controllers/discover_controller.rb +++ b/app/controllers/discover_controller.rb @@ -1,5 +1,4 @@ class DiscoverController < ApplicationController def index - end end \ No newline at end of file diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 000000000..d8a7ea921 --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -0,0 +1,5 @@ +class MoviesController < ApplicationController + def index + + end +end \ No newline at end of file diff --git a/app/views/discover/index.html.erb b/app/views/discover/index.html.erb index 83e113888..d981de2a5 100644 --- a/app/views/discover/index.html.erb +++ b/app/views/discover/index.html.erb @@ -1 +1,13 @@ -

Discover Movies

\ No newline at end of file +

Discover Movies

+ +
+

<%= button_to "Discover Top Rated Movies", user_movies_path, method: :get %> +

+ + \ No newline at end of file diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb new file mode 100644 index 000000000..0c9f11b23 --- /dev/null +++ b/app/views/movies/index.html.erb @@ -0,0 +1 @@ +

Welcome to the Movies Page

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 86ded13af..9cb591c73 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,5 +9,6 @@ resources :users, only: %i[show new create] do resources :discover, only: [:index] + resources :movies, only: [:index] end end diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 0ea16c411..a18ab1611 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "line": 96.77 + "line": 97.27 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 5bc432a6b..9392fdbe1 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -248,6 +248,7 @@ null, 1, 1, + 1, null, null ] @@ -266,6 +267,44 @@ null ] }, + "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/spec/features/landing_page/index_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + 1, + 1, + 1, + null, + 1, + null, + 1, + 1, + null, + 1, + null, + 1, + 1, + 1, + 1, + null, + 1, + null, + 1, + null, + null, + 1, + null, + 1, + null, + 1, + null, + 1, + null, + null + ] + }, "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/spec/features/users/show_spec.rb": { "lines": [ 1, @@ -404,11 +443,10 @@ null ] }, - "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/app/controllers/landing_page_controller.rb": { + "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/app/controllers/discover_controller.rb": { "lines": [ 1, 1, - 2, null, null ] @@ -421,6 +459,24 @@ null ] }, + "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/app/controllers/movies_controller.rb": { + "lines": [ + 1, + 1, + null, + null, + null + ] + }, + "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/app/controllers/landing_page_controller.rb": { + "lines": [ + 1, + 1, + 2, + null, + null + ] + }, "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/app/controllers/users_controller.rb": { "lines": [ 1, @@ -442,17 +498,8 @@ null, null ] - }, - "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/app/controllers/discover_controller.rb": { - "lines": [ - 1, - 1, - null, - null, - null - ] } }, - "timestamp": 1697073511 + "timestamp": 1697147391 } } diff --git a/coverage/index.html b/coverage/index.html index 130a319cb..2ca65aeae 100644 --- a/coverage/index.html +++ b/coverage/index.html @@ -14,7 +14,7 @@ loading
-
Generated 2023-10-11T19:18:31-06:00
+
Generated 2023-10-12T15:49:51-06:00
    @@ -23,14 +23,14 @@

    All Files ( - 96.77% + 97.28% covered at - 1.16 + 1.14 hits/line ) @@ -39,15 +39,15 @@

    - 25 files in total. + 27 files in total.
    - 124 relevant lines, - 120 lines covered and + 147 relevant lines, + 143 lines covered and 4 lines missed. ( - 96.77% + 97.28% )
    @@ -84,7 +84,7 @@

    app/controllers/discover_controller.rb 100.00 % - 5 + 4 2 2 0 @@ -103,6 +103,17 @@

    + + app/controllers/movies_controller.rb + 100.00 % + 5 + 2 + 2 + 0 + 1.00 + + + app/controllers/users_controller.rb 55.56 % @@ -282,9 +293,20 @@

    config/routes.rb 100.00 % - 13 - 4 - 4 + 14 + 5 + 5 + 0 + 1.00 + + + + + spec/features/landing_page/index_spec.rb + 100.00 % + 34 + 20 + 20 0 1.00 @@ -492,7 +514,82 @@

    - + end + +

    + +
    +
  • + + + + + + end +
  • +
    + + + +
    + + +
    +
    +

    app/controllers/landing_page_controller.rb

    +

    + + 100.0% + + + lines covered +

    + + + +
    + 3 relevant lines. + 3 lines covered and + 0 lines missed. +
    + + + +
    + +
    +    
      + +
      +
    1. + 1 + + + + + class LandingPageController < ApplicationController +
    2. +
      + +
      +
    3. + 1 + + + + + def index +
    4. +
      + +
      +
    5. + 2 + + + + + @users = User.all
    6. @@ -523,9 +620,9 @@

    -
    +
    -

    app/controllers/landing_page_controller.rb

    +

    app/controllers/movies_controller.rb

    100.0% @@ -537,8 +634,8 @@

    - 3 relevant lines. - 3 lines covered and + 2 relevant lines. + 2 lines covered and 0 lines missed.
    @@ -556,7 +653,7 @@

    - class LandingPageController < ApplicationController + class MoviesController < ApplicationController

    @@ -572,13 +669,13 @@

    -
  • - 2 +
  • + - @users = User.all +
  • @@ -3770,8 +3867,8 @@

    - 4 relevant lines. - 4 lines covered and + 5 relevant lines. + 5 lines covered and 0 lines missed.
    @@ -3904,7 +4001,18 @@

    -
  • +
  • + 1 + + + + + resources :movies, only: [:index] +
  • +
    + +
    +
  • @@ -3914,6 +4022,180 @@

  • +
    +
  • + + + + + + end +
  • +
    + + + + + + +
    +
    +

    spec/features/landing_page/index_spec.rb

    +

    + + 100.0% + + + lines covered +

    + + + +
    + 20 relevant lines. + 20 lines covered and + 0 lines missed. +
    + + + +
    + +
    +    
      + +
      +
    1. + 1 + + + + + require 'rails_helper' +
    2. +
      + +
      +
    3. + + + + + + +
    4. +
      + +
      +
    5. + 1 + + + + + RSpec.describe 'landing page', type: :feature do +
    6. +
      + +
      +
    7. + 1 + + + + + it 'landing page has title, new user button, and links' do +
    8. +
      + +
      +
    9. + 1 + + + + + u1 = User.create!(name: 'Sean', email: 'championlyfe@gmail.com') +
    10. +
      + +
      +
    11. + 1 + + + + + u2 = User.create!(name: 'Volk', email: 'primeathlete@gmail.com') +
    12. +
      + +
      +
    13. + 1 + + + + + u3 = User.create!(name: 'Izzy', email: 'animeever@gmail.com') +
    14. +
      + +
      +
    15. + + + + + + +
    16. +
      + +
      +
    17. + 1 + + + + + visit root_path +
    18. +
      + +
      +
    19. + + + + + + +
    20. +
      + +
      +
    21. + 1 + + + + + expect(page).to have_content('Viewing Party Lite') +
    22. +
      + +
      +
    23. + 1 + + + + + expect(page).to have_button('New User') +
    24. +
      +
    25. @@ -3921,6 +4203,237 @@

      + +

    26. +
      + +
      +
    27. + 1 + + + + + expect(page).to have_link('Landing Page') +
    28. +
      + +
      +
    29. + + + + + + +
    30. +
      + +
      +
    31. + 1 + + + + + within('#users') do +
    32. +
      + +
      +
    33. + 1 + + + + + expect(page).to have_link(u1.name.to_s) +
    34. +
      + +
      +
    35. + 1 + + + + + expect(page).to have_link(u2.name.to_s) +
    36. +
      + +
      +
    37. + 1 + + + + + expect(page).to have_link(u3.name.to_s) +
    38. +
      + +
      +
    39. + + + + + + +
    40. +
      + +
      +
    41. + 1 + + + + + click_link(u1.name.to_s) +
    42. +
      + +
      +
    43. + + + + + + +
    44. +
      + +
      +
    45. + 1 + + + + + expect(current_path).to eq(user_path(u1)) +
    46. +
      + +
      +
    47. + + + + + + end +
    48. +
      + +
      +
    49. + + + + + + +
    50. +
      + +
      +
    51. + 1 + + + + + click_link('Landing Page') +
    52. +
      + +
      +
    53. + + + + + + +
    54. +
      + +
      +
    55. + 1 + + + + + expect(current_path).to eq(root_path) +
    56. +
      + +
      +
    57. + + + + + + +
    58. +
      + +
      +
    59. + 1 + + + + + click_button('New User') +
    60. +
      + +
      +
    61. + + + + + + +
    62. +
      + +
      +
    63. + 1 + + + + + expect(current_path).to eq(new_user_path) +
    64. +
      + +
      +
    65. + + + + + + end +
    66. +
      + +
      +
    67. + + + + + end
    68. diff --git a/spec/features/discover/index_spec.rb b/spec/features/discover/index_spec.rb new file mode 100644 index 000000000..b05176223 --- /dev/null +++ b/spec/features/discover/index_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' + +RSpec.describe 'Discover Movies Page' do + before :each do + @u1 = User.create!(name: 'Brian', email: 'brian@brian.com') + @u2 = User.create!(name: 'Lorien', email: 'lorienlorienl.com') + @u3 = User.create!(name: 'Rachel', email: 'rachel@rachel.com') + end + it 'has a button to discover movies' do + visit user_discover_index_path(@u1) + + within('#top_movies') do + expect(page).to have_button('Discover Top Rated Movies') + click_button 'Discover Top Rated Movies' + expect(current_path).to eq user_movies_path(@u1) + end + end + + it 'has a search field to search by movie title' do + visit user_discover_index_path(@u1) + + within('#movie_search') do + expect(page).to have_field('Search By Movie Title') + fill_in 'Search By Movie Title', with: 'Barbie' + click_button 'Search' + expect(current_path).to eq user_movies_path(@u1) + end + end + +end