From cda108cf0583b2e8a1d70f89d6796da9c29578e5 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 12:28:39 -0800 Subject: [PATCH 01/64] create models --- app/models/album.rb | 2 + app/models/book.rb | 2 + app/models/movie.rb | 2 + db/migrate/20151130202443_create_movies.rb | 12 ++++++ db/migrate/20151130202453_create_books.rb | 12 ++++++ db/migrate/20151130202501_create_albums.rb | 12 ++++++ db/schema.rb | 43 ++++++++++++++++++++++ 7 files changed, 85 insertions(+) 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/20151130202443_create_movies.rb create mode 100644 db/migrate/20151130202453_create_books.rb create mode 100644 db/migrate/20151130202501_create_albums.rb create mode 100644 db/schema.rb 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/20151130202443_create_movies.rb b/db/migrate/20151130202443_create_movies.rb new file mode 100644 index 0000000000..05b1257f63 --- /dev/null +++ b/db/migrate/20151130202443_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.text :description + t.integer :ranked, default: 0 + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151130202453_create_books.rb b/db/migrate/20151130202453_create_books.rb new file mode 100644 index 0000000000..0e38f71061 --- /dev/null +++ b/db/migrate/20151130202453_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.text :description + t.integer :ranked, default: 0 + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151130202501_create_albums.rb b/db/migrate/20151130202501_create_albums.rb new file mode 100644 index 0000000000..7b904fb9eb --- /dev/null +++ b/db/migrate/20151130202501_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.text :description + t.integer :ranked, default: 0 + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..dcca742011 --- /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: 20151130202501) do + + create_table "albums", force: :cascade do |t| + t.string "name" + t.string "artist" + t.text "description" + t.integer "ranked", default: 0 + 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.text "description" + t.integer "ranked", default: 0 + 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.text "description" + t.integer "ranked", default: 0 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end From 4792c9031e8ee5d2270b09e1ca17bceb500c40da Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 13:35:37 -0800 Subject: [PATCH 02/64] Create controllers --- app/assets/javascripts/albums.coffee | 3 +++ app/assets/javascripts/books.coffee | 3 +++ app/assets/javascripts/movies.coffee | 3 +++ app/assets/stylesheets/albums.scss | 3 +++ app/assets/stylesheets/books.scss | 3 +++ app/assets/stylesheets/movies.scss | 3 +++ app/controllers/albums_controller.rb | 2 ++ app/controllers/books_controller.rb | 2 ++ app/controllers/movies_controller.rb | 2 ++ app/helpers/albums_helper.rb | 2 ++ app/helpers/books_helper.rb | 2 ++ app/helpers/movies_helper.rb | 2 ++ 12 files changed, 30 insertions(+) create mode 100644 app/assets/javascripts/albums.coffee create mode 100644 app/assets/javascripts/books.coffee create mode 100644 app/assets/javascripts/movies.coffee create mode 100644 app/assets/stylesheets/albums.scss create mode 100644 app/assets/stylesheets/books.scss create mode 100644 app/assets/stylesheets/movies.scss create mode 100644 app/controllers/albums_controller.rb create mode 100644 app/controllers/books_controller.rb create mode 100644 app/controllers/movies_controller.rb create mode 100644 app/helpers/albums_helper.rb create mode 100644 app/helpers/books_helper.rb create mode 100644 app/helpers/movies_helper.rb diff --git a/app/assets/javascripts/albums.coffee b/app/assets/javascripts/albums.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/albums.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/albums.scss b/app/assets/stylesheets/albums.scss new file mode 100644 index 0000000000..0eb33ca0f6 --- /dev/null +++ b/app/assets/stylesheets/albums.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the albums 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/albums_controller.rb b/app/controllers/albums_controller.rb new file mode 100644 index 0000000000..2f800bd33f --- /dev/null +++ b/app/controllers/albums_controller.rb @@ -0,0 +1,2 @@ +class AlbumsController < 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/albums_helper.rb b/app/helpers/albums_helper.rb new file mode 100644 index 0000000000..d976b7cef8 --- /dev/null +++ b/app/helpers/albums_helper.rb @@ -0,0 +1,2 @@ +module AlbumsHelper +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 From c3d93d24c0903e97f3afa6f9418a47d0b1455560 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 13:37:28 -0800 Subject: [PATCH 03/64] Add routes --- config/routes.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 3f66539d54..4db40d8f0c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,7 @@ 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 7febcc95c585fd1bb2e31904897e0796fe58ac23 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 13:40:52 -0800 Subject: [PATCH 04/64] Create CRUD controller methods --- app/controllers/albums_controller.rb | 25 +++++++++++++++++++++++++ app/controllers/books_controller.rb | 25 +++++++++++++++++++++++++ app/controllers/movies_controller.rb | 25 +++++++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 2f800bd33f..555158360c 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,2 +1,27 @@ class AlbumsController < ApplicationController + def index + end + + def show + end + + def new + end + + def create + end + + def edit + end + + def update + end + + def destroy + end + + private + + def album_params + end end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index cdb437b99f..7650467b40 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,2 +1,27 @@ class BooksController < ApplicationController + def index + end + + def show + end + + def new + end + + def create + end + + def edit + end + + def update + end + + def destroy + end + + private + + def book_params + end end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 6c4c516140..8afabbd552 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,2 +1,27 @@ class MoviesController < ApplicationController + def index + end + + def show + end + + def new + end + + def create + end + + def edit + end + + def update + end + + def destroy + end + + private + + def movie_params + end end From de26c24fa786dd54604a32538653f358f297220a Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 13:54:03 -0800 Subject: [PATCH 05/64] Add movie index view and update controller method --- app/controllers/movies_controller.rb | 3 ++- app/views/movies/index.html.erb | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 app/views/movies/index.html.erb diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 8afabbd552..a8121f5263 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,5 +1,6 @@ class MoviesController < ApplicationController def index + @movies = Movie.all end def show @@ -21,7 +22,7 @@ def destroy end private - + def movie_params end end diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb new file mode 100644 index 0000000000..a379d162bc --- /dev/null +++ b/app/views/movies/index.html.erb @@ -0,0 +1,26 @@ + + <% @movies.each do |movie| %> + + + + + + + + + + + <% end %> +
+ Ranking + + Name + + Upvote +
+ Ranked: <%= movie.ranked %> + + <%= link_to movie.name, movie_path(movie) %> + + Upvote Button Will Go Here +
From 994b7cbf1e75212a8f4b3ff7d0ce37eb298e4da9 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 14:01:04 -0800 Subject: [PATCH 06/64] Fix movie index view, add book index view, update book index controller --- app/controllers/books_controller.rb | 1 + app/views/books/index.html.erb | 26 ++++++++++++++++++++++++++ app/views/movies/index.html.erb | 22 +++++++++++----------- 3 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 app/views/books/index.html.erb diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 7650467b40..5d73c41e22 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,5 +1,6 @@ class BooksController < ApplicationController def index + @books = Book.all end def show diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb new file mode 100644 index 0000000000..3d4fb6877a --- /dev/null +++ b/app/views/books/index.html.erb @@ -0,0 +1,26 @@ + + + + + + + <% @books.each do |book| %> + + + + + + <% end %> +
+ Ranking + + Name + + Upvote +
+ Ranked: <%= book.ranked %> + + <%= link_to book.name, book_path(book) %> + + Upvote Button Will Go Here +
diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index a379d162bc..68fe1c94e3 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -1,16 +1,16 @@ + + + + + <% @movies.each do |movie| %> - - - - - <% end %>
+ Ranking + + Name + + Upvote +
- Ranking - - Name - - Upvote -
Ranked: <%= movie.ranked %> From d4b318cb25b3a87f566f5891adc143327ef9c674 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 14:03:35 -0800 Subject: [PATCH 07/64] Add album index view and update index method in controller --- app/controllers/albums_controller.rb | 1 + app/views/albums/index.html.erb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 app/views/albums/index.html.erb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 555158360c..33d1063a81 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,5 +1,6 @@ class AlbumsController < ApplicationController def index + @albums = Album.all end def show diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb new file mode 100644 index 0000000000..943c6df32a --- /dev/null +++ b/app/views/albums/index.html.erb @@ -0,0 +1,26 @@ + + + + + + + <% @albums.each do |album| %> + + + + + + <% end %> +
+ Ranking + + Name + + Upvote +
+ Ranked: <%= album.ranked %> + + <%= link_to album.name, album_path(album) %> + + Upvote Button Will Go Here +
From ecb205af1548e559fbdc059f6381ef5303a64a58 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 14:26:13 -0800 Subject: [PATCH 08/64] Create show views and update show method for all three controllers --- app/controllers/albums_controller.rb | 1 + app/controllers/books_controller.rb | 1 + app/controllers/movies_controller.rb | 1 + app/views/albums/show.html.erb | 11 +++++++++++ app/views/books/show.html.erb | 11 +++++++++++ app/views/movies/show.html.erb | 11 +++++++++++ 6 files changed, 36 insertions(+) create mode 100644 app/views/albums/show.html.erb create mode 100644 app/views/books/show.html.erb create mode 100644 app/views/movies/show.html.erb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 33d1063a81..34e32d4a6a 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -4,6 +4,7 @@ def index end def show + @album = Album.find(params[:id]) end def new diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 5d73c41e22..413a0550a9 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -4,6 +4,7 @@ def index end def show + @book = Book.find(params[:id]) end def new diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index a8121f5263..e965c6ac5d 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -4,6 +4,7 @@ def index end def show + @movie = Movie.find(params[:id]) end def new diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb new file mode 100644 index 0000000000..279eb9a296 --- /dev/null +++ b/app/views/albums/show.html.erb @@ -0,0 +1,11 @@ +

<%= @album.name %>

Recorded by: <%= @album.artist%>

+
+

Ranked: <%= @album.ranked %>

+
+

+ <%= @album.description %> +

+
+Upvote Button Here +
+<%= button_to "Edit #{@album.name}", edit_album_path(@album) %> <%= button_to "DELETE", "/albums/#{@album.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Albums Button Here View All Media Button Here diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb new file mode 100644 index 0000000000..6fd5cec7df --- /dev/null +++ b/app/views/books/show.html.erb @@ -0,0 +1,11 @@ +

<%= @book.name %>

Written by: <%= @book.author%>

+
+

Ranked: <%= @book.ranked %>

+
+

+ <%= @book.description %> +

+
+Upvote Button Here +
+<%= button_to "Edit #{@book.name}", edit_book_path(@book) %> <%= button_to "DELETE", "/books/#{@book.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Books Button Here View All Media Button Here diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb new file mode 100644 index 0000000000..1e9f00648b --- /dev/null +++ b/app/views/movies/show.html.erb @@ -0,0 +1,11 @@ +

<%= @movie.name %>

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

+
+

Ranked: <%= @movie.ranked %>

+
+

+ <%= @movie.description %> +

+
+Upvote Button Here +
+<%= button_to "Edit #{@movie.name}", edit_movie_path(@movie) %> <%= button_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Movies Button Here View All Media Button Here From a7903423e7c942aeae0062e8554337d7f8184b91 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 14:42:36 -0800 Subject: [PATCH 09/64] Create form and edit view files for all controllers, create form for books --- app/controllers/books_controller.rb | 4 ++++ app/views/albums/_form.html.erb | 1 + app/views/albums/edit.html.erb | 2 ++ app/views/albums/show.html.erb | 2 +- app/views/books/_form.html.erb | 15 +++++++++++++++ app/views/books/edit.html.erb | 2 ++ app/views/books/show.html.erb | 2 +- app/views/movies/_form.html.erb | 0 app/views/movies/edit.html.erb | 0 app/views/movies/show.html.erb | 2 +- 10 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 app/views/albums/_form.html.erb create mode 100644 app/views/albums/edit.html.erb create mode 100644 app/views/books/_form.html.erb create mode 100644 app/views/books/edit.html.erb create mode 100644 app/views/movies/_form.html.erb create mode 100644 app/views/movies/edit.html.erb diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 413a0550a9..85f1b4a727 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -14,9 +14,12 @@ def create end def edit + @book = Book.find(params[:id]) end def update + @book = Book.find(params[:id]) + @book.update(book_params) end def destroy @@ -25,5 +28,6 @@ def destroy private def book_params + params.require(:book).permit([:name, :author, :description]) end end diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/app/views/albums/_form.html.erb @@ -0,0 +1 @@ + diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb new file mode 100644 index 0000000000..354306603e --- /dev/null +++ b/app/views/albums/edit.html.erb @@ -0,0 +1,2 @@ +

Edit Album

+<%= render 'form' %> diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index 279eb9a296..bd432e8d81 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -8,4 +8,4 @@
Upvote Button Here
-<%= button_to "Edit #{@album.name}", edit_album_path(@album) %> <%= button_to "DELETE", "/albums/#{@album.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Albums Button Here View All Media Button Here +<%= button_to "Edit #{@album.name}", edit_album_path(@album), method: :get %> <%= button_to "DELETE", "/albums/#{@album.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Albums Button Here View All Media Button Here diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb new file mode 100644 index 0000000000..b5b62717ae --- /dev/null +++ b/app/views/books/_form.html.erb @@ -0,0 +1,15 @@ +<%= form_for @book do |f| %> + <%= f.label :name %> +
+ <%= f.text_field :name %> +
+ <%= f.label :author %> +
+ <%= f.text_field :author %> +
+ <%= f.label :description %> +
+ <%= f.text_area :description %> +
+ <%= f.submit "Save" %> +<% end %> diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb new file mode 100644 index 0000000000..49e2b8b1fa --- /dev/null +++ b/app/views/books/edit.html.erb @@ -0,0 +1,2 @@ +

Edit Book

+<%= render 'form' %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index 6fd5cec7df..44404e6509 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -8,4 +8,4 @@
Upvote Button Here
-<%= button_to "Edit #{@book.name}", edit_book_path(@book) %> <%= button_to "DELETE", "/books/#{@book.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Books Button Here View All Media Button Here +<%= button_to "Edit #{@book.name}", edit_book_path(@book), method: :get %> <%= button_to "DELETE", "/books/#{@book.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Books Button Here View All Media Button Here diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 1e9f00648b..5ee9bdb8bd 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -8,4 +8,4 @@
Upvote Button Here
-<%= button_to "Edit #{@movie.name}", edit_movie_path(@movie) %> <%= button_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Movies Button Here View All Media Button Here +<%= button_to "Edit #{@movie.name}", edit_movie_path(@movie), method: :get %> <%= button_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Movies Button Here View All Media Button Here From d5c74fdecd1c9e7140524cdbb90a612e2d52654d Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 14:48:44 -0800 Subject: [PATCH 10/64] Create form for movie and album --- app/controllers/albums_controller.rb | 4 ++++ app/controllers/movies_controller.rb | 4 ++++ app/views/albums/_form.html.erb | 16 +++++++++++++++- app/views/movies/_form.html.erb | 15 +++++++++++++++ app/views/movies/edit.html.erb | 2 ++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 34e32d4a6a..ba2b9a37f1 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -14,9 +14,12 @@ def create end def edit + @album = Album.find(params[:id]) end def update + @album = Album.find(params[:id]) + @album.update(album_params) end def destroy @@ -25,5 +28,6 @@ def destroy private def album_params + params.require(:album).permit([:name, :artist, :description]) end end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index e965c6ac5d..00d3499373 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -14,9 +14,12 @@ def create end def edit + @movie = Movie.find(params[:id]) end def update + @movie = Movie.find(params[:id]) + @movie.update(movie_params) end def destroy @@ -25,5 +28,6 @@ def destroy private def movie_params + params.require(:movie).permit([:name, :director, :description]) end end diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb index 8b13789179..8d87ed5cbe 100644 --- a/app/views/albums/_form.html.erb +++ b/app/views/albums/_form.html.erb @@ -1 +1,15 @@ - +<%= form_for @album do |f| %> + <%= f.label :name %> +
+ <%= f.text_field :name %> +
+ <%= f.label :artist %> +
+ <%= f.text_field :artist %> +
+ <%= f.label :description %> +
+ <%= f.text_area :description %> +
+ <%= f.submit "Save" %> +<% end %> diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb index e69de29bb2..b927675f66 100644 --- a/app/views/movies/_form.html.erb +++ b/app/views/movies/_form.html.erb @@ -0,0 +1,15 @@ +<%= form_for @movie do |f| %> + <%= f.label :name %> +
+ <%= f.text_field :name %> +
+ <%= f.label :director %> +
+ <%= f.text_field :director %> +
+ <%= f.label :description %> +
+ <%= f.text_area :description %> +
+ <%= f.submit "Save" %> +<% end %> diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb index e69de29bb2..a6dc942fcd 100644 --- a/app/views/movies/edit.html.erb +++ b/app/views/movies/edit.html.erb @@ -0,0 +1,2 @@ +

