From 36502aee14c357a2ea9eb69e7c079fe3d23791da Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 13:40:47 -0800 Subject: [PATCH 01/38] Created models and controllers for movies, books and albums --- app/assets/javascripts/album.coffee | 3 ++ app/assets/javascripts/books.coffee | 3 ++ app/assets/javascripts/movies.coffee | 3 ++ app/assets/stylesheets/album.scss | 3 ++ app/assets/stylesheets/books.scss | 3 ++ app/assets/stylesheets/movies.scss | 3 ++ app/controllers/album_controller.rb | 2 + app/controllers/books_controller.rb | 2 + app/controllers/movies_controller.rb | 2 + app/helpers/album_helper.rb | 2 + app/helpers/books_helper.rb | 2 + app/helpers/movies_helper.rb | 2 + app/models/album.rb | 2 + app/models/book.rb | 2 + app/models/movie.rb | 2 + db/migrate/20151130213629_create_movies.rb | 12 ++++++ db/migrate/20151130213656_create_books.rb | 12 ++++++ db/migrate/20151130213741_create_albums.rb | 12 ++++++ db/schema.rb | 43 ++++++++++++++++++++++ 19 files changed, 115 insertions(+) create mode 100644 app/assets/javascripts/album.coffee create mode 100644 app/assets/javascripts/books.coffee create mode 100644 app/assets/javascripts/movies.coffee create mode 100644 app/assets/stylesheets/album.scss create mode 100644 app/assets/stylesheets/books.scss create mode 100644 app/assets/stylesheets/movies.scss create mode 100644 app/controllers/album_controller.rb create mode 100644 app/controllers/books_controller.rb create mode 100644 app/controllers/movies_controller.rb create mode 100644 app/helpers/album_helper.rb create mode 100644 app/helpers/books_helper.rb create mode 100644 app/helpers/movies_helper.rb create mode 100644 app/models/album.rb create mode 100644 app/models/book.rb create mode 100644 app/models/movie.rb create mode 100644 db/migrate/20151130213629_create_movies.rb create mode 100644 db/migrate/20151130213656_create_books.rb create mode 100644 db/migrate/20151130213741_create_albums.rb create mode 100644 db/schema.rb diff --git a/app/assets/javascripts/album.coffee b/app/assets/javascripts/album.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/album.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/books.coffee b/app/assets/javascripts/books.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/books.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/movies.coffee b/app/assets/javascripts/movies.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/movies.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/album.scss b/app/assets/stylesheets/album.scss new file mode 100644 index 0000000000..2bb51d310f --- /dev/null +++ b/app/assets/stylesheets/album.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the album controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/books.scss b/app/assets/stylesheets/books.scss new file mode 100644 index 0000000000..81379d103f --- /dev/null +++ b/app/assets/stylesheets/books.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the books controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/movies.scss b/app/assets/stylesheets/movies.scss new file mode 100644 index 0000000000..70aaa8a9a4 --- /dev/null +++ b/app/assets/stylesheets/movies.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the movies controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/album_controller.rb b/app/controllers/album_controller.rb new file mode 100644 index 0000000000..954eeb990d --- /dev/null +++ b/app/controllers/album_controller.rb @@ -0,0 +1,2 @@ +class AlbumController < ApplicationController +end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000000..cdb437b99f --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,2 @@ +class BooksController < ApplicationController +end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 0000000000..6c4c516140 --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -0,0 +1,2 @@ +class MoviesController < ApplicationController +end diff --git a/app/helpers/album_helper.rb b/app/helpers/album_helper.rb new file mode 100644 index 0000000000..23ace66827 --- /dev/null +++ b/app/helpers/album_helper.rb @@ -0,0 +1,2 @@ +module AlbumHelper +end diff --git a/app/helpers/books_helper.rb b/app/helpers/books_helper.rb new file mode 100644 index 0000000000..4b9311e0be --- /dev/null +++ b/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/app/helpers/movies_helper.rb b/app/helpers/movies_helper.rb new file mode 100644 index 0000000000..493eee555f --- /dev/null +++ b/app/helpers/movies_helper.rb @@ -0,0 +1,2 @@ +module MoviesHelper +end diff --git a/app/models/album.rb b/app/models/album.rb new file mode 100644 index 0000000000..46fa309e4e --- /dev/null +++ b/app/models/album.rb @@ -0,0 +1,2 @@ +class Album < ActiveRecord::Base +end diff --git a/app/models/book.rb b/app/models/book.rb new file mode 100644 index 0000000000..6f68b44465 --- /dev/null +++ b/app/models/book.rb @@ -0,0 +1,2 @@ +class Book < ActiveRecord::Base +end diff --git a/app/models/movie.rb b/app/models/movie.rb new file mode 100644 index 0000000000..49198a7d97 --- /dev/null +++ b/app/models/movie.rb @@ -0,0 +1,2 @@ +class Movie < ActiveRecord::Base +end diff --git a/db/migrate/20151130213629_create_movies.rb b/db/migrate/20151130213629_create_movies.rb new file mode 100644 index 0000000000..ade12491f2 --- /dev/null +++ b/db/migrate/20151130213629_create_movies.rb @@ -0,0 +1,12 @@ +class CreateMovies < ActiveRecord::Migration + def change + create_table :movies do |t| + t.string :name + t.string :director + t.string :description + t.integer :ranking + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151130213656_create_books.rb b/db/migrate/20151130213656_create_books.rb new file mode 100644 index 0000000000..fb1a5f87fe --- /dev/null +++ b/db/migrate/20151130213656_create_books.rb @@ -0,0 +1,12 @@ +class CreateBooks < ActiveRecord::Migration + def change + create_table :books do |t| + t.string :name + t.string :author + t.string :description + t.integer :ranking + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151130213741_create_albums.rb b/db/migrate/20151130213741_create_albums.rb new file mode 100644 index 0000000000..04aa7740ee --- /dev/null +++ b/db/migrate/20151130213741_create_albums.rb @@ -0,0 +1,12 @@ +class CreateAlbums < ActiveRecord::Migration + def change + create_table :albums do |t| + t.string :name + t.string :artist + t.string :description + t.integer :ranking + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..e1b6c51019 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,43 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20151130213741) do + + create_table "albums", force: :cascade do |t| + t.string "name" + t.string "artist" + t.string "description" + t.integer "ranking" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "books", force: :cascade do |t| + t.string "name" + t.string "author" + t.string "description" + t.integer "ranking" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "movies", force: :cascade do |t| + t.string "name" + t.string "director" + t.string "description" + t.integer "ranking" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end From 8a74a2bb0d1c49d96435f261c52f0323771900b8 Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 13:43:51 -0800 Subject: [PATCH 02/38] oops forgot to save, igrated db again --- db/migrate/20151130213629_create_movies.rb | 2 +- db/migrate/20151130213656_create_books.rb | 2 +- db/migrate/20151130213741_create_albums.rb | 2 +- db/schema.rb | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/migrate/20151130213629_create_movies.rb b/db/migrate/20151130213629_create_movies.rb index ade12491f2..1c40a5f879 100644 --- a/db/migrate/20151130213629_create_movies.rb +++ b/db/migrate/20151130213629_create_movies.rb @@ -4,7 +4,7 @@ def change t.string :name t.string :director t.string :description - t.integer :ranking + t.integer :rank t.timestamps null: false end diff --git a/db/migrate/20151130213656_create_books.rb b/db/migrate/20151130213656_create_books.rb index fb1a5f87fe..12eb4ee8b2 100644 --- a/db/migrate/20151130213656_create_books.rb +++ b/db/migrate/20151130213656_create_books.rb @@ -4,7 +4,7 @@ def change t.string :name t.string :author t.string :description - t.integer :ranking + t.integer :rank t.timestamps null: false end diff --git a/db/migrate/20151130213741_create_albums.rb b/db/migrate/20151130213741_create_albums.rb index 04aa7740ee..9f04354899 100644 --- a/db/migrate/20151130213741_create_albums.rb +++ b/db/migrate/20151130213741_create_albums.rb @@ -4,7 +4,7 @@ def change t.string :name t.string :artist t.string :description - t.integer :ranking + t.integer :rank t.timestamps null: false end diff --git a/db/schema.rb b/db/schema.rb index e1b6c51019..e9b5473eeb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -17,7 +17,7 @@ t.string "name" t.string "artist" t.string "description" - t.integer "ranking" + t.integer "rank" t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -26,7 +26,7 @@ t.string "name" t.string "author" t.string "description" - t.integer "ranking" + t.integer "rank" t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -35,7 +35,7 @@ t.string "name" t.string "director" t.string "description" - t.integer "ranking" + t.integer "rank" t.datetime "created_at", null: false t.datetime "updated_at", null: false end From 5dcc343950757bbf85000f2e5d98fc72929773f6 Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 13:46:02 -0800 Subject: [PATCH 03/38] added resources routes for movies, books and albums --- config/routes.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 3f66539d54..8020d6cbf9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,11 @@ Rails.application.routes.draw do + + resources :movies + + resources :books + + resources :albums + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". From 5ef1452feebe2de5ac3121673f257904ee6042cb Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 14:10:35 -0800 Subject: [PATCH 04/38] added index page for movies --- app/controllers/movies_controller.rb | 4 ++++ app/views/layouts/application.html.erb | 4 ++++ app/views/movies/index.html.erb | 21 +++++++++++++++++++++ db/seeds.rb | 12 ++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 app/views/movies/index.html.erb diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 6c4c516140..ceeab4a55a 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,2 +1,6 @@ class MoviesController < ApplicationController + + def index + @movies = Movie.all + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2d02e8fbd4..a11f392b16 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,6 +7,10 @@ <%= csrf_meta_tags %> +

+ <%= link_to "Media Ranker", "/" %> + Ranking the Best of Everything +

<%= yield %> diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb new file mode 100644 index 0000000000..6c2378951e --- /dev/null +++ b/app/views/movies/index.html.erb @@ -0,0 +1,21 @@ + + + + + + + + + + <% @movies.each do |movie| %> + + + + + + <% end %> + +
RankingNameUpvote
Ranked: <%= movie.rank %><%= movie.name %>UPVOTE BUTTON
+ +<%= link_to "View All Media", "/" %> +<%= link_to "Add a Movie", new_movie_path %> diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e857e..cb9c2f972a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,15 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) + + +seed_movies = [ + {name:"Cats", director:"Mr. Cat", description:"A movie about cats", rank:2}, + {name:"Another Movie", director:"Hello", description:"Hi", rank:4}, + {name:"Dogs", director:"Mr.Dog", description:"Great Movie", rank:1} + +] + +seed_movies.each do |seed| + Movie.create(seed) +end From a98198e736dd1288d60964aa4b7e786c0119856b Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 14:35:55 -0800 Subject: [PATCH 05/38] added new and create method for movie --- app/controllers/movies_controller.rb | 17 +++++++++++++++++ app/views/movies/_form.html.erb | 16 ++++++++++++++++ app/views/movies/new.html.erb | 2 ++ 3 files changed, 35 insertions(+) create mode 100644 app/views/movies/_form.html.erb create mode 100644 app/views/movies/new.html.erb diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index ceeab4a55a..1297b30c34 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -3,4 +3,21 @@ class MoviesController < ApplicationController def index @movies = Movie.all end + + def new + @movie = Movie.new + end + + def create + new_movie = Movie.create(movie_params[:movie]) + redirect_to movie_path(new_movie) + end + + private + + def movie_params + params.permit(movie:[:name, :director, :description, :rank]) + end + + end diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb new file mode 100644 index 0000000000..cddeb61d58 --- /dev/null +++ b/app/views/movies/_form.html.erb @@ -0,0 +1,16 @@ +
+ <%= form_for movie, url:{action: action} do |f| %> + +

