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| %>
+
+
+ Ranking
+ |
+
+ Name
+ |
+
+ Upvote
+ |
+
+
+
+ Ranked: <%= movie.ranked %>
+ |
+
+ <%= link_to movie.name, movie_path(movie) %>
+ |
+
+ Upvote Button Will Go Here
+ |
+
+ <% end %>
+
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 @@
+
+
+
+ Ranking
+ |
+
+ Name
+ |
+
+ Upvote
+ |
+
+ <% @books.each do |book| %>
+
+
+ Ranked: <%= book.ranked %>
+ |
+
+ <%= link_to book.name, book_path(book) %>
+ |
+
+ Upvote Button Will Go Here
+ |
+
+ <% end %>
+
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 @@
+
+
+ Ranking
+ |
+
+ Name
+ |
+
+ Upvote
+ |
+
<% @movies.each do |movie| %>
-
-
- 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 @@
+
+
+
+ Ranking
+ |
+
+ Name
+ |
+
+ Upvote
+ |
+
+ <% @albums.each do |album| %>
+
+
+ Ranked: <%= album.ranked %>
+ |
+
+ <%= link_to album.name, album_path(album) %>
+ |
+
+ Upvote Button Will Go Here
+ |
+
+ <% end %>
+
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 @@
|
<% end %>
+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 %>
+