Edit Movie

+<%= render 'form' %> From 3c9847ee691c9eb26d8de821fe4dbcf81d02259d Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 14:53:44 -0800 Subject: [PATCH 11/64] Add redirect to update method of all 3 controllers --- app/controllers/albums_controller.rb | 1 + app/controllers/books_controller.rb | 1 + app/controllers/movies_controller.rb | 1 + 3 files changed, 3 insertions(+) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index ba2b9a37f1..c06051577f 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -20,6 +20,7 @@ def edit def update @album = Album.find(params[:id]) @album.update(album_params) + redirect_to album_path(@album) end def destroy diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 85f1b4a727..994450753c 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -20,6 +20,7 @@ def edit def update @book = Book.find(params[:id]) @book.update(book_params) + redirect_to book_path(@book) end def destroy diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 00d3499373..5fff1eae81 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -20,6 +20,7 @@ def edit def update @movie = Movie.find(params[:id]) @movie.update(movie_params) + redirect_to movie_path(@movie) end def destroy From a3aecd6b4f0af0643a7b0e7a681307585e17479c Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 14:58:36 -0800 Subject: [PATCH 12/64] Create new views, add new button to index views --- app/views/albums/index.html.erb | 1 + app/views/albums/new.html.erb | 2 ++ app/views/books/index.html.erb | 1 + app/views/books/new.html.erb | 2 ++ app/views/movies/index.html.erb | 1 + app/views/movies/new.html.erb | 2 ++ 6 files changed, 9 insertions(+) create mode 100644 app/views/albums/new.html.erb create mode 100644 app/views/books/new.html.erb create mode 100644 app/views/movies/new.html.erb diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index 943c6df32a..d0092f3791 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -24,3 +24,4 @@
+View All Media <%= button_to "Add an Album", new_album_path, method: :get %> diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb new file mode 100644 index 0000000000..4cc6b207a1 --- /dev/null +++ b/app/views/albums/new.html.erb @@ -0,0 +1,2 @@ +

New Album

+<%= render 'form' %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index 3d4fb6877a..f3c539a4ad 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -24,3 +24,4 @@ <% end %> +View All Media <%= button_to "Add a Book", new_book_path, method: :get %> diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb new file mode 100644 index 0000000000..068b2dc310 --- /dev/null +++ b/app/views/books/new.html.erb @@ -0,0 +1,2 @@ +

New Book

+<%= render 'form' %> diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index 68fe1c94e3..0a8ead550c 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -24,3 +24,4 @@ <% end %> +View All Media <%= button_to "Add a Movie", new_movie_path, method: :get %> diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb new file mode 100644 index 0000000000..4987ff793a --- /dev/null +++ b/app/views/movies/new.html.erb @@ -0,0 +1,2 @@ +

New Movie

+<%= render 'form' %> From 14c38f32e2e7d874afd1e06455c890927f4c3832 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 15:04:52 -0800 Subject: [PATCH 13/64] Complete new and create methods for all three controllers --- app/controllers/albums_controller.rb | 3 +++ app/controllers/books_controller.rb | 3 +++ app/controllers/movies_controller.rb | 3 +++ 3 files changed, 9 insertions(+) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index c06051577f..2db9faebb8 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -8,9 +8,12 @@ def show end def new + @album = Album.new end def create + album = Album.create(album_params) + redirect_to album_path(album) end def edit diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 994450753c..63d98b855c 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -8,9 +8,12 @@ def show end def new + @book = Book.new end def create + book = Book.create(book_params) + redirect_to book_path(book) end def edit diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 5fff1eae81..26efebdb1e 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -8,9 +8,12 @@ def show end def new + @movie = Movie.new end def create + movie = Movie.create(movie_params) + redirect_to movie_path(movie) end def edit From 1f3a49c7b94b9410d0a82e7658b19f29f4185778 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 15:08:20 -0800 Subject: [PATCH 14/64] Complete destroy methods for all 3 controllers --- app/controllers/albums_controller.rb | 3 +++ app/controllers/books_controller.rb | 3 +++ app/controllers/movies_controller.rb | 3 +++ 3 files changed, 9 insertions(+) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 2db9faebb8..fd0311484e 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -27,6 +27,9 @@ def update end def destroy + album = Album.find(params[:id]) + album.destroy + redirect_to albums_path end private diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 63d98b855c..502494f684 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -27,6 +27,9 @@ def update end def destroy + book = Book.find(params[:id]) + book.destroy + redirect_to books_path end private diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 26efebdb1e..14f6aea364 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -27,6 +27,9 @@ def update end def destroy + movie = Movie.find(params[:id]) + movie.destroy + redirect_to movies_path end private From c94ac27f9fe0c32f1c5a805459b3a1407d43cc2a Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 15:32:08 -0800 Subject: [PATCH 15/64] Create upvote method for movies --- app/controllers/movies_controller.rb | 7 +++++++ app/views/movies/show.html.erb | 2 +- config/routes.rb | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 14f6aea364..751108a311 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -32,6 +32,13 @@ def destroy redirect_to movies_path end + def upvote + movie = Movie.find(params[:id]) + movie.ranked += 1 + movie.save + redirect_to movie_path(movie) + end + private def movie_params diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 5ee9bdb8bd..0de2679905 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -6,6 +6,6 @@ <%= @movie.description %>


-Upvote Button Here +<%= button_to "Upvote", upvote_path(@movie), method: :patch %>
<%= button_to "Edit #{@movie.name}", edit_movie_path(@movie), method: :get %> <%= button_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Movies Button Here View All Media Button Here diff --git a/config/routes.rb b/config/routes.rb index 4db40d8f0c..85cdcdad3a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + patch '/movies/:id/upvote' => 'movies#upvote', as: :upvote resources :movies resources :books resources :albums From 6930d6b97091ece37b5a52bb1fa7894f2be1e40a Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 15:37:46 -0800 Subject: [PATCH 16/64] Add upvote methods to books and albums --- app/controllers/albums_controller.rb | 7 +++++++ app/controllers/books_controller.rb | 7 +++++++ app/views/albums/show.html.erb | 2 +- app/views/books/show.html.erb | 2 +- app/views/movies/show.html.erb | 2 +- config/routes.rb | 5 ++++- 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index fd0311484e..87a888fdd9 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -32,6 +32,13 @@ def destroy redirect_to albums_path end + def upvote + album = Album.find(params[:id]) + album.ranked += 1 + album.save + redirect_to album_path(album) + end + private def album_params diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 502494f684..0a5ef1bbf9 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -32,6 +32,13 @@ def destroy redirect_to books_path end + def upvote + book = Book.find(params[:id]) + book.ranked += 1 + book.save + redirect_to book_path(book) + end + private def book_params diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index bd432e8d81..18a94b5eda 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -6,6 +6,6 @@ <%= @album.description %>


-Upvote Button Here +<%= button_to "Upvote", album_upvote_path(@album), method: :patch %>
<%= button_to "Edit #{@album.name}", edit_album_path(@album), method: :get %> <%= button_to "DELETE", "/albums/#{@album.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Albums Button Here View All Media Button Here diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index 44404e6509..52ed6ba823 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -6,6 +6,6 @@ <%= @book.description %>


-Upvote Button Here +<%= button_to "Upvote", book_upvote_path(@book), method: :patch %>
<%= button_to "Edit #{@book.name}", edit_book_path(@book), method: :get %> <%= button_to "DELETE", "/books/#{@book.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Books Button Here View All Media Button Here diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 0de2679905..82173718b7 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -6,6 +6,6 @@ <%= @movie.description %>


-<%= button_to "Upvote", upvote_path(@movie), method: :patch %> +<%= button_to "Upvote", movie_upvote_path(@movie), method: :patch %>
<%= button_to "Edit #{@movie.name}", edit_movie_path(@movie), method: :get %> <%= button_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Movies Button Here View All Media Button Here diff --git a/config/routes.rb b/config/routes.rb index 85cdcdad3a..4a8c3f0f2c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ Rails.application.routes.draw do - patch '/movies/:id/upvote' => 'movies#upvote', as: :upvote + patch '/movies/:id/upvote' => 'movies#upvote', as: :movie_upvote + patch '/books/:id/upvote' => 'books#upvote', as: :book_upvote + patch '/albums/:id/upvote' => 'albums#upvote', as: :album_upvote + resources :movies resources :books resources :albums From 01450e536c32c53c3dec68ffe3ca5d9957bbe4cc Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 15:54:56 -0800 Subject: [PATCH 17/64] Create root route with list of 10 from each table --- app/assets/javascripts/welcome.coffee | 3 +++ app/assets/stylesheets/welcome.scss | 3 +++ app/controllers/welcome_controller.rb | 7 +++++++ app/helpers/welcome_helper.rb | 2 ++ app/views/welcome/index.html.erb | 18 ++++++++++++++++++ config/routes.rb | 2 ++ 6 files changed, 35 insertions(+) create mode 100644 app/assets/javascripts/welcome.coffee create mode 100644 app/assets/stylesheets/welcome.scss create mode 100644 app/controllers/welcome_controller.rb create mode 100644 app/helpers/welcome_helper.rb create mode 100644 app/views/welcome/index.html.erb diff --git a/app/assets/javascripts/welcome.coffee b/app/assets/javascripts/welcome.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/welcome.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/welcome.scss b/app/assets/stylesheets/welcome.scss new file mode 100644 index 0000000000..77ce11a740 --- /dev/null +++ b/app/assets/stylesheets/welcome.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the welcome 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/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 0000000000..ff03e63aba --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,7 @@ +class WelcomeController < ApplicationController + def index + @movies = Movie.all.limit(10) + @books = Book.all.limit(10) + @albums = Album.all.limit(10) + end +end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb new file mode 100644 index 0000000000..eeead45fc9 --- /dev/null +++ b/app/helpers/welcome_helper.rb @@ -0,0 +1,2 @@ +module WelcomeHelper +end diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb new file mode 100644 index 0000000000..1fedf9010a --- /dev/null +++ b/app/views/welcome/index.html.erb @@ -0,0 +1,18 @@ +

Top Movies

+<% @movies.each do |movie| %> + <%= link_to movie.name, movie_path(movie) %> + Ranked: <%= movie.ranked %> +
+<% end %> +

Top Books

+<% @books.each do |book| %> + <%= link_to book.name, book_path(book) %> + Ranked: <%= book.ranked %> +
+<% end %> +

Top Albums

+<% @albums.each do |album| %> + <%= link_to album.name, album_path(album) %> + Ranked: <%= album.ranked %> +
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index 4a8c3f0f2c..b43c2fcdbe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do + root 'welcome#index' + patch '/movies/:id/upvote' => 'movies#upvote', as: :movie_upvote patch '/books/:id/upvote' => 'books#upvote', as: :book_upvote patch '/albums/:id/upvote' => 'albums#upvote', as: :album_upvote From 02822b62fe262603c854cc41e18c7d3478969d21 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 15:57:53 -0800 Subject: [PATCH 18/64] Order by rank on root page --- app/controllers/welcome_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index ff03e63aba..3bbbcf1ddd 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,7 +1,7 @@ class WelcomeController < ApplicationController def index - @movies = Movie.all.limit(10) - @books = Book.all.limit(10) - @albums = Album.all.limit(10) + @movies = Movie.order(ranked: :desc).limit(10) + @books = Book.order(ranked: :desc).limit(10) + @albums = Album.order(ranked: :desc).limit(10) end end From e360b69b76de91a8c65495fb401b6dd52f4fc6cc Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 15:59:42 -0800 Subject: [PATCH 19/64] order by ranked on show pages --- app/controllers/albums_controller.rb | 3 ++- app/controllers/books_controller.rb | 2 +- app/controllers/movies_controller.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 87a888fdd9..5b6e5f0cef 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,6 +1,7 @@ class AlbumsController < ApplicationController def index - @albums = Album.all + @albums = Album.all.order(ranked: :desc) + Movie.order(ranked: :desc).limit(10) end def show diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 0a5ef1bbf9..506ec801f3 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,6 +1,6 @@ class BooksController < ApplicationController def index - @books = Book.all + @books = Book.order(ranked: :desc) end def show diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 751108a311..ea526a41ce 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,6 +1,6 @@ class MoviesController < ApplicationController def index - @movies = Movie.all + @movies = Movie.order(ranked: :desc) end def show From 8fb8a131d752acc7b0c295c2f0ea11efe4622dc8 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 16:04:21 -0800 Subject: [PATCH 20/64] Add links to index views on root view --- app/views/welcome/index.html.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 1fedf9010a..ca0d770ecf 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -4,15 +4,18 @@ Ranked: <%= movie.ranked %>
<% end %> +<%= link_to "View More Movies", movies_path %>

Top Books

<% @books.each do |book| %> <%= link_to book.name, book_path(book) %> Ranked: <%= book.ranked %>
<% end %> +<%= link_to "View More Books", books_path %>

Top Albums

<% @albums.each do |album| %> <%= link_to album.name, album_path(album) %> Ranked: <%= album.ranked %>
<% end %> +<%= link_to "View More Albums", books_path %> From c89bcee0ed6b13592ac9ac913572ab5868eb7982 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 16:06:58 -0800 Subject: [PATCH 21/64] Add View All Media button to index pages --- app/views/albums/index.html.erb | 2 +- app/views/books/index.html.erb | 2 +- app/views/movies/index.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index d0092f3791..59c53becd1 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -24,4 +24,4 @@ <% end %> -View All Media <%= button_to "Add an Album", new_album_path, method: :get %> +<%= button_to "View All Media", root_path, method: :get %> <%= button_to "Add an Album", new_album_path, method: :get %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index f3c539a4ad..c49352f18a 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -24,4 +24,4 @@ <% end %> -View All Media <%= button_to "Add a Book", new_book_path, method: :get %> +<%= button_to "View All Media", root_path, method: :get %> <%= button_to "Add a Book", new_book_path, method: :get %> diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index 0a8ead550c..7240880b0e 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -24,4 +24,4 @@ <% end %> -View All Media <%= button_to "Add a Movie", new_movie_path, method: :get %> +<%= button_to "View All Media", root_path, method: :get %> <%= button_to "Add a Movie", new_movie_path, method: :get %> From b6d27643279b382facead5533b5c320caf1a3d2f Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 16:10:03 -0800 Subject: [PATCH 22/64] Add Upvote button to index pages --- app/controllers/albums_controller.rb | 3 +-- app/views/albums/index.html.erb | 2 +- app/views/books/index.html.erb | 2 +- app/views/movies/index.html.erb | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 5b6e5f0cef..3000fea64f 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,7 +1,6 @@ class AlbumsController < ApplicationController def index - @albums = Album.all.order(ranked: :desc) - Movie.order(ranked: :desc).limit(10) + @albums = Album.order(ranked: :desc) end def show diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index 59c53becd1..92437eb2ab 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -19,7 +19,7 @@ <%= link_to album.name, album_path(album) %> - Upvote Button Will Go Here + <%= button_to "Upvote", album_upvote_path(album), method: :patch %> <% end %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index c49352f18a..714134b124 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -19,7 +19,7 @@ <%= link_to book.name, book_path(book) %> - Upvote Button Will Go Here + <%= button_to "Upvote", book_upvote_path(book), method: :patch %> <% end %> diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index 7240880b0e..d46e5dd600 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -19,7 +19,7 @@ <%= link_to movie.name, movie_path(movie) %> - Upvote Button Will Go Here + <%= button_to "Upvote", movie_upvote_path(movie), method: :patch %> <% end %> From bc49cc236234e244b896bf2786db57da65c83d54 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 16:17:16 -0800 Subject: [PATCH 23/64] Add links to index pages from show pages --- app/views/albums/show.html.erb | 2 +- app/views/books/show.html.erb | 2 +- app/views/movies/show.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index 18a94b5eda..1ea98adde3 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -8,4 +8,4 @@
<%= button_to "Upvote", album_upvote_path(@album), method: :patch %>
-<%= button_to "Edit #{@album.name}", edit_album_path(@album), method: :get %> <%= button_to "DELETE", "/albums/#{@album.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Albums Button Here View All Media Button Here +<%= button_to "Edit #{@album.name}", edit_album_path(@album), method: :get %> <%= button_to "DELETE", "/albums/#{@album.id}", method: "delete", data: { confirm: "Are you sure?" } %> <%= button_to "View All Albums", albums_path, method: :get %> <%= button_to "View All Media", root_path, method: :get %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index 52ed6ba823..ee01bbefbc 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -8,4 +8,4 @@
<%= button_to "Upvote", book_upvote_path(@book), method: :patch %>
-<%= button_to "Edit #{@book.name}", edit_book_path(@book), method: :get %> <%= button_to "DELETE", "/books/#{@book.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Books Button Here View All Media Button Here +<%= button_to "Edit #{@book.name}", edit_book_path(@book), method: :get %> <%= button_to "DELETE", "/books/#{@book.id}", method: "delete", data: { confirm: "Are you sure?" } %> <%= button_to "View All Books", books_path, method: :get %> <%= button_to "View All Media", root_path, method: :get %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 82173718b7..8267b69ab1 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -8,4 +8,4 @@
<%= button_to "Upvote", movie_upvote_path(@movie), method: :patch %>
-<%= button_to "Edit #{@movie.name}", edit_movie_path(@movie), method: :get %> <%= button_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" } %> View All Movies Button Here View All Media Button Here +<%= button_to "Edit #{@movie.name}", edit_movie_path(@movie), method: :get %> <%= button_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" } %> <%= button_to "View All Movies", movies_path, method: :get %> <%= button_to "View All Media", root_path, method: :get %> From ad730c9c5b181676185f970a1b30c235cf61606a Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 16:30:47 -0800 Subject: [PATCH 24/64] Add header, add validation to all 3 models --- app/models/album.rb | 1 + app/models/book.rb | 1 + app/models/movie.rb | 1 + app/views/layouts/application.html.erb | 1 + 4 files changed, 4 insertions(+) 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/app/models/movie.rb b/app/models/movie.rb index 49198a7d97..02e279fc1c 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,2 +1,3 @@ class Movie < ActiveRecord::Base + validates :name, presence: true end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2d02e8fbd4..16c3de2cc5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,6 +7,7 @@ <%= csrf_meta_tags %> +

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