<%= title %>

+
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+ <%= f.label :director %>
+ <%= f.text_field :director %>
+ <%= f.label :description %>
+ <%= f.text_area :description %>
+ <%= f.hidden_field :rank, :value => rank_value %> + <%= f.submit "Save" %> + <% end %> + +
diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb new file mode 100644 index 0000000000..5b3eeb7197 --- /dev/null +++ b/app/views/movies/new.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'form', + locals:{movie:@movie, action: :create, title: "New Movie", rank_value: 0} %> From 7ace56ffb3f4c1125d0f2ffc42621e6eb6286982 Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 14:48:01 -0800 Subject: [PATCH 06/38] created show page for movie --- app/controllers/movies_controller.rb | 4 ++++ app/views/movies/index.html.erb | 2 +- app/views/movies/show.html.erb | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 app/views/movies/show.html.erb diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 1297b30c34..c9f8f01da6 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -13,6 +13,10 @@ def create redirect_to movie_path(new_movie) end + def show + @movie = Movie.find(params[:id]) + end + private def movie_params diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index 6c2378951e..b6826420a2 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -10,7 +10,7 @@ <% @movies.each do |movie| %> Ranked: <%= movie.rank %> - <%= movie.name %> + <%= link_to movie.name, movie_path(movie) %> UPVOTE BUTTON <% end %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb new file mode 100644 index 0000000000..29912b38b3 --- /dev/null +++ b/app/views/movies/show.html.erb @@ -0,0 +1,2 @@ +<%= @movie.name %> Directed by: <%= @movie.director %> +

Ranked: <%= @movie.rank %>

From 196dc63cab34a611c8a33cfcb58e3db9e28abbf7 Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 15:02:22 -0800 Subject: [PATCH 07/38] added edit and update for movies --- app/controllers/movies_controller.rb | 9 +++++++++ app/views/movies/edit.html.erb | 2 ++ app/views/movies/show.html.erb | 13 ++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 app/views/movies/edit.html.erb diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index c9f8f01da6..029325dbf0 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -17,6 +17,15 @@ def show @movie = Movie.find(params[:id]) end + def edit + @movie = Movie.find(params[:id]) + end + + def update + Movie.update(params[:id], movie_params[:movie]) + redirect_to movie_path(params[:id]) + end + private def movie_params diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb new file mode 100644 index 0000000000..efde984c76 --- /dev/null +++ b/app/views/movies/edit.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'form', + locals:{movie:@movie, action: :update, title: "Edit Movie", rank_value: @movie.rank} %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 29912b38b3..2721786b9b 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -1,2 +1,13 @@ <%= @movie.name %> Directed by: <%= @movie.director %> -

Ranked: <%= @movie.rank %>

+

+ Ranked: <%= @movie.rank %> +

+

+ <%= @movie.description %> +

+ +<%= link_to "Upvote", "/" %>
+<%= link_to "Edit #{@movie.name}", edit_movie_path(@movie) %> +<%= link_to "DELETE", movie_path, method: :delete %> +<%= link_to "View All Movies", movies_path %> +<%= link_to "View All Media", "/" %> From 64740efeea18c2d0175282ce99abb315484474e7 Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 15:08:35 -0800 Subject: [PATCH 08/38] added Delete method for movies --- app/controllers/movies_controller.rb | 5 +++++ app/views/movies/show.html.erb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 029325dbf0..cb31982346 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -26,6 +26,11 @@ def update redirect_to movie_path(params[:id]) end + def destroy + Movie.destroy(params[:id]) + redirect_to movies_path + end + private def movie_params diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 2721786b9b..0a39251877 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -8,6 +8,6 @@ <%= link_to "Upvote", "/" %>
<%= link_to "Edit #{@movie.name}", edit_movie_path(@movie) %> -<%= link_to "DELETE", movie_path, method: :delete %> +<%= link_to "DELETE", movie_path, method: :delete, data: { confirm: "Are you sure?" } %> <%= link_to "View All Movies", movies_path %> <%= link_to "View All Media", "/" %> From e6c3c7e39073de6e39d577c5725ba71b44099a9a Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 15:42:42 -0800 Subject: [PATCH 09/38] added upvote function to movie detail page --- app/controllers/movies_controller.rb | 7 +++++++ app/models/movie.rb | 1 + app/views/movies/show.html.erb | 8 ++++---- config/routes.rb | 4 +++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index cb31982346..a12faef7b3 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -31,6 +31,13 @@ def destroy redirect_to movies_path end + def upvote + m = Movie.find(params[:id]) + m.rank += 1 + m.save + redirect_to movie_path(m) + end + private def movie_params diff --git a/app/models/movie.rb b/app/models/movie.rb index 49198a7d97..13d73ce457 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,2 +1,3 @@ class Movie < ActiveRecord::Base + end diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 0a39251877..9e019dbf40 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -1,12 +1,12 @@ -<%= @movie.name %> Directed by: <%= @movie.director %> -

+

<%= @movie.name %> Directed by: <%= @movie.director %>

+

Ranked: <%= @movie.rank %> -

+

<%= @movie.description %>

