diff --git a/Gemfile b/Gemfile index b7248242c..e561500ea 100644 --- a/Gemfile +++ b/Gemfile @@ -74,6 +74,7 @@ group :test do gem 'launchy' gem 'rspec-rails' gem 'simplecov' + gem 'shoulda-matchers' end diff --git a/Gemfile.lock b/Gemfile.lock index 2dbd7d796..df818f74e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -223,6 +223,8 @@ GEM rubocop (>= 1.33.0, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) + shoulda-matchers (5.3.0) + activesupport (>= 5.2.0) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) @@ -282,6 +284,7 @@ DEPENDENCIES rails (~> 7.0.4, >= 7.0.4.2) rspec-rails rubocop-rails + shoulda-matchers simplecov sprockets-rails stimulus-rails diff --git a/app/models/user.rb b/app/models/user.rb index 379658a50..44dc41cc8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,8 @@ class User < ApplicationRecord + validates_presence_of :name, :email + validates :email, uniqueness: { case_sensitive: false } + + has_many :user_viewing_parties + has_many :viewing_parties, through: :user_viewing_parties + end diff --git a/app/models/user_viewing_party.rb b/app/models/user_viewing_party.rb new file mode 100644 index 000000000..93f43bca2 --- /dev/null +++ b/app/models/user_viewing_party.rb @@ -0,0 +1,4 @@ +class UserViewingParty < ApplicationRecord + belongs_to :user + belongs_to :viewing_party +end \ No newline at end of file diff --git a/app/models/viewing_party.rb b/app/models/viewing_party.rb new file mode 100644 index 000000000..c98916633 --- /dev/null +++ b/app/models/viewing_party.rb @@ -0,0 +1,7 @@ +class ViewingParty < ApplicationRecord + validates_presence_of :movie_title, :movie_image, :start_time + validates_numericality_of :movie_id, :duration + + has_many :user_viewing_parties + has_many :users, through: :user_viewing_parties +end \ No newline at end of file diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 3b1151b00..52d2bf299 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "line": 93.44 + "line": 100.0 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 99c84cfcd..9944f4d61 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -268,6 +268,12 @@ "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/app/models/user.rb": { "lines": [ 1, + 1, + 1, + null, + 1, + 1, + null, null ] }, @@ -280,37 +286,59 @@ null ] }, - "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/app/controllers/users_controller.rb": { + "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/spec/models/user_viewing_party_spec.rb": { "lines": [ + 1, + null, 1, 1, 2, + 2, null, - null, + null + ] + }, + "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/app/models/user_viewing_party.rb": { + "lines": [ + 1, + 1, + 1, + null + ] + }, + "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/spec/models/viewing_party_spec.rb": { + "lines": [ 1, null, + 1, + 1, + 2, + 2, + 2, + 2, + 2, null, null, 1, - 0, - 0, - 0, - null, - 0, + 2, + 2, null, null, null ] }, - "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/app/controllers/application_controller.rb": { + "/Users/noellehemphill/turing_work/3mod/projects/viewing_party_lite_7/app/models/viewing_party.rb": { "lines": [ + 1, + 1, + 1, null, - null, + 1, 1, null ] } }, - "timestamp": 1697039978 + "timestamp": 1697042045 } } diff --git a/coverage/index.html b/coverage/index.html index 651cd0f66..7d8fee5d6 100644 --- a/coverage/index.html +++ b/coverage/index.html @@ -14,7 +14,7 @@ loading
-
Generated 2023-10-11T09:59:38-06:00
+
Generated 2023-10-11T10:34:05-06:00
@@ -23,14 +23,14 @@

All Files ( - 93.44% + 100.0% covered at - - 0.95 + + 1.11 hits/line ) @@ -39,15 +39,15 @@

- 17 files in total. + 19 files in total.
- 61 relevant lines, - 57 lines covered and - 4 lines missed. + 79 relevant lines, + 79 lines covered and + 0 lines missed. ( - 93.44% + 100.0% )
@@ -71,7 +71,7 @@

- app/controllers/application_controller.rb + app/helpers/application_helper.rb 100.00 % 4 1 @@ -82,20 +82,9 @@

- app/controllers/users_controller.rb - 55.56 % - 18 - 9 - 5 - 4 - 0.67 - - - - - app/helpers/application_helper.rb + app/helpers/landing_page_helper.rb 100.00 % - 4 + 2 1 1 0 @@ -104,33 +93,44 @@

- app/helpers/landing_page_helper.rb + app/models/application_record.rb 100.00 % + 5 + 2 2 - 1 - 1 0 1.00 - app/models/application_record.rb + app/models/user.rb 100.00 % + 8 + 5 5 - 2 - 2 0 1.00 - app/models/user.rb + app/models/user_viewing_party.rb 100.00 % - 2 - 1 - 1 + 4 + 3 + 3 + 0 + 1.00 + + + + + app/models/viewing_party.rb + 100.00 % + 7 + 5 + 5 0 1.00 @@ -246,6 +246,28 @@