<%= yield %> From 80ac7208b3c6f92e46b4bf994676cd0840cfb2fb Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 16:38:07 -0800 Subject: [PATCH 25/64] Add name validation for 3 models --- app/controllers/albums_controller.rb | 8 ++++++-- app/controllers/books_controller.rb | 8 ++++++-- app/controllers/movies_controller.rb | 8 ++++++-- app/views/welcome/index.html.erb | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 3000fea64f..3342337403 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -12,8 +12,12 @@ def new end def create - album = Album.create(album_params) - redirect_to album_path(album) + @album = Album.create(album_params) + if @album.save + redirect_to album_path(@album) + else + render "new" + end end def edit diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 506ec801f3..384eca31a4 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -12,8 +12,12 @@ def new end def create - book = Book.create(book_params) - redirect_to book_path(book) + @book = Book.create(book_params) + if @book.save + redirect_to book_path(@book) + else + render "new" + end end def edit diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index ea526a41ce..8a9265741f 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -12,8 +12,12 @@ def new end def create - movie = Movie.create(movie_params) - redirect_to movie_path(movie) + @movie = Movie.create(movie_params) + if @movie.save + redirect_to movie_path(@movie) + else + render "new" + end end def edit diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index ca0d770ecf..fd346e7845 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -18,4 +18,4 @@ Ranked: <%= album.ranked %>
<% end %> -<%= link_to "View More Albums", books_path %> +<%= link_to "View More Albums", albums_path %> From 3cda762a80cc653660affc477d480f4bd18d5746 Mon Sep 17 00:00:00 2001 From: Kelly Date: Mon, 30 Nov 2015 16:49:56 -0800 Subject: [PATCH 26/64] Added before_action to all 3 controllers --- app/controllers/albums_controller.rb | 19 ++++++++++--------- app/controllers/books_controller.rb | 19 ++++++++++--------- app/controllers/movies_controller.rb | 19 ++++++++++--------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 3342337403..9befc8368a 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,10 +1,15 @@ class AlbumsController < ApplicationController + before_action :get_album, only: [:show, :edit, :destroy, :upvote, :update] + + def get_album + @album = Album.find(params[:id]) + end + def index @albums = Album.order(ranked: :desc) end def show - @album = Album.find(params[:id]) end def new @@ -21,26 +26,22 @@ def create end def edit - @album = Album.find(params[:id]) end def update - @album = Album.find(params[:id]) @album.update(album_params) redirect_to album_path(@album) end def destroy - album = Album.find(params[:id]) - album.destroy + @album.destroy redirect_to albums_path end def upvote - album = Album.find(params[:id]) - album.ranked += 1 - album.save - redirect_to album_path(album) + @album.ranked += 1 + @album.save + redirect_to album_path(@album) end private diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 384eca31a4..a0b187980a 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,10 +1,15 @@ class BooksController < ApplicationController + before_action :get_book, only: [:show, :edit, :destroy, :upvote, :update] + + def get_book + @book = Book.find(params[:id]) + end + def index @books = Book.order(ranked: :desc) end def show - @book = Book.find(params[:id]) end def new @@ -21,26 +26,22 @@ def create end def edit - @book = Book.find(params[:id]) end def update - @book = Book.find(params[:id]) @book.update(book_params) redirect_to book_path(@book) end def destroy - book = Book.find(params[:id]) - book.destroy + @book.destroy redirect_to books_path end def upvote - book = Book.find(params[:id]) - book.ranked += 1 - book.save - redirect_to book_path(book) + @book.ranked += 1 + @book.save + redirect_to book_path(@book) end private diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 8a9265741f..8d0c3aedb3 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,10 +1,15 @@ class MoviesController < ApplicationController + before_action :get_movie, only: [:show, :edit, :destroy, :upvote, :update] + + def get_movie + @movie = Movie.find(params[:id]) + end + def index @movies = Movie.order(ranked: :desc) end def show - @movie = Movie.find(params[:id]) end def new @@ -21,26 +26,22 @@ def create end def edit - @movie = Movie.find(params[:id]) end def update - @movie = Movie.find(params[:id]) @movie.update(movie_params) redirect_to movie_path(@movie) end def destroy - movie = Movie.find(params[:id]) - movie.destroy + @movie.destroy redirect_to movies_path end def upvote - movie = Movie.find(params[:id]) - movie.ranked += 1 - movie.save - redirect_to movie_path(movie) + @movie.ranked += 1 + @movie.save + redirect_to movie_path(@movie) end private From 836d0af0dd31125dfe3719ac6b76cfe39e928472 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 11:08:31 -0800 Subject: [PATCH 27/64] Setup rspec and manually create files --- .rspec | 2 + Gemfile | 1 + Gemfile.lock | 19 +++++ spec/controllers/albums_controller_spec.rb | 10 +++ spec/controllers/books_controller_spec.rb | 10 +++ spec/controllers/movies_controller_spec.rb | 10 +++ spec/controllers/welcome_controller_spec.rb | 10 +++ spec/helpers/albums_helper_spec.rb | 15 ++++ spec/helpers/books_helper_spec.rb | 15 ++++ spec/helpers/movies_helper_spec.rb | 15 ++++ spec/models/album_spec.rb | 21 +++++ spec/models/book_spec.rb | 21 +++++ spec/models/movie_spec.rb | 21 +++++ spec/rails_helper.rb | 57 +++++++++++++ spec/spec_helper.rb | 92 +++++++++++++++++++++ 15 files changed, 319 insertions(+) create mode 100644 .rspec create mode 100644 spec/controllers/albums_controller_spec.rb create mode 100644 spec/controllers/books_controller_spec.rb create mode 100644 spec/controllers/movies_controller_spec.rb create mode 100644 spec/controllers/welcome_controller_spec.rb create mode 100644 spec/helpers/albums_helper_spec.rb create mode 100644 spec/helpers/books_helper_spec.rb create mode 100644 spec/helpers/movies_helper_spec.rb create mode 100644 spec/models/album_spec.rb create mode 100644 spec/models/book_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 5b9b12caea..64b52018db 100644 --- a/Gemfile +++ b/Gemfile @@ -37,6 +37,7 @@ gem 'rails-erd' 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/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb new file mode 100644 index 0000000000..4dfb328bd8 --- /dev/null +++ b/spec/controllers/albums_controller_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe AlbumsController, 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/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb new file mode 100644 index 0000000000..d04297370c --- /dev/null +++ b/spec/controllers/books_controller_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe BooksController, 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/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb new file mode 100644 index 0000000000..13ead9227e --- /dev/null +++ b/spec/controllers/movies_controller_spec.rb @@ -0,0 +1,10 @@ +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/controllers/welcome_controller_spec.rb b/spec/controllers/welcome_controller_spec.rb new file mode 100644 index 0000000000..8ca345d635 --- /dev/null +++ b/spec/controllers/welcome_controller_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe WelcomeController, 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/albums_helper_spec.rb b/spec/helpers/albums_helper_spec.rb new file mode 100644 index 0000000000..723772d171 --- /dev/null +++ b/spec/helpers/albums_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the AlbumsHelper. For example: +# +# describe AlbumsHelper 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 AlbumsHelper, type: :helper do + #pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/books_helper_spec.rb b/spec/helpers/books_helper_spec.rb new file mode 100644 index 0000000000..ac88fae54d --- /dev/null +++ b/spec/helpers/books_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the BooksHelper. For example: +# +# describe BooksHelper 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 BooksHelper, 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 new file mode 100644 index 0000000000..02d79d50ed --- /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 MoviesHelper. For example: +# +# describe MoviesHelper 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/album_spec.rb b/spec/models/album_spec.rb new file mode 100644 index 0000000000..e13406faa9 --- /dev/null +++ b/spec/models/album_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe Album, type: :model do + # describe ".validates" do + # it "must have a body" do + # expect(Post.new(body: nil)).to_not be_valid + # end + # + # it "can't have 141 characters" do + # expect(Post.new(body: "a" * 141)).to be_invalid + # end + # + # it "can have 140 characters" do + # expect(Post.new(body: "a" * 140)).to be_valid + # end + # end + # + # it "counts its characters" do + # expect(Post.new(body: "b" * 122).character_count).to eq 122 + # end +end diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb new file mode 100644 index 0000000000..8abf4a72bc --- /dev/null +++ b/spec/models/book_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe Book, type: :model do + # describe ".validates" do + # it "must have a body" do + # expect(Post.new(body: nil)).to_not be_valid + # end + # + # it "can't have 141 characters" do + # expect(Post.new(body: "a" * 141)).to be_invalid + # end + # + # it "can have 140 characters" do + # expect(Post.new(body: "a" * 140)).to be_valid + # end + # end + # + # it "counts its characters" do + # expect(Post.new(body: "b" * 122).character_count).to eq 122 + # end +end diff --git a/spec/models/movie_spec.rb b/spec/models/movie_spec.rb new file mode 100644 index 0000000000..427a03ce8f --- /dev/null +++ b/spec/models/movie_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe Movie, type: :model do + # describe ".validates" do + # it "must have a body" do + # expect(Post.new(body: nil)).to_not be_valid + # end + # + # it "can't have 141 characters" do + # expect(Post.new(body: "a" * 141)).to be_invalid + # end + # + # it "can have 140 characters" do + # expect(Post.new(body: "a" * 140)).to be_valid + # end + # end + # + # it "counts its characters" do + # expect(Post.new(body: "b" * 122).character_count).to eq 122 + # 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 2a1b470e28dd6e8075beecb37658b74266dd4c31 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 11:30:54 -0800 Subject: [PATCH 28/64] Add test to album spec --- spec/helpers/welcome_helper_spec.rb | 15 +++++++++++++++ spec/models/album_spec.rb | 23 ++++++----------------- 2 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 spec/helpers/welcome_helper_spec.rb diff --git a/spec/helpers/welcome_helper_spec.rb b/spec/helpers/welcome_helper_spec.rb new file mode 100644 index 0000000000..63ec43a202 --- /dev/null +++ b/spec/helpers/welcome_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the WelcomeHelper. For example: +# +# describe WelcomeHelper 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 WelcomeHelper, type: :helper do + #pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index e13406faa9..6264a8f4b9 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -1,21 +1,10 @@ require 'rails_helper' RSpec.describe Album, type: :model do - # describe ".validates" do - # it "must have a body" do - # expect(Post.new(body: nil)).to_not be_valid - # end - # - # it "can't have 141 characters" do - # expect(Post.new(body: "a" * 141)).to be_invalid - # end - # - # it "can have 140 characters" do - # expect(Post.new(body: "a" * 140)).to be_valid - # end - # end - # - # it "counts its characters" do - # expect(Post.new(body: "b" * 122).character_count).to eq 122 - # end + describe ".validates" do + it "must have a name" do + expect(Album.new(name: nil)).to_not be_valid + end + + end end From 78245b3a8f9018d1a821ce8ae9692e7d06e7027c Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 11:32:16 -0800 Subject: [PATCH 29/64] Add tests to movie and book specs --- spec/models/album_spec.rb | 1 - spec/models/book_spec.rb | 22 +++++----------------- spec/models/movie_spec.rb | 22 +++++----------------- 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index 6264a8f4b9..3674825d2b 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -5,6 +5,5 @@ it "must have a name" do expect(Album.new(name: nil)).to_not be_valid end - end end diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb index 8abf4a72bc..61adf8e84f 100644 --- a/spec/models/book_spec.rb +++ b/spec/models/book_spec.rb @@ -1,21 +1,9 @@ require 'rails_helper' RSpec.describe Book, type: :model do - # describe ".validates" do - # it "must have a body" do - # expect(Post.new(body: nil)).to_not be_valid - # end - # - # it "can't have 141 characters" do - # expect(Post.new(body: "a" * 141)).to be_invalid - # end - # - # it "can have 140 characters" do - # expect(Post.new(body: "a" * 140)).to be_valid - # end - # end - # - # it "counts its characters" do - # expect(Post.new(body: "b" * 122).character_count).to eq 122 - # end + describe ".validates" do + it "must have a name" do + expect(Book.new(name: nil)).to_not be_valid + end + end end diff --git a/spec/models/movie_spec.rb b/spec/models/movie_spec.rb index 427a03ce8f..cedd126408 100644 --- a/spec/models/movie_spec.rb +++ b/spec/models/movie_spec.rb @@ -1,21 +1,9 @@ require 'rails_helper' RSpec.describe Movie, type: :model do - # describe ".validates" do - # it "must have a body" do - # expect(Post.new(body: nil)).to_not be_valid - # end - # - # it "can't have 141 characters" do - # expect(Post.new(body: "a" * 141)).to be_invalid - # end - # - # it "can have 140 characters" do - # expect(Post.new(body: "a" * 140)).to be_valid - # end - # end - # - # it "counts its characters" do - # expect(Post.new(body: "b" * 122).character_count).to eq 122 - # end + describe ".validates" do + it "must have a name" do + expect(Movie.new(name: nil)).to_not be_valid + end + end end From a753812302e16e7595ba06d0326d94e993c37e53 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 11:35:16 -0800 Subject: [PATCH 30/64] Add GET index tests to controller specs --- spec/controllers/albums_controller_spec.rb | 12 ++++++------ spec/controllers/books_controller_spec.rb | 12 ++++++------ spec/controllers/movies_controller_spec.rb | 12 ++++++------ spec/controllers/welcome_controller_spec.rb | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 4dfb328bd8..a7b08018f6 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' RSpec.describe AlbumsController, type: :controller do - # describe "GET index" do - # it "is successful" do - # get :index - # expect(response.status).to eq 200 - # end - # end + describe "GET index" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end + end end diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index d04297370c..24d0160798 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' RSpec.describe BooksController, type: :controller do - # describe "GET index" do - # it "is successful" do - # get :index - # expect(response.status).to eq 200 - # end - # end + describe "GET index" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end + end end diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 13ead9227e..8d68cc1cd4 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -1,10 +1,10 @@ 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 index" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end + end end diff --git a/spec/controllers/welcome_controller_spec.rb b/spec/controllers/welcome_controller_spec.rb index 8ca345d635..d142c32388 100644 --- a/spec/controllers/welcome_controller_spec.rb +++ b/spec/controllers/welcome_controller_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' RSpec.describe WelcomeController, type: :controller do - # describe "GET index" do - # it "is successful" do - # get :index - # expect(response.status).to eq 200 - # end - # end + describe "GET index" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end + end end From f79af1ed723c48d43b86813f28e05448a46a2065 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 13:55:22 -0800 Subject: [PATCH 31/64] Added album controller tests for GET new, POST create, and GET show --- spec/controllers/albums_controller_spec.rb | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index a7b08018f6..a11ceb8d81 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -1,10 +1,40 @@ require 'rails_helper' RSpec.describe AlbumsController, type: :controller do - describe "GET index" do + describe "GET 'index'" do it "is successful" do get :index expect(response.status).to eq 200 end end + + describe "GET 'show'" do + album = Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") + + it "renders the show view" do + get :show, id: album.id + expect(subject).to render_template :show + 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 (:params) do + { + album: { name: "Test Album", description: "Album's description", artist: "Album's artist" + } + } + end + + it "redirects to show page" do + post :create, params + expect(subject).to redirect_to album_path(assigns(:album).id) + end + end end From 77f0c5214a9c03d0bd78f37eb2ce0294b7203edb Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 14:02:25 -0800 Subject: [PATCH 32/64] add test for post create with bad params (album controller) --- spec/controllers/albums_controller_spec.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index a11ceb8d81..0171bba04c 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -25,16 +25,29 @@ end describe "POST 'create'" do - let (:params) do + let (:good_params) do { album: { name: "Test Album", description: "Album's description", artist: "Album's artist" } } end + let (:bad_params) do + { + album: { description: "Album's description", artist: "Album's artist" + } + } + end + it "redirects to show page" do - post :create, params + post :create, good_params expect(subject).to redirect_to album_path(assigns(:album).id) end + + it "renders new template on error" do + post :create, bad_params + expect(subject).to render_template :new + end end + end From cab896fb72da2e9f2698a4fdf65d2ff9293c615e Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 14:34:29 -0800 Subject: [PATCH 33/64] Add album controller tests for edit with good params --- spec/controllers/albums_controller_spec.rb | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 0171bba04c..8bbf787316 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -50,4 +50,42 @@ end end + describe "GET 'edit'" do + album = Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") + + it "renders edit view" do + get :edit, id: album.id + expect(subject).to render_template :edit + end + end + + describe "PATCH 'update'" do + let (:album) do + Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") + end + + let (:good_params) do + { + album: { name: "Test Album", description: "Album's description", artist: "Album's artist" + } + } + end + + # let (:bad_params) do + # { + # album: { name: "", description: "Album's description", artist: "Album's artist" + # } + # } + # end + + it "redirects to show page" do + patch :update, id: album, album: good_params + expect(subject).to redirect_to album_path(album) + end + + # it "renders new template on error" do + # patch :update, bad_params + # expect(subject).to render_template :edit + # end + end end From 1c0060f1b193c21bdec66d4ecb8f2c2b8d88c301 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 15:57:37 -0800 Subject: [PATCH 34/64] complete album PATCH update tes --- app/controllers/albums_controller.rb | 6 ++++- spec/controllers/albums_controller_spec.rb | 30 +++++++++++++--------- spec/spec_helper.rb | 3 +++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 9befc8368a..8915fb83cb 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -30,7 +30,11 @@ def edit def update @album.update(album_params) - redirect_to album_path(@album) + if @album.save + redirect_to album_path(@album) + else + render "edit" + end end def destroy diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 8bbf787316..2847ba8aa9 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -66,26 +66,32 @@ let (:good_params) do { - album: { name: "Test Album", description: "Album's description", artist: "Album's artist" + id: album.id, + album: { name: "zzzTest Album", description: "zzzzAlbum's description", artist: "zzzAlbum's artist" } } end - # let (:bad_params) do - # { - # album: { name: "", description: "Album's description", artist: "Album's artist" - # } - # } - # end + let (:bad_params) do + { + id: album.id, + album: { name: "", description: "Album's description", artist: "Album's artist" + } + } + end it "redirects to show page" do - patch :update, id: album, album: good_params + patch :update, good_params expect(subject).to redirect_to album_path(album) + expect(Album.find(album.id).name).to eq "zzzTest Album" end - # it "renders new template on error" do - # patch :update, bad_params - # expect(subject).to render_template :edit - # end + it "renders edit template on error" do + patch :update, bad_params + expect(subject).to render_template :edit + expect(Album.find(album.id).name).to eq "Test Album" + end + + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61e27385c3..43e9c3f2ff 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,7 +16,10 @@ # users commonly want. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +require 'pry' 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. From 392006d838b4d32755129072bfa7112d323b3214 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 16:42:27 -0800 Subject: [PATCH 35/64] Add album destroy test --- spec/controllers/albums_controller_spec.rb | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 2847ba8aa9..b0561fc7ab 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -1,6 +1,8 @@ require 'rails_helper' RSpec.describe AlbumsController, type: :controller do + + describe "GET 'index'" do it "is successful" do get :index @@ -91,7 +93,28 @@ expect(subject).to render_template :edit expect(Album.find(album.id).name).to eq "Test Album" end + end + + describe "DELETE 'destroy'" do + album = Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") + + it "redirects to index page" do + delete :destroy, id: album.id + expect(subject).to redirect_to albums_path + end + end + + describe "PATCH 'upvote'" do + album = Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") + it "increases ranked by 1" do + patch :upvote, id: album.id + expect(Album.find(album.id).ranked).to eq 1 + end + it "redirects to show page" do + patch :upvote, id: album.id + expect(subject).to redirect_to album_path(album) + end end end From cfdf59982518f2d8ea3b9bc1366f03546fcc602d Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 16:47:15 -0800 Subject: [PATCH 36/64] in albums test, defined album object via let before any of the class's methods --- spec/controllers/albums_controller_spec.rb | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index b0561fc7ab..2530bc1907 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -1,7 +1,9 @@ require 'rails_helper' RSpec.describe AlbumsController, type: :controller do - + let (:album) do + Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") + end describe "GET 'index'" do it "is successful" do @@ -11,8 +13,6 @@ end describe "GET 'show'" do - album = Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") - it "renders the show view" do get :show, id: album.id expect(subject).to render_template :show @@ -53,8 +53,6 @@ end describe "GET 'edit'" do - album = Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") - it "renders edit view" do get :edit, id: album.id expect(subject).to render_template :edit @@ -62,10 +60,6 @@ end describe "PATCH 'update'" do - let (:album) do - Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") - end - let (:good_params) do { id: album.id, @@ -96,8 +90,6 @@ end describe "DELETE 'destroy'" do - album = Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") - it "redirects to index page" do delete :destroy, id: album.id expect(subject).to redirect_to albums_path @@ -105,8 +97,6 @@ end describe "PATCH 'upvote'" do - album = Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") - it "increases ranked by 1" do patch :upvote, id: album.id expect(Album.find(album.id).ranked).to eq 1 From d23dd2b0093f440fa1917f273b6b31eb5d06c99b Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 16:54:11 -0800 Subject: [PATCH 37/64] Add book controller tests --- app/controllers/books_controller.rb | 6 +- spec/controllers/books_controller_spec.rb | 102 +++++++++++++++++++++- 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index a0b187980a..53f4cadf87 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -30,7 +30,11 @@ def edit def update @book.update(book_params) - redirect_to book_path(@book) + if @book.save + redirect_to book_path(@book) + else + render "edit" + end end def destroy diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index 24d0160798..c4fa3d4e8d 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -1,10 +1,110 @@ require 'rails_helper' RSpec.describe BooksController, type: :controller do - describe "GET index" do + let (:book) do + Book.create(name: "Test Book", description: "Book's description", author: "Book's author") + end + + describe "GET 'index'" do it "is successful" do get :index expect(response.status).to eq 200 end end + + describe "GET 'show'" do + it "renders the show view" do + get :show, id: book.id + expect(subject).to render_template :show + 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 + { + book: { name: "Test Book", description: "Book's description", author: "Book's author" + } + } + end + + let (:bad_params) do + { + book: { description: "Book's description", author: "Book's author" + } + } + end + + it "redirects to show page" do + post :create, good_params + expect(subject).to redirect_to book_path(assigns(:book).id) + end + + it "renders new template on error" do + post :create, bad_params + expect(subject).to render_template :new + end + end + + describe "GET 'edit'" do + it "renders edit view" do + get :edit, id: book.id + expect(subject).to render_template :edit + end + end + + describe "PATCH 'update'" do + let (:good_params) do + { + id: book.id, + book: { name: "zzzTest Book", description: "zzzzBook's description", author: "zzzBook's author" + } + } + end + + let (:bad_params) do + { + id: book.id, + book: { name: "", description: "Book's description", author: "Book's author" + } + } + end + + it "redirects to show page" do + patch :update, good_params + expect(subject).to redirect_to book_path(book) + expect(Book.find(book.id).name).to eq "zzzTest Book" + end + + it "renders edit template on error" do + patch :update, bad_params + expect(subject).to render_template :edit + expect(Book.find(book.id).name).to eq "Test Book" + end + end + + describe "DELETE 'destroy'" do + it "redirects to index page" do + delete :destroy, id: book.id + expect(subject).to redirect_to books_path + end + end + + describe "PATCH 'upvote'" do + it "increases ranked by 1" do + patch :upvote, id: book.id + expect(Book.find(book.id).ranked).to eq 1 + end + + it "redirects to show page" do + patch :upvote, id: book.id + expect(subject).to redirect_to book_path(book) + end + end end From c46ed1ac0d174f3f4046bd1f7a98152714ea688b Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 1 Dec 2015 16:55:55 -0800 Subject: [PATCH 38/64] Added controller tests for movie --- app/controllers/movies_controller.rb | 6 +- spec/controllers/movies_controller_spec.rb | 102 ++++++++++++++++++++- 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 8d0c3aedb3..a4affa988c 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -30,7 +30,11 @@ def edit def update @movie.update(movie_params) - redirect_to movie_path(@movie) + if @movie.save + redirect_to movie_path(@movie) + else + render "edit" + end end def destroy diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 8d68cc1cd4..17e41ed93f 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -1,10 +1,110 @@ require 'rails_helper' RSpec.describe MoviesController, type: :controller do - describe "GET index" do + let (:movie) do + Movie.create(name: "Test Movie", description: "Movie's description", director: "Movie's director") + end + + describe "GET 'index'" do it "is successful" do get :index expect(response.status).to eq 200 end end + + describe "GET 'show'" do + it "renders the show view" do + get :show, id: movie.id + expect(subject).to render_template :show + 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: "Test Movie", description: "Movie's description", director: "Movie's director" + } + } + end + + let (:bad_params) do + { + movie: { description: "Movie's description", director: "Movie's director" + } + } + end + + it "redirects to show page" do + post :create, good_params + expect(subject).to redirect_to movie_path(assigns(:movie).id) + end + + it "renders new template on error" do + post :create, bad_params + expect(subject).to render_template :new + end + end + + describe "GET 'edit'" do + it "renders edit view" do + get :edit, id: movie.id + expect(subject).to render_template :edit + end + end + + describe "PATCH 'update'" do + let (:good_params) do + { + id: movie.id, + movie: { name: "zzzTest Movie", description: "zzzzMovie's description", director: "zzzMovie's director" + } + } + end + + let (:bad_params) do + { + id: movie.id, + movie: { name: "", description: "Movie's description", director: "Movie's director" + } + } + end + + it "redirects to show page" do + patch :update, good_params + expect(subject).to redirect_to movie_path(movie) + expect(Movie.find(movie.id).name).to eq "zzzTest Movie" + end + + it "renders edit template on error" do + patch :update, bad_params + expect(subject).to render_template :edit + expect(Movie.find(movie.id).name).to eq "Test Movie" + end + end + + describe "DELETE 'destroy'" do + it "redirects to index page" do + delete :destroy, id: movie.id + expect(subject).to redirect_to movies_path + end + end + + describe "PATCH 'upvote'" do + it "increases ranked by 1" do + patch :upvote, id: movie.id + expect(Movie.find(movie.id).ranked).to eq 1 + end + + it "redirects to show page" do + patch :upvote, id: movie.id + expect(subject).to redirect_to movie_path(movie) + end + end end From 4ea084bdb5f61c5dc6f99afa67f1f87ee67e7d01 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 2 Dec 2015 13:46:14 -0800 Subject: [PATCH 39/64] Add SimpleCov gem --- .gitignore | 1 + Gemfile | 2 ++ Gemfile.lock | 7 +++++++ spec/spec_helper.rb | 7 +++++-- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 050c9d95c7..6d3b796529 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ /log/* !/log/.keep /tmp +coverage diff --git a/Gemfile b/Gemfile index 64b52018db..49f2aed9df 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,8 @@ gem 'sdoc', '~> 0.4.0', group: :doc gem 'rails-erd' +gem 'simplecov', :require => false, :group => :test + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' diff --git a/Gemfile.lock b/Gemfile.lock index dd55459cce..a9721d73b2 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.1) + 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/spec/spec_helper.rb b/spec/spec_helper.rb index 43e9c3f2ff..6242547dd7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,6 @@ +require 'simplecov' +SimpleCov.start + # 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 @@ -18,8 +21,6 @@ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration require 'pry' 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. @@ -43,6 +44,8 @@ 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 From e79c849f2b1dfcbd352360d3ea63c39e993171da Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 2 Dec 2015 13:53:34 -0800 Subject: [PATCH 40/64] Add bootstrap gem --- Gemfile | 2 ++ Gemfile.lock | 7 +++++++ app/assets/javascripts/application.js | 1 + .../stylesheets/{application.css => application.scss} | 5 +++-- app/views/layouts/application.html.erb | 6 +++--- 5 files changed, 16 insertions(+), 5 deletions(-) rename app/assets/stylesheets/{application.css => application.scss} (82%) diff --git a/Gemfile b/Gemfile index 49f2aed9df..f541dc8d72 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,8 @@ source 'https://rubygems.org' gem 'rails', '4.2.5' # Use sqlite3 as the database for Active Record gem 'sqlite3' +# Bootstrap for styling: +gem 'bootstrap-sass', '~> 3.3.6' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets diff --git a/Gemfile.lock b/Gemfile.lock index a9721d73b2..244482acb0 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/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 82% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index f9cd5b3483..441df06919 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.scss @@ -10,6 +10,7 @@ * 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 */ + // "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables" + @import "bootstrap-sprockets"; + @import "bootstrap"; diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 16c3de2cc5..48a2d51779 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,8 +8,8 @@

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