-<%= link_to "Upvote", "/" %>
+<%= link_to "Upvote", upvote_movie_path, method: :patch %>
<%= link_to "Edit #{@movie.name}", edit_movie_path(@movie) %> <%= link_to "DELETE", movie_path, method: :delete, data: { confirm: "Are you sure?" } %> <%= link_to "View All Movies", movies_path %> diff --git a/config/routes.rb b/config/routes.rb index 8020d6cbf9..4f251378b8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,13 @@ Rails.application.routes.draw do + patch 'movies/:id/upvote' => 'movies#upvote', as: :upvote_movie + resources :movies resources :books resources :albums - + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". From 538cbf5328d139435a574f1424af80a1b72d67fa Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 15:51:43 -0800 Subject: [PATCH 10/38] added upvote to main movie page and sorted by rank --- app/controllers/movies_controller.rb | 2 +- app/views/movies/index.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index a12faef7b3..e4e985770e 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,7 +1,7 @@ class MoviesController < ApplicationController def index - @movies = Movie.all + @movies = Movie.all.sort_by { |movie| -movie.rank } end def new diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index b6826420a2..937dcc3529 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -11,7 +11,7 @@ Ranked: <%= movie.rank %> <%= link_to movie.name, movie_path(movie) %> - UPVOTE BUTTON + <%= link_to "Upvote", upvote_movie_path(movie), method: :patch %> <% end %> From e238363caf8c7781fcd995c28a8305398177f17e Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 16:28:18 -0800 Subject: [PATCH 11/38] created partial for index page --- app/views/movies/index.html.erb | 23 ++--------------------- app/views/shared/_index.html.erb | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 app/views/shared/_index.html.erb diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index 937dcc3529..ffd747c3b7 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -1,21 +1,2 @@ - - - - - - - - - - <% @movies.each do |movie| %> - - - - - - <% end %> - -
RankingNameUpvote
Ranked: <%= movie.rank %><%= link_to movie.name, movie_path(movie) %><%= link_to "Upvote", upvote_movie_path(movie), method: :patch %>
- -<%= link_to "View All Media", "/" %> -<%= link_to "Add a Movie", new_movie_path %> +<%= render partial:'shared/index', + locals:{media:@movies, media_type: :movie } %> diff --git a/app/views/shared/_index.html.erb b/app/views/shared/_index.html.erb new file mode 100644 index 0000000000..4778f2fb8d --- /dev/null +++ b/app/views/shared/_index.html.erb @@ -0,0 +1,21 @@ + + + + + + + + + + <% media.each do |m| %> + + + + + + <% end %> + +
RankingNameUpvote
Ranked: <%= m.rank %><%= link_to m.name, polymorphic_path(m) %><%= link_to "Upvote", polymorphic_path(m, action: :upvote ), method: :patch %>
+ +<%= link_to "View All Media", "/" %> +<%= link_to "Add a #{media_type.capitalize}", new_polymorphic_path(media_type) %> From 49ff71dc57e1799c1ef1e0b3557728031ed777bf Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 16:31:03 -0800 Subject: [PATCH 12/38] added index for books --- app/controllers/books_controller.rb | 4 ++++ app/views/books/index.html.erb | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 app/views/books/index.html.erb diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index cdb437b99f..1d4b459297 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,2 +1,6 @@ class BooksController < ApplicationController + + def index + @books = Book.all.sort_by { |book| -book.rank } + end end diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb new file mode 100644 index 0000000000..4ecd01613f --- /dev/null +++ b/app/views/books/index.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/index', + locals:{media:@books, media_type: :book } %> From 172608c93c62e645d0381463556690c3fac2d8c7 Mon Sep 17 00:00:00 2001 From: emgord Date: Mon, 30 Nov 2015 16:45:32 -0800 Subject: [PATCH 13/38] added index for albums, seed data, and upvote for albums and books --- app/controllers/album_controller.rb | 2 -- app/controllers/albums_controller.rb | 14 ++++++++++++++ app/controllers/books_controller.rb | 8 ++++++++ app/views/albums/index.html.erb | 2 ++ config/routes.rb | 2 ++ db/seeds.rb | 22 ++++++++++++++++++++++ 6 files changed, 48 insertions(+), 2 deletions(-) delete mode 100644 app/controllers/album_controller.rb create mode 100644 app/controllers/albums_controller.rb create mode 100644 app/views/albums/index.html.erb diff --git a/app/controllers/album_controller.rb b/app/controllers/album_controller.rb deleted file mode 100644 index 954eeb990d..0000000000 --- a/app/controllers/album_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class AlbumController < ApplicationController -end diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb new file mode 100644 index 0000000000..84a894d8cf --- /dev/null +++ b/app/controllers/albums_controller.rb @@ -0,0 +1,14 @@ +class AlbumsController < ApplicationController + + def index + @albums = Album.all.sort_by { |album| -album.rank } + end + + def upvote + a = Album.find(params[:id]) + a.rank += 1 + a.save + redirect_to album_path(a) + end + +end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 1d4b459297..b8ca0e05b5 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -3,4 +3,12 @@ class BooksController < ApplicationController def index @books = Book.all.sort_by { |book| -book.rank } end + + def upvote + b = Book.find(params[:id]) + b.rank += 1 + b.save + redirect_to book_path(b) + end + end diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb new file mode 100644 index 0000000000..d65c78cecd --- /dev/null +++ b/app/views/albums/index.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/index', + locals:{media:@albums, media_type: :album } %> diff --git a/config/routes.rb b/config/routes.rb index 4f251378b8..ea0652d9bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ Rails.application.routes.draw do patch 'movies/:id/upvote' => 'movies#upvote', as: :upvote_movie + patch 'albums/:id/upvote' => 'albums#upvote', as: :upvote_album + patch 'book/:id/upvote' => 'books#upvote', as: :upvote_book resources :movies diff --git a/db/seeds.rb b/db/seeds.rb index cb9c2f972a..0755115177 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -17,3 +17,25 @@ seed_movies.each do |seed| Movie.create(seed) end + +seed_books = [ + {name:"Friends", author:"Emily", description:"A book about friends", rank:12}, + {name:"Another Book", author:"Emily", description:"Hi", rank:2}, + {name:"Cats and Dogs", author:"You", description:"Great Book", rank:1} + +] + +seed_books.each do |seed| + Book.create(seed) +end + +seed_albums = [ + {name:"Songs to Sing", artist:"Emily", description:"Good Songs", rank:2}, + {name:"Christmas Songs", artist:"Santa", description:"Songs for the Holiday", rank:23}, + {name:"Songs about Cats", artist:"You", description:"Happy Songs", rank:23} + +] + +seed_albums.each do |seed| + Album.create(seed) +end From 98db05dffeb411546bcfc8baf8650eaa8b5f3297 Mon Sep 17 00:00:00 2001 From: emgord Date: Tue, 1 Dec 2015 11:12:40 -0800 Subject: [PATCH 14/38] added rspec --- .rspec | 2 + Gemfile | 1 + Gemfile.lock | 19 +++++ app/controllers/books_controller.rb | 4 + app/models/movie.rb | 1 + app/views/books/new.html.erb | 2 + spec/controllers/movies_controller_spec.rb | 11 +++ spec/helpers/movies_helper_spec.rb | 15 ++++ spec/models/movie_spec.rb | 13 +++ spec/rails_helper.rb | 57 ++++++++++++++ spec/spec_helper.rb | 92 ++++++++++++++++++++++ 11 files changed, 217 insertions(+) create mode 100644 .rspec create mode 100644 app/views/books/new.html.erb create mode 100644 spec/controllers/movies_controller_spec.rb create mode 100644 spec/helpers/movies_helper_spec.rb create mode 100644 spec/models/movie_spec.rb create mode 100644 spec/rails_helper.rb create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000000..83e16f8044 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/Gemfile b/Gemfile index 69890fc981..57145188db 100644 --- a/Gemfile +++ b/Gemfile @@ -33,6 +33,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + gem 'rspec-rails' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index dee2f0686a..dd55459cce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -55,6 +55,7 @@ GEM execjs coffee-script-source (1.10.0) debug_inspector (0.0.2) + diff-lcs (1.2.5) erubis (2.7.0) execjs (2.6.0) globalid (0.3.6) @@ -120,6 +121,23 @@ GEM thor (>= 0.18.1, < 2.0) rake (10.4.2) rdoc (4.2.0) + rspec-core (3.4.1) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-mocks (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-rails (3.4.0) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + railties (>= 3.0, < 4.3) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) ruby-graphviz (1.2.2) sass (3.4.19) sass-rails (5.0.4) @@ -170,6 +188,7 @@ DEPENDENCIES pry-rails rails (= 4.2.5) rails-erd + rspec-rails sass-rails (~> 5.0) sdoc (~> 0.4.0) spring diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index b8ca0e05b5..94329b8788 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -11,4 +11,8 @@ def upvote redirect_to book_path(b) end + def new + @book = Book.new + end + end diff --git a/app/models/movie.rb b/app/models/movie.rb index 13d73ce457..1ea78bec6a 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,3 +1,4 @@ class Movie < ActiveRecord::Base + validates :name, presence: true end diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb new file mode 100644 index 0000000000..ddfcb91e29 --- /dev/null +++ b/app/views/books/new.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'form', + locals:{media: @books, action: :create, title: "New Book", rank_value: 0, creator: :author} %> diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb new file mode 100644 index 0000000000..e3af8fc3f5 --- /dev/null +++ b/spec/controllers/movies_controller_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe MoviesController, type: :controller do + describe "GET 'index'" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end + end + +end diff --git a/spec/helpers/movies_helper_spec.rb b/spec/helpers/movies_helper_spec.rb new file mode 100644 index 0000000000..355b810c3c --- /dev/null +++ b/spec/helpers/movies_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the PostsHelper. For example: +# +# describe PostsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe MoviesHelper, type: :helper do + # pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/movie_spec.rb b/spec/models/movie_spec.rb new file mode 100644 index 0000000000..dbc52d0d60 --- /dev/null +++ b/spec/models/movie_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' + +RSpec.describe Movie, type: :model do + describe ".validates" do + it "must have a name" do + expect(Movie.new(name: nil)).to_not be_valid + end + end + + + + +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000000..6f1ab14638 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,57 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'spec_helper' +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } + +# Checks for pending migration and applies them before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000000..61e27385c3 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,92 @@ +# 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 +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow 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. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # 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: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#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 +end From e9c0d4e8b2a065a1cc4e70f357c80fa92661556c Mon Sep 17 00:00:00 2001 From: emgord Date: Tue, 1 Dec 2015 11:40:38 -0800 Subject: [PATCH 15/38] added validation for name on movies --- app/controllers/movies_controller.rb | 17 +++++++++++++---- app/views/movies/edit.html.erb | 2 +- app/views/movies/new.html.erb | 2 +- app/views/{movies => shared}/_form.html.erb | 0 4 files changed, 15 insertions(+), 6 deletions(-) rename app/views/{movies => shared}/_form.html.erb (100%) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index e4e985770e..e58cfd5c16 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -9,8 +9,12 @@ def new end def create - new_movie = Movie.create(movie_params[:movie]) - redirect_to movie_path(new_movie) + @movie = Movie.new(movie_params[:movie]) + if @movie.save + redirect_to movie_path(@movie) + else + render "new" + end end def show @@ -22,8 +26,13 @@ def edit end def update - Movie.update(params[:id], movie_params[:movie]) - redirect_to movie_path(params[:id]) + @movie = Movie.find(params[:id]) + @movie.update( movie_params[:movie]) + if @movie.save + redirect_to movie_path(@movie) + else + render "edit" + end end def destroy diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb index efde984c76..4eaa000c0d 100644 --- a/app/views/movies/edit.html.erb +++ b/app/views/movies/edit.html.erb @@ -1,2 +1,2 @@ -<%= render partial:'form', +<%= render partial:'shared/form', locals:{movie:@movie, action: :update, title: "Edit Movie", rank_value: @movie.rank} %> diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb index 5b3eeb7197..3fadba9ed2 100644 --- a/app/views/movies/new.html.erb +++ b/app/views/movies/new.html.erb @@ -1,2 +1,2 @@ -<%= render partial:'form', +<%= render partial:'shared/form', locals:{movie:@movie, action: :create, title: "New Movie", rank_value: 0} %> diff --git a/app/views/movies/_form.html.erb b/app/views/shared/_form.html.erb similarity index 100% rename from app/views/movies/_form.html.erb rename to app/views/shared/_form.html.erb From 2271b5f22b663a082e9a688a90d41c1793c5c9c3 Mon Sep 17 00:00:00 2001 From: emgord Date: Tue, 1 Dec 2015 14:02:53 -0800 Subject: [PATCH 16/38] added simplecov --- .gitignore | 2 ++ Gemfile | 4 ++++ Gemfile.lock | 7 +++++++ app/views/shared/_form.html.erb | 20 ++++++++++++++++++++ spec/controllers/movies_controller_spec.rb | 16 +++++++++++----- spec/spec_helper.rb | 3 +++ 6 files changed, 47 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 050c9d95c7..2eb6f54617 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ /log/* !/log/.keep /tmp + +coverage diff --git a/Gemfile b/Gemfile index 57145188db..578de8c946 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,10 @@ group :development, :test do gem 'rspec-rails' end +group :test do + gem 'simplecov', require: false +end + group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' diff --git a/Gemfile.lock b/Gemfile.lock index dd55459cce..ffb9abfa35 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -56,6 +56,7 @@ GEM coffee-script-source (1.10.0) debug_inspector (0.0.2) diff-lcs (1.2.5) + docile (1.1.5) erubis (2.7.0) execjs (2.6.0) globalid (0.3.6) @@ -149,6 +150,11 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + simplecov (0.11.0) + docile (~> 1.1.0) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) slop (3.6.0) spring (1.5.0) sprockets (3.4.1) @@ -191,6 +197,7 @@ DEPENDENCIES rspec-rails sass-rails (~> 5.0) sdoc (~> 0.4.0) + simplecov spring sqlite3 turbolinks diff --git a/app/views/shared/_form.html.erb b/app/views/shared/_form.html.erb index cddeb61d58..f2a85b22c9 100644 --- a/app/views/shared/_form.html.erb +++ b/app/views/shared/_form.html.erb @@ -14,3 +14,23 @@ <% end %> + + + + + diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index e3af8fc3f5..44a914d796 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -1,11 +1,17 @@ require 'rails_helper' RSpec.describe MoviesController, type: :controller do - describe "GET 'index'" do - it "is successful" do - get :index - expect(response.status).to eq 200 + describe "GET 'index'" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end end - end + describe "GET 'new'" do + it "renders new view" do + get :new + expect(subject).to render_template :new + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61e27385c3..c1697e0176 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,6 @@ +require 'simplecov' +SimpleCov.start 'rails' + # 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 From 05ecd42b19f10a1ab890ff0fb179901a8ccfdfaf Mon Sep 17 00:00:00 2001 From: emgord Date: Tue, 1 Dec 2015 16:36:01 -0800 Subject: [PATCH 17/38] adding specs for movie controller --- spec/controllers/movies_controller_spec.rb | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 44a914d796..122dad4cf4 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -14,4 +14,86 @@ expect(subject).to render_template :new end end + + describe "POST 'create'" do + let(:good_params) do + { + movie:{ + name: "Hello", director: "You", description: "A Good Movie", rank: 0 + } + } + end + let(:bad_params) do + { + movie:{ + director: "You", description: "A Good Movie", rank: 0 + } + } + end + it "redirects to show page" do + post :create, good_params + expect(subject).to redirect_to movie_path(assigns(:movie)) + end + it "renders new template on error" do + post :create, bad_params + expect(subject).to render_template :new + end + end + + describe "GET 'show'" do + test_movie = Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) + + it "renders the show view" do + get :show, id: test_movie.id + expect(subject).to render_template :show + end + end + + describe "GET 'edit'" do + let(:test_movie){ + Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) + } + it "renders edit view" do + get :edit, id: test_movie.id + expect(subject).to render_template :edit + end +end + +describe "PATCH 'update'" do + let(:good_params) do + { + id: 1, + movie:{ + name: "Hello", director: "You", description: "A Good Movie", rank: 0 + } + } + end + + let(:bad_params) do + { + id: 1, + movie: { name: nil, director: "You", description: "A Good Movie", rank: 0 } + } + end + it "redirects to show page" do + patch :update, good_params + expect(subject).to redirect_to movie_path(assigns(:movie)) + end + it "renders edit template on error" do + patch :update, bad_params + expect(subject).to render_template :edit + end +end + +describe "DELETE 'destroy'" do + let(:test_movie){ + Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) + } + + it "redirects to the index view" do + delete :destroy, id: test_movie.id + expect(subject).to redirect_to movies_path + end +end + end From 6ee89b11cb7c88de0499627e8e19d463d3faac57 Mon Sep 17 00:00:00 2001 From: emgord Date: Tue, 1 Dec 2015 16:55:42 -0800 Subject: [PATCH 18/38] added spec for upvote --- spec/controllers/movies_controller_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 122dad4cf4..f9a3e4b402 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -96,4 +96,22 @@ end end +describe "PATCH 'upvote'" do + start_rank = Movie.find(1).rank + + let(:upvote_params) do { + id: 1 + } + end + + it "redirects to show page" do + patch :upvote, upvote_params + expect(subject).to redirect_to movie_path(1) + end + it "increases the rank value by 1" do + patch :upvote, upvote_params + expect(Movie.find(1).rank).to eq (start_rank + 1) + end + end + end From 6c4a42585231c66c4a1e49efe07751fdbf3a230e Mon Sep 17 00:00:00 2001 From: emgord Date: Wed, 2 Dec 2015 15:14:56 -0800 Subject: [PATCH 19/38] added bootstrap styling --- Gemfile | 2 +- Gemfile.lock | 7 ++ app/assets/images/owl.jpg | Bin 0 -> 13218 bytes app/assets/javascripts/application.js | 1 + .../{application.css => application.scss} | 18 +++++- app/views/layouts/application.html.erb | 17 +++-- app/views/movies/show.html.erb | 30 +++++---- app/views/shared/_form.html.erb | 60 ++++++++---------- app/views/shared/_index.html.erb | 38 +++++------ 9 files changed, 100 insertions(+), 73 deletions(-) create mode 100644 app/assets/images/owl.jpg rename app/assets/stylesheets/{application.css => application.scss} (73%) diff --git a/Gemfile b/Gemfile index 578de8c946..922f613846 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.5' # Use sqlite3 as the database for Active Record - +gem 'bootstrap-sass', '~> 3.3.6' gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' diff --git a/Gemfile.lock b/Gemfile.lock index ffb9abfa35..801083d137 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,12 +37,18 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.3) + autoprefixer-rails (6.1.2) + execjs + json better_errors (2.1.1) coderay (>= 1.0.0) erubis (>= 2.6.6) rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) + bootstrap-sass (3.3.6) + autoprefixer-rails (>= 5.2.1) + sass (>= 3.3.4) builder (3.2.2) byebug (8.2.1) choice (0.2.0) @@ -186,6 +192,7 @@ PLATFORMS DEPENDENCIES better_errors binding_of_caller + bootstrap-sass (~> 3.3.6) byebug coffee-rails (~> 4.1.0) jbuilder (~> 2.0) diff --git a/app/assets/images/owl.jpg b/app/assets/images/owl.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b3ded309503e7f923da57cb00fa145fbf656ae56 GIT binary patch literal 13218 zcmbVy2UrtJ_xD0*f`TX=1q4I{DJn&31O-H;OD_>26zNR@gyafR1OWj-MF9Z;ktQAK zy(mSxbP}o*NvHu5@-5!`dhh)|@AI|Ev%9}NbLPxBXJ*cs-3|FWc?LLnTU}EfprD`t zZh=35jHRvAym14jtFNQ3c~=dr007z#*6!}klzaf-;_B_Guc69kVrs@mI|@(&oB#vB z1u$6Kc)6?S>fQywa>RRd{dd_J20%#wFd+8d>;KLDKkgW8;a)ZXKtTu6-E6&VTtJKf z0BUC&cTaBspqT^d*L=O*K}>rF#4Mhmf*_VW!uEgSn@9M;pV;IV&prJcAkUGmj5ZF| zwjf4=_|k)a(Cz<$|I`8G0Oe@FUE!XNHhf3E(Dih)b99FPs`&Htf2jTk=l>46IQxJ$ z|0+D-`M8&p!5#1_d}O6WrW%MZftbg^=hk2HA-BCA8644n$?~s4q}Hq|M!1_b(kFORmn^M}2|zQZd54e%T1hge-YG+ym$7QClh*Z_j&w zwWTt%b5z&-iy!Ik{A(_Px>3FN^wB@k4U|vy&Dv8<1H_;lstvfS;gR1!OwD0yee=k- z;viNAj3}%DIN%060M9mnD?kGH0DV9MPzA5b#wh2I+J{zFebz#jMkYWk-f55NcP`A82VK=nD7kMQp{d_kTtN1NUl9H`CTR=WLN z56by%F{rcKKRp0=fgbpebz=YYQ#-PT<97|;5LKnc!0~n@p!0w7FZCSt67>*x9;Kf6 zyFK+d^#u4E1ysNhaQ>x{3#gUjuaWTj%_sIR8yZ1QZ@?NnV?aJPP}l!x`mYhSbA8VB zcg>L};9=T3+Cb2yzp0WVl53Jfl4+9fC0G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ns06aD2OvUM=UWhVkcck<4g86H61xP2Qi6V>@~tGL1G{m84>NvN3Bju+gd7ww^VX zn$X>5Ti&Lc`1TaWzDvsI5NJ$l(50@il8$_I;N@x2j@fx5C00FOIbGm~W&1Ov95|nR zTT>YD*f19sp`cqn zxFxEj+Gbc;`Z)w1p|jOy3neXFS*`S~Uo|=yR~V+OObFH)I#l?v zbGbx|CJG3}wLg35$U4cAg1OFX0Mkd_!N299C71{1mZ-a#_!%)59c)U@;;c*#=y43t z;9ai5Rq**>LVXi4wPTPg&;dp4@h+Q_<^{<>jYcNw4%QiOntTy{O)yiqeXO@rZR+xN zys=e^{nA^yPkVueudtKp(8y5F5YnYz~ek z)b8MEt7jZ+tw>YcZlf|gAr)6P^Wtk7pi$+V_(@m$#>NLVQnkJLDi6Fo2Lbo77jC7Zt>ktzGsSO7in z;0b-_Ru9IH^oZ-o_4M&Z@b76u=XU+bP?dZ0m5Ym7aSU$)p}`H-O+ zA)Y2Pdbyj!NARRdV|oNJ<02T*c)&*knCM~l)BYB?c zl%{Q`u6+~vFm?@a7tKtMAn{%x10ETN9EZ0EtIee4Y(naSd!6Ed_nJ=gF!QomU}72< ztfk|naIM-QD?VRXcAC_fN{_(KFzuagCK^Jw=Au);z#03tzL|-{ ZFR+vzabUC16e0W$Ojvqq0Gd4dzW|J{wv7M) literal 0 HcmV?d00001 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e07c5a830f..f91cae5d9b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -11,6 +11,7 @@ // about supported directives. // //= require jquery +//= require bootstrap-sprockets //= require jquery_ujs //= require turbolinks //= require_tree . diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.scss similarity index 73% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index f9cd5b3483..f6a8e870fa 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.scss @@ -10,6 +10,20 @@ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new * file per style scope. * - *= require_tree . - *= require_self */ + +@import "bootstrap-sprockets"; +@import "bootstrap"; + +.page-header { + background-image: image-url("owl.jpg"); + background-repeat: no-repeat; +} + +.page-header h1 { + margin-left: 150px; +} + +form .btn-primary { + margin-bottom: 10px; +} diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a11f392b16..0adcafd4e5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,12 +7,19 @@ <%= csrf_meta_tags %> -

