Skip to content

Commit

Permalink
Merge pull request #17 from josephlee702/setup/database
Browse files Browse the repository at this point in the history
Setup/database
  • Loading branch information
josephlee702 authored Nov 29, 2023
2 parents 4447f3d + a9b55ba commit f48c5cf
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ end
group :test do
gem 'capybara'
gem 'launchy'
gem 'shoulda-matchers'
gem 'simplecov'
gem "shoulda-matchers"
end
6 changes: 0 additions & 6 deletions app/models/movie.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class User < ApplicationRecord
has_many :viewing_parties
has_many :user_viewing_parties
Expand Down
4 changes: 4 additions & 0 deletions app/models/user_viewing_party.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# frozen_string_literal: true

class UserViewingParty < ApplicationRecord
belongs_to :user
belongs_to :viewing_party

validates :user_id, :viewing_party_id, presence: true
end
6 changes: 3 additions & 3 deletions app/models/viewing_party.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class ViewingParty < ApplicationRecord
belongs_to :movie
belongs_to :user
has_many :user_viewing_parties
has_many :users, through: :user_viewing_parties

validates :user_id, :start_time, presence: true
validates :movie_id, :start_time, presence: true
end
2 changes: 2 additions & 0 deletions db/migrate/20231128000020_create_users.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
Expand Down
16 changes: 0 additions & 16 deletions db/migrate/20231128001030_create_movies.rb

This file was deleted.

3 changes: 3 additions & 0 deletions db/migrate/20231128002343_create_viewing_parties.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# frozen_string_literal: true

class CreateViewingParties < ActiveRecord::Migration[7.0]
def change
create_table :viewing_parties do |t|
t.datetime :start_time
t.string :movie_id

t.timestamps
end
Expand Down
3 changes: 3 additions & 0 deletions db/migrate/20231128002839_create_user_viewing_parties.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# frozen_string_literal: true

class CreateUserViewingParties < ActiveRecord::Migration[7.0]
def change
create_table :user_viewing_parties do |t|
t.references :user, null: false, foreign_key: true
t.references :viewing_party, null: false, foreign_key: true
t.boolean :host, null: false, default: false

t.timestamps
end
Expand Down
5 changes: 0 additions & 5 deletions db/migrate/20231128003643_add_movie_to_viewing_parties.rb

This file was deleted.

5 changes: 0 additions & 5 deletions db/migrate/20231128050911_add_user_to_viewing_parties.rb

This file was deleted.

23 changes: 3 additions & 20 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions spec/models/movie_spec.rb

This file was deleted.

2 changes: 2 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe User, type: :model do
Expand Down
15 changes: 15 additions & 0 deletions spec/models/user_viewing_party_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe UserViewingParty, type: :model do
describe 'relationships' do
it { should belong_to(:user) }
it { should belong_to(:viewing_party) }
end

describe 'validations' do
it { should validate_presence_of(:user_id) }
it { should validate_presence_of(:viewing_party_id) }
end
end
5 changes: 3 additions & 2 deletions spec/models/viewing_party_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe ViewingParty, type: :model do
describe 'relationships' do
it { should belong_to(:movie) }
it { should have_many(:users).through(:user_viewing_parties) }
end

describe 'validations' do
it { should validate_presence_of(:user_id) }
it { should validate_presence_of(:movie_id) }
it { should validate_presence_of(:start_time) }
end
end
4 changes: 3 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: true

# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!

Expand Down
94 changes: 47 additions & 47 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
Expand Down Expand Up @@ -44,51 +46,49 @@
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# This allows you to limit a spec run to individual examples or groups
# you care about by tagging them with `:focus` metadata. When nothing
# is tagged with `:focus`, all examples get run. RSpec also provides
# aliases for `it`, `describe`, and `context` that include `:focus`
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
config.filter_run_when_matching :focus
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
config.disable_monkey_patching!
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = "doc"
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
=end
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# # This allows you to limit a spec run to individual examples or groups
# # you care about by tagging them with `:focus` metadata. When nothing
# # is tagged with `:focus`, all examples get run. RSpec also provides
# # aliases for `it`, `describe`, and `context` that include `:focus`
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
# config.filter_run_when_matching :focus
#
# # Allows RSpec to persist some state between runs in order to support
# # the `--only-failures` and `--next-failure` CLI options. We recommend
# # you configure your source control system to ignore this file.
# config.example_status_persistence_file_path = "spec/examples.txt"
#
# # Limits the available syntax to the non-monkey patched syntax that is
# # recommended. For more details, see:
# # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
# config.disable_monkey_patching!
#
# # Many RSpec users commonly either run the entire suite or an individual
# # file, and it's useful to allow more verbose output when running an
# # individual spec file.
# if config.files_to_run.one?
# # Use the documentation formatter for detailed output,
# # unless a formatter has already been configured
# # (e.g. via a command-line flag).
# config.default_formatter = "doc"
# end
#
# # Print the 10 slowest examples and example groups at the
# # end of the spec run, to help surface which specs are running
# # particularly slow.
# config.profile_examples = 10
#
# # Run specs in random order to surface order dependencies. If you find an
# # order dependency and want to debug it, you can fix the order by providing
# # the seed, which is printed after each run.
# # --seed 1234
# config.order = :random
#
# # Seed global randomization in this process using the `--seed` CLI option.
# # Setting this allows you to use `--seed` to deterministically reproduce
# # test failures related to randomization by passing the same `--seed` value
# # as the one that triggered the failure.
# Kernel.srand config.seed
end

0 comments on commit f48c5cf

Please sign in to comment.