- -<%= yield %> - +
+ <%= yield %> +
From 131373ef86ba34148a05386cee11317304fde3af Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 2 Dec 2015 14:42:08 -0800 Subject: [PATCH 41/64] Style header --- app/assets/images/owl.jpg | Bin 0 -> 13218 bytes app/assets/stylesheets/application.scss | 12 ++++++ app/views/layouts/application.html.erb | 6 ++- app/views/welcome/index.html.erb | 50 ++++++++++++++---------- 4 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 app/assets/images/owl.jpg 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 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 ZFR+vzabUC16e0W$Ojvqq0Gd4dzW|J{wv7M) literal 0 HcmV?d00001 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 441df06919..303a7a5cb3 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -14,3 +14,15 @@ // "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables" @import "bootstrap-sprockets"; @import "bootstrap"; + + .page-header { + background: url(/assets/owl.jpg); + background-repeat: no-repeat; + padding-bottom: 9px; + margin: 40px 0 20px; + border-bottom: 1px solid #eee; + } + + .page-header h1 { + margin-left: 150px; + } diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 48a2d51779..65ba754f3f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,8 +7,12 @@ <%= csrf_meta_tags %> -

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

+
+ +
<%= yield %>
diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index fd346e7845..793099793d 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -1,21 +1,29 @@ -

Top Movies

-<% @movies.each do |movie| %> - <%= link_to movie.name, movie_path(movie) %> - Ranked: <%= movie.ranked %> -
-<% end %> -<%= link_to "View More Movies", movies_path %> -

Top Books

-<% @books.each do |book| %> - <%= link_to book.name, book_path(book) %> - Ranked: <%= book.ranked %> -
-<% end %> -<%= link_to "View More Books", books_path %> -

Top Albums

-<% @albums.each do |album| %> - <%= link_to album.name, album_path(album) %> - Ranked: <%= album.ranked %> -
-<% end %> -<%= link_to "View More Albums", albums_path %> +
+
+

Top Movies

+ <% @movies.each do |movie| %> + <%= link_to movie.name, movie_path(movie) %> + Ranked: <%= movie.ranked %> +
+ <% end %> + <%= link_to "View More Movies", movies_path %> +
+
+

Top Books

+ <% @books.each do |book| %> + <%= link_to book.name, book_path(book) %> + Ranked: <%= book.ranked %> +
+ <% end %> + <%= link_to "View More Books", books_path %> +
+
+

Top Albums