- <%= link_to "Media Ranker", "/" %> - Ranking the Best of Everything -

+
+
+ +
-<%= yield %> + + <%= yield %> +
diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 9e019dbf40..1858a3ef64 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -1,13 +1,19 @@ -

<%= @movie.name %> Directed by: <%= @movie.director %>

-

- Ranked: <%= @movie.rank %> -

-

- <%= @movie.description %> -

+
+
+

<%= @movie.name %> Directed by: <%= @movie.director %>

+

+ Ranked: <%= @movie.rank %> +

+

+ <%= @movie.description %> +

+
+ <%= link_to "Upvote", upvote_movie_path, method: :patch, class: "btn btn-primary" %> +
-<%= link_to "Upvote", upvote_movie_path, method: :patch %>
-<%= link_to "Edit #{@movie.name}", edit_movie_path(@movie) %> -<%= link_to "DELETE", movie_path, method: :delete, data: { confirm: "Are you sure?" } %> -<%= link_to "View All Movies", movies_path %> -<%= link_to "View All Media", "/" %> + <%= link_to "Edit #{@movie.name}", edit_movie_path(@movie), class: "btn btn-default" %> + <%= link_to "DELETE", movie_path, method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> + <%= link_to "View All Movies", movies_path, class: "btn btn-default" %> + <%= link_to "View All Media", "/", class: "btn btn-default" %> +
+
diff --git a/app/views/shared/_form.html.erb b/app/views/shared/_form.html.erb index f2a85b22c9..3e43e493db 100644 --- a/app/views/shared/_form.html.erb +++ b/app/views/shared/_form.html.erb @@ -1,36 +1,26 @@ -
- <%= form_for movie, url:{action: action} do |f| %> - -

<%= title %>

-
- <%= f.label :name %>
- <%= f.text_field :name %>
- <%= f.label :director %>
- <%= f.text_field :director %>
- <%= f.label :description %>
- <%= f.text_area :description %>
- <%= f.hidden_field :rank, :value => rank_value %> - <%= f.submit "Save" %> - <% end %> +
+
+
+ <%= form_for movie, url:{action: action}, :html => {:class => "form" } do |f| %> + +

<%= title %>

+
+
+ <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> +
+
+ <%= f.label :director %> + <%= f.text_field :director, class: "form-control" %> +
+
+ <%= f.label :description %>
+ <%= f.text_area :description, class: "form-control" %>
+
+ <%= f.hidden_field :rank, :value => rank_value %> + <%= f.submit "Save", class: "btn btn-default" %> + <% end %> -
- - - - - +
+ + diff --git a/app/views/shared/_index.html.erb b/app/views/shared/_index.html.erb index 4778f2fb8d..7501d1ea4d 100644 --- a/app/views/shared/_index.html.erb +++ b/app/views/shared/_index.html.erb @@ -1,21 +1,23 @@ - - - - - - - - - - <% media.each do |m| %> +
+
RankingNameUpvote
+ - - - + + + - <% end %> - -
Ranked: <%= m.rank %><%= link_to m.name, polymorphic_path(m) %><%= link_to "Upvote", polymorphic_path(m, action: :upvote ), method: :patch %>RankingNameUpvote
+ + + <% media.each do |m| %> + + Ranked: <%= m.rank %> + <%= link_to m.name, polymorphic_path(m) %> + <%= link_to "Upvote", polymorphic_path(m, action: :upvote ), method: :patch, class: "btn btn-default" %> + + <% end %> + + -<%= link_to "View All Media", "/" %> -<%= link_to "Add a #{media_type.capitalize}", new_polymorphic_path(media_type) %> + <%= link_to "View All Media", "/", class: "btn btn-default" %> + <%= link_to "Add a #{media_type.capitalize}", new_polymorphic_path(media_type), class: "btn btn-default" %> + From aee69fafb720a37fba1b0a21a14d8572efc6614c Mon Sep 17 00:00:00 2001 From: emgord Date: Wed, 2 Dec 2015 15:22:08 -0800 Subject: [PATCH 20/38] added home controller and page --- app/assets/javascripts/home.coffee | 3 +++ app/assets/stylesheets/home.scss | 3 +++ app/controllers/home_controller.rb | 2 ++ app/helpers/home_helper.rb | 2 ++ app/views/home/index.html.erb | 1 + config/routes.rb | 2 +- spec/controllers/home_controller_spec.rb | 5 +++++ spec/helpers/home_helper_spec.rb | 15 +++++++++++++++ 8 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/home.coffee create mode 100644 app/assets/stylesheets/home.scss create mode 100644 app/controllers/home_controller.rb create mode 100644 app/helpers/home_helper.rb create mode 100644 app/views/home/index.html.erb create mode 100644 spec/controllers/home_controller_spec.rb create mode 100644 spec/helpers/home_helper_spec.rb diff --git a/app/assets/javascripts/home.coffee b/app/assets/javascripts/home.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/home.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/home.scss b/app/assets/stylesheets/home.scss new file mode 100644 index 0000000000..f0ddc6846a --- /dev/null +++ b/app/assets/stylesheets/home.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000000..fc0b4743ac --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,2 @@ +class HomeController < ApplicationController +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000000..23de56ac60 --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000000..5df79fccdc --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1 @@ +

