-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9af4bd9
commit 2b03239
Showing
14 changed files
with
281 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
class MoviesController < ApplicationController | ||
before_action :set_movie, only: %i[ show edit update destroy ] | ||
|
||
# GET /movies or /movies.json | ||
def index | ||
@movies = Movie.all | ||
end | ||
|
||
# GET /movies/1 or /movies/1.json | ||
def show | ||
end | ||
|
||
# GET /movies/new | ||
def new | ||
@movie = Movie.new | ||
end | ||
|
||
# GET /movies/1/edit | ||
def edit | ||
end | ||
|
||
# POST /movies or /movies.json | ||
def create | ||
@movie = Movie.new(movie_params) | ||
|
||
respond_to do |format| | ||
if @movie.save | ||
format.html { redirect_to movie_url(@movie), notice: "Movie was successfully created." } | ||
format.json { render :show, status: :created, location: @movie } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @movie.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /movies/1 or /movies/1.json | ||
def update | ||
respond_to do |format| | ||
if @movie.update(movie_params) | ||
format.html { redirect_to movie_url(@movie), notice: "Movie was successfully updated." } | ||
format.json { render :show, status: :ok, location: @movie } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @movie.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /movies/1 or /movies/1.json | ||
def destroy | ||
@movie.destroy! | ||
|
||
respond_to do |format| | ||
format.html { redirect_to movies_url, notice: "Movie was successfully destroyed." } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_movie | ||
@movie = Movie.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def movie_params | ||
params.require(:movie).permit(:title, :rating, :description, :release_date) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module MoviesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<%= form_with(model: movie) do |form| %> | ||
<% if movie.errors.any? %> | ||
<div style="color: red"> | ||
<h2><%= pluralize(movie.errors.count, "error") %> prohibited this movie from being saved:</h2> | ||
|
||
<ul> | ||
<% movie.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div> | ||
<%= form.label :title, style: "display: block" %> | ||
<%= form.text_field :title %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :rating, style: "display: block" %> | ||
<%= form.text_field :rating %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :description, style: "display: block" %> | ||
<%= form.text_field :description %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :release_date, style: "display: block" %> | ||
<%= form.text_field :release_date %> | ||
</div> | ||
|
||
<div> | ||
<%= form.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div id="<%= dom_id movie %>"> | ||
<p> | ||
<strong>Title:</strong> | ||
<%= movie.title %> | ||
</p> | ||
|
||
<p> | ||
<strong>Rating:</strong> | ||
<%= movie.rating %> | ||
</p> | ||
|
||
<p> | ||
<strong>Description:</strong> | ||
<%= movie.description %> | ||
</p> | ||
|
||
<p> | ||
<strong>Release date:</strong> | ||
<%= movie.release_date %> | ||
</p> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.extract! movie, :id, :title, :rating, :description, :release_date, :created_at, :updated_at | ||
json.url movie_url(movie, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<% content_for :title, "Editing movie" %> | ||
|
||
<h1>Editing movie</h1> | ||
|
||
<%= render "form", movie: @movie %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Show this movie", @movie %> | | ||
<%= link_to "Back to movies", movies_path %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<% content_for :title, "Movies" %> | ||
|
||
<h1>Movies</h1> | ||
|
||
<div id="movies"> | ||
<% @movies.each do |movie| %> | ||
<%= render movie %> | ||
<p> | ||
<%= link_to "Show this movie", movie %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<%= link_to "New movie", new_movie_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.array! @movies, partial: "movies/movie", as: :movie |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<% content_for :title, "New movie" %> | ||
|
||
<h1>New movie</h1> | ||
|
||
<%= render "form", movie: @movie %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Back to movies", movies_path %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<%= render @movie %> | ||
|
||
<div> | ||
<%= link_to "Edit this movie", edit_movie_path(@movie) %> | | ||
<%= link_to "Back to movies", movies_path %> | ||
|
||
<%= button_to "Destroy this movie", @movie, method: :delete %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "movies/movie", movie: @movie |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,4 @@ | ||
Rails.application.routes.draw do | ||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html | ||
|
||
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. | ||
# Can be used by load balancers and uptime monitors to verify that the app is live. | ||
get "up" => "rails/health#show", as: :rails_health_check | ||
|
||
# Render dynamic PWA files from app/views/pwa/* | ||
get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker | ||
get "manifest" => "rails/pwa#manifest", as: :pwa_manifest | ||
|
||
# Defines the root path route ("/") | ||
# root "posts#index" | ||
resources :movies | ||
root :to => redirect('/movies') | ||
Check failure on line 3 in config/routes.rb GitHub Actions / lint
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require "test_helper" | ||
|
||
class MoviesControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@movie = movies(:one) | ||
end | ||
|
||
test "should get index" do | ||
get movies_url | ||
assert_response :success | ||
end | ||
|
||
test "should get new" do | ||
get new_movie_url | ||
assert_response :success | ||
end | ||
|
||
test "should create movie" do | ||
assert_difference("Movie.count") do | ||
post movies_url, params: { movie: { description: @movie.description, rating: @movie.rating, release_date: @movie.release_date, title: @movie.title } } | ||
end | ||
|
||
assert_redirected_to movie_url(Movie.last) | ||
end | ||
|
||
test "should show movie" do | ||
get movie_url(@movie) | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get edit_movie_url(@movie) | ||
assert_response :success | ||
end | ||
|
||
test "should update movie" do | ||
patch movie_url(@movie), params: { movie: { description: @movie.description, rating: @movie.rating, release_date: @movie.release_date, title: @movie.title } } | ||
assert_redirected_to movie_url(@movie) | ||
end | ||
|
||
test "should destroy movie" do | ||
assert_difference("Movie.count", -1) do | ||
delete movie_url(@movie) | ||
end | ||
|
||
assert_redirected_to movies_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require "application_system_test_case" | ||
|
||
class MoviesTest < ApplicationSystemTestCase | ||
setup do | ||
@movie = movies(:one) | ||
end | ||
|
||
test "visiting the index" do | ||
visit movies_url | ||
assert_selector "h1", text: "Movies" | ||
end | ||
|
||
test "should create movie" do | ||
visit movies_url | ||
click_on "New movie" | ||
|
||
fill_in "Description", with: @movie.description | ||
fill_in "Rating", with: @movie.rating | ||
fill_in "Release date", with: @movie.release_date | ||
fill_in "Title", with: @movie.title | ||
click_on "Create Movie" | ||
|
||
assert_text "Movie was successfully created" | ||
click_on "Back" | ||
end | ||
|
||
test "should update Movie" do | ||
visit movie_url(@movie) | ||
click_on "Edit this movie", match: :first | ||
|
||
fill_in "Description", with: @movie.description | ||
fill_in "Rating", with: @movie.rating | ||
fill_in "Release date", with: @movie.release_date | ||
fill_in "Title", with: @movie.title | ||
click_on "Update Movie" | ||
|
||
assert_text "Movie was successfully updated" | ||
click_on "Back" | ||
end | ||
|
||
test "should destroy Movie" do | ||
visit movie_url(@movie) | ||
click_on "Destroy this movie", match: :first | ||
|
||
assert_text "Movie was successfully destroyed" | ||
end | ||
end |