+ <% @albums.each do |album| %> + <%= link_to album.name, album_path(album) %> + Ranked: <%= album.ranked %> +
+ <% end %> + <%= link_to "View More Albums", albums_path %> +
+
From c8c91a43cc0adea539c6eb9fba5cf1ca07e4ed96 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 2 Dec 2015 14:56:30 -0800 Subject: [PATCH 42/64] Add bootstrap styling to home page --- app/assets/stylesheets/application.scss | 4 ++++ app/views/welcome/index.html.erb | 15 ++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 303a7a5cb3..30a840a2c2 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -26,3 +26,7 @@ .page-header h1 { margin-left: 150px; } + + a { + color: #428bca; + } diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 793099793d..8df9d568ac 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -2,27 +2,24 @@

Top Movies

<% @movies.each do |movie| %> - <%= link_to movie.name, movie_path(movie) %> - Ranked: <%= movie.ranked %> -
+

<%= link_to movie.name, movie_path(movie) %> + Ranked: <%= movie.ranked %>

<% end %> <%= link_to "View More Movies", movies_path %>

Top Books

<% @books.each do |book| %> - <%= link_to book.name, book_path(book) %> - Ranked: <%= book.ranked %> -
+

<%= link_to book.name, book_path(book) %> + Ranked: <%= book.ranked %>

<% end %> <%= link_to "View More Books", books_path %>

Top Albums

<% @albums.each do |album| %> - <%= link_to album.name, album_path(album) %> - Ranked: <%= album.ranked %> -
+

<%= link_to album.name, album_path(album) %> + Ranked: <%= album.ranked %>

<% end %> <%= link_to "View More Albums", albums_path %>
From fcad9cb56196f5e113189d6336104b47a6d65b3e Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 2 Dec 2015 15:32:22 -0800 Subject: [PATCH 43/64] Add bootstrap styling to movie index page --- app/views/movies/index.html.erb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index d46e5dd600..6023216008 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -1,4 +1,4 @@ - +
<% end %>
Ranking @@ -19,9 +19,10 @@ <%= link_to movie.name, movie_path(movie) %> - <%= button_to "Upvote", movie_upvote_path(movie), method: :patch %> + <%= button_to "Upvote", movie_upvote_path(movie), method: :patch, class: "btn btn-default" %>
-<%= button_to "View All Media", root_path, method: :get %> <%= button_to "Add a Movie", new_movie_path, method: :get %> +
View All Media +Add a Movie From 464b1d46b932bc296905e8767e957ce4af4a3506 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 2 Dec 2015 16:01:51 -0800 Subject: [PATCH 44/64] Added some boostrap styling to movie show page --- app/assets/stylesheets/application.scss | 4 ++++ app/views/movies/index.html.erb | 4 ++-- app/views/movies/show.html.erb | 7 ++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 30a840a2c2..054f25fd45 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -30,3 +30,7 @@ a { color: #428bca; } + +form .btn-primary { + margin-bottom: 10px; +} diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index 6023216008..a783d63cd6 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -24,5 +24,5 @@ <% end %> -View All Media -Add a Movie +<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> +<%= link_to "Add a Movie", new_movie_path, method: :get, class: "btn btn-default" %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 8267b69ab1..09951ea813 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -6,6 +6,7 @@ <%= @movie.description %>


-<%= button_to "Upvote", movie_upvote_path(@movie), method: :patch %> -
-<%= button_to "Edit #{@movie.name}", edit_movie_path(@movie), method: :get %> <%= button_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" } %> <%= button_to "View All Movies", movies_path, method: :get %> <%= button_to "View All Media", root_path, method: :get %> +<%= button_to "Upvote", movie_upvote_path(@movie), method: :patch, class: "btn btn-primary" %> +<%= link_to "Edit #{@movie.name}", edit_movie_path(@movie), method: :get, class: "btn btn-default" %> +<%= link_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> +<%= link_to "View All Movies", movies_path, method: :get, class: "btn btn-default" %> <%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> From ab3ec4718ced35f36fb8fb174a203cce4ba5f477 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 10:41:00 -0800 Subject: [PATCH 45/64] Style edit and new movie views with bootsrap --- app/views/movies/_form.html.erb | 27 ++++++++++++--------------- app/views/movies/edit.html.erb | 8 ++++++-- app/views/movies/new.html.erb | 8 ++++++-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb index b927675f66..965fb666db 100644 --- a/app/views/movies/_form.html.erb +++ b/app/views/movies/_form.html.erb @@ -1,15 +1,12 @@ -<%= form_for @movie do |f| %> - <%= f.label :name %> -
- <%= f.text_field :name %> -
- <%= f.label :director %> -
- <%= f.text_field :director %> -
- <%= f.label :description %> -
- <%= f.text_area :description %> -
- <%= f.submit "Save" %> -<% end %> +
+ <%= form_for @movie do |f| %> + <%= 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.submit "Save", class: "btn btn-default" %> + <% end %> +
diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb index a6dc942fcd..77f5ffe054 100644 --- a/app/views/movies/edit.html.erb +++ b/app/views/movies/edit.html.erb @@ -1,2 +1,6 @@ -

Edit Movie

-<%= render 'form' %> +
+
+

Edit Movie

+ <%= render 'form' %> +
+
diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb index 4987ff793a..053bad5181 100644 --- a/app/views/movies/new.html.erb +++ b/app/views/movies/new.html.erb @@ -1,2 +1,6 @@ -

New Movie

-<%= render 'form' %> +
+
+

New Movie

+ <%= render 'form' %> +
+
From e1c51e8ef5cc17f1ccb14e502ae27fd952665b23 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 10:53:38 -0800 Subject: [PATCH 46/64] Finish styling movie show page with bootstrap --- app/views/movies/edit.html.erb | 8 ++------ app/views/movies/new.html.erb | 8 ++------ app/views/movies/show.html.erb | 7 ++----- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb index 77f5ffe054..87a6c641f1 100644 --- a/app/views/movies/edit.html.erb +++ b/app/views/movies/edit.html.erb @@ -1,6 +1,2 @@ -
-
-

Edit Movie

- <%= render 'form' %> -
-
+

Edit Movie

+<%= render 'form' %> diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb index 053bad5181..846ce77309 100644 --- a/app/views/movies/new.html.erb +++ b/app/views/movies/new.html.erb @@ -1,6 +1,2 @@ -
-
-

New Movie

- <%= render 'form' %> -
-
+

New Movie

+<%= render 'form' %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 09951ea813..7329bd711e 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -1,11 +1,8 @@ -

<%= @movie.name %>

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

-
-

Ranked: <%= @movie.ranked %>

-
+

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

+

Ranked: <%= @movie.ranked %>

<%= @movie.description %>

-
<%= button_to "Upvote", movie_upvote_path(@movie), method: :patch, class: "btn btn-primary" %> <%= link_to "Edit #{@movie.name}", edit_movie_path(@movie), method: :get, class: "btn btn-default" %> <%= link_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> From 6dee57cdae26590b1fcd21f4b710ffc00e4767be Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 11:19:16 -0800 Subject: [PATCH 47/64] Add bootstrap styling to all views of albums and books --- app/views/albums/_form.html.erb | 27 ++++++++++++--------------- app/views/albums/edit.html.erb | 2 +- app/views/albums/index.html.erb | 7 ++++--- app/views/albums/new.html.erb | 2 +- app/views/albums/show.html.erb | 15 +++++++-------- app/views/books/_form.html.erb | 27 ++++++++++++--------------- app/views/books/edit.html.erb | 2 +- app/views/books/index.html.erb | 7 ++++--- app/views/books/new.html.erb | 2 +- app/views/books/show.html.erb | 15 +++++++-------- app/views/movies/show.html.erb | 3 ++- 11 files changed, 52 insertions(+), 57 deletions(-) diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb index 8d87ed5cbe..4bfb2fd64d 100644 --- a/app/views/albums/_form.html.erb +++ b/app/views/albums/_form.html.erb @@ -1,15 +1,12 @@ -<%= form_for @album do |f| %> - <%= f.label :name %> -
- <%= f.text_field :name %> -
- <%= f.label :artist %> -
- <%= f.text_field :artist %> -
- <%= f.label :description %> -
- <%= f.text_area :description %> -
- <%= f.submit "Save" %> -<% end %> +
+ <%= form_for @album do |f| %> + <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> + <%= f.label :artist %> + <%= f.text_field :artist, class: "form-control" %> + <%= f.label :description %> + <%= f.text_area :description, class: "form-control" %> +
+ <%= f.submit "Save", class: "btn btn-default" %> + <% end %> +
diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb index 354306603e..3e79476e02 100644 --- a/app/views/albums/edit.html.erb +++ b/app/views/albums/edit.html.erb @@ -1,2 +1,2 @@ -

Edit Album

+

Edit Album

<%= render 'form' %> diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index 92437eb2ab..bdf3ee2fe1 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -1,4 +1,4 @@ - +
<% end %>
Ranking @@ -19,9 +19,10 @@ <%= link_to album.name, album_path(album) %> - <%= button_to "Upvote", album_upvote_path(album), method: :patch %> + <%= button_to "Upvote", album_upvote_path(album), method: :patch, class: "btn btn-default" %>
-<%= button_to "View All Media", root_path, method: :get %> <%= button_to "Add an Album", new_album_path, method: :get %> +<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> + <%= link_to "Add an Album", new_album_path, method: :get, class: "btn btn-default" %> diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb index 4cc6b207a1..3a32a180fa 100644 --- a/app/views/albums/new.html.erb +++ b/app/views/albums/new.html.erb @@ -1,2 +1,2 @@ -

New Album

+

New Album

<%= render 'form' %> diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index 1ea98adde3..da3951d763 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -1,11 +1,10 @@ -

<%= @album.name %>

Recorded by: <%= @album.artist%>

-
-

Ranked: <%= @album.ranked %>

-
+

<%= @album.name %> Recorded by: <%= @album.artist%>

+

Ranked: <%= @album.ranked %>

<%= @album.description %>

-
-<%= button_to "Upvote", album_upvote_path(@album), method: :patch %> -
-<%= button_to "Edit #{@album.name}", edit_album_path(@album), method: :get %> <%= button_to "DELETE", "/albums/#{@album.id}", method: "delete", data: { confirm: "Are you sure?" } %> <%= button_to "View All Albums", albums_path, method: :get %> <%= button_to "View All Media", root_path, method: :get %> +<%= button_to "Upvote", album_upvote_path(@album), method: :patch, class: "btn btn-primary" %> +<%= link_to "Edit #{@album.name}", edit_album_path(@album), method: :get, class: "btn btn-default" %> +<%= link_to "DELETE", "/albums/#{@album.id}", method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> +<%= link_to "View All Albums", albums_path, method: :get, class: "btn btn-default" %> +<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb index b5b62717ae..0c71800fcb 100644 --- a/app/views/books/_form.html.erb +++ b/app/views/books/_form.html.erb @@ -1,15 +1,12 @@ -<%= form_for @book do |f| %> - <%= f.label :name %> -
- <%= f.text_field :name %> -
- <%= f.label :author %> -
- <%= f.text_field :author %> -
- <%= f.label :description %> -
- <%= f.text_area :description %> -
- <%= f.submit "Save" %> -<% end %> +
+ <%= form_for @book do |f| %> + <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> + <%= f.label :author %> + <%= f.text_field :author, class: "form-control" %> + <%= f.label :description %> + <%= f.text_area :description, class: "form-control" %> +
+ <%= f.submit "Save", class: "btn btn-default" %> + <% end %> +
diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb index 49e2b8b1fa..840e1fcd4f 100644 --- a/app/views/books/edit.html.erb +++ b/app/views/books/edit.html.erb @@ -1,2 +1,2 @@ -

Edit Book

+

Edit Book

<%= render 'form' %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index 714134b124..5ef368eb33 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -1,4 +1,4 @@ - +
<% end %>
Ranking @@ -19,9 +19,10 @@ <%= link_to book.name, book_path(book) %> - <%= button_to "Upvote", book_upvote_path(book), method: :patch %> + <%= button_to "Upvote", book_upvote_path(book), method: :patch, class: "btn btn-default" %>
-<%= button_to "View All Media", root_path, method: :get %> <%= button_to "Add a Book", new_book_path, method: :get %> +<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> +<%= link_to "Add a Book", new_book_path, method: :get, class: "btn btn-default" %> diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb index 068b2dc310..cd36e15933 100644 --- a/app/views/books/new.html.erb +++ b/app/views/books/new.html.erb @@ -1,2 +1,2 @@ -

New Book

+

New Book

<%= render 'form' %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index ee01bbefbc..eee6c85690 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -1,11 +1,10 @@ -

<%= @book.name %>

Written by: <%= @book.author%>

-
-

Ranked: <%= @book.ranked %>

-
+

<%= @book.name %> Written by: <%= @book.author%>

+

Ranked: <%= @book.ranked %>

<%= @book.description %>

-
-<%= button_to "Upvote", book_upvote_path(@book), method: :patch %> -
-<%= button_to "Edit #{@book.name}", edit_book_path(@book), method: :get %> <%= button_to "DELETE", "/books/#{@book.id}", method: "delete", data: { confirm: "Are you sure?" } %> <%= button_to "View All Books", books_path, method: :get %> <%= button_to "View All Media", root_path, method: :get %> +<%= button_to "Upvote", book_upvote_path(@book), method: :patch, class: "btn btn-primary" %> +<%= link_to "Edit #{@book.name}", edit_book_path(@book), method: :get, class: "btn btn-default" %> +<%= link_to "DELETE", "/books/#{@book.id}", method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> +<%= link_to "View All Books", books_path, method: :get, class: "btn btn-default" %> +<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 7329bd711e..d89cb43524 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -6,4 +6,5 @@ <%= button_to "Upvote", movie_upvote_path(@movie), method: :patch, class: "btn btn-primary" %> <%= link_to "Edit #{@movie.name}", edit_movie_path(@movie), method: :get, class: "btn btn-default" %> <%= link_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> -<%= link_to "View All Movies", movies_path, method: :get, class: "btn btn-default" %> <%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> +<%= link_to "View All Movies", movies_path, method: :get, class: "btn btn-default" %> +<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> From e833054e2de2b9d00a8fc84029bea7c447893b6c Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 12:14:19 -0800 Subject: [PATCH 48/64] Add shared example for model specs --- spec/models/album_spec.rb | 6 +----- spec/models/book_spec.rb | 6 +----- spec/models/movie_spec.rb | 6 +----- spec/spec_helper.rb | 7 ++++++- spec/support/medium_model_spec.rb | 9 +++++++++ 5 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 spec/support/medium_model_spec.rb diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index 3674825d2b..2738352a3d 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -1,9 +1,5 @@ require 'rails_helper' RSpec.describe Album, type: :model do - describe ".validates" do - it "must have a name" do - expect(Album.new(name: nil)).to_not be_valid - end - end + it_behaves_like "a medium model" end diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb index 61adf8e84f..3d377d1cb9 100644 --- a/spec/models/book_spec.rb +++ b/spec/models/book_spec.rb @@ -1,9 +1,5 @@ require 'rails_helper' RSpec.describe Book, type: :model do - describe ".validates" do - it "must have a name" do - expect(Book.new(name: nil)).to_not be_valid - end - end + it_behaves_like "a medium model" end diff --git a/spec/models/movie_spec.rb b/spec/models/movie_spec.rb index cedd126408..a81e6430de 100644 --- a/spec/models/movie_spec.rb +++ b/spec/models/movie_spec.rb @@ -1,9 +1,5 @@ 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 model" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6242547dd7..6e83295cf9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,8 @@ require 'simplecov' -SimpleCov.start +require 'rails_helper' +SimpleCov.start do + add_filter '/support/' +end # 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`. @@ -21,6 +24,8 @@ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration require 'pry' RSpec.configure do |config| + config.include Rails.application.routes.url_helpers + Dir["./spec/support/**/*.rb"].sort.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_model_spec.rb b/spec/support/medium_model_spec.rb new file mode 100644 index 0000000000..5421b7e96c --- /dev/null +++ b/spec/support/medium_model_spec.rb @@ -0,0 +1,9 @@ +RSpec.shared_examples "a medium model" do + describe "model validations" do + it "requires a name" do + medium = described_class.new(name: nil) + expect(medium).to be_invalid + expect(medium.errors.keys).to include :name + end + end +end From 0b63f4f8d32669565fb37ce73c2f6d9731b8a510 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 12:26:19 -0800 Subject: [PATCH 49/64] Add shared example test for 3 controllers for GET index --- spec/controllers/albums_controller_spec.rb | 9 ++------- spec/controllers/books_controller_spec.rb | 9 ++------- spec/controllers/movies_controller_spec.rb | 9 ++------- spec/support/medium_controller_spec.rb | 10 ++++++++++ 4 files changed, 16 insertions(+), 21 deletions(-) create mode 100644 spec/support/medium_controller_spec.rb diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 2530bc1907..5629f4b70f 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -1,17 +1,12 @@ require 'rails_helper' RSpec.describe AlbumsController, type: :controller do + it_behaves_like "a medium controller" + let (:album) do Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") end - describe "GET 'index'" do - it "is successful" do - get :index - expect(response.status).to eq 200 - end - end - describe "GET 'show'" do it "renders the show view" do get :show, id: album.id diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index c4fa3d4e8d..b2c9e78ff3 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -1,17 +1,12 @@ require 'rails_helper' RSpec.describe BooksController, type: :controller do + it_behaves_like "a medium controller" + let (:book) do Book.create(name: "Test Book", description: "Book's description", author: "Book's author") end - describe "GET 'index'" do - it "is successful" do - get :index - expect(response.status).to eq 200 - end - end - describe "GET 'show'" do it "renders the show view" do get :show, id: book.id diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 17e41ed93f..f0c2bc4189 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -1,17 +1,12 @@ require 'rails_helper' RSpec.describe MoviesController, type: :controller do + it_behaves_like "a medium controller" + let (:movie) do Movie.create(name: "Test Movie", description: "Movie's description", director: "Movie's director") end - describe "GET 'index'" do - it "is successful" do - get :index - expect(response.status).to eq 200 - end - end - describe "GET 'show'" do it "renders the show view" do get :show, id: movie.id diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb new file mode 100644 index 0000000000..238cdac7ed --- /dev/null +++ b/spec/support/medium_controller_spec.rb @@ -0,0 +1,10 @@ +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 + + +end From 79af199363f6107c29c58541c407243234290117 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 14:05:10 -0800 Subject: [PATCH 50/64] Add shared examples for show and new tests --- spec/controllers/albums_controller_spec.rb | 187 ++++++++--------- spec/controllers/books_controller_spec.rb | 186 ++++++++--------- spec/controllers/movies_controller_spec.rb | 193 +++++++++--------- spec/models/album_spec.rb | 2 +- spec/models/book_spec.rb | 2 +- spec/models/movie_spec.rb | 2 +- spec/support/medium_controller_spec.rb | 16 +- .../{medium_model_spec.rb => medium_spec.rb} | 2 +- 8 files changed, 288 insertions(+), 302 deletions(-) rename spec/support/{medium_model_spec.rb => medium_spec.rb} (83%) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 5629f4b70f..6f39c2aa5e 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -1,105 +1,94 @@ require 'rails_helper' RSpec.describe AlbumsController, type: :controller do - it_behaves_like "a medium controller" - - let (:album) do - Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") - end - - describe "GET 'show'" do - it "renders the show view" do - get :show, id: album.id - expect(subject).to render_template :show - end + it_behaves_like "a medium controller" do + let(:model) { Album } 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 - { - album: { name: "Test Album", description: "Album's description", artist: "Album's artist" - } - } - end - - let (:bad_params) do - { - album: { description: "Album's description", artist: "Album's artist" - } - } - end - - it "redirects to show page" do - post :create, good_params - expect(subject).to redirect_to album_path(assigns(:album).id) - end - - it "renders new template on error" do - post :create, bad_params - expect(subject).to render_template :new - end - end - - describe "GET 'edit'" do - it "renders edit view" do - get :edit, id: album.id - expect(subject).to render_template :edit - end - end - - describe "PATCH 'update'" do - let (:good_params) do - { - id: album.id, - album: { name: "zzzTest Album", description: "zzzzAlbum's description", artist: "zzzAlbum's artist" - } - } - end - - let (:bad_params) do - { - id: album.id, - album: { name: "", description: "Album's description", artist: "Album's artist" - } - } - end - - it "redirects to show page" do - patch :update, good_params - expect(subject).to redirect_to album_path(album) - expect(Album.find(album.id).name).to eq "zzzTest Album" - end - - it "renders edit template on error" do - patch :update, bad_params - expect(subject).to render_template :edit - expect(Album.find(album.id).name).to eq "Test Album" - end - end - - describe "DELETE 'destroy'" do - it "redirects to index page" do - delete :destroy, id: album.id - expect(subject).to redirect_to albums_path - end - end - - describe "PATCH 'upvote'" do - it "increases ranked by 1" do - patch :upvote, id: album.id - expect(Album.find(album.id).ranked).to eq 1 - end - - it "redirects to show page" do - patch :upvote, id: album.id - expect(subject).to redirect_to album_path(album) - end - end + # let (:album) do + # Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") + # end + + + # describe "POST 'create'" do + # let (:good_params) do + # { + # album: { name: "Test Album", description: "Album's description", artist: "Album's artist" + # } + # } + # end + # + # let (:bad_params) do + # { + # album: { description: "Album's description", artist: "Album's artist" + # } + # } + # end + # + # it "redirects to show page" do + # post :create, good_params + # expect(subject).to redirect_to album_path(assigns(:album).id) + # end + # + # it "renders new template on error" do + # post :create, bad_params + # expect(subject).to render_template :new + # end + # end + # + # describe "GET 'edit'" do + # it "renders edit view" do + # get :edit, id: album.id + # expect(subject).to render_template :edit + # end + # end + # + # describe "PATCH 'update'" do + # let (:good_params) do + # { + # id: album.id, + # album: { name: "zzzTest Album", description: "zzzzAlbum's description", artist: "zzzAlbum's artist" + # } + # } + # end + # + # let (:bad_params) do + # { + # id: album.id, + # album: { name: "", description: "Album's description", artist: "Album's artist" + # } + # } + # end + # + # it "redirects to show page" do + # patch :update, good_params + # expect(subject).to redirect_to album_path(album) + # expect(Album.find(album.id).name).to eq "zzzTest Album" + # end + # + # it "renders edit template on error" do + # patch :update, bad_params + # expect(subject).to render_template :edit + # expect(Album.find(album.id).name).to eq "Test Album" + # end + # end + # + # describe "DELETE 'destroy'" do + # it "redirects to index page" do + # delete :destroy, id: album.id + # expect(subject).to redirect_to albums_path + # end + # end + # + # describe "PATCH 'upvote'" do + # it "increases ranked by 1" do + # patch :upvote, id: album.id + # expect(Album.find(album.id).ranked).to eq 1 + # end + # + # it "redirects to show page" do + # patch :upvote, id: album.id + # expect(subject).to redirect_to album_path(album) + # end + # end end diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index b2c9e78ff3..f62c7075a8 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -1,105 +1,93 @@ require 'rails_helper' RSpec.describe BooksController, type: :controller do - it_behaves_like "a medium controller" - - let (:book) do - Book.create(name: "Test Book", description: "Book's description", author: "Book's author") - end - - describe "GET 'show'" do - it "renders the show view" do - get :show, id: book.id - expect(subject).to render_template :show - end + it_behaves_like "a medium controller" do + let(:model) { Book } 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 - { - book: { name: "Test Book", description: "Book's description", author: "Book's author" - } - } - end - - let (:bad_params) do - { - book: { description: "Book's description", author: "Book's author" - } - } - end - - it "redirects to show page" do - post :create, good_params - expect(subject).to redirect_to book_path(assigns(:book).id) - end - - it "renders new template on error" do - post :create, bad_params - expect(subject).to render_template :new - end - end - - describe "GET 'edit'" do - it "renders edit view" do - get :edit, id: book.id - expect(subject).to render_template :edit - end - end - - describe "PATCH 'update'" do - let (:good_params) do - { - id: book.id, - book: { name: "zzzTest Book", description: "zzzzBook's description", author: "zzzBook's author" - } - } - end - - let (:bad_params) do - { - id: book.id, - book: { name: "", description: "Book's description", author: "Book's author" - } - } - end - - it "redirects to show page" do - patch :update, good_params - expect(subject).to redirect_to book_path(book) - expect(Book.find(book.id).name).to eq "zzzTest Book" - end - - it "renders edit template on error" do - patch :update, bad_params - expect(subject).to render_template :edit - expect(Book.find(book.id).name).to eq "Test Book" - end - end - - describe "DELETE 'destroy'" do - it "redirects to index page" do - delete :destroy, id: book.id - expect(subject).to redirect_to books_path - end - end - - describe "PATCH 'upvote'" do - it "increases ranked by 1" do - patch :upvote, id: book.id - expect(Book.find(book.id).ranked).to eq 1 - end - - it "redirects to show page" do - patch :upvote, id: book.id - expect(subject).to redirect_to book_path(book) - end - end + # let (:book) do + # Book.create(name: "Test Book", description: "Book's description", author: "Book's author") + # end + + # describe "POST 'create'" do + # let (:good_params) do + # { + # book: { name: "Test Book", description: "Book's description", author: "Book's author" + # } + # } + # end + # + # let (:bad_params) do + # { + # book: { description: "Book's description", author: "Book's author" + # } + # } + # end + # + # it "redirects to show page" do + # post :create, good_params + # expect(subject).to redirect_to book_path(assigns(:book).id) + # end + # + # it "renders new template on error" do + # post :create, bad_params + # expect(subject).to render_template :new + # end + # end + # + # describe "GET 'edit'" do + # it "renders edit view" do + # get :edit, id: book.id + # expect(subject).to render_template :edit + # end + # end + # + # describe "PATCH 'update'" do + # let (:good_params) do + # { + # id: book.id, + # book: { name: "zzzTest Book", description: "zzzzBook's description", author: "zzzBook's author" + # } + # } + # end + # + # let (:bad_params) do + # { + # id: book.id, + # book: { name: "", description: "Book's description", author: "Book's author" + # } + # } + # end + # + # it "redirects to show page" do + # patch :update, good_params + # expect(subject).to redirect_to book_path(book) + # expect(Book.find(book.id).name).to eq "zzzTest Book" + # end + # + # it "renders edit template on error" do + # patch :update, bad_params + # expect(subject).to render_template :edit + # expect(Book.find(book.id).name).to eq "Test Book" + # end + # end + # + # describe "DELETE 'destroy'" do + # it "redirects to index page" do + # delete :destroy, id: book.id + # expect(subject).to redirect_to books_path + # end + # end + # + # describe "PATCH 'upvote'" do + # it "increases ranked by 1" do + # patch :upvote, id: book.id + # expect(Book.find(book.id).ranked).to eq 1 + # end + # + # it "redirects to show page" do + # patch :upvote, id: book.id + # expect(subject).to redirect_to book_path(book) + # end + # end end diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index f0c2bc4189..4f3bacbe31 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -1,105 +1,100 @@ require 'rails_helper' RSpec.describe MoviesController, type: :controller do - it_behaves_like "a medium controller" - - let (:movie) do - Movie.create(name: "Test Movie", description: "Movie's description", director: "Movie's director") - end - - describe "GET 'show'" do - it "renders the show view" do - get :show, id: movie.id - expect(subject).to render_template :show - end + it_behaves_like "a medium controller" do + let(:model) { Movie } 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: "Test Movie", description: "Movie's description", director: "Movie's director" - } - } - end - - let (:bad_params) do - { - movie: { description: "Movie's description", director: "Movie's director" - } - } - end - - it "redirects to show page" do - post :create, good_params - expect(subject).to redirect_to movie_path(assigns(:movie).id) - end - - it "renders new template on error" do - post :create, bad_params - expect(subject).to render_template :new - end - end - - describe "GET 'edit'" do - it "renders edit view" do - get :edit, id: movie.id - expect(subject).to render_template :edit - end - end - - describe "PATCH 'update'" do - let (:good_params) do - { - id: movie.id, - movie: { name: "zzzTest Movie", description: "zzzzMovie's description", director: "zzzMovie's director" - } - } - end - - let (:bad_params) do - { - id: movie.id, - movie: { name: "", description: "Movie's description", director: "Movie's director" - } - } - end - - it "redirects to show page" do - patch :update, good_params - expect(subject).to redirect_to movie_path(movie) - expect(Movie.find(movie.id).name).to eq "zzzTest Movie" - end - - it "renders edit template on error" do - patch :update, bad_params - expect(subject).to render_template :edit - expect(Movie.find(movie.id).name).to eq "Test Movie" - end - end - - describe "DELETE 'destroy'" do - it "redirects to index page" do - delete :destroy, id: movie.id - expect(subject).to redirect_to movies_path - end - end - - describe "PATCH 'upvote'" do - it "increases ranked by 1" do - patch :upvote, id: movie.id - expect(Movie.find(movie.id).ranked).to eq 1 - end - - it "redirects to show page" do - patch :upvote, id: movie.id - expect(subject).to redirect_to movie_path(movie) - end - end + # let (:movie) do + # Movie.create(name: "Test Movie", description: "Movie's description", director: "Movie's director") + # 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: "Test Movie", description: "Movie's description", director: "Movie's director" + # } + # } + # end + # + # let (:bad_params) do + # { + # movie: { description: "Movie's description", director: "Movie's director" + # } + # } + # end + # + # it "redirects to show page" do + # post :create, good_params + # expect(subject).to redirect_to movie_path(assigns(:movie).id) + # end + # + # it "renders new template on error" do + # post :create, bad_params + # expect(subject).to render_template :new + # end + # end + # + # describe "GET 'edit'" do + # it "renders edit view" do + # get :edit, id: movie.id + # expect(subject).to render_template :edit + # end + # end + # + # describe "PATCH 'update'" do + # let (:good_params) do + # { + # id: movie.id, + # movie: { name: "zzzTest Movie", description: "zzzzMovie's description", director: "zzzMovie's director" + # } + # } + # end + # + # let (:bad_params) do + # { + # id: movie.id, + # movie: { name: "", description: "Movie's description", director: "Movie's director" + # } + # } + # end + # + # it "redirects to show page" do + # patch :update, good_params + # expect(subject).to redirect_to movie_path(movie) + # expect(Movie.find(movie.id).name).to eq "zzzTest Movie" + # end + # + # it "renders edit template on error" do + # patch :update, bad_params + # expect(subject).to render_template :edit + # expect(Movie.find(movie.id).name).to eq "Test Movie" + # end + # end + # + # describe "DELETE 'destroy'" do + # it "redirects to index page" do + # delete :destroy, id: movie.id + # expect(subject).to redirect_to movies_path + # end + # end + # + # describe "PATCH 'upvote'" do + # it "increases ranked by 1" do + # patch :upvote, id: movie.id + # expect(Movie.find(movie.id).ranked).to eq 1 + # end + # + # it "redirects to show page" do + # patch :upvote, id: movie.id + # expect(subject).to redirect_to movie_path(movie) + # end + # end end diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index 2738352a3d..0850820994 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' RSpec.describe Album, type: :model do - it_behaves_like "a medium model" + it_behaves_like "a medium" end diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb index 3d377d1cb9..abdb683972 100644 --- a/spec/models/book_spec.rb +++ b/spec/models/book_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' RSpec.describe Book, type: :model do - it_behaves_like "a medium model" + it_behaves_like "a medium" end diff --git a/spec/models/movie_spec.rb b/spec/models/movie_spec.rb index a81e6430de..abb1ffcce0 100644 --- a/spec/models/movie_spec.rb +++ b/spec/models/movie_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' RSpec.describe Movie, type: :model do - it_behaves_like "a medium model" + it_behaves_like "a medium" end diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb index 238cdac7ed..bbdb2e86b4 100644 --- a/spec/support/medium_controller_spec.rb +++ b/spec/support/medium_controller_spec.rb @@ -6,5 +6,19 @@ end end - + describe "GET 'show'" do + it "renders the show view" do + medium = model.create(name: "Test") + get :show, id: medium.id + expect(subject).to render_template :show + 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/support/medium_model_spec.rb b/spec/support/medium_spec.rb similarity index 83% rename from spec/support/medium_model_spec.rb rename to spec/support/medium_spec.rb index 5421b7e96c..a7a9c838aa 100644 --- a/spec/support/medium_model_spec.rb +++ b/spec/support/medium_spec.rb @@ -1,4 +1,4 @@ -RSpec.shared_examples "a medium model" do +RSpec.shared_examples "a medium" do describe "model validations" do it "requires a name" do medium = described_class.new(name: nil) From 25743ddf0fece98451648578cef1c41cf785ef81 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 14:38:28 -0800 Subject: [PATCH 51/64] Add shared example test for POST create --- spec/controllers/albums_controller_spec.rb | 38 ++++++------------ spec/controllers/books_controller_spec.rb | 39 +++++++----------- spec/controllers/movies_controller_spec.rb | 46 +++++++--------------- spec/support/medium_controller_spec.rb | 13 ++++++ 4 files changed, 54 insertions(+), 82 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 6f39c2aa5e..e8f435613e 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -3,6 +3,19 @@ RSpec.describe AlbumsController, type: :controller do it_behaves_like "a medium controller" do let(:model) { Album } + let (:good_params) do + { + album: { name: "Test Album", description: "Album's description", artist: "Album's artist" + } + } + end + + let (:bad_params) do + { + album: { description: "Album's description", artist: "Album's artist" + } + } + end end # let (:album) do @@ -10,31 +23,6 @@ # end - # describe "POST 'create'" do - # let (:good_params) do - # { - # album: { name: "Test Album", description: "Album's description", artist: "Album's artist" - # } - # } - # end - # - # let (:bad_params) do - # { - # album: { description: "Album's description", artist: "Album's artist" - # } - # } - # end - # - # it "redirects to show page" do - # post :create, good_params - # expect(subject).to redirect_to album_path(assigns(:album).id) - # end - # - # it "renders new template on error" do - # post :create, bad_params - # expect(subject).to render_template :new - # end - # end # # describe "GET 'edit'" do # it "renders edit view" do diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index f62c7075a8..6281ad7b05 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -3,37 +3,26 @@ RSpec.describe BooksController, type: :controller do it_behaves_like "a medium controller" do let(:model) { Book } + let (:good_params) do + { + book: { name: "Test Book", description: "Book's description", author: "Book's author" + } + } + end + + let (:bad_params) do + { + book: { description: "Book's description", author: "Book's author" + } + } + end end # let (:book) do # Book.create(name: "Test Book", description: "Book's description", author: "Book's author") # end - # describe "POST 'create'" do - # let (:good_params) do - # { - # book: { name: "Test Book", description: "Book's description", author: "Book's author" - # } - # } - # end - # - # let (:bad_params) do - # { - # book: { description: "Book's description", author: "Book's author" - # } - # } - # end - # - # it "redirects to show page" do - # post :create, good_params - # expect(subject).to redirect_to book_path(assigns(:book).id) - # end - # - # it "renders new template on error" do - # post :create, bad_params - # expect(subject).to render_template :new - # end - # end + # # describe "GET 'edit'" do # it "renders edit view" do diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 4f3bacbe31..b4099b2063 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -3,44 +3,26 @@ RSpec.describe MoviesController, type: :controller do it_behaves_like "a medium controller" do let(:model) { Movie } + let (:good_params) do + { + movie: { name: "Test Movie", description: "Movie's description", director: "Movie's director" + } + } + end + + let (:bad_params) do + { + movie: { description: "Movie's description", director: "Movie's director" + } + } + end end # let (:movie) do # Movie.create(name: "Test Movie", description: "Movie's description", director: "Movie's director") # 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: "Test Movie", description: "Movie's description", director: "Movie's director" - # } - # } - # end - # - # let (:bad_params) do - # { - # movie: { description: "Movie's description", director: "Movie's director" - # } - # } - # end - # - # it "redirects to show page" do - # post :create, good_params - # expect(subject).to redirect_to movie_path(assigns(:movie).id) - # end - # - # it "renders new template on error" do - # post :create, bad_params - # expect(subject).to render_template :new - # end - # end + # # describe "GET 'edit'" do # it "renders edit view" do diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb index bbdb2e86b4..6679cfc0f2 100644 --- a/spec/support/medium_controller_spec.rb +++ b/spec/support/medium_controller_spec.rb @@ -21,4 +21,17 @@ end end + describe "POST 'create'" do + + it "redirects to show page" do + post :create, good_params + expect(subject).to redirect_to polymorphic_path(model.all.last) + end + + it "renders new template on error" do + post :create, bad_params + expect(subject).to render_template :new + end + end + end From 145af640620dacf9cd7beb48955b327de2108887 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 14:41:13 -0800 Subject: [PATCH 52/64] Add shared example GET edit --- spec/controllers/albums_controller_spec.rb | 8 -------- spec/controllers/books_controller_spec.rb | 9 +-------- spec/controllers/movies_controller_spec.rb | 8 -------- spec/support/medium_controller_spec.rb | 8 ++++++++ 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index e8f435613e..ce4e5e7141 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -23,14 +23,6 @@ # end - # - # describe "GET 'edit'" do - # it "renders edit view" do - # get :edit, id: album.id - # expect(subject).to render_template :edit - # end - # end - # # describe "PATCH 'update'" do # let (:good_params) do # { diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index 6281ad7b05..d5a5ebd092 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -23,14 +23,7 @@ # end - # - # describe "GET 'edit'" do - # it "renders edit view" do - # get :edit, id: book.id - # expect(subject).to render_template :edit - # end - # end - # + # describe "PATCH 'update'" do # let (:good_params) do # { diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index b4099b2063..b3200926d3 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -23,14 +23,6 @@ # end - # - # describe "GET 'edit'" do - # it "renders edit view" do - # get :edit, id: movie.id - # expect(subject).to render_template :edit - # end - # end - # # describe "PATCH 'update'" do # let (:good_params) do # { diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb index 6679cfc0f2..1e708774c2 100644 --- a/spec/support/medium_controller_spec.rb +++ b/spec/support/medium_controller_spec.rb @@ -34,4 +34,12 @@ end end + describe "GET 'edit'" do + it "renders edit view" do + medium = model.create(name: "Test") + get :edit, id: medium.id + expect(subject).to render_template :edit + end + end + end From 8a0ba69227e78105f081da159ae819ccf28ea781 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 15:19:11 -0800 Subject: [PATCH 53/64] Add shared examples for PATCH update --- spec/controllers/albums_controller_spec.rb | 33 ++------------------ spec/controllers/books_controller_spec.rb | 35 ++-------------------- spec/controllers/movies_controller_spec.rb | 34 ++------------------- spec/support/medium_controller_spec.rb | 18 +++++++++++ 4 files changed, 24 insertions(+), 96 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index ce4e5e7141..f71e03c6a9 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -5,14 +5,14 @@ let(:model) { Album } let (:good_params) do { - album: { name: "Test Album", description: "Album's description", artist: "Album's artist" + album: { name: "zzzTest", description: "Album's description", artist: "Album's artist" } } end let (:bad_params) do { - album: { description: "Album's description", artist: "Album's artist" + album: { name: "", description: "Album's description", artist: "Album's artist" } } end @@ -23,35 +23,6 @@ # end - # describe "PATCH 'update'" do - # let (:good_params) do - # { - # id: album.id, - # album: { name: "zzzTest Album", description: "zzzzAlbum's description", artist: "zzzAlbum's artist" - # } - # } - # end - # - # let (:bad_params) do - # { - # id: album.id, - # album: { name: "", description: "Album's description", artist: "Album's artist" - # } - # } - # end - # - # it "redirects to show page" do - # patch :update, good_params - # expect(subject).to redirect_to album_path(album) - # expect(Album.find(album.id).name).to eq "zzzTest Album" - # end - # - # it "renders edit template on error" do - # patch :update, bad_params - # expect(subject).to render_template :edit - # expect(Album.find(album.id).name).to eq "Test Album" - # end - # end # # describe "DELETE 'destroy'" do # it "redirects to index page" do diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index d5a5ebd092..baf7ae35b8 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -5,14 +5,14 @@ let(:model) { Book } let (:good_params) do { - book: { name: "Test Book", description: "Book's description", author: "Book's author" + book: { name: "zzzTest", description: "Book's description", author: "Book's author" } } end let (:bad_params) do { - book: { description: "Book's description", author: "Book's author" + book: { name: "", description: "Book's description", author: "Book's author" } } end @@ -22,37 +22,6 @@ # Book.create(name: "Test Book", description: "Book's description", author: "Book's author") # end - - - # describe "PATCH 'update'" do - # let (:good_params) do - # { - # id: book.id, - # book: { name: "zzzTest Book", description: "zzzzBook's description", author: "zzzBook's author" - # } - # } - # end - # - # let (:bad_params) do - # { - # id: book.id, - # book: { name: "", description: "Book's description", author: "Book's author" - # } - # } - # end - # - # it "redirects to show page" do - # patch :update, good_params - # expect(subject).to redirect_to book_path(book) - # expect(Book.find(book.id).name).to eq "zzzTest Book" - # end - # - # it "renders edit template on error" do - # patch :update, bad_params - # expect(subject).to render_template :edit - # expect(Book.find(book.id).name).to eq "Test Book" - # end - # end # # describe "DELETE 'destroy'" do # it "redirects to index page" do diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index b3200926d3..6aaaaea531 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -5,14 +5,14 @@ let(:model) { Movie } let (:good_params) do { - movie: { name: "Test Movie", description: "Movie's description", director: "Movie's director" + movie: { name: "zzzTest", description: "Movie's description", director: "Movie's director" } } end let (:bad_params) do { - movie: { description: "Movie's description", director: "Movie's director" + movie: { name: "", description: "Movie's description", director: "Movie's director" } } end @@ -22,36 +22,6 @@ # Movie.create(name: "Test Movie", description: "Movie's description", director: "Movie's director") # end - - # describe "PATCH 'update'" do - # let (:good_params) do - # { - # id: movie.id, - # movie: { name: "zzzTest Movie", description: "zzzzMovie's description", director: "zzzMovie's director" - # } - # } - # end - # - # let (:bad_params) do - # { - # id: movie.id, - # movie: { name: "", description: "Movie's description", director: "Movie's director" - # } - # } - # end - # - # it "redirects to show page" do - # patch :update, good_params - # expect(subject).to redirect_to movie_path(movie) - # expect(Movie.find(movie.id).name).to eq "zzzTest Movie" - # end - # - # it "renders edit template on error" do - # patch :update, bad_params - # expect(subject).to render_template :edit - # expect(Movie.find(movie.id).name).to eq "Test Movie" - # end - # end # # describe "DELETE 'destroy'" do # it "redirects to index page" do diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb index 1e708774c2..082c3067f1 100644 --- a/spec/support/medium_controller_spec.rb +++ b/spec/support/medium_controller_spec.rb @@ -42,4 +42,22 @@ end end + describe "PATCH 'update'" do + let (:medium) do + model.create(name: "Test") + end + + it "redirects to show page" do + patch :update, good_params.merge({id: medium.id}) + expect(subject).to redirect_to polymorphic_path(medium) + expect(model.all.last.name).to eq "zzzTest" + end + + it "renders edit template on error" do + patch :update, bad_params.merge({id: medium.id}) + expect(subject).to render_template :edit + expect(model.all.last.name).to eq "Test" + end + end + end From d1028968a8b85c09ef19dd800d42687925f428bd Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 15:24:10 -0800 Subject: [PATCH 54/64] Add DELETE destroy shared example --- spec/controllers/albums_controller_spec.rb | 7 ------- spec/controllers/books_controller_spec.rb | 8 +------- spec/controllers/movies_controller_spec.rb | 9 +-------- spec/support/medium_controller_spec.rb | 8 ++++++++ 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index f71e03c6a9..3f0da3d58b 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -23,13 +23,6 @@ # end - # - # describe "DELETE 'destroy'" do - # it "redirects to index page" do - # delete :destroy, id: album.id - # expect(subject).to redirect_to albums_path - # end - # end # # describe "PATCH 'upvote'" do # it "increases ranked by 1" do diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index baf7ae35b8..05477ac4ef 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -22,13 +22,7 @@ # Book.create(name: "Test Book", description: "Book's description", author: "Book's author") # end - # - # describe "DELETE 'destroy'" do - # it "redirects to index page" do - # delete :destroy, id: book.id - # expect(subject).to redirect_to books_path - # end - # end + # # describe "PATCH 'upvote'" do # it "increases ranked by 1" do diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 6aaaaea531..d476b1c95e 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -22,14 +22,7 @@ # Movie.create(name: "Test Movie", description: "Movie's description", director: "Movie's director") # end - # - # describe "DELETE 'destroy'" do - # it "redirects to index page" do - # delete :destroy, id: movie.id - # expect(subject).to redirect_to movies_path - # end - # end - # + # describe "PATCH 'upvote'" do # it "increases ranked by 1" do # patch :upvote, id: movie.id diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb index 082c3067f1..b94ddfc1c6 100644 --- a/spec/support/medium_controller_spec.rb +++ b/spec/support/medium_controller_spec.rb @@ -60,4 +60,12 @@ end end + describe "DELETE 'destroy'" do + it "redirects to index page" do + medium = model.create(name: "Test") + delete :destroy, id: medium.id + expect(subject).to redirect_to polymorphic_path(model.name.downcase.pluralize) + end + end + end From fac53c883e899c95d594ce7e851151936942d146 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 15:29:30 -0800 Subject: [PATCH 55/64] Add PATCH upvote shared tests --- spec/controllers/albums_controller_spec.rb | 18 ------------------ spec/controllers/books_controller_spec.rb | 18 ------------------ spec/controllers/movies_controller_spec.rb | 17 ----------------- spec/support/medium_controller_spec.rb | 15 +++++++++++++++ 4 files changed, 15 insertions(+), 53 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 3f0da3d58b..9a4b0f185e 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -17,22 +17,4 @@ } end end - - # let (:album) do - # Album.create(name: "Test Album", description: "Album's description", artist: "Album's artist") - # end - - - # - # describe "PATCH 'upvote'" do - # it "increases ranked by 1" do - # patch :upvote, id: album.id - # expect(Album.find(album.id).ranked).to eq 1 - # end - # - # it "redirects to show page" do - # patch :upvote, id: album.id - # expect(subject).to redirect_to album_path(album) - # end - # end end diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index 05477ac4ef..577b9c396d 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -17,22 +17,4 @@ } end end - - # let (:book) do - # Book.create(name: "Test Book", description: "Book's description", author: "Book's author") - # end - - - # - # describe "PATCH 'upvote'" do - # it "increases ranked by 1" do - # patch :upvote, id: book.id - # expect(Book.find(book.id).ranked).to eq 1 - # end - # - # it "redirects to show page" do - # patch :upvote, id: book.id - # expect(subject).to redirect_to book_path(book) - # end - # end end diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index d476b1c95e..67516d6a6a 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -17,21 +17,4 @@ } end end - - # let (:movie) do - # Movie.create(name: "Test Movie", description: "Movie's description", director: "Movie's director") - # end - - - # describe "PATCH 'upvote'" do - # it "increases ranked by 1" do - # patch :upvote, id: movie.id - # expect(Movie.find(movie.id).ranked).to eq 1 - # end - # - # it "redirects to show page" do - # patch :upvote, id: movie.id - # expect(subject).to redirect_to movie_path(movie) - # end - # end end diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb index b94ddfc1c6..8aa269e3ca 100644 --- a/spec/support/medium_controller_spec.rb +++ b/spec/support/medium_controller_spec.rb @@ -68,4 +68,19 @@ end end + describe "PATCH 'upvote'" do + let (:medium) do + model.create(name: "Test") + end + + it "increases ranked by 1" do + patch :upvote, id: medium.id + expect(model.all.last.ranked).to eq 1 + end + + it "redirects to show page" do + patch :upvote, id: medium.id + expect(subject).to redirect_to polymorphic_path(medium) + end + end end From eacd01e785b1d270c7f0d3a2df07178fd2f559bf Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 16:06:09 -0800 Subject: [PATCH 56/64] Add partial for movie index view --- app/views/movies/index.html.erb | 29 +---------------------------- app/views/shared/_form.html.erb | 0 app/views/shared/_index.html.erb | 28 ++++++++++++++++++++++++++++ app/views/shared/_show.html.erb | 0 app/views/shared/_top_list.html.erb | 0 5 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 app/views/shared/_form.html.erb create mode 100644 app/views/shared/_index.html.erb create mode 100644 app/views/shared/_show.html.erb create mode 100644 app/views/shared/_top_list.html.erb diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index a783d63cd6..0146483c61 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -1,28 +1 @@ - - - - - - - <% @movies.each do |movie| %> - - - - - - <% end %> -
- Ranking - - Name - - Upvote -
- Ranked: <%= movie.ranked %> - - <%= link_to movie.name, movie_path(movie) %> - - <%= button_to "Upvote", movie_upvote_path(movie), method: :patch, class: "btn btn-default" %> -
-<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> -<%= link_to "Add a Movie", new_movie_path, method: :get, class: "btn btn-default" %> +<%= render partial: 'shared/index', locals: { media: @movies, name: "movie" } %> diff --git a/app/views/shared/_form.html.erb b/app/views/shared/_form.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/shared/_index.html.erb b/app/views/shared/_index.html.erb new file mode 100644 index 0000000000..a55a3d8e5a --- /dev/null +++ b/app/views/shared/_index.html.erb @@ -0,0 +1,28 @@ + + + + + + + <% media.each do |medium| %> + + + + + + <% end %> +
+ Ranking + + Name + + Upvote +
+ Ranked: <%= medium.ranked %> + + <%= link_to medium.name, polymorphic_path(medium) %> + + <%= button_to "Upvote", polymorphic_path([medium, :upvote]), method: :patch, class: "btn btn-default" %> +
+<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> +<%= link_to "Add a #{name.capitalize}", new_polymorphic_path(name), method: :get, class: "btn btn-default" %> diff --git a/app/views/shared/_show.html.erb b/app/views/shared/_show.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/shared/_top_list.html.erb b/app/views/shared/_top_list.html.erb new file mode 100644 index 0000000000..e69de29bb2 From 7c69b5b8ebe27d88a6b6b57cde76c8d1ef4589a2 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 16:09:25 -0800 Subject: [PATCH 57/64] Add reference to index partial in albums and movies index --- app/views/albums/index.html.erb | 29 +---------------------------- app/views/books/index.html.erb | 29 +---------------------------- 2 files changed, 2 insertions(+), 56 deletions(-) diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index bdf3ee2fe1..0a31b1bf7a 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -1,28 +1 @@ - - - - - - - <% @albums.each do |album| %> - - - - - - <% end %> -
- Ranking - - Name - - Upvote -
- Ranked: <%= album.ranked %> - - <%= link_to album.name, album_path(album) %> - - <%= button_to "Upvote", album_upvote_path(album), method: :patch, class: "btn btn-default" %> -
-<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> - <%= link_to "Add an Album", new_album_path, method: :get, class: "btn btn-default" %> +<%= render partial: 'shared/index', locals: { media: @albums, name: "album" } %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index 5ef368eb33..f61fff3543 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -1,28 +1 @@ - - - - - - - <% @books.each do |book| %> - - - - - - <% end %> -
- Ranking - - Name - - Upvote -
- Ranked: <%= book.ranked %> - - <%= link_to book.name, book_path(book) %> - - <%= button_to "Upvote", book_upvote_path(book), method: :patch, class: "btn btn-default" %> -
-<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> -<%= link_to "Add a Book", new_book_path, method: :get, class: "btn btn-default" %> +<%= render partial: 'shared/index', locals: { media: @books, name: "book" } %> From ae16f87b9e200ec42828d51ee0cc29cc73c95ca6 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 16:50:54 -0800 Subject: [PATCH 58/64] Added show partial and reference to it in movies show view --- app/views/movies/show.html.erb | 11 +---------- app/views/shared/_show.html.erb | 10 ++++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index d89cb43524..48fc8c8243 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -1,10 +1 @@ -

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