HELLLO!

diff --git a/config/routes.rb b/config/routes.rb index ea0652d9bd..4169a4d12f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - + root 'home#index' patch 'movies/:id/upvote' => 'movies#upvote', as: :upvote_movie patch 'albums/:id/upvote' => 'albums#upvote', as: :upvote_album patch 'book/:id/upvote' => 'books#upvote', as: :upvote_book diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb new file mode 100644 index 0000000000..e672b25e4d --- /dev/null +++ b/spec/controllers/home_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeController, type: :controller do + +end diff --git a/spec/helpers/home_helper_spec.rb b/spec/helpers/home_helper_spec.rb new file mode 100644 index 0000000000..e537d8d9a8 --- /dev/null +++ b/spec/helpers/home_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the HomeHelper. For example: +# +# describe HomeHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe HomeHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end From c87dae50e95445bd64e067b8a5cc7706d4fb4609 Mon Sep 17 00:00:00 2001 From: emgord Date: Wed, 2 Dec 2015 16:01:39 -0800 Subject: [PATCH 21/38] added home page, still need to rank media and only show top 10 --- app/controllers/home_controller.rb | 6 ++++++ app/views/home/_list.html.erb | 11 +++++++++++ app/views/home/index.html.erb | 17 ++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 app/views/home/_list.html.erb diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index fc0b4743ac..9309f7a6e0 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,2 +1,8 @@ class HomeController < ApplicationController + + def index + @movies = Movie.all + @albums = Album.all + @books = Book.all + end end diff --git a/app/views/home/_list.html.erb b/app/views/home/_list.html.erb new file mode 100644 index 0000000000..e08530852f --- /dev/null +++ b/app/views/home/_list.html.erb @@ -0,0 +1,11 @@ +
+

Top <%= media_type.capitalize %>

+ <% media.each do |item| %> +

+ <%= link_to item.name, polymorphic_path(item) %> + Ranked: <%= item.rank %> +

+ <% end %> + + <%= link_to "View More Movies", polymorphic_path(media_type) %> +
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 5df79fccdc..f8cac1229a 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1 +1,16 @@ -

HELLLO!