+ + spec/models/user_viewing_party_spec.rb + 100.00 % + 8 + 5 + 5 + 0 + 1.40 + + + + + spec/models/viewing_party_spec.rb + 100.00 % + 17 + 11 + 11 + 0 + 1.64 + + + spec/spec_helper.rb 100.00 % @@ -274,9 +296,9 @@

-
+
-

app/controllers/application_controller.rb

+

app/helpers/application_helper.rb

100.0% @@ -329,7 +351,7 @@

- class ApplicationController < ActionController::Base + module ApplicationHelper

@@ -349,12 +371,12 @@

-
+
-

app/controllers/users_controller.rb

+

app/helpers/landing_page_helper.rb

- - 55.56% + + 100.0% lines covered @@ -363,9 +385,9 @@

- 9 relevant lines. - 5 lines covered and - 4 lines missed. + 1 relevant lines. + 1 lines covered and + 0 lines missed.
@@ -382,45 +404,65 @@

- class UsersController < ApplicationController + module LandingPageHelper

-
  • - 1 +
  • + - def show + end
  • -
    -
  • - 2 - + + +
  • - + +
    +
    +

    app/models/application_record.rb

    +

    + + 100.0% + - @user = User.find(params[:id]) - -

    + lines covered +

    + + + +
    + 2 relevant lines. + 2 lines covered and + 0 lines missed. +
    + + + +

    + +
    +    
      -
    1. +
    2. - end + # frozen_string_literal: true
    3. -
    4. +
    5. @@ -431,139 +473,148 @@

    6. -
    7. +
    8. 1 - def new + class ApplicationRecord < ActiveRecord::Base
    9. -
    10. - +
    11. + 1 - + primary_abstract_class
    12. -
    13. +
    14. - end + end
    15. -
      -
    16. - - - - +
    +
    +
    - - - -
    -
  • - 1 - +
    +
    +

    app/models/user.rb

    +

    + + 100.0% + - + lines covered +

    - def create -
  • -
    + + +
    + 5 relevant lines. + 5 lines covered and + 0 lines missed. +
    + + + + + +
    +    
      -
    1. - +
    2. + 1 - @user = User.new(name: params[:name], email: params[:email]) + class User < ApplicationRecord
    3. -
    4. - +
    5. + 1 - if @user.save + validates_presence_of :name, :email
    6. -
    7. - +
    8. + 1 - redirect_to user_path(@user) + validates :email, uniqueness: { case_sensitive: false }
    9. -
    10. +
    11. - else +
    12. -
    13. - +
    14. + 1 - render :new + has_many :user_viewing_parties
    15. -
    16. - +
    17. + 1 - end + has_many :viewing_parties, through: :user_viewing_parties
    18. -
    19. +
    20. - end +
    21. -
    22. +
    23. @@ -578,9 +629,9 @@

    24. -
      +
      -

      app/helpers/application_helper.rb

      +

      app/models/user_viewing_party.rb

      100.0% @@ -592,8 +643,8 @@

      - 1 relevant lines. - 1 lines covered and + 3 relevant lines. + 3 lines covered and 0 lines missed.
      @@ -605,24 +656,24 @@

        -
      1. - +
      2. + 1 - # frozen_string_literal: true + class UserViewingParty < ApplicationRecord
      3. -
      4. - +
      5. + 1 - + belongs_to :user
      6. @@ -633,7 +684,7 @@

        - module ApplicationHelper + belongs_to :viewing_party

      @@ -653,9 +704,9 @@

      -
      +
      -

      app/helpers/landing_page_helper.rb

      +

      app/models/viewing_party.rb

      100.0% @@ -667,8 +718,8 @@

      - 1 relevant lines. - 1 lines covered and + 5 relevant lines. + 5 lines covered and 0 lines missed.
      @@ -686,65 +737,34 @@

      - module LandingPageHelper + class ViewingParty < ApplicationRecord

      -
    25. - +
    26. + 1 - end + validates_presence_of :movie_title, :movie_image, :start_time
    27. -
    -
    - - - -
    -
    -

    app/models/application_record.rb

    -

    - - 100.0% - - - lines covered -

    - - - -
    - 2 relevant lines. - 2 lines covered and - 0 lines missed. -
    - - - -
    - -
    -    
      -
      -
    1. - +
    2. + 1 - # frozen_string_literal: true + validates_numericality_of :movie_id, :duration
    3. -
    4. +
    5. @@ -755,82 +775,29 @@

    6. -
    7. - 1 - - - - - class ApplicationRecord < ActiveRecord::Base -
    8. -
      - -
      -
    9. +
    10. 1 - primary_abstract_class + has_many :user_viewing_parties
    11. -
    12. - - - - - - end -
    13. -
      - -
    -
    -
    - - -
    -
    -

    app/models/user.rb

    -

    - - 100.0% - - - lines covered -

    - - - -
    - 1 relevant lines. - 1 lines covered and - 0 lines missed. -
    - - - -
    - -
    -    
      - -
      -
    1. +
    2. 1 - class User < ApplicationRecord + has_many :users, through: :user_viewing_parties
    3. -
    4. +
    5. @@ -3401,6 +3368,343 @@

      + end +

    6. +
      + +
    +
    +
    + + +
    +
    +

    spec/models/user_viewing_party_spec.rb

    +

    + + 100.0% + + + lines covered +

    + + + +
    + 5 relevant lines. + 5 lines covered and + 0 lines missed. +
    + + + +
    + +
    +    
      + +
      +
    1. + 1 + + + + + require 'rails_helper' +
    2. +
      + +
      +
    3. + + + + + + +
    4. +
      + +
      +
    5. + 1 + + + + + RSpec.describe UserViewingParty, type: :model do +
    6. +
      + +
      +
    7. + 1 + + + + + describe "relationships" do +
    8. +
      + +
      +
    9. + 2 + + + + + it { should belong_to :user} +
    10. +
      + +
      +
    11. + 2 + + + + + it { should belong_to :viewing_party} +
    12. +
      + +
      +
    13. + + + + + + end +
    14. +
      + +
      +
    15. + + + + + + end +
    16. +
      + +
    +
    +
    + + +
    +
    +

    spec/models/viewing_party_spec.rb

    +

    + + 100.0% + + + lines covered +

    + + + +
    + 11 relevant lines. + 11 lines covered and + 0 lines missed. +
    + + + +
    + +
    +    
      + +
      +
    1. + 1 + + + + + require 'rails_helper' +
    2. +
      + +
      +
    3. + + + + + + +
    4. +
      + +
      +
    5. + 1 + + + + + RSpec.describe ViewingParty, type: :model do +
    6. +
      + +
      +
    7. + 1 + + + + + describe "validations" do +
    8. +
      + +
      +
    9. + 2 + + + + + it { should validate_presence_of :movie_title} +
    10. +
      + +
      +
    11. + 2 + + + + + it { should validate_numericality_of :movie_id} +
    12. +
      + +
      +
    13. + 2 + + + + + it { should validate_presence_of :movie_image} +
    14. +
      + +
      +
    15. + 2 + + + + + it { should validate_numericality_of :duration} +
    16. +
      + +
      +
    17. + 2 + + + + + it { should validate_presence_of :start_time} +
    18. +
      + +
      +
    19. + + + + + + end +
    20. +
      + +
      +
    21. + + + + + + +
    22. +
      + +
      +
    23. + 1 + + + + + describe "relationships" do +
    24. +
      + +
      +
    25. + 2 + + + + + it { should have_many :user_viewing_parties} +
    26. +
      + +
      +
    27. + 2 + + + + + it { should have_many(:users).through(:user_viewing_parties)} +
    28. +
      + +
      +
    29. + + + + + + end +
    30. +
      + +
      +
    31. + + + + + + +
    32. +
      + +
      +
    33. + + + + + end
    34. diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 000000000..90cffcaaa --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe User, type: :model do + describe "validations" do + it { should validate_presence_of :name } + it { should validate_presence_of :email} + it { should validate_uniqueness_of(:email).case_insensitive} + end + + describe "relationships" do + it { should have_many(:user_viewing_parties) } + it { should have_many(:viewing_parties).through(:user_viewing_parties) } + end + +end \ No newline at end of file diff --git a/spec/models/user_viewing_party_spec.rb b/spec/models/user_viewing_party_spec.rb new file mode 100644 index 000000000..8767c1ff2 --- /dev/null +++ b/spec/models/user_viewing_party_spec.rb @@ -0,0 +1,8 @@ +require 'rails_helper' + +RSpec.describe UserViewingParty, type: :model do + describe "relationships" do + it { should belong_to :user} + it { should belong_to :viewing_party} + end +end \ No newline at end of file diff --git a/spec/models/viewing_party_spec.rb b/spec/models/viewing_party_spec.rb new file mode 100644 index 000000000..b93db6b89 --- /dev/null +++ b/spec/models/viewing_party_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +RSpec.describe ViewingParty, type: :model do + describe "validations" do + it { should validate_presence_of :movie_title} + it { should validate_numericality_of :movie_id} + it { should validate_presence_of :movie_image} + it { should validate_numericality_of :duration} + it { should validate_presence_of :start_time} + end + + describe "relationships" do + it { should have_many :user_viewing_parties} + it { should have_many(:users).through(:user_viewing_parties)} + end + +end \ No newline at end of file diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 37775a5bb..b6e000aa4 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -67,12 +67,12 @@ # config.filter_gems_from_backtrace("gem name") end -# Shoulda::Matchers.configure do |config| -# config.integrate do |with| -# with.test_framework :rspec -# with.library :rails -# end -# end +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end # VCR.configure do |config| # config.cassette_library_dir = 'spec/fixtures/vcr_cassettes' # config.hook_into :webmock