-

Ranked: <%= @movie.ranked %>

-

- <%= @movie.description %> -

-<%= button_to "Upvote", movie_upvote_path(@movie), method: :patch, class: "btn btn-primary" %> -<%= link_to "Edit #{@movie.name}", edit_movie_path(@movie), method: :get, class: "btn btn-default" %> -<%= link_to "DELETE", "/movies/#{@movie.id}", method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> -<%= link_to "View All Movies", movies_path, method: :get, class: "btn btn-default" %> -<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> +<%= render partial: 'shared/show', locals: { medium: @movie, name: "movie", creator: @movie.director, create_type: "Directed" } %> diff --git a/app/views/shared/_show.html.erb b/app/views/shared/_show.html.erb index e69de29bb2..609c162389 100644 --- a/app/views/shared/_show.html.erb +++ b/app/views/shared/_show.html.erb @@ -0,0 +1,10 @@ +

<%= medium.name %> <%= create_type %> by: <%= creator %>

+

Ranked: <%= medium.ranked %>

+

+ <%= medium.description %> +

+<%= button_to "Upvote", polymorphic_path([medium, :upvote]), method: :patch, class: "btn btn-primary" %> +<%= link_to "Edit #{medium.name}", new_polymorphic_path(name), method: :get, class: "btn btn-default" %> +<%= link_to "DELETE", "/#{name.pluralize}/#{medium.id}", method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> +<%= link_to "View All Movies", polymorphic_path(name.pluralize), method: :get, class: "btn btn-default" %> +<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> From fec3d5ae46e231725a74f720f9c4a3c958be2f9e Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 3 Dec 2015 17:01:04 -0800 Subject: [PATCH 59/64] Add partials to books and albums show --- app/views/albums/show.html.erb | 11 +---------- app/views/books/show.html.erb | 11 +---------- app/views/shared/_show.html.erb | 2 +- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index da3951d763..3524e85bc4 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -1,10 +1 @@ -