+
+
+
+ + <%= render partial:'list', + locals:{media: @movies, media_type: :movies} %> + <%= render partial:'list', + locals:{media: @books, media_type: :books} %> + <%= render partial:'list', + locals:{media: @albums, media_type: :albums} %> + + + +
+
+
From bdaefc402b5473f57373fd3086a7befa9015fa4f Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 10:30:51 -0800 Subject: [PATCH 22/38] ranked and grabbed top ten for home page, added general medium spec and controller spec to begin drying up tests --- app/controllers/home_controller.rb | 6 +++--- app/views/home/index.html.erb | 4 ---- spec/rails_helper.rb | 2 +- spec/spec_helper.rb | 1 + spec/support/medium_controller_spec.rb | 0 spec/support/medium_spec.rb | 0 6 files changed, 5 insertions(+), 8 deletions(-) create mode 100644 spec/support/medium_controller_spec.rb create mode 100644 spec/support/medium_spec.rb diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 9309f7a6e0..6170b646cf 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,8 +1,8 @@ class HomeController < ApplicationController def index - @movies = Movie.all - @albums = Album.all - @books = Book.all + @movies = Movie.all.sort_by { |movie| -movie.rank }.first(10) + @albums = Album.all.sort_by { |album| -album.rank }.first(10) + @books = Book.all.sort_by { |book| -book.rank }.first(10) end end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index f8cac1229a..82224e38c2 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,16 +1,12 @@
- <%= render partial:'list', locals:{media: @movies, media_type: :movies} %> <%= render partial:'list', locals:{media: @books, media_type: :books} %> <%= render partial:'list', locals:{media: @albums, media_type: :albums} %> - - -
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6f1ab14638..438342967e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -20,7 +20,7 @@ # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # -# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } +Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } # Checks for pending migration and applies them before tests are run. # If you are not using ActiveRecord, you can remove this line. diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c1697e0176..e92c9eea42 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,6 +20,7 @@ # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| + Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/support/medium_spec.rb b/spec/support/medium_spec.rb new file mode 100644 index 0000000000..e69de29bb2 From 48a93062c5ab4ea677a59210e43093a9f0f7ca3b Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 10:56:56 -0800 Subject: [PATCH 23/38] successfully created shared spec for movie --- spec/helpers/home_helper_spec.rb | 6 +++--- spec/helpers/movies_helper_spec.rb | 6 +++--- spec/models/movie_spec.rb | 9 +-------- spec/rails_helper.rb | 4 ++++ spec/spec_helper.rb | 1 - spec/support/medium_spec.rb | 9 +++++++++ 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/spec/helpers/home_helper_spec.rb b/spec/helpers/home_helper_spec.rb index e537d8d9a8..f480eeab4f 100644 --- a/spec/helpers/home_helper_spec.rb +++ b/spec/helpers/home_helper_spec.rb @@ -10,6 +10,6 @@ # end # end # end -RSpec.describe HomeHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end +# RSpec.describe HomeHelper, type: :helper do +# pending "add some examples to (or delete) #{__FILE__}" +# end diff --git a/spec/helpers/movies_helper_spec.rb b/spec/helpers/movies_helper_spec.rb index 355b810c3c..374e9d62b0 100644 --- a/spec/helpers/movies_helper_spec.rb +++ b/spec/helpers/movies_helper_spec.rb @@ -10,6 +10,6 @@ # end # end # end -RSpec.describe MoviesHelper, type: :helper do - # pending "add some examples to (or delete) #{__FILE__}" -end +# RSpec.describe MoviesHelper, type: :helper do +# # pending "add some examples to (or delete) #{__FILE__}" +# end diff --git a/spec/models/movie_spec.rb b/spec/models/movie_spec.rb index dbc52d0d60..848984679f 100644 --- a/spec/models/movie_spec.rb +++ b/spec/models/movie_spec.rb @@ -1,13 +1,6 @@ require 'rails_helper' RSpec.describe Movie, type: :model do - describe ".validates" do - it "must have a name" do - expect(Movie.new(name: nil)).to_not be_valid - end - end - - - + it_behaves_like "a medium" end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 438342967e..de00292b71 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -22,6 +22,10 @@ # Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } +SimpleCov.start do + add_filter "/support/" +end + # Checks for pending migration and applies them before tests are run. # If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.maintain_test_schema! diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e92c9eea42..c1697e0176 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,7 +20,6 @@ # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| - Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. diff --git a/spec/support/medium_spec.rb b/spec/support/medium_spec.rb index e69de29bb2..cb844c1533 100644 --- a/spec/support/medium_spec.rb +++ b/spec/support/medium_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.shared_examples "a medium" do + describe ".validates" do + it "must have a name" do + expect(described_class.new(name: nil)).to_not be_valid + end + end +end From 6bc50d1a345e28ccafbb83893347db9470a55ee1 Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 11:01:23 -0800 Subject: [PATCH 24/38] added spec to validate presence of name for album and book, and validation in the model --- app/models/album.rb | 1 + app/models/book.rb | 1 + spec/models/album_spec.rb | 6 ++++++ spec/models/book_spec.rb | 6 ++++++ 4 files changed, 14 insertions(+) create mode 100644 spec/models/album_spec.rb create mode 100644 spec/models/book_spec.rb diff --git a/app/models/album.rb b/app/models/album.rb index 46fa309e4e..b965f608d0 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -1,2 +1,3 @@ class Album < ActiveRecord::Base + validates :name, presence: true end diff --git a/app/models/book.rb b/app/models/book.rb index 6f68b44465..7b27cc85bd 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,2 +1,3 @@ class Book < ActiveRecord::Base + validates :name, presence: true end diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb new file mode 100644 index 0000000000..df364d0def --- /dev/null +++ b/spec/models/album_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +RSpec.describe Album, type: :model do + it_behaves_like "a medium" + +end diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb new file mode 100644 index 0000000000..c51e7859d3 --- /dev/null +++ b/spec/models/book_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +RSpec.describe Book, type: :model do + it_behaves_like "a medium" + +end From 120689225dec0225588a1b787e670916c295e40b Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 12:02:36 -0800 Subject: [PATCH 25/38] movied all movie specs to shared specs --- spec/controllers/movies_controller_spec.rb | 228 ++++++++++++--------- spec/support/medium_controller_spec.rb | 84 ++++++++ 2 files changed, 220 insertions(+), 92 deletions(-) diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index f9a3e4b402..e3f10a58a4 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -1,21 +1,7 @@ require 'rails_helper' RSpec.describe MoviesController, type: :controller do - describe "GET 'index'" do - it "is successful" do - get :index - expect(response.status).to eq 200 - end - end - - describe "GET 'new'" do - it "renders new view" do - get :new - expect(subject).to render_template :new - end - end - - describe "POST 'create'" do + it_behaves_like "a medium controller" do let(:good_params) do { movie:{ @@ -30,88 +16,146 @@ } } end - it "redirects to show page" do - post :create, good_params - expect(subject).to redirect_to movie_path(assigns(:movie)) - end - it "renders new template on error" do - post :create, bad_params - expect(subject).to render_template :new + let(:media_type) do + :movie end - end - - describe "GET 'show'" do - test_movie = Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) - - it "renders the show view" do - get :show, id: test_movie.id - expect(subject).to render_template :show + let(:media_type_plural) do + :movies end - end - - describe "GET 'edit'" do - let(:test_movie){ + let(:test_medium) do Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) - } - it "renders edit view" do - get :edit, id: test_movie.id - expect(subject).to render_template :edit - end -end + end + let(:good_update_params) do + { + id: 1, + movie:{ + name: "Hello", director: "You", description: "A Good Movie", rank: 0 + } + } + end -describe "PATCH 'update'" do - let(:good_params) do - { - id: 1, - movie:{ - name: "Hello", director: "You", description: "A Good Movie", rank: 0 + let(:bad_update_params) do + { + id: 1, + movie: { name: nil, director: "You", description: "A Good Movie", rank: 0 } } - } - end - - let(:bad_params) do - { - id: 1, - movie: { name: nil, director: "You", description: "A Good Movie", rank: 0 } - } - end - it "redirects to show page" do - patch :update, good_params - expect(subject).to redirect_to movie_path(assigns(:movie)) - end - it "renders edit template on error" do - patch :update, bad_params - expect(subject).to render_template :edit - end -end - -describe "DELETE 'destroy'" do - let(:test_movie){ - Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) - } - - it "redirects to the index view" do - delete :destroy, id: test_movie.id - expect(subject).to redirect_to movies_path + end end end -describe "PATCH 'upvote'" do - start_rank = Movie.find(1).rank - - let(:upvote_params) do { - id: 1 - } - end - - it "redirects to show page" do - patch :upvote, upvote_params - expect(subject).to redirect_to movie_path(1) - end - it "increases the rank value by 1" do - patch :upvote, upvote_params - expect(Movie.find(1).rank).to eq (start_rank + 1) - end - end - -end +# +# +# +# +# describe "GET 'index'" do +# it "is successful" do +# get :index +# expect(response.status).to eq 200 +# end +# end +# +# describe "GET 'new'" do +# it "renders new view" do +# get :new +# expect(subject).to render_template :new +# end +# end +# +# describe "POST 'create'" do +# let(:good_params) do +# { +# movie:{ +# name: "Hello", director: "You", description: "A Good Movie", rank: 0 +# } +# } +# end +# let(:bad_params) do +# { +# movie:{ +# director: "You", description: "A Good Movie", rank: 0 +# } +# } +# end +# it "redirects to show page" do +# post :create, good_params +# expect(subject).to redirect_to movie_path(assigns(:movie)) +# end +# it "renders new template on error" do +# post :create, bad_params +# expect(subject).to render_template :new +# end +# end +# +# describe "GET 'show'" do +# test_movie = Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) +# +# it "renders the show view" do +# get :show, id: test_movie.id +# expect(subject).to render_template :show +# end +# end +# +# describe "GET 'edit'" do +# let(:test_movie){ +# Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) +# } +# it "renders edit view" do +# get :edit, id: test_movie.id +# expect(subject).to render_template :edit +# end +# end +# +# describe "PATCH 'update'" do +# let(:good_params) do +# { +# id: 1, +# movie:{ +# name: "Hello", director: "You", description: "A Good Movie", rank: 0 +# } +# } +# end +# +# let(:bad_params) do +# { +# id: 1, +# movie: { name: nil, director: "You", description: "A Good Movie", rank: 0 } +# } +# end +# it "redirects to show page" do +# patch :update, good_params +# expect(subject).to redirect_to movie_path(assigns(:movie)) +# end +# it "renders edit template on error" do +# patch :update, bad_params +# expect(subject).to render_template :edit +# end +# end +# +# describe "DELETE 'destroy'" do +# let(:test_movie){ +# Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) +# } +# +# it "redirects to the index view" do +# delete :destroy, id: test_movie.id +# expect(subject).to redirect_to movies_path +# end +# end +# +# describe "PATCH 'upvote'" do +# start_rank = Movie.find(1).rank +# +# let(:upvote_params) do { +# id: 1 +# } +# end +# +# it "redirects to show page" do +# patch :upvote, upvote_params +# expect(subject).to redirect_to movie_path(1) +# end +# it "increases the rank value by 1" do +# patch :upvote, upvote_params +# expect(Movie.find(1).rank).to eq (start_rank + 1) +# end +# end diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb index e69de29bb2..8e9ce3b59d 100644 --- a/spec/support/medium_controller_spec.rb +++ b/spec/support/medium_controller_spec.rb @@ -0,0 +1,84 @@ +require 'rails_helper' + +include Rails.application.routes.url_helpers + +RSpec.shared_examples "a medium controller" do + + describe "GET 'index'" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end + end + + describe "GET 'new'" do + it "renders new view" do + get :new + expect(subject).to render_template :new + end + end + + describe "POST 'create'" do + + it "redirects to show page" do + post :create, good_params + expect(subject).to redirect_to polymorphic_path(assigns(media_type)) + end + it "renders new template on error" do + post :create, bad_params + expect(subject).to render_template :new + end + end + + describe "GET 'show'" do + it "renders the show view" do + get :show, id: test_medium.id + expect(subject).to render_template :show + end + end + + describe "GET 'edit'" do + it "renders edit view" do + get :edit, id: test_medium.id + expect(subject).to render_template :edit + end + end + + describe "PATCH 'update'" do + + it "redirects to show page" do + patch :update, good_update_params + expect(subject).to redirect_to polymorphic_path(assigns(media_type)) + end + it "renders edit template on error" do + patch :update, bad_update_params + expect(subject).to render_template :edit + end + end + + describe "DELETE 'destroy'" do + it "redirects to the index view" do + delete :destroy, id: test_medium.id + expect(subject).to redirect_to polymorphic_path(media_type_plural) + end + end + + describe "PATCH 'upvote'" do + + let(:upvote_params) do { + id: test_medium.id + } + end + + it "redirects to show page" do + patch :upvote, upvote_params + expect(subject).to redirect_to polymorphic_path(test_medium) + end + + it "increases the rank value by 1" do + patch :upvote, upvote_params + test_medium.reload + expect(test_medium.rank).to eq 1 + end + end +end From 0b5d70a95a24741fecbd3df86acec198d490dd36 Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 12:11:37 -0800 Subject: [PATCH 26/38] added tests for books and albums --- spec/controllers/albums_controller_spec.rb | 44 ++++++++ spec/controllers/books_controller_spec.rb | 44 ++++++++ spec/controllers/movies_controller_spec.rb | 117 --------------------- 3 files changed, 88 insertions(+), 117 deletions(-) create mode 100644 spec/controllers/albums_controller_spec.rb create mode 100644 spec/controllers/books_controller_spec.rb diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb new file mode 100644 index 0000000000..f5890276b0 --- /dev/null +++ b/spec/controllers/albums_controller_spec.rb @@ -0,0 +1,44 @@ +require 'rails_helper' + +RSpec.describe AlbumsController, type: :controller do + it_behaves_like "a medium controller" do + let(:good_params) do + { + album:{ + name: "Songs", artist: "You", description: "A Good Album", rank: 0 + } + } + end + let(:bad_params) do + { + album:{ + artist: "Me", description: "So many good songs", rank: 0 + } + } + end + let(:media_type) do + :album + end + let(:media_type_plural) do + :albums + end + let(:test_medium) do + Album.create( name: "An album", artist: "You", description: "SONGS", rank: 0 ) + end + let(:good_update_params) do + { + id: 1, + album:{ + name: "Songs", artist: "You", description: "SONGS", rank: 0 + } + } + end + + let(:bad_update_params) do + { + id: 1, + album: { name: nil, artist: "You", description: "A Good Album", rank: 0 } + } + end + end +end diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb new file mode 100644 index 0000000000..3355aa7fe4 --- /dev/null +++ b/spec/controllers/books_controller_spec.rb @@ -0,0 +1,44 @@ +require 'rails_helper' + +RSpec.describe BooksController, type: :controller do + it_behaves_like "a medium controller" do + let(:good_params) do + { + book:{ + name: "A Book", author: "You", description: "A Good Book", rank: 0 + } + } + end + let(:bad_params) do + { + book:{ + author: "You", description: "A Good Book", rank: 0 + } + } + end + let(:media_type) do + :book + end + let(:media_type_plural) do + :books + end + let(:test_medium) do + Book.create( name: "A Book", author: "You", description: "A Good Book", rank: 0 ) + end + let(:good_update_params) do + { + id: 1, + book:{ + name: "A Book", author: "You", description: "A Good Book", rank: 0 + } + } + end + + let(:bad_update_params) do + { + id: 1, + movie: { name: nil, author: "You", description: "A Good Book", rank: 0 } + } + end + end +end diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index e3f10a58a4..fcf23cd7cd 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -42,120 +42,3 @@ end end end - -# -# -# -# -# describe "GET 'index'" do -# it "is successful" do -# get :index -# expect(response.status).to eq 200 -# end -# end -# -# describe "GET 'new'" do -# it "renders new view" do -# get :new -# expect(subject).to render_template :new -# end -# end -# -# describe "POST 'create'" do -# let(:good_params) do -# { -# movie:{ -# name: "Hello", director: "You", description: "A Good Movie", rank: 0 -# } -# } -# end -# let(:bad_params) do -# { -# movie:{ -# director: "You", description: "A Good Movie", rank: 0 -# } -# } -# end -# it "redirects to show page" do -# post :create, good_params -# expect(subject).to redirect_to movie_path(assigns(:movie)) -# end -# it "renders new template on error" do -# post :create, bad_params -# expect(subject).to render_template :new -# end -# end -# -# describe "GET 'show'" do -# test_movie = Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) -# -# it "renders the show view" do -# get :show, id: test_movie.id -# expect(subject).to render_template :show -# end -# end -# -# describe "GET 'edit'" do -# let(:test_movie){ -# Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) -# } -# it "renders edit view" do -# get :edit, id: test_movie.id -# expect(subject).to render_template :edit -# end -# end -# -# describe "PATCH 'update'" do -# let(:good_params) do -# { -# id: 1, -# movie:{ -# name: "Hello", director: "You", description: "A Good Movie", rank: 0 -# } -# } -# end -# -# let(:bad_params) do -# { -# id: 1, -# movie: { name: nil, director: "You", description: "A Good Movie", rank: 0 } -# } -# end -# it "redirects to show page" do -# patch :update, good_params -# expect(subject).to redirect_to movie_path(assigns(:movie)) -# end -# it "renders edit template on error" do -# patch :update, bad_params -# expect(subject).to render_template :edit -# end -# end -# -# describe "DELETE 'destroy'" do -# let(:test_movie){ -# Movie.create( name: "Hello", director: "You", description: "A Good Movie", rank: 0 ) -# } -# -# it "redirects to the index view" do -# delete :destroy, id: test_movie.id -# expect(subject).to redirect_to movies_path -# end -# end -# -# describe "PATCH 'upvote'" do -# start_rank = Movie.find(1).rank -# -# let(:upvote_params) do { -# id: 1 -# } -# end -# -# it "redirects to show page" do -# patch :upvote, upvote_params -# expect(subject).to redirect_to movie_path(1) -# end -# it "increases the rank value by 1" do -# patch :upvote, upvote_params -# expect(Movie.find(1).rank).to eq (start_rank + 1) -# end -# end From a23f32aa1659f280a19d972df69e59d0822cf001 Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 12:21:39 -0800 Subject: [PATCH 27/38] added test for home controller --- spec/controllers/home_controller_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index e672b25e4d..447c04c3bb 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -2,4 +2,11 @@ RSpec.describe HomeController, type: :controller do + describe "GET 'index'" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end + end + end From 53d5b93f188a444ef3879df5b851ee2a52cceade Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 12:28:39 -0800 Subject: [PATCH 28/38] updated form partial so it can be used for all media. --- app/views/movies/edit.html.erb | 2 +- app/views/movies/new.html.erb | 2 +- app/views/shared/_form.html.erb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb index 4eaa000c0d..79b9c659ed 100644 --- a/app/views/movies/edit.html.erb +++ b/app/views/movies/edit.html.erb @@ -1,2 +1,2 @@ <%= render partial:'shared/form', - locals:{movie:@movie, action: :update, title: "Edit Movie", rank_value: @movie.rank} %> + locals:{ medium: @movie, action: :update, title: "Edit Movie", creator: :director, rank_value: @movie.rank} %> diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb index 3fadba9ed2..1128469322 100644 --- a/app/views/movies/new.html.erb +++ b/app/views/movies/new.html.erb @@ -1,2 +1,2 @@ <%= render partial:'shared/form', - locals:{movie:@movie, action: :create, title: "New Movie", rank_value: 0} %> + locals:{ medium: @movie, action: :create, title: "New Movie", creator: :director, rank_value: 0} %> diff --git a/app/views/shared/_form.html.erb b/app/views/shared/_form.html.erb index 3e43e493db..1cf1ee197c 100644 --- a/app/views/shared/_form.html.erb +++ b/app/views/shared/_form.html.erb @@ -1,7 +1,7 @@
- <%= form_for movie, url:{action: action}, :html => {:class => "form" } do |f| %> + <%= form_for medium, url:{action: action}, :html => {:class => "form" } do |f| %>