<%= @album.name %> Recorded by: <%= @album.artist%>

-

Ranked: <%= @album.ranked %>

-

- <%= @album.description %> -

-<%= button_to "Upvote", album_upvote_path(@album), method: :patch, class: "btn btn-primary" %> -<%= link_to "Edit #{@album.name}", edit_album_path(@album), method: :get, class: "btn btn-default" %> -<%= link_to "DELETE", "/albums/#{@album.id}", method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> -<%= link_to "View All Albums", albums_path, method: :get, class: "btn btn-default" %> -<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> +<%= render partial: 'shared/show', locals: { medium: @album, name: "album", creator: @album.artist, create_type: "Recorded" } %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index eee6c85690..0204f58130 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -1,10 +1 @@ -

<%= @book.name %> Written by: <%= @book.author%>

-

Ranked: <%= @book.ranked %>

-

- <%= @book.description %> -

-<%= button_to "Upvote", book_upvote_path(@book), method: :patch, class: "btn btn-primary" %> -<%= link_to "Edit #{@book.name}", edit_book_path(@book), method: :get, class: "btn btn-default" %> -<%= link_to "DELETE", "/books/#{@book.id}", method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> -<%= link_to "View All Books", books_path, method: :get, class: "btn btn-default" %> -<%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> +<%= render partial: 'shared/show', locals: { medium: @book, name: "book", creator: @book.author, create_type: "Written" } %> diff --git a/app/views/shared/_show.html.erb b/app/views/shared/_show.html.erb index 609c162389..b2189cb33f 100644 --- a/app/views/shared/_show.html.erb +++ b/app/views/shared/_show.html.erb @@ -4,7 +4,7 @@ <%= medium.description %>

<%= button_to "Upvote", polymorphic_path([medium, :upvote]), method: :patch, class: "btn btn-primary" %> -<%= link_to "Edit #{medium.name}", new_polymorphic_path(name), method: :get, class: "btn btn-default" %> +<%= link_to "Edit #{medium.name}", edit_polymorphic_path(name), method: :get, class: "btn btn-default" %> <%= link_to "DELETE", "/#{name.pluralize}/#{medium.id}", method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> <%= link_to "View All Movies", polymorphic_path(name.pluralize), method: :get, class: "btn btn-default" %> <%= link_to "View All Media", root_path, method: :get, class: "btn btn-default" %> From b88cc422997235ea4177f53ecd9eb69c6d0475ec Mon Sep 17 00:00:00 2001 From: Kelly Date: Fri, 4 Dec 2015 09:33:56 -0800 Subject: [PATCH 60/64] add partial for forms, reference in edit and new views and delete controller-specific form files --- app/views/albums/_form.html.erb | 12 ------------ app/views/albums/edit.html.erb | 2 +- app/views/albums/new.html.erb | 2 +- app/views/books/_form.html.erb | 12 ------------ app/views/books/edit.html.erb | 2 +- app/views/books/new.html.erb | 2 +- app/views/movies/_form.html.erb | 12 ------------ app/views/movies/edit.html.erb | 2 +- app/views/movies/new.html.erb | 2 +- app/views/shared/_form.html.erb | 12 ++++++++++++ 10 files changed, 18 insertions(+), 42 deletions(-) delete mode 100644 app/views/albums/_form.html.erb delete mode 100644 app/views/books/_form.html.erb delete mode 100644 app/views/movies/_form.html.erb diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb deleted file mode 100644 index 4bfb2fd64d..0000000000 --- a/app/views/albums/_form.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -
- <%= form_for @album do |f| %> - <%= f.label :name %> - <%= f.text_field :name, class: "form-control" %> - <%= f.label :artist %> - <%= f.text_field :artist, class: "form-control" %> - <%= f.label :description %> - <%= f.text_area :description, class: "form-control" %> -
- <%= f.submit "Save", class: "btn btn-default" %> - <% end %> -
diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb index 3e79476e02..c8bc1b99cf 100644 --- a/app/views/albums/edit.html.erb +++ b/app/views/albums/edit.html.erb @@ -1,2 +1,2 @@

Edit Album

-<%= render 'form' %> +<%= render partial: 'shared/form', locals: { medium: @album, creator_field: :artist } %> diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb index 3a32a180fa..fad4fc2b6c 100644 --- a/app/views/albums/new.html.erb +++ b/app/views/albums/new.html.erb @@ -1,2 +1,2 @@

New Album

-<%= render 'form' %> +<%= render partial: 'shared/form', locals: { medium: @album, creator_field: :artist } %> diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb deleted file mode 100644 index 0c71800fcb..0000000000 --- a/app/views/books/_form.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -
- <%= form_for @book do |f| %> - <%= f.label :name %> - <%= f.text_field :name, class: "form-control" %> - <%= f.label :author %> - <%= f.text_field :author, class: "form-control" %> - <%= f.label :description %> - <%= f.text_area :description, class: "form-control" %> -
- <%= f.submit "Save", class: "btn btn-default" %> - <% end %> -
diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb index 840e1fcd4f..d4cb6d5ad7 100644 --- a/app/views/books/edit.html.erb +++ b/app/views/books/edit.html.erb @@ -1,2 +1,2 @@

Edit Book

-<%= render 'form' %> +<%= render partial: 'shared/form', locals: { medium: @book, creator_field: :author } %> diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb index cd36e15933..c867acf3bd 100644 --- a/app/views/books/new.html.erb +++ b/app/views/books/new.html.erb @@ -1,2 +1,2 @@

New Book

-<%= render 'form' %> +<%= render partial: 'shared/form', locals: { medium: @book, creator_field: :author } %> diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb deleted file mode 100644 index 965fb666db..0000000000 --- a/app/views/movies/_form.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -
- <%= form_for @movie do |f| %> - <%= 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.submit "Save", class: "btn btn-default" %> - <% end %> -
diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb index 87a6c641f1..bf5d744ae9 100644 --- a/app/views/movies/edit.html.erb +++ b/app/views/movies/edit.html.erb @@ -1,2 +1,2 @@

Edit Movie

-<%= render 'form' %> +<%= render partial: 'shared/form', locals: { medium: @movie, creator_field: :director } %> diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb index 846ce77309..196031d95b 100644 --- a/app/views/movies/new.html.erb +++ b/app/views/movies/new.html.erb @@ -1,2 +1,2 @@

New Movie

-<%= render 'form' %> +<%= render partial: 'shared/form', locals: { medium: @movie, creator_field: :director } %> diff --git a/app/views/shared/_form.html.erb b/app/views/shared/_form.html.erb index e69de29bb2..0877174a94 100644 --- a/app/views/shared/_form.html.erb +++ b/app/views/shared/_form.html.erb @@ -0,0 +1,12 @@ +
+ <%= form_for medium do |f| %> + <%= f.label :name %> + <%= f.text_field :name, class: "form-control" %> + <%= f.label creator_field %> + <%= f.text_field creator_field, class: "form-control" %> + <%= f.label :description %> + <%= f.text_area :description, class: "form-control" %> +
+ <%= f.submit "Save", class: "btn btn-default" %> + <% end %> +
From c7cf3642b6875bd793bfd4e92d2a26019d7044e7 Mon Sep 17 00:00:00 2001 From: Kelly Date: Fri, 4 Dec 2015 09:44:36 -0800 Subject: [PATCH 61/64] Add top list partial and reference it for each controller in welcome#index --- app/views/shared/_top_list.html.erb | 8 ++++++++ app/views/welcome/index.html.erb | 27 +++------------------------ 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/app/views/shared/_top_list.html.erb b/app/views/shared/_top_list.html.erb index e69de29bb2..e5a2ed8985 100644 --- a/app/views/shared/_top_list.html.erb +++ b/app/views/shared/_top_list.html.erb @@ -0,0 +1,8 @@ +
+

Top <%= name %>

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

<%= link_to medium.name, polymorphic_path(medium) %> + Ranked: <%= medium.ranked %>

+ <% end %> + <%= link_to "View More #{name}", polymorphic_path(name.downcase) %> +
diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 8df9d568ac..1cbedbb952 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -1,26 +1,5 @@
-
-

Top Movies

- <% @movies.each do |movie| %> -

<%= link_to movie.name, movie_path(movie) %> - Ranked: <%= movie.ranked %>

- <% end %> - <%= link_to "View More Movies", movies_path %> -
-
-

Top Books

- <% @books.each do |book| %> -

<%= link_to book.name, book_path(book) %> - Ranked: <%= book.ranked %>

- <% end %> - <%= link_to "View More Books", books_path %> -
-
-

Top Albums

- <% @albums.each do |album| %> -

<%= link_to album.name, album_path(album) %> - Ranked: <%= album.ranked %>

- <% end %> - <%= link_to "View More Albums", albums_path %> -
+ <%= render partial: 'shared/top_list', locals: { media: @movies, name: "Movies" } %> + <%= render partial: 'shared/top_list', locals: { media: @books, name: "Books" } %> + <%= render partial: 'shared/top_list', locals: { media: @albums, name: "Albums" } %>
From 781903a6a317b755da4c01651c499e63afc5084a Mon Sep 17 00:00:00 2001 From: Kelly Date: Fri, 4 Dec 2015 13:47:55 -0800 Subject: [PATCH 62/64] Add space in --- app/views/layouts/application.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 65ba754f3f..9d6dc65919 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,7 +1,7 @@ <!DOCTYPE html> <html> <head> - <title>MediaRanker + Media Ranker <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> From 85340db78ed676b2332dcafae8997aeacfdf9d27 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 12 Jan 2016 17:12:07 -0800 Subject: [PATCH 63/64] setup factory girl --- Gemfile | 1 + Gemfile.lock | 6 ++++++ spec/factories.rb | 4 ++++ spec/spec_helper.rb | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 spec/factories.rb diff --git a/Gemfile b/Gemfile index f541dc8d72..ad3138f319 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.1.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby +gem 'factory_girl_rails' # Use jquery as the JavaScript library gem 'jquery-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 244482acb0..a80e288fbb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,6 +65,11 @@ GEM docile (1.1.5) erubis (2.7.0) execjs (2.6.0) + factory_girl (4.5.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.5.0) + factory_girl (~> 4.5.0) + railties (>= 3.0.0) globalid (0.3.6) activesupport (>= 4.1.0) i18n (0.7.0) @@ -195,6 +200,7 @@ DEPENDENCIES bootstrap-sass (~> 3.3.6) byebug coffee-rails (~> 4.1.0) + factory_girl_rails jbuilder (~> 2.0) jquery-rails pg diff --git a/spec/factories.rb b/spec/factories.rb new file mode 100644 index 0000000000..99a5f082fa --- /dev/null +++ b/spec/factories.rb @@ -0,0 +1,4 @@ +FactoryGirl.define do + + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6e83295cf9..812daa6490 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ require 'simplecov' require 'rails_helper' +require 'factory_girl' SimpleCov.start do add_filter '/support/' end @@ -49,7 +50,7 @@ mocks.verify_partial_doubles = true end - + config.include FactoryGirl::Syntax::Methods # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. From 54cb44265879c0d422737567001cc6a51ac0eb4a Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 12 Jan 2016 19:35:16 -0800 Subject: [PATCH 64/64] update rspec to include factories --- spec/controllers/albums_controller_spec.rb | 2 ++ spec/controllers/books_controller_spec.rb | 2 ++ spec/controllers/movies_controller_spec.rb | 2 ++ spec/factories.rb | 17 ++++++++++++++++- spec/support/medium_controller_spec.rb | 11 ----------- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 9a4b0f185e..b402050a51 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -10,6 +10,8 @@ } end + let (:medium) { create(:album) } + let (:bad_params) do { album: { name: "", description: "Album's description", artist: "Album's artist" diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index 577b9c396d..64c6165b10 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -10,6 +10,8 @@ } end + let (:medium) { create(:book) } + let (:bad_params) do { book: { name: "", description: "Book's description", author: "Book's author" diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 67516d6a6a..78dc27e301 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -10,6 +10,8 @@ } end + let (:medium) { create(:movie) } + let (:bad_params) do { movie: { name: "", description: "Movie's description", director: "Movie's director" diff --git a/spec/factories.rb b/spec/factories.rb index 99a5f082fa..784464ee46 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,4 +1,19 @@ FactoryGirl.define do + factory :album do + name "Test" + description "Album's description" + artist "Album's artist" + end - + factory :book do + name "Test" + description "Book's description" + author "Book's author" + end + + factory :movie do + name "Test" + description "Movie's description" + director "Movie's director" + end end diff --git a/spec/support/medium_controller_spec.rb b/spec/support/medium_controller_spec.rb index 8aa269e3ca..f876f9f372 100644 --- a/spec/support/medium_controller_spec.rb +++ b/spec/support/medium_controller_spec.rb @@ -8,7 +8,6 @@ describe "GET 'show'" do it "renders the show view" do - medium = model.create(name: "Test") get :show, id: medium.id expect(subject).to render_template :show end @@ -36,17 +35,12 @@ describe "GET 'edit'" do it "renders edit view" do - medium = model.create(name: "Test") get :edit, id: medium.id expect(subject).to render_template :edit end end describe "PATCH 'update'" do - let (:medium) do - model.create(name: "Test") - end - it "redirects to show page" do patch :update, good_params.merge({id: medium.id}) expect(subject).to redirect_to polymorphic_path(medium) @@ -62,17 +56,12 @@ describe "DELETE 'destroy'" do it "redirects to index page" do - medium = model.create(name: "Test") delete :destroy, id: medium.id expect(subject).to redirect_to polymorphic_path(model.name.downcase.pluralize) end end describe "PATCH 'upvote'" do - let (:medium) do - model.create(name: "Test") - end - it "increases ranked by 1" do patch :upvote, id: medium.id expect(model.all.last.ranked).to eq 1