<%= title %>

@@ -10,8 +10,8 @@ <%= f.text_field :name, class: "form-control" %>
- <%= f.label :director %> - <%= f.text_field :director, class: "form-control" %> + <%= f.label creator %> + <%= f.text_field creator, class: "form-control" %>
<%= f.label :description %>
From f26666693599f6015938731ae04cc3ec3819f827 Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 13:41:19 -0800 Subject: [PATCH 29/38] added new and create for album and book --- app/controllers/albums_controller.rb | 19 +++++++++++++++++++ app/controllers/books_controller.rb | 9 +++++++++ app/views/albums/new.html.erb | 2 ++ app/views/books/new.html.erb | 4 ++-- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 app/views/albums/new.html.erb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 84a894d8cf..e45c136550 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -11,4 +11,23 @@ def upvote redirect_to album_path(a) end + def new + @album = Album.new + end + + def create + @album = Album.new(album_params[:album]) + if @album.save + redirect_to album_path(@album) + else + render "new" + end + end + + private + + def album_params + params.permit(album:[:name, :artist, :description, :rank]) + end + end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 94329b8788..c795d06c5c 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -15,4 +15,13 @@ def new @book = Book.new end + def create + @book = Book.new(book_params[:book]) + if @book.save + redirect_to album_path(@book) + else + render "new" + end + end + end diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb new file mode 100644 index 0000000000..84f0f0a9f8 --- /dev/null +++ b/app/views/albums/new.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/form', + locals:{ medium: @album, action: :create, title: "New Album", creator: :artist, rank_value: 0} %> diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb index ddfcb91e29..a0813b365f 100644 --- a/app/views/books/new.html.erb +++ b/app/views/books/new.html.erb @@ -1,2 +1,2 @@ -<%= render partial:'form', - locals:{media: @books, action: :create, title: "New Book", rank_value: 0, creator: :author} %> +<%= render partial:'shared/form', + locals:{ medium: @book, action: :create, title: "New Book", creator: :author, rank_value: 0} %> From 411d76c4443d4ed00949093c7ee695934ea516ba Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 14:05:48 -0800 Subject: [PATCH 30/38] created partial for the show and got it working for movie --- app/views/home/_list.html.erb | 2 +- app/views/movies/show.html.erb | 21 ++------------------- app/views/shared/_detail.html.erb | 19 +++++++++++++++++++ app/views/shared/_index.html.erb | 2 +- 4 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 app/views/shared/_detail.html.erb diff --git a/app/views/home/_list.html.erb b/app/views/home/_list.html.erb index e08530852f..c8dd9da734 100644 --- a/app/views/home/_list.html.erb +++ b/app/views/home/_list.html.erb @@ -7,5 +7,5 @@ <% end %> - <%= link_to "View More Movies", polymorphic_path(media_type) %> + <%= link_to "View More " + media_type.to_s.capitalize, polymorphic_path(media_type) %>
diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 1858a3ef64..ffb621d9b8 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -1,19 +1,2 @@ -
-
-

<%= @movie.name %> Directed by: <%= @movie.director %>

-

- Ranked: <%= @movie.rank %> -

-

- <%= @movie.description %> -

-
- <%= link_to "Upvote", upvote_movie_path, method: :patch, class: "btn btn-primary" %> -
- - <%= link_to "Edit #{@movie.name}", edit_movie_path(@movie), class: "btn btn-default" %> - <%= link_to "DELETE", movie_path, method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> - <%= link_to "View All Movies", movies_path, class: "btn btn-default" %> - <%= link_to "View All Media", "/", class: "btn btn-default" %> -
-
+<%= render partial:'shared/detail', + locals:{ medium: @movie, creator: @movie.director, byline: "Directed by: ", media_type: :movies} %> diff --git a/app/views/shared/_detail.html.erb b/app/views/shared/_detail.html.erb new file mode 100644 index 0000000000..aa9d507828 --- /dev/null +++ b/app/views/shared/_detail.html.erb @@ -0,0 +1,19 @@ +
+
+

<%= medium.name %> <%= byline %><%= creator %>

+

+ Ranked: <%= medium.rank %> +

+

+ <%= medium.description %> +

+
+ <%= link_to "Upvote", polymorphic_path(medium, action: :upvote ), method: :patch, class: "btn btn-primary" %> +
+ + <%= link_to "Edit #{medium.name}", edit_polymorphic_path(medium), class: "btn btn-default" %> + <%= link_to "DELETE", polymorphic_path(medium), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> + <%= link_to "View All Movies", polymorphic_path(media_type), class: "btn btn-default" %> + <%= link_to "View All Media", root_path, class: "btn btn-default" %> +
+
diff --git a/app/views/shared/_index.html.erb b/app/views/shared/_index.html.erb index 7501d1ea4d..f321ddd866 100644 --- a/app/views/shared/_index.html.erb +++ b/app/views/shared/_index.html.erb @@ -18,6 +18,6 @@ - <%= link_to "View All Media", "/", class: "btn btn-default" %> + <%= link_to "View All Media", root_path, class: "btn btn-default" %> <%= link_to "Add a #{media_type.capitalize}", new_polymorphic_path(media_type), class: "btn btn-default" %>
From 18bc3a17e811e48c8f487bbea1450a0d9ce4ddae Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 14:10:06 -0800 Subject: [PATCH 31/38] added show for albums and books --- app/controllers/albums_controller.rb | 4 ++++ app/controllers/books_controller.rb | 11 +++++++++++ app/views/albums/show.html.erb | 2 ++ app/views/books/show.html.erb | 2 ++ 4 files changed, 19 insertions(+) create mode 100644 app/views/albums/show.html.erb create mode 100644 app/views/books/show.html.erb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index e45c136550..963f15a8a3 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -24,6 +24,10 @@ def create end end + def show + @album = Album.find(params[:id]) + end + private def album_params diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index c795d06c5c..a893c513c1 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -24,4 +24,15 @@ def create end end + def show + @book = Book.find(params[:id]) + end + + private + + def book_params + params.permit(book:[:name, :author, :description, :rank]) + end + + end diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb new file mode 100644 index 0000000000..41ada7c2d4 --- /dev/null +++ b/app/views/albums/show.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/detail', + locals:{ medium: @album, creator: @album.artist, byline: "Recorded by: ", media_type: :albums} %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb new file mode 100644 index 0000000000..848c96905a --- /dev/null +++ b/app/views/books/show.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/detail', + locals:{ medium: @book, creator: @book.author, byline: "Written by: ", media_type: :books} %> From b768ce90b7f9653e3692096ac4d948207d1cc2a2 Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 14:25:53 -0800 Subject: [PATCH 32/38] added edit method for album and books --- app/controllers/albums_controller.rb | 14 ++++++++++++++ app/controllers/books_controller.rb | 14 ++++++++++++++ app/views/albums/edit.html.erb | 2 ++ app/views/books/edit.html.erb | 2 ++ 4 files changed, 32 insertions(+) create mode 100644 app/views/albums/edit.html.erb create mode 100644 app/views/books/edit.html.erb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 963f15a8a3..0b44fd49de 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -28,6 +28,20 @@ def show @album = Album.find(params[:id]) end + def edit + @album = Album.find(params[:id]) + end + + def update + @album = Album.find(params[:id]) + @album.update( album_params[:album]) + if @album.save + redirect_to album_path(@album) + else + render "edit" + end + end + private def album_params diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index a893c513c1..34f08c7ea5 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -28,6 +28,20 @@ def show @book = Book.find(params[:id]) end + def edit + @book = Book.find(params[:id]) + end + + def update + @book = Book.find(params[:id]) + @book.update( book_params[:book]) + if @book.save + redirect_to book_path(@book) + else + render "edit" + end + end + private def book_params diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb new file mode 100644 index 0000000000..42c50caa33 --- /dev/null +++ b/app/views/albums/edit.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/form', + locals:{ medium: @album, action: :update, title: "Edit Album", creator: :artist, rank_value: @album.rank} %> diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb new file mode 100644 index 0000000000..e52bb31153 --- /dev/null +++ b/app/views/books/edit.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/form', + locals:{ medium: @book, action: :update, title: "Edit Book", creator: :author, rank_value: @book.rank} %> From 333f71699678fe3f39d091b4731fb335dbe4577d Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 14:28:22 -0800 Subject: [PATCH 33/38] added delete for albums and movies --- app/controllers/albums_controller.rb | 5 +++++ app/controllers/books_controller.rb | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 0b44fd49de..4524235d38 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -42,6 +42,11 @@ def update end end + def destroy + Album.destroy(params[:id]) + redirect_to albums_path + end + private def album_params diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 34f08c7ea5..47897e260c 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -42,6 +42,11 @@ def update end end + def destroy + Book.destroy(params[:id]) + redirect_to books_path + end + private def book_params From dea33730d96dac0764cae190fd1630b495efb551 Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 14:58:31 -0800 Subject: [PATCH 34/38] fixed typos and got all specs working --- app/controllers/books_controller.rb | 2 +- app/views/shared/_detail.html.erb | 2 +- spec/controllers/albums_controller_spec.rb | 4 ++-- spec/controllers/books_controller_spec.rb | 6 +++--- spec/controllers/movies_controller_spec.rb | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 47897e260c..2b78754339 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -18,7 +18,7 @@ def new def create @book = Book.new(book_params[:book]) if @book.save - redirect_to album_path(@book) + redirect_to book_path(@book) else render "new" end diff --git a/app/views/shared/_detail.html.erb b/app/views/shared/_detail.html.erb index aa9d507828..1999a99e92 100644 --- a/app/views/shared/_detail.html.erb +++ b/app/views/shared/_detail.html.erb @@ -13,7 +13,7 @@ <%= link_to "Edit #{medium.name}", edit_polymorphic_path(medium), class: "btn btn-default" %> <%= link_to "DELETE", polymorphic_path(medium), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> - <%= link_to "View All Movies", polymorphic_path(media_type), class: "btn btn-default" %> + <%= link_to "View All " + media_type.to_s.capitalize, polymorphic_path(media_type), class: "btn btn-default" %> <%= link_to "View All Media", root_path, class: "btn btn-default" %> diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index f5890276b0..a3b53ef6a8 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -27,7 +27,7 @@ end let(:good_update_params) do { - id: 1, + id: test_medium.id, album:{ name: "Songs", artist: "You", description: "SONGS", rank: 0 } @@ -36,7 +36,7 @@ let(:bad_update_params) do { - id: 1, + id: test_medium.id, album: { name: nil, artist: "You", description: "A Good Album", rank: 0 } } end diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index 3355aa7fe4..848e0103d6 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -27,7 +27,7 @@ end let(:good_update_params) do { - id: 1, + id: test_medium.id, book:{ name: "A Book", author: "You", description: "A Good Book", rank: 0 } @@ -36,8 +36,8 @@ let(:bad_update_params) do { - id: 1, - movie: { name: nil, author: "You", description: "A Good Book", rank: 0 } + id: test_medium.id, + book: { name: nil, author: "You", description: "A Good Book", rank: 0 } } end end diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index fcf23cd7cd..5c6fec4b38 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -27,7 +27,7 @@ end let(:good_update_params) do { - id: 1, + id: test_medium.id, movie:{ name: "Hello", director: "You", description: "A Good Movie", rank: 0 } @@ -36,7 +36,7 @@ let(:bad_update_params) do { - id: 1, + id: test_medium.id, movie: { name: nil, director: "You", description: "A Good Movie", rank: 0 } } end From e39af028e1116b77451748ed5beec1a08541526f Mon Sep 17 00:00:00 2001 From: emgord Date: Thu, 3 Dec 2015 15:20:35 -0800 Subject: [PATCH 35/38] double checked that styling is all the same, made a few small changes --- app/views/shared/_form.html.erb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/shared/_form.html.erb b/app/views/shared/_form.html.erb index 1cf1ee197c..e40916e44d 100644 --- a/app/views/shared/_form.html.erb +++ b/app/views/shared/_form.html.erb @@ -2,9 +2,7 @@
<%= form_for medium, url:{action: action}, :html => {:class => "form" } do |f| %> - -

<%= title %>

-
+

<%= title %>

<%= f.label :name %> <%= f.text_field :name, class: "form-control" %> From 346df5c9aa0348b25f8675a4edfecb7f2d269a1e Mon Sep 17 00:00:00 2001 From: emgord Date: Fri, 4 Dec 2015 10:28:27 -0800 Subject: [PATCH 36/38] added test to make sure update is actually changing as expected, and changed some variable names throughout to make more clear --- app/controllers/albums_controller.rb | 8 ++++---- app/controllers/books_controller.rb | 14 +++++++------- app/controllers/movies_controller.rb | 8 ++++---- app/views/shared/_index.html.erb | 8 ++++---- spec/controllers/albums_controller_spec.rb | 2 +- spec/controllers/books_controller_spec.rb | 2 +- spec/controllers/movies_controller_spec.rb | 2 +- spec/support/medium_controller_spec.rb | 21 +++++++++++++++++---- 8 files changed, 39 insertions(+), 26 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 4524235d38..957c2c1dfd 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -5,10 +5,10 @@ def index end def upvote - a = Album.find(params[:id]) - a.rank += 1 - a.save - redirect_to album_path(a) + album = Album.find(params[:id]) + album.rank += 1 + album.save + redirect_to album_path(album) end def new diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 2b78754339..a88afb2766 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -5,10 +5,10 @@ def index end def upvote - b = Book.find(params[:id]) - b.rank += 1 - b.save - redirect_to book_path(b) + book = Book.find(params[:id]) + book.rank += 1 + book.save + redirect_to book_path(book) end def new @@ -16,7 +16,7 @@ def new end def create - @book = Book.new(book_params[:book]) + @book = Book.new(book_params) if @book.save redirect_to book_path(@book) else @@ -34,7 +34,7 @@ def edit def update @book = Book.find(params[:id]) - @book.update( book_params[:book]) + @book.update( book_params ) if @book.save redirect_to book_path(@book) else @@ -50,7 +50,7 @@ def destroy private def book_params - params.permit(book:[:name, :author, :description, :rank]) + params.require(:book).permit(:name, :author, :description, :rank) end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index e58cfd5c16..9774b91bb4 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -41,10 +41,10 @@ def destroy end def upvote - m = Movie.find(params[:id]) - m.rank += 1 - m.save - redirect_to movie_path(m) + movie = Movie.find(params[:id]) + movie.rank += 1 + movie.save + redirect_to movie_path(movie) end private diff --git a/app/views/shared/_index.html.erb b/app/views/shared/_index.html.erb index f321ddd866..53e4fd8560 100644 --- a/app/views/shared/_index.html.erb +++ b/app/views/shared/_index.html.erb @@ -8,11 +8,11 @@ - <% media.each do |m| %> + <% media.each do |medium| %> - Ranked: <%= m.rank %> - <%= link_to m.name, polymorphic_path(m) %> - <%= link_to "Upvote", polymorphic_path(m, action: :upvote ), method: :patch, class: "btn btn-default" %> + Ranked: <%= medium.rank %> + <%= link_to medium.name, polymorphic_path(medium) %> + <%= link_to "Upvote", polymorphic_path(medium, action: :upvote ), method: :patch, class: "btn btn-default" %> <% end %> diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index a3b53ef6a8..728c34f4c6 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -29,7 +29,7 @@ { id: test_medium.id, album:{ - name: "Songs", artist: "You", description: "SONGS", rank: 0 + name: "New name", artist: "You", description: "SONGS", rank: 0 } } end diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index 848e0103d6..ef790635d7 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -29,7 +29,7 @@ { id: test_medium.id, book:{ - name: "A Book", author: "You", description: "A Good Book", rank: 0 + name: "New name", author: "You", description: "A Good Book", rank: 0 } } end diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 5c6fec4b38..416b43d9f4 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -29,7 +29,7 @@ { id: test_medium.id, movie:{ - name: "Hello", director: "You", description: "A Good Movie", rank: 0 + name: "New name", director: "new director", description: "A very Good Movie", rank: 0 } } end diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb index 8e9ce3b59d..0de2343aee 100644 --- a/spec/support/medium_controller_spec.rb +++ b/spec/support/medium_controller_spec.rb @@ -19,11 +19,14 @@ end describe "POST 'create'" do + before :each do + post :create, good_params + end it "redirects to show page" do - post :create, good_params expect(subject).to redirect_to polymorphic_path(assigns(media_type)) end + it "renders new template on error" do post :create, bad_params expect(subject).to render_template :new @@ -45,11 +48,19 @@ end describe "PATCH 'update'" do + before :each do + patch :update, good_update_params + end it "redirects to show page" do - patch :update, good_update_params expect(subject).to redirect_to polymorphic_path(assigns(media_type)) end + + it "updates the item" do + test_medium.reload + expect(test_medium.name).to eq("New name") + end + it "renders edit template on error" do patch :update, bad_update_params expect(subject).to render_template :edit @@ -70,13 +81,15 @@ } end - it "redirects to show page" do + before :each do patch :upvote, upvote_params + end + + it "redirects to show page" do expect(subject).to redirect_to polymorphic_path(test_medium) end it "increases the rank value by 1" do - patch :upvote, upvote_params test_medium.reload expect(test_medium.rank).to eq 1 end From 24db221427a33b91cc2e95aef0aac77866635085 Mon Sep 17 00:00:00 2001 From: emgord Date: Fri, 4 Dec 2015 14:01:45 -0800 Subject: [PATCH 37/38] project complete --- spec/support/medium_controller_spec.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb index 0de2343aee..3366f1d9f8 100644 --- a/spec/support/medium_controller_spec.rb +++ b/spec/support/medium_controller_spec.rb @@ -65,11 +65,18 @@ patch :update, bad_update_params expect(subject).to render_template :edit end + + it "does not change the item if params are bad" do + patch :update, bad_update_params + expect(test_medium.name).not_to eql("New name") + end end describe "DELETE 'destroy'" do - it "redirects to the index view" do + before :each do delete :destroy, id: test_medium.id + end + it "redirects to the index view" do expect(subject).to redirect_to polymorphic_path(media_type_plural) end end From 6d959297a5416dd260cb2ffbcfbee9afa02ba831 Mon Sep 17 00:00:00 2001 From: emgord Date: Fri, 4 Dec 2015 14:21:58 -0800 Subject: [PATCH 38/38] just kidding. added validation for max length of name, description and creator --- app/models/album.rb | 5 ++++- app/models/book.rb | 5 ++++- app/models/movie.rb | 4 +++- spec/models/album_spec.rb | 8 ++++++++ spec/models/book_spec.rb | 8 ++++++++ spec/models/movie_spec.rb | 8 ++++++++ spec/support/medium_spec.rb | 16 ++++++++++++++++ 7 files changed, 51 insertions(+), 3 deletions(-) diff --git a/app/models/album.rb b/app/models/album.rb index b965f608d0..cbbf38bde0 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -1,3 +1,6 @@ class Album < ActiveRecord::Base - validates :name, presence: true + validates :name, presence: true, length: { maximum: 100 } + validates :description, length: {maximum: 500 } + validates :artist, length: {maximum: 100 } + end diff --git a/app/models/book.rb b/app/models/book.rb index 7b27cc85bd..c72e044a92 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,3 +1,6 @@ class Book < ActiveRecord::Base - validates :name, presence: true + validates :name, presence: true, length: { maximum: 100 } + validates :description, length: {maximum: 500 } + validates :author, length: {maximum: 100 } + end diff --git a/app/models/movie.rb b/app/models/movie.rb index 1ea78bec6a..11064ae833 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,4 +1,6 @@ class Movie < ActiveRecord::Base - validates :name, presence: true + validates :name, presence: true, length: { maximum: 100 } + validates :description, length: {maximum: 500 } + validates :director, length: {maximum: 100 } end diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index df364d0def..6dd2940c97 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -3,4 +3,12 @@ RSpec.describe Album, type: :model do it_behaves_like "a medium" + it "artist cannot have 101 characters" do + expect(Album.new(name: "a", artist: "a" * 101)).to be_invalid + end + + it "director can have 100 characters" do + expect(Album.new(name: "a", artist: "a" * 100)).to be_valid + end + end diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb index c51e7859d3..480c0bc3e6 100644 --- a/spec/models/book_spec.rb +++ b/spec/models/book_spec.rb @@ -3,4 +3,12 @@ RSpec.describe Book, type: :model do it_behaves_like "a medium" + it "author cannot have 101 characters" do + expect(Book.new(name: "a", author: "a" * 101)).to be_invalid + end + + it "director can have 100 characters" do + expect(Book.new(name: "a", author: "a" * 100)).to be_valid + end + end diff --git a/spec/models/movie_spec.rb b/spec/models/movie_spec.rb index 848984679f..31c8b2aa16 100644 --- a/spec/models/movie_spec.rb +++ b/spec/models/movie_spec.rb @@ -3,4 +3,12 @@ RSpec.describe Movie, type: :model do it_behaves_like "a medium" + it "director cannot have 101 characters" do + expect(Movie.new(name: "a", director: "a" * 101)).to be_invalid + end + + it "director can have 100 characters" do + expect(Movie.new(name: "a", director: "a" * 100)).to be_valid + end + end diff --git a/spec/support/medium_spec.rb b/spec/support/medium_spec.rb index cb844c1533..9bcfcd15af 100644 --- a/spec/support/medium_spec.rb +++ b/spec/support/medium_spec.rb @@ -6,4 +6,20 @@ expect(described_class.new(name: nil)).to_not be_valid end end + + it "name cannot have 101 characters" do + expect(described_class.new(name: "a" * 101)).to be_invalid + end + + it "name can have 100 characters" do + expect(described_class.new(name: "a" * 100)).to be_valid + end + + it "description cannot have 501 characters" do + expect(described_class.new(name: "a", description: "a" * 501)).to be_invalid + end + + it "description can have 500 characters" do + expect(described_class.new(name: "a", description: "a" * 500)).to be_valid + end end