From 3af9465dd1353cb6fe0a021d135a81eb0e003368 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 14:46:15 -0800 Subject: [PATCH 01/60] create homepage controller --- app/controllers/homepage_controller.rb | 2 ++ app/views/homepage/index.html.erb | 1 + 2 files changed, 3 insertions(+) create mode 100644 app/views/homepage/index.html.erb diff --git a/app/controllers/homepage_controller.rb b/app/controllers/homepage_controller.rb index 73c66a44a8..e09cc6e590 100644 --- a/app/controllers/homepage_controller.rb +++ b/app/controllers/homepage_controller.rb @@ -1,2 +1,4 @@ class HomepageController < ApplicationController + def index + end end diff --git a/app/views/homepage/index.html.erb b/app/views/homepage/index.html.erb new file mode 100644 index 0000000000..3fe0a5751a --- /dev/null +++ b/app/views/homepage/index.html.erb @@ -0,0 +1 @@ +Hello, world! This is the homepage From bba80b3b2736d8749068ddb4cfb89c5640f6ef29 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 14:47:27 -0800 Subject: [PATCH 02/60] add better errors and spring to gemfile --- Gemfile | 6 +++--- Gemfile.lock | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index bd3387b438..4777258197 100644 --- a/Gemfile +++ b/Gemfile @@ -36,10 +36,10 @@ group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' - # gem 'spring' + gem 'spring' # Add better errors gems - # gem 'better_errors' - # gem 'binding_of_caller' + gem 'better_errors' + gem 'binding_of_caller' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Create ERD for project diff --git a/Gemfile.lock b/Gemfile.lock index 1270c2c6ad..6e69ab417c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,6 +40,10 @@ GEM 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) @@ -48,6 +52,7 @@ GEM builder (3.2.2) byebug (8.2.1) choice (0.2.0) + coderay (1.1.0) coffee-rails (4.1.0) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -125,6 +130,7 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + spring (1.5.0) sprockets (3.4.1) rack (> 1, < 3) sprockets-rails (2.3.3) @@ -152,6 +158,8 @@ PLATFORMS ruby DEPENDENCIES + better_errors + binding_of_caller bootstrap-sass (~> 3.3.6) byebug coffee-rails (~> 4.1.0) @@ -162,6 +170,7 @@ DEPENDENCIES rails-erd sass-rails (~> 5.0) sdoc (~> 0.4.0) + spring sqlite3 turbolinks uglifier (>= 1.3.0) From ff38fbca8cb0866424495ffa6cbbf44a5e9cc066 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 14:49:29 -0800 Subject: [PATCH 03/60] add bootstrap to css and javascript --- app/assets/javascripts/application.js | 1 + app/assets/stylesheets/{application.css => application.scss} | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) rename app/assets/stylesheets/{application.css => application.scss} (92%) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e07c5a830f..7465856729 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,4 +13,5 @@ //= require jquery //= require jquery_ujs //= require turbolinks +//= require bootstrap-sprockets //= require_tree . diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.scss similarity index 92% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index f9cd5b3483..2eb37b4e7c 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 */ + +@import "bootstrap-sprockets"; +@import "bootstrap"; From 19d78c4da5e283379e4a0f6eb2e7a6bacfad7479 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 16:03:01 -0800 Subject: [PATCH 04/60] add default value to upvotes --- app/models/album.rb | 6 ++++++ app/models/book.rb | 6 ++++++ app/models/movie.rb | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/app/models/album.rb b/app/models/album.rb index 4b630eebc5..a5a3529897 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -1,4 +1,10 @@ class Album < ActiveRecord::Base validates :title, presence: true validates :artist, presence: true + + after_initialize :init + + def init + self.upvotes ||= 0 + end end diff --git a/app/models/book.rb b/app/models/book.rb index 4bcc056a96..b286f5c0eb 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,4 +1,10 @@ class Book < ActiveRecord::Base validates :title, presence: true validates :author, presence: true + + after_initialize :init + + def init + self.upvotes ||= 0 + end end diff --git a/app/models/movie.rb b/app/models/movie.rb index f3946488b0..4566791d9e 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,4 +1,11 @@ class Movie < ActiveRecord::Base validates :title, presence: true validates :director, presence: true + + after_initialize :init + + def init + self.upvotes ||= 0 + end + end From bd47dc9bfc3d270bcb4123fdfb9ede3210b26b88 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 16:06:09 -0800 Subject: [PATCH 05/60] create homepage --- app/controllers/homepage_controller.rb | 4 ++++ app/views/homepage/index.html.erb | 24 +++++++++++++++++++++++- app/views/layouts/_header.html.erb | 3 +++ app/views/layouts/application.html.erb | 5 ++++- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 app/views/layouts/_header.html.erb diff --git a/app/controllers/homepage_controller.rb b/app/controllers/homepage_controller.rb index e09cc6e590..9a9a14f077 100644 --- a/app/controllers/homepage_controller.rb +++ b/app/controllers/homepage_controller.rb @@ -1,4 +1,8 @@ class HomepageController < ApplicationController def index + max = 10 + @books = Book.limit(max) + @movies = Movie.limit(max) + @albums = Album.limit(max) end end diff --git a/app/views/homepage/index.html.erb b/app/views/homepage/index.html.erb index 3fe0a5751a..f16d895832 100644 --- a/app/views/homepage/index.html.erb +++ b/app/views/homepage/index.html.erb @@ -1 +1,23 @@ -Hello, world! This is the homepage +
+
+

Top Movies

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

<%= link_to movie.title, movie_path(movie) %> Upvotes: <%= movie.upvotes %>

+ <% end %> +

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

+
+
+

Top Books

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

<%= link_to book.title, book_path(book) %> Upvotes: <%= book.upvotes %>

+ <% end %> +

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

+
+
+

Top Albums

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

<%= link_to album.title, album_path(album) %> Upvotes: <%= album.upvotes %>

+ <% end %> +

<%= link_to "View More Albums", albums_path %>

+
+
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb new file mode 100644 index 0000000000..315d196e3b --- /dev/null +++ b/app/views/layouts/_header.html.erb @@ -0,0 +1,3 @@ +
+

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

+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9d1c48b8e9..2b0c71d4f2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,8 +7,11 @@ <%= csrf_meta_tags %> +
+ <%= render 'layouts/header' %> + <%= yield %> +
-<%= yield %> From 571defdd0683baa65280126fa2f4b8915910997a Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 16:10:49 -0800 Subject: [PATCH 06/60] create default in migration --- app/models/album.rb | 6 ------ app/models/book.rb | 6 ------ app/models/movie.rb | 7 ------- .../20151201000752_add_default_to_book.rb | 5 +++++ db/migrate/20151201000941_add_defaults.rb | 6 ++++++ db/schema.rb | 20 +++++++++---------- 6 files changed, 21 insertions(+), 29 deletions(-) create mode 100644 db/migrate/20151201000752_add_default_to_book.rb create mode 100644 db/migrate/20151201000941_add_defaults.rb diff --git a/app/models/album.rb b/app/models/album.rb index a5a3529897..4b630eebc5 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -1,10 +1,4 @@ class Album < ActiveRecord::Base validates :title, presence: true validates :artist, presence: true - - after_initialize :init - - def init - self.upvotes ||= 0 - end end diff --git a/app/models/book.rb b/app/models/book.rb index b286f5c0eb..4bcc056a96 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,10 +1,4 @@ class Book < ActiveRecord::Base validates :title, presence: true validates :author, presence: true - - after_initialize :init - - def init - self.upvotes ||= 0 - end end diff --git a/app/models/movie.rb b/app/models/movie.rb index 4566791d9e..f3946488b0 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,11 +1,4 @@ class Movie < ActiveRecord::Base validates :title, presence: true validates :director, presence: true - - after_initialize :init - - def init - self.upvotes ||= 0 - end - end diff --git a/db/migrate/20151201000752_add_default_to_book.rb b/db/migrate/20151201000752_add_default_to_book.rb new file mode 100644 index 0000000000..8977eb09c4 --- /dev/null +++ b/db/migrate/20151201000752_add_default_to_book.rb @@ -0,0 +1,5 @@ +class AddDefaultToBook < ActiveRecord::Migration + def change + change_column_default(:albums, :upvotes, 0) + end +end diff --git a/db/migrate/20151201000941_add_defaults.rb b/db/migrate/20151201000941_add_defaults.rb new file mode 100644 index 0000000000..1a47808c93 --- /dev/null +++ b/db/migrate/20151201000941_add_defaults.rb @@ -0,0 +1,6 @@ +class AddDefaults < ActiveRecord::Migration + def change + change_column_default(:books, :upvotes, 0) + change_column_default(:movies, :upvotes, 0) + end +end diff --git a/db/schema.rb b/db/schema.rb index 3145350f95..fb60605b14 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,33 +11,33 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151130222746) do +ActiveRecord::Schema.define(version: 20151201000941) do create_table "albums", force: :cascade do |t| t.string "title" t.string "artist" t.string "description" - t.integer "upvotes" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "upvotes", default: 0 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "books", force: :cascade do |t| t.string "title" t.string "author" t.string "description" - t.integer "upvotes" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "upvotes", default: 0 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "movies", force: :cascade do |t| t.string "title" t.string "director" t.string "description" - t.integer "upvotes" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "upvotes", default: 0 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end end From 155f8ea11dd6d50f0c4214d5db29a721346064e8 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 16:18:59 -0800 Subject: [PATCH 07/60] create index for all views --- app/controllers/albums_controller.rb | 9 +++++++++ app/controllers/books_controller.rb | 8 ++++++++ app/controllers/movies_controller.rb | 9 +++++++++ app/views/albums/index.html.erb | 0 app/views/books/index.html.erb | 0 app/views/movies/index.html.erb | 0 6 files changed, 26 insertions(+) create mode 100644 app/views/albums/index.html.erb create mode 100644 app/views/books/index.html.erb create mode 100644 app/views/movies/index.html.erb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 2f800bd33f..f485a19623 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,2 +1,11 @@ class AlbumsController < ApplicationController + before_action :get_album only:[:show, :destroy, :update, :edit] + def index + + end + + private + def get_album + @album = Album.find(params[:id]) + end end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index cdb437b99f..8a9e75e56b 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,2 +1,10 @@ class BooksController < ApplicationController + before_action :get_book only:[:show, :destroy, :update, :edit] + def index + end + + private + def get_book + @book = Book.find(params[:id]) + end end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 6c4c516140..b67bccca49 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,2 +1,11 @@ class MoviesController < ApplicationController + before_action :get_movie only:[:show, :destroy, :update, :edit] + + def index + end + + private + def get_movie + @movie = Movie.find(params[:id]) + end end diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb new file mode 100644 index 0000000000..e69de29bb2 From 3276ebb29c1a477250ae72150a7474654d824021 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 16:34:35 -0800 Subject: [PATCH 08/60] create index view for all models --- app/controllers/albums_controller.rb | 14 +++++++++++++- app/controllers/books_controller.rb | 15 ++++++++++++++- app/controllers/movies_controller.rb | 15 ++++++++++++++- app/views/albums/index.html.erb | 24 ++++++++++++++++++++++++ app/views/books/index.html.erb | 24 ++++++++++++++++++++++++ app/views/layouts/_header.html.erb | 4 +++- app/views/movies/index.html.erb | 24 ++++++++++++++++++++++++ 7 files changed, 116 insertions(+), 4 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index f485a19623..3990574346 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,7 +1,19 @@ class AlbumsController < ApplicationController - before_action :get_album only:[:show, :destroy, :update, :edit] + before_action :get_album, only:[:show, :destroy, :update, :edit] def index + @albums = Album.all + end + + def show + end + + def destroy + end + + def update + end + def edit end private diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 8a9e75e56b..0110901318 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,6 +1,19 @@ class BooksController < ApplicationController - before_action :get_book only:[:show, :destroy, :update, :edit] + before_action :get_book, only:[:show, :destroy, :update, :edit] def index + @books = Book.all + end + + def show + end + + def destroy + end + + def update + end + + def edit end private diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index b67bccca49..5978dce9ff 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,7 +1,20 @@ class MoviesController < ApplicationController - before_action :get_movie only:[:show, :destroy, :update, :edit] + before_action :get_movie, only:[:show, :destroy, :update, :edit] def index + @movies = Movie.all + end + + def show + end + + def destroy + end + + def update + end + + def edit end private diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index e69de29bb2..c1ef71a040 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -0,0 +1,24 @@ +
+
+ + + + + + + + + + <% @albums.each do |album| %> + + + + + + <% end %> + +
RankingNameUpvote
Upvotes: <%= album.upvotes %><%= link_to album.title, album_path(album) %>Upvote button
+ <%= link_to "View All Media", root_path, class: "btn btn-default" %> + <%= link_to "Add an Album", new_album_path, class: "btn btn-default" %> +
+
diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index e69de29bb2..7c5f1998d8 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -0,0 +1,24 @@ +
+
+ + + + + + + + + + <% @books.each do |book| %> + + + + + + <% end %> + +
RankingNameUpvote
Upvotes: <%= book.upvotes %><%= link_to book.title, book_path(book) %>Upvote button
+ <%= link_to "View All Media", root_path, class: "btn btn-default" %> + <%= link_to "Add a Book", new_book_path, class: "btn btn-default" %> +
+
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 315d196e3b..04a9696429 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -1,3 +1,5 @@
-

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

+
diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index e69de29bb2..e170beaff2 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -0,0 +1,24 @@ +
+
+ + + + + + + + + + <% @movies.each do |movie| %> + + + + + + <% end %> + +
RankingNameUpvote
Upvotes: <%= movie.upvotes %><%= link_to movie.title, movie_path(movie) %>Upvote button
+ <%= link_to "View All Media", root_path, class: "btn btn-default" %> + <%= link_to "Add a Movie", new_movie_path, class: "btn btn-default" %> +
+
From ea579bff7998dadbdaf4a1fd703771fe755b14d2 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 16:45:01 -0800 Subject: [PATCH 09/60] create show page for book --- app/views/books/show.html.erb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/views/books/show.html.erb diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb new file mode 100644 index 0000000000..0d4548941d --- /dev/null +++ b/app/views/books/show.html.erb @@ -0,0 +1,12 @@ +
+
+

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

+

Upvotes: <%= @book.upvotes %>

+

<%= @book.description %>

+ <%= button_to "Upvote", "#", class: "btn btn-primary" %> + <%= link_to "Edit #{@book.title}", edit_book_path(@book), method: :get, class: "btn btn-default" %> + <%= link_to "DELETE", book_path(@book), method: :delete, data: { confirm: "Are you sure you want to delete #{@book.title}?"}, class: "btn btn-danger" %> + <%= link_to "View all Books", books_path, class: "btn btn-default" %> + <%= link_to "View all Media", root_path, class: "btn btn-default" %> +
+
From a9eb5a467260a129d1dd15d1f03207f8777becb7 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 16:45:43 -0800 Subject: [PATCH 10/60] create destroy for books --- app/controllers/books_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 0110901318..e361be4f9a 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -8,6 +8,8 @@ def show end def destroy + @book.destroy + redirect_to books_path end def update From 4dff574b5af5381a6202a251eebd1e40c2722f56 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 16:48:51 -0800 Subject: [PATCH 11/60] create show for all models --- app/controllers/albums_controller.rb | 2 ++ app/controllers/movies_controller.rb | 2 ++ app/views/albums/show.html.erb | 12 ++++++++++++ app/views/movies/show.html.erb | 12 ++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 app/views/albums/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 3990574346..3b672aed27 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -8,6 +8,8 @@ def show end def destroy + @album.destroy + redirect_to albums_path end def update diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 5978dce9ff..e2c5955c5a 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -9,6 +9,8 @@ def show end def destroy + @movie.destroy + redirect_to movies_path end def update diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb new file mode 100644 index 0000000000..f85f9e5b5b --- /dev/null +++ b/app/views/albums/show.html.erb @@ -0,0 +1,12 @@ +
+
+

<%= @album.title %> Written by: <%= @album.artist %>

+

Upvotes: <%= @album.upvotes %>

+

<%= @album.description %>

+ <%= button_to "Upvote", "#", class: "btn btn-primary" %> + <%= link_to "Edit #{@album.title}", edit_album_path(@album), method: :get, class: "btn btn-default" %> + <%= link_to "DELETE", album_path(@album), method: :delete, data: { confirm: "Are you sure you want to delete #{@album.title}?"}, class: "btn btn-danger" %> + <%= link_to "View all albums", albums_path, class: "btn btn-default" %> + <%= link_to "View all Media", root_path, class: "btn btn-default" %> +
+
diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb new file mode 100644 index 0000000000..e9d5dca120 --- /dev/null +++ b/app/views/movies/show.html.erb @@ -0,0 +1,12 @@ +
+
+

<%= @movie.title %> Written by: <%= @movie.director %>

+

Upvotes: <%= @movie.upvotes %>

+

<%= @movie.description %>

+ <%= button_to "Upvote", "#", class: "btn btn-primary" %> + <%= link_to "Edit #{@movie.title}", edit_movie_path(@movie), method: :get, class: "btn btn-default" %> + <%= link_to "DELETE", movie_path(@movie), method: :delete, data: { confirm: "Are you sure you want to delete #{@movie.title}?"}, class: "btn btn-danger" %> + <%= link_to "View all movies", movies_path, class: "btn btn-default" %> + <%= link_to "View all Media", root_path, class: "btn btn-default" %> +
+
From b0bf8bfc2dcbac374a09b73ff6c6412c368b6163 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 20:59:02 -0800 Subject: [PATCH 12/60] complete edit and create movie views --- app/controllers/albums_controller.rb | 4 ++++ app/controllers/books_controller.rb | 5 +++++ app/controllers/movies_controller.rb | 16 ++++++++++++++++ app/views/albums/edit.html.erb | 0 app/views/books/edit.html.erb | 0 app/views/movies/_form.html.erb | 14 ++++++++++++++ app/views/movies/edit.html.erb | 2 ++ app/views/movies/new.html.erb | 2 ++ 8 files changed, 43 insertions(+) create mode 100644 app/views/albums/edit.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 create mode 100644 app/views/movies/new.html.erb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 3b672aed27..d14f7a5e49 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -4,6 +4,10 @@ def index @albums = Album.all end + def new + @album = Album.new + end + def show end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index e361be4f9a..30a3f85ae9 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -4,6 +4,11 @@ def index @books = Book.all end + def new + @book = Book.new + end + + def show end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index e2c5955c5a..e9c50f1766 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -5,6 +5,16 @@ def index @movies = Movie.all end + def new + @movie = Movie.new + end + + def create + Movie.create(movie_params[:movie]) + redirect_to movies_path + end + + def show end @@ -14,6 +24,8 @@ def destroy end def update + @movie.update(movie_params[:movie]) + redirect_to movie_path(@movie) end def edit @@ -23,4 +35,8 @@ def edit def get_movie @movie = Movie.find(params[:id]) end + + def movie_params + params.permit(movie:[:id, :title, :director, :description, :upvotes]) + end end diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb new file mode 100644 index 0000000000..bc05c9a6f4 --- /dev/null +++ b/app/views/movies/_form.html.erb @@ -0,0 +1,14 @@ +
+
+

<%= yield(:title) %>

+ <%= form_for @movie, :html => {:class => "form-group"} do |f| %> + <%= f.label :title %> + <%= f.text_field :title, class: 'form-control', :required => true %> + <%= f.label :director %> + <%= f.text_field :director, class: 'form-control', :required => true %> + <%= f.label :description %> + <%= f.text_area :description, class: 'form-control' %> + <%= f.submit value: "Save", class: "btn btn-default"%> + <% end %> +
+
diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb new file mode 100644 index 0000000000..a0476302de --- /dev/null +++ b/app/views/movies/edit.html.erb @@ -0,0 +1,2 @@ +<% provide(:title, "Edit Movie")%> +<%= render partial: 'form' %> diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb new file mode 100644 index 0000000000..253d40a68e --- /dev/null +++ b/app/views/movies/new.html.erb @@ -0,0 +1,2 @@ +<% provide(:title, "New Movie")%> +<%= render partial: 'form' %> From 88715341d140558f0b1c622dde1254a182e42084 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 21:05:30 -0800 Subject: [PATCH 13/60] create and edit books --- app/controllers/books_controller.rb | 11 +++++++++++ app/views/albums/_form.html.erb | 14 ++++++++++++++ app/views/albums/edit.html.erb | 2 ++ app/views/albums/new.html.erb | 2 ++ app/views/books/_form.html.erb | 14 ++++++++++++++ app/views/books/edit.html.erb | 2 ++ app/views/books/new.html.erb | 2 ++ 7 files changed, 47 insertions(+) create mode 100644 app/views/albums/_form.html.erb create mode 100644 app/views/albums/new.html.erb create mode 100644 app/views/books/_form.html.erb create mode 100644 app/views/books/new.html.erb diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 30a3f85ae9..5389895e5d 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -18,6 +18,13 @@ def destroy end def update + @book.update(book_params[:book]) + redirect_to book_path(@book) + end + + def create + Book.create(book_params[:book]) + redirect_to books_path end def edit @@ -27,4 +34,8 @@ def edit def get_book @book = Book.find(params[:id]) end + + def book_params + params.permit(book:[:id, :title, :author, :description, :upvotes]) + end end diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb new file mode 100644 index 0000000000..81d4d8adce --- /dev/null +++ b/app/views/albums/_form.html.erb @@ -0,0 +1,14 @@ +
+
+

<%= yield(:title) %>

+ <%= form_for @album, :html => {:class => "form-group"} do |f| %> + <%= f.label :title %> + <%= f.text_field :title, class: 'form-control', :required => true %> + <%= f.label :artist %> + <%= f.text_field :artist, class: 'form-control', :required => true %> + <%= f.label :description %> + <%= f.text_area :description, class: 'form-control' %> + <%= f.submit value: "Save", class: "btn btn-default"%> + <% end %> +
+
diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb index e69de29bb2..5724b22f14 100644 --- a/app/views/albums/edit.html.erb +++ b/app/views/albums/edit.html.erb @@ -0,0 +1,2 @@ +<% provide(:title, "Edit Album")%> +<%= render partial: 'form' %> diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb new file mode 100644 index 0000000000..a090f367f9 --- /dev/null +++ b/app/views/albums/new.html.erb @@ -0,0 +1,2 @@ +<% provide(:title, "New Album")%> +<%= render partial: 'form' %> diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb new file mode 100644 index 0000000000..357f9d2e93 --- /dev/null +++ b/app/views/books/_form.html.erb @@ -0,0 +1,14 @@ +
+
+

<%= yield(:title) %>

+ <%= form_for @book, :html => {:class => "form-group"} do |f| %> + <%= f.label :title %> + <%= f.text_field :title, class: 'form-control', :required => true %> + <%= f.label :author %> + <%= f.text_field :author, class: 'form-control', :required => true %> + <%= f.label :description %> + <%= f.text_area :description, class: 'form-control' %> + <%= f.submit value: "Save", class: "btn btn-default"%> + <% end %> +
+
diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb index e69de29bb2..d33102e7a2 100644 --- a/app/views/books/edit.html.erb +++ b/app/views/books/edit.html.erb @@ -0,0 +1,2 @@ +<% provide(:title, "Edit Book")%> +<%= render partial: 'form' %> diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb new file mode 100644 index 0000000000..601a52e05f --- /dev/null +++ b/app/views/books/new.html.erb @@ -0,0 +1,2 @@ +<% provide(:title, "New Book")%> +<%= render partial: 'form' %> From c55f339210e6ec019f36ee9f86ff3d86517a73a4 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 21:09:11 -0800 Subject: [PATCH 14/60] add and edit albums --- app/controllers/albums_controller.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index d14f7a5e49..4c3a5f1a2f 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -17,6 +17,13 @@ def destroy end def update + @album.update(album_params[:album]) + redirect_to album_path(@album) + end + + def create + Album.create(album_params[:album]) + redirect_to albums_path end def edit @@ -26,4 +33,8 @@ def edit def get_album @album = Album.find(params[:id]) end + + def album_params + params.permit(album:[:id, :title, :artist, :description, :upvotes]) + end end From 12e8db6acd9e9648e35efb3a7362a2e6f756abd4 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 21:11:22 -0800 Subject: [PATCH 15/60] change typos --- app/views/albums/show.html.erb | 2 +- app/views/movies/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index f85f9e5b5b..a5818275a4 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -1,6 +1,6 @@
-

<%= @album.title %> Written by: <%= @album.artist %>

+

<%= @album.title %> Performed by: <%= @album.artist %>

Upvotes: <%= @album.upvotes %>

<%= @album.description %>

<%= button_to "Upvote", "#", class: "btn btn-primary" %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index e9d5dca120..21365edaa0 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -1,6 +1,6 @@
-

<%= @movie.title %> Written by: <%= @movie.director %>

+

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

Upvotes: <%= @movie.upvotes %>

<%= @movie.description %>

<%= button_to "Upvote", "#", class: "btn btn-primary" %> From b3fbdd66bf54eff3ffc216391ac0885741073afa Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 21:27:09 -0800 Subject: [PATCH 16/60] create upvotes for albums --- app/controllers/albums_controller.rb | 8 +++++++- app/views/albums/index.html.erb | 2 +- app/views/albums/show.html.erb | 2 +- config/routes.rb | 18 +++++++++++++++--- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 4c3a5f1a2f..37888baef6 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,5 +1,5 @@ class AlbumsController < ApplicationController - before_action :get_album, only:[:show, :destroy, :update, :edit] + before_action :get_album, only:[:show, :destroy, :update, :edit, :upvote] def index @albums = Album.all end @@ -29,6 +29,12 @@ def create def edit end + def upvote + @album.upvotes += 1 + @album.save + redirect_to album_path(@album) + end + private def get_album @album = Album.find(params[:id]) diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index c1ef71a040..29e748f287 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -13,7 +13,7 @@ Upvotes: <%= album.upvotes %> <%= link_to album.title, album_path(album) %> - Upvote button + <%= button_to "Upvote", upvote_album_path(album), method: :post, class: "btn btn-default" %> <% end %> diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index a5818275a4..5edee1fc3b 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -3,7 +3,7 @@

<%= @album.title %> Performed by: <%= @album.artist %>

Upvotes: <%= @album.upvotes %>

<%= @album.description %>

- <%= button_to "Upvote", "#", class: "btn btn-primary" %> + <%= button_to "Upvote", upvote_album_path(@album), method: :post, class: "btn btn-primary" %> <%= link_to "Edit #{@album.title}", edit_album_path(@album), method: :get, class: "btn btn-default" %> <%= link_to "DELETE", album_path(@album), method: :delete, data: { confirm: "Are you sure you want to delete #{@album.title}?"}, class: "btn btn-danger" %> <%= link_to "View all albums", albums_path, class: "btn btn-default" %> diff --git a/config/routes.rb b/config/routes.rb index 1b70cf0e48..15de8360cf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,18 @@ Rails.application.routes.draw do root 'homepage#index' - resources :movies - resources :books - resources :albums + resources :movies do + member do + post 'upvote' + end + end + resources :books do + member do + post 'upvote' + end + end + resources :albums do + member do + post 'upvote' + end + end end From 0e30023c4d49827cb5b7502b2d784aa77f1b3f7e Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 21:31:39 -0800 Subject: [PATCH 17/60] upvote for books --- app/controllers/books_controller.rb | 8 +++++++- app/views/books/index.html.erb | 2 +- app/views/books/show.html.erb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 5389895e5d..e2ce199c7b 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,5 +1,5 @@ class BooksController < ApplicationController - before_action :get_book, only:[:show, :destroy, :update, :edit] + before_action :get_book, only:[:show, :destroy, :update, :edit, :upvote] def index @books = Book.all end @@ -30,6 +30,12 @@ def create def edit end + def upvote + @book.upvotes += 1 + @book.save + redirect_to book_path(@book) + end + private def get_book @book = Book.find(params[:id]) diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index 7c5f1998d8..139f2b6ae2 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -13,7 +13,7 @@ Upvotes: <%= book.upvotes %> <%= link_to book.title, book_path(book) %> - Upvote button + <%= button_to "Upvote", upvote_book_path(book), method: :post, class: "btn btn-default" %> <% end %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index 0d4548941d..1268657140 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -3,7 +3,7 @@

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

Upvotes: <%= @book.upvotes %>

<%= @book.description %>

- <%= button_to "Upvote", "#", class: "btn btn-primary" %> + <%= button_to "Upvote", upvote_book_path(@book), method: :post, class: "btn btn-default" %> <%= link_to "Edit #{@book.title}", edit_book_path(@book), method: :get, class: "btn btn-default" %> <%= link_to "DELETE", book_path(@book), method: :delete, data: { confirm: "Are you sure you want to delete #{@book.title}?"}, class: "btn btn-danger" %> <%= link_to "View all Books", books_path, class: "btn btn-default" %> From 384808fee638f9a675b4462cf0b21fbf218803ac Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 21:34:46 -0800 Subject: [PATCH 18/60] upvote for movies --- app/controllers/movies_controller.rb | 8 +++++++- app/views/movies/index.html.erb | 2 +- app/views/movies/show.html.erb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index e9c50f1766..2e7d9c4faa 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,5 +1,5 @@ class MoviesController < ApplicationController - before_action :get_movie, only:[:show, :destroy, :update, :edit] + before_action :get_movie, only:[:show, :destroy, :update, :edit, :upvote] def index @movies = Movie.all @@ -31,6 +31,12 @@ def update def edit end + def upvote + @movie.upvotes += 1 + @movie.save + redirect_to movie_path(@movie) + end + private def get_movie @movie = Movie.find(params[:id]) diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index e170beaff2..f3591c921f 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -13,7 +13,7 @@ Upvotes: <%= movie.upvotes %> <%= link_to movie.title, movie_path(movie) %> - Upvote button + <%= button_to "Upvote", upvote_movie_path(movie), method: :post, class: "btn btn-default" %> <% end %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 21365edaa0..9404e5aca3 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -3,7 +3,7 @@

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

Upvotes: <%= @movie.upvotes %>

<%= @movie.description %>

- <%= button_to "Upvote", "#", class: "btn btn-primary" %> + <%= button_to "Upvote", upvote_movie_path(@movie), method: :post, class: "btn btn-primary" %> <%= link_to "Edit #{@movie.title}", edit_movie_path(@movie), method: :get, class: "btn btn-default" %> <%= link_to "DELETE", movie_path(@movie), method: :delete, data: { confirm: "Are you sure you want to delete #{@movie.title}?"}, class: "btn btn-danger" %> <%= link_to "View all movies", movies_path, class: "btn btn-default" %> From 84a56cd9aea9f7a829ccb1dda121e289439a925d Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 21:45:59 -0800 Subject: [PATCH 19/60] create random num of upvotes in seed --- db/seeds.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 4efe899b5d..6be36e1eee 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -89,6 +89,20 @@ author: "Sandi Metz"}, ] -albums.each { |album| Album.create(album) } -movies.each { |movie| Movie.create(movie) } -books.each { |book| Book.create(book) } +albums.each do |album| + a = Album.create(album) + a.upvotes = rand(1..50) + a.save +end + +movies.each do |movie| + m = Movie.create(movie) + m.upvotes = rand(1..50) + m.save +end + +books.each do |book| + b = Book.create(book) + b.upvotes = rand(1..50) + b.save +end From ae0146bfeb4332d33a073a36e903201783873b1e Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Mon, 30 Nov 2015 21:53:41 -0800 Subject: [PATCH 20/60] order results by number of upvotes --- app/controllers/albums_controller.rb | 2 +- app/controllers/books_controller.rb | 2 +- app/controllers/homepage_controller.rb | 6 +++--- app/controllers/movies_controller.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 37888baef6..b2e0024737 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,7 +1,7 @@ class AlbumsController < ApplicationController before_action :get_album, only:[:show, :destroy, :update, :edit, :upvote] def index - @albums = Album.all + @albums = Album.all.order(:upvotes).reverse end def new diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index e2ce199c7b..46889ff321 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,7 +1,7 @@ class BooksController < ApplicationController before_action :get_book, only:[:show, :destroy, :update, :edit, :upvote] def index - @books = Book.all + @books = Book.all.order(:upvotes).reverse end def new diff --git a/app/controllers/homepage_controller.rb b/app/controllers/homepage_controller.rb index 9a9a14f077..5adbfcff0c 100644 --- a/app/controllers/homepage_controller.rb +++ b/app/controllers/homepage_controller.rb @@ -1,8 +1,8 @@ class HomepageController < ApplicationController def index max = 10 - @books = Book.limit(max) - @movies = Movie.limit(max) - @albums = Album.limit(max) + @books = Book.limit(max).order(:upvotes).reverse + @movies = Movie.limit(max).order(:upvotes).reverse + @albums = Album.limit(max).order(:upvotes).reverse end end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 2e7d9c4faa..a1103a1a1f 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -2,7 +2,7 @@ class MoviesController < ApplicationController before_action :get_movie, only:[:show, :destroy, :update, :edit, :upvote] def index - @movies = Movie.all + @movies = Movie.all.order(:upvotes).reverse end def new From 9114f8f78b8266bb264d39a643afb20996dd2984 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 10:33:36 -0800 Subject: [PATCH 21/60] refactor form partial --- app/views/movies/_form.html.erb | 17 +++-------------- app/views/movies/new.html.erb | 2 +- app/views/shared/_form.html.erb | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 app/views/shared/_form.html.erb diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb index bc05c9a6f4..1688f89e45 100644 --- a/app/views/movies/_form.html.erb +++ b/app/views/movies/_form.html.erb @@ -1,14 +1,3 @@ -
-
-

<%= yield(:title) %>

- <%= form_for @movie, :html => {:class => "form-group"} do |f| %> - <%= f.label :title %> - <%= f.text_field :title, class: 'form-control', :required => true %> - <%= f.label :director %> - <%= f.text_field :director, class: 'form-control', :required => true %> - <%= f.label :description %> - <%= f.text_area :description, class: 'form-control' %> - <%= f.submit value: "Save", class: "btn btn-default"%> - <% end %> -
-
+ + +<% render partial: 'shared/form', locals: {media: @movie, who_by: "director"} %> diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb index 253d40a68e..59b42e84bd 100644 --- a/app/views/movies/new.html.erb +++ b/app/views/movies/new.html.erb @@ -1,2 +1,2 @@ <% provide(:title, "New Movie")%> -<%= render partial: 'form' %> +<%= render partial: 'shared/form', locals: {media: @movie, who_by: "director"} %> diff --git a/app/views/shared/_form.html.erb b/app/views/shared/_form.html.erb new file mode 100644 index 0000000000..a112f9c665 --- /dev/null +++ b/app/views/shared/_form.html.erb @@ -0,0 +1,14 @@ +
+
+

<%= yield(:title) %>

+ <%= form_for media, :html => {:class => "form-group"} do |f| %> + <%= f.label :title %> + <%= f.text_field :title, class: 'form-control', :required => true %> + <%= f.label who_by %> + <%= f.text_field who_by, class: 'form-control', :required => true %> + <%= f.label :description %> + <%= f.text_area :description, class: 'form-control' %> + <%= f.submit value: "Save", class: "btn btn-default"%> + <% end %> +
+
From 9705ad6deb079335f004de5239b59f253fcd4dd7 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 10:55:52 -0800 Subject: [PATCH 22/60] add rspec to project --- Gemfile | 21 +-------------------- Gemfile.lock | 27 +++++++++++++++++++-------- app/views/movies/_form.html.erb | 3 --- 3 files changed, 20 insertions(+), 31 deletions(-) delete mode 100644 app/views/movies/_form.html.erb diff --git a/Gemfile b/Gemfile index 4777258197..d7ccd72d66 100644 --- a/Gemfile +++ b/Gemfile @@ -1,26 +1,13 @@ source 'https://rubygems.org' - -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.5' -# Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' -# Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' -# Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.1.0' -# See https://github.com/rails/execjs#readme for more supported runtimes -# gem 'therubyracer', platforms: :ruby - -# Use jquery as the JavaScript library gem 'jquery-rails' -# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' -# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' -# bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc -# add bootstrap gem 'bootstrap-sass', '~> 3.3.6' group :production do @@ -28,20 +15,14 @@ group :production do end 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 - # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' - gem 'spring' - # Add better errors gems gem 'better_errors' gem 'binding_of_caller' - # Use sqlite3 as the database for Active Record gem 'sqlite3' - # Create ERD for project - gem 'rails-erd' end diff --git a/Gemfile.lock b/Gemfile.lock index 6e69ab417c..8e0d6c43f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,7 +51,6 @@ GEM sass (>= 3.3.4) builder (3.2.2) byebug (8.2.1) - choice (0.2.0) coderay (1.1.0) coffee-rails (4.1.0) coffee-script (>= 2.2.0) @@ -61,6 +60,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) @@ -105,11 +105,6 @@ GEM activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) - rails-erd (1.4.4) - activerecord (>= 3.2) - activesupport (>= 3.2) - choice (~> 0.2.0) - ruby-graphviz (~> 1.2) rails-html-sanitizer (1.0.2) loofah (~> 2.0) railties (4.2.5) @@ -119,7 +114,23 @@ GEM thor (>= 0.18.1, < 2.0) rake (10.4.2) rdoc (4.2.0) - ruby-graphviz (1.2.2) + 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) sass (3.4.19) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -167,7 +178,7 @@ DEPENDENCIES jquery-rails pg rails (= 4.2.5) - rails-erd + rspec-rails sass-rails (~> 5.0) sdoc (~> 0.4.0) spring diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb deleted file mode 100644 index 1688f89e45..0000000000 --- a/app/views/movies/_form.html.erb +++ /dev/null @@ -1,3 +0,0 @@ - - -<% render partial: 'shared/form', locals: {media: @movie, who_by: "director"} %> From a907fcc64d59d750cedd2b0ca7a6d473ec6c905a Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 11:01:32 -0800 Subject: [PATCH 23/60] refactor add and edit to use form partial --- app/views/albums/_form.html.erb | 14 -------------- app/views/albums/edit.html.erb | 2 +- app/views/albums/new.html.erb | 2 +- app/views/books/_form.html.erb | 14 -------------- app/views/books/edit.html.erb | 2 +- app/views/books/new.html.erb | 2 +- app/views/movies/edit.html.erb | 2 +- 7 files changed, 5 insertions(+), 33 deletions(-) delete mode 100644 app/views/albums/_form.html.erb delete mode 100644 app/views/books/_form.html.erb diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb deleted file mode 100644 index 81d4d8adce..0000000000 --- a/app/views/albums/_form.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -
-
-

<%= yield(:title) %>

- <%= form_for @album, :html => {:class => "form-group"} do |f| %> - <%= f.label :title %> - <%= f.text_field :title, class: 'form-control', :required => true %> - <%= f.label :artist %> - <%= f.text_field :artist, class: 'form-control', :required => true %> - <%= f.label :description %> - <%= f.text_area :description, class: 'form-control' %> - <%= f.submit value: "Save", class: "btn btn-default"%> - <% end %> -
-
diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb index 5724b22f14..9227f2aac1 100644 --- a/app/views/albums/edit.html.erb +++ b/app/views/albums/edit.html.erb @@ -1,2 +1,2 @@ <% provide(:title, "Edit Album")%> -<%= render partial: 'form' %> +<%= render partial: 'shared/form', locals: {media: @album, who_by: "artist"} %> diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb index a090f367f9..e356cb360d 100644 --- a/app/views/albums/new.html.erb +++ b/app/views/albums/new.html.erb @@ -1,2 +1,2 @@ <% provide(:title, "New Album")%> -<%= render partial: 'form' %> +<%= render partial: 'shared/form', locals: {media: @album, who_by: "artist"} %> diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb deleted file mode 100644 index 357f9d2e93..0000000000 --- a/app/views/books/_form.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -
-
-

<%= yield(:title) %>

- <%= form_for @book, :html => {:class => "form-group"} do |f| %> - <%= f.label :title %> - <%= f.text_field :title, class: 'form-control', :required => true %> - <%= f.label :author %> - <%= f.text_field :author, class: 'form-control', :required => true %> - <%= f.label :description %> - <%= f.text_area :description, class: 'form-control' %> - <%= f.submit value: "Save", class: "btn btn-default"%> - <% end %> -
-
diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb index d33102e7a2..5a6cde73f5 100644 --- a/app/views/books/edit.html.erb +++ b/app/views/books/edit.html.erb @@ -1,2 +1,2 @@ <% provide(:title, "Edit Book")%> -<%= render partial: 'form' %> +<%= render partial: 'shared/form', locals: {media: @book, who_by: "author"} %> diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb index 601a52e05f..14c52cf3aa 100644 --- a/app/views/books/new.html.erb +++ b/app/views/books/new.html.erb @@ -1,2 +1,2 @@ <% provide(:title, "New Book")%> -<%= render partial: 'form' %> +<%= render partial: 'shared/form', locals: {media: @book, who_by: "author"} %> diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb index a0476302de..d8ceca4730 100644 --- a/app/views/movies/edit.html.erb +++ b/app/views/movies/edit.html.erb @@ -1,2 +1,2 @@ <% provide(:title, "Edit Movie")%> -<%= render partial: 'form' %> +<%= render partial: 'shared/form', locals: {media: @movie, who_by: "director"} %> From 8aebab808cb08d8e11dc916dbcb626a926ac26db Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 11:16:54 -0800 Subject: [PATCH 24/60] create tests for controllers and models --- .rspec | 2 + spec/controllers/albums_controller_spec.rb | 10 +++ spec/controllers/books_controller_spec.rb | 10 +++ spec/controllers/movies_controller_spec.rb | 10 +++ spec/models/album_spec.rb | 11 +++ spec/models/book_spec.rb | 11 +++ spec/models/movie_spec.rb | 11 +++ spec/rails_helper.rb | 57 ++++++++++++++ spec/spec_helper.rb | 92 ++++++++++++++++++++++ 9 files changed, 214 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/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/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb new file mode 100644 index 0000000000..58bb18171c --- /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..034e5e082f --- /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..d3bf540e93 --- /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/models/album_spec.rb b/spec/models/album_spec.rb new file mode 100644 index 0000000000..1135e1f5df --- /dev/null +++ b/spec/models/album_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe Album, type: :model do + describe ".validates" do + it "must have a title and an artist" do + expect(Album.new(title: "a", artist: nil)).to_not be_valid + expect(Album.new(title: nil, artist: "a")).to_not be_valid + expect(Album.new(title: "a", artist: "a")).to be_valid + end + end +end diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb new file mode 100644 index 0000000000..6d262c903a --- /dev/null +++ b/spec/models/book_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe Book, type: :model do + describe ".validates" do + it "must have a title and an author" do + expect(Book.new(title: "a", author: nil)).to_not be_valid + expect(Book.new(title: nil, author: "a")).to_not be_valid + expect(Book.new(title: "a", author: "a")).to be_valid + end + end +end diff --git a/spec/models/movie_spec.rb b/spec/models/movie_spec.rb new file mode 100644 index 0000000000..87b7e907ff --- /dev/null +++ b/spec/models/movie_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe Movie, type: :model do + describe ".validates" do + it "must have a title and a director" do + expect(Movie.new(title: "a", director: nil)).to_not be_valid + expect(Movie.new(title: nil, director: "a")).to_not be_valid + expect(Movie.new(title: "a", director: "a")).to be_valid + end + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000000..6f1ab14638 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,57 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'spec_helper' +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } + +# Checks for pending migration and applies them before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000000..61e27385c3 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,92 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end From 6386c16fd6b8eeed02b38470d7506128dd615357 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 11:40:24 -0800 Subject: [PATCH 25/60] refactor index page --- app/views/albums/index.html.erb | 25 +------------------------ app/views/books/index.html.erb | 25 +------------------------ app/views/movies/index.html.erb | 25 +------------------------ app/views/shared/_index.html.erb | 24 ++++++++++++++++++++++++ 4 files changed, 27 insertions(+), 72 deletions(-) create mode 100644 app/views/shared/_index.html.erb diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index 29e748f287..481150b63e 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -1,24 +1 @@ -
-
- - - - - - - - - - <% @albums.each do |album| %> - - - - - - <% end %> - -
RankingNameUpvote
Upvotes: <%= album.upvotes %><%= link_to album.title, album_path(album) %><%= button_to "Upvote", upvote_album_path(album), method: :post, class: "btn btn-default" %>
- <%= link_to "View All Media", root_path, class: "btn btn-default" %> - <%= link_to "Add an Album", new_album_path, class: "btn btn-default" %> -
-
+<%= render partial: 'shared/index', locals: {objects: @albums} %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index 139f2b6ae2..c9df05cbca 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -1,24 +1 @@ -
-
- - - - - - - - - - <% @books.each do |book| %> - - - - - - <% end %> - -
RankingNameUpvote
Upvotes: <%= book.upvotes %><%= link_to book.title, book_path(book) %><%= button_to "Upvote", upvote_book_path(book), method: :post, class: "btn btn-default" %>
- <%= link_to "View All Media", root_path, class: "btn btn-default" %> - <%= link_to "Add a Book", new_book_path, class: "btn btn-default" %> -
-
+<%= render partial: 'shared/index', locals: {objects: @books} %> diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index f3591c921f..494249c09c 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -1,24 +1 @@ -
-
- - - - - - - - - - <% @movies.each do |movie| %> - - - - - - <% end %> - -
RankingNameUpvote
Upvotes: <%= movie.upvotes %><%= link_to movie.title, movie_path(movie) %><%= button_to "Upvote", upvote_movie_path(movie), method: :post, class: "btn btn-default" %>
- <%= link_to "View All Media", root_path, class: "btn btn-default" %> - <%= link_to "Add a Movie", new_movie_path, class: "btn btn-default" %> -
-
+<%= render partial: 'shared/index', locals: {objects: @movies} %> diff --git a/app/views/shared/_index.html.erb b/app/views/shared/_index.html.erb new file mode 100644 index 0000000000..b88d070da6 --- /dev/null +++ b/app/views/shared/_index.html.erb @@ -0,0 +1,24 @@ +
+
+ + + + + + + + + + <% objects.each do |object| %> + + + + + + <% end %> + +
RankingNameUpvote
Upvotes: <%= object.upvotes %><%= link_to object.title, polymorphic_path(object) %><%= button_to "Upvote", polymorphic_path([:upvote, object]), method: :post, class: "btn btn-default" %>
+ <%= link_to "View All Media", root_path, class: "btn btn-default" %> + <%= link_to "Add a #{objects.first.class}", new_polymorphic_path(objects.first.class), class: "btn btn-default" %> +
+
From 94770c8f890529142cb7c08a04020c028a21d30e Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 13:47:10 -0800 Subject: [PATCH 26/60] refactor show pages --- app/views/albums/show.html.erb | 14 ++------------ app/views/books/show.html.erb | 14 ++------------ app/views/movies/show.html.erb | 14 ++------------ app/views/shared/_show.html.erb | 12 ++++++++++++ 4 files changed, 18 insertions(+), 36 deletions(-) create mode 100644 app/views/shared/_show.html.erb diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index 5edee1fc3b..d2d3c41923 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -1,12 +1,2 @@ -
-
-

<%= @album.title %> Performed by: <%= @album.artist %>

-

Upvotes: <%= @album.upvotes %>

-

<%= @album.description %>

- <%= button_to "Upvote", upvote_album_path(@album), method: :post, class: "btn btn-primary" %> - <%= link_to "Edit #{@album.title}", edit_album_path(@album), method: :get, class: "btn btn-default" %> - <%= link_to "DELETE", album_path(@album), method: :delete, data: { confirm: "Are you sure you want to delete #{@album.title}?"}, class: "btn btn-danger" %> - <%= link_to "View all albums", albums_path, class: "btn btn-default" %> - <%= link_to "View all Media", root_path, class: "btn btn-default" %> -
-
+<% provide(:who_by, "Recorded by:") %> +<%= render partial: 'shared/show', locals: {object: @album, by: @album.artist} %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index 1268657140..cf97506c8c 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -1,12 +1,2 @@ -
-
-

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

-

Upvotes: <%= @book.upvotes %>

-

<%= @book.description %>

- <%= button_to "Upvote", upvote_book_path(@book), method: :post, class: "btn btn-default" %> - <%= link_to "Edit #{@book.title}", edit_book_path(@book), method: :get, class: "btn btn-default" %> - <%= link_to "DELETE", book_path(@book), method: :delete, data: { confirm: "Are you sure you want to delete #{@book.title}?"}, class: "btn btn-danger" %> - <%= link_to "View all Books", books_path, class: "btn btn-default" %> - <%= link_to "View all Media", root_path, class: "btn btn-default" %> -
-
+<% provide(:who_by, "Written by:") %> +<%= render partial: 'shared/show', locals: {object: @book, by: @book.author} %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 9404e5aca3..6844e20d61 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -1,12 +1,2 @@ -
-
-

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

-

Upvotes: <%= @movie.upvotes %>

-

<%= @movie.description %>

- <%= button_to "Upvote", upvote_movie_path(@movie), method: :post, class: "btn btn-primary" %> - <%= link_to "Edit #{@movie.title}", edit_movie_path(@movie), method: :get, class: "btn btn-default" %> - <%= link_to "DELETE", movie_path(@movie), method: :delete, data: { confirm: "Are you sure you want to delete #{@movie.title}?"}, class: "btn btn-danger" %> - <%= link_to "View all movies", movies_path, class: "btn btn-default" %> - <%= link_to "View all Media", root_path, class: "btn btn-default" %> -
-
+<% provide(:who_by, "Directed by:") %> +<%= render partial: 'shared/show', locals: {object: @movie, by: @movie.director} %> diff --git a/app/views/shared/_show.html.erb b/app/views/shared/_show.html.erb new file mode 100644 index 0000000000..527180d9b8 --- /dev/null +++ b/app/views/shared/_show.html.erb @@ -0,0 +1,12 @@ +
+
+

<%= object.title %> <%= yield(:who_by) %> <%= by %>

+

Upvotes: <%= object.upvotes %>

+

<%= object.description %>

+ <%= button_to "Upvote", polymorphic_path([:upvote, object]), method: :post, class: "btn btn-primary" %> + <%= link_to "Edit #{object.title}", edit_polymorphic_path(object), method: :get, class: "btn btn-default" %> + <%= link_to "DELETE", polymorphic_path(object), method: :delete, data: { confirm: "Are you sure you want to delete #{object.title}?"}, class: "btn btn-danger" %> + <%= link_to "View all #{object.class}s", polymorphic_path(object), class: "btn btn-default" %> + <%= link_to "View all Media", root_path, class: "btn btn-default" %> +
+
From 66760e68e0775a290cf2d34529a808162452fb20 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 14:06:07 -0800 Subject: [PATCH 27/60] create empty methods for movies controller --- spec/controllers/movies_controller_spec.rb | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index d3bf540e93..c1b79b3bdf 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -7,4 +7,34 @@ expect(response.status).to eq 200 end end + + describe "POST 'create'" do + + end + + describe "GET 'new'" do + + end + + describe "GET 'edit'" do + + end + + describe "GET 'show'" do + + end + + describe "PATCH 'update'" do + + end + + describe "DELETE 'destroy'" do + + end + + describe "POST 'upvote'" do + + end + + end From dc3fcf412f10eaf9acdcfc253dd8ce7277449875 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 14:21:08 -0800 Subject: [PATCH 28/60] add some tests for movies controller --- spec/controllers/movies_controller_spec.rb | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index c1b79b3bdf..ea6670d8c6 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -8,19 +8,32 @@ end end - describe "POST 'create'" do - - end - describe "GET 'new'" do - + it "renders new view" do + get :new + expect(subject).to render_template :new + end end - describe "GET 'edit'" do + # describe "GET 'edit'" do + # it "renders edit view" do + # movie = Movie.first + # get :edit, movie + # expect(subject).to render_template :edit, movie + # end + # end + describe "GET 'show'" do + let(:new_movie) do + Movie.create(title:"Schindler's List 2", director: "Steven Spielberg") + end + it "renders show view" do + get :show, id: new_movie.id + expect(subject).to render_template :show + end end - describe "GET 'show'" do + describe "POST 'create'" do end From 2eaf315e893b19319501ed81caea77b12e446349 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 14:22:42 -0800 Subject: [PATCH 29/60] add empty methods to albums and books controller tests --- spec/controllers/albums_controller_spec.rb | 23 +++++++++++++++++ spec/controllers/books_controller_spec.rb | 29 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 58bb18171c..669847e8a0 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -7,4 +7,27 @@ expect(response.status).to eq 200 end end + + describe "GET 'edit'" do + end + + describe "GET 'show'" do + + end + + describe "POST 'create'" do + + end + + describe "PATCH 'update'" do + + end + + describe "DELETE 'destroy'" do + + end + + describe "POST 'upvote'" do + + end end diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index 034e5e082f..62e6cc060e 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -7,4 +7,33 @@ expect(response.status).to eq 200 end end + describe "GET 'new'" do + it "renders new view" do + get :new + expect(subject).to render_template :new + end + end + + describe "GET 'edit'" do + end + + describe "GET 'show'" do + + end + + describe "POST 'create'" do + + end + + describe "PATCH 'update'" do + + end + + describe "DELETE 'destroy'" do + + end + + describe "POST 'upvote'" do + + end end From 117c39833c083364975b3a2078baf94dac983af8 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 14:30:43 -0800 Subject: [PATCH 30/60] create test for create fail --- spec/controllers/movies_controller_spec.rb | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index ea6670d8c6..3d44537628 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -34,7 +34,29 @@ end describe "POST 'create'" do - + let(:good_params) do + { + movie: { + title: "Schindler's List 2", + director: "Steven Spielberg" + } + } + end + let(:bad_params) do + { + movie: { + title: "Schindler's List 2", + } + } + end + it "redirects to show page on success" do + post :create, good_params + expect(subject).to redirect_to movies_path + end + it "renders new page on fail" do + post :create, bad_params + expect(subject).to render_template :create + end end describe "PATCH 'update'" do From d5c41936f7d4797074f5b02c0f9edf0457a86df4 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 14:34:00 -0800 Subject: [PATCH 31/60] change create method to render new page on failed submission --- app/controllers/movies_controller.rb | 4 ++-- spec/controllers/movies_controller_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index a1103a1a1f..4c0800f8ed 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -10,8 +10,8 @@ def new end def create - Movie.create(movie_params[:movie]) - redirect_to movies_path + movie = Movie.new(movie_params[:movie]) + movie.save ? (redirect_to movies_path) : (render :new) end diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 3d44537628..1003020e98 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -55,7 +55,7 @@ end it "renders new page on fail" do post :create, bad_params - expect(subject).to render_template :create + expect(subject).to render_template :new end end From 51c871fae8b21cfcd0ced97a1f6770b00e104774 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 15:02:51 -0800 Subject: [PATCH 32/60] create test for patch update --- spec/controllers/movies_controller_spec.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 1003020e98..6d68cf81d7 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -60,7 +60,18 @@ end describe "PATCH 'update'" do - + it "redirects to show page" do + movie = Movie.create(title: "Schindler's List", director: "Steven Spielberg") + update_params = { + movie: { + title: "Schindler's List 2", + director: "Steven Spielberg" + }, + id: movie.id + } + patch :update, update_params + expect(subject).to redirect_to movie_path(movie.id) + end end describe "DELETE 'destroy'" do From bf2b38277d875e3911f1641482ae5aafd64f5cd1 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 15:56:23 -0800 Subject: [PATCH 33/60] refactor redirecting new movie to show page --- app/controllers/movies_controller.rb | 2 +- app/views/shared/_show.html.erb | 2 +- spec/controllers/movies_controller_spec.rb | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 4c0800f8ed..8b825b3632 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -11,7 +11,7 @@ def new def create movie = Movie.new(movie_params[:movie]) - movie.save ? (redirect_to movies_path) : (render :new) + movie.save ? (redirect_to movie_path(movie)) : (render :new) end diff --git a/app/views/shared/_show.html.erb b/app/views/shared/_show.html.erb index 527180d9b8..30b12e1330 100644 --- a/app/views/shared/_show.html.erb +++ b/app/views/shared/_show.html.erb @@ -6,7 +6,7 @@ <%= button_to "Upvote", polymorphic_path([:upvote, object]), method: :post, class: "btn btn-primary" %> <%= link_to "Edit #{object.title}", edit_polymorphic_path(object), method: :get, class: "btn btn-default" %> <%= link_to "DELETE", polymorphic_path(object), method: :delete, data: { confirm: "Are you sure you want to delete #{object.title}?"}, class: "btn btn-danger" %> - <%= link_to "View all #{object.class}s", polymorphic_path(object), class: "btn btn-default" %> + <%= link_to "View all #{object.class}s", polymorphic_path(object.class.to_s.downcase.pluralize), class: "btn btn-default" %> <%= link_to "View all Media", root_path, class: "btn btn-default" %>
diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 6d68cf81d7..fe653d0393 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -17,7 +17,7 @@ # describe "GET 'edit'" do # it "renders edit view" do - # movie = Movie.first + # movie = Movie.create(title:"Schindler's List 2", director: "Steven Spielberg") # get :edit, movie # expect(subject).to render_template :edit, movie # end @@ -51,7 +51,8 @@ end it "redirects to show page on success" do post :create, good_params - expect(subject).to redirect_to movies_path + new_movie = Movie.last + expect(subject).to redirect_to movie_path(new_movie.id) end it "renders new page on fail" do post :create, bad_params @@ -60,7 +61,7 @@ end describe "PATCH 'update'" do - it "redirects to show page" do + it "redirects to show page on success" do movie = Movie.create(title: "Schindler's List", director: "Steven Spielberg") update_params = { movie: { From 6485ffb6df2c48c2ee8c439e62f18be9a77d4057 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 16:05:46 -0800 Subject: [PATCH 34/60] create edit test for movie --- .gitignore | 2 ++ Gemfile | 1 + Gemfile.lock | 7 +++++++ spec/controllers/movies_controller_spec.rb | 14 +++++++------- spec/spec_helper.rb | 3 +++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 050c9d95c7..2eb6f54617 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ /log/* !/log/.keep /tmp + +coverage diff --git a/Gemfile b/Gemfile index d7ccd72d66..e38bc8f054 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem 'turbolinks' gem 'jbuilder', '~> 2.0' gem 'sdoc', '~> 0.4.0', group: :doc gem 'bootstrap-sass', '~> 3.3.6' +gem 'simplecov', :require => false, :group => :test group :production do gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index 8e0d6c43f7..18a5cd5e56 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,6 +61,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) @@ -141,6 +142,11 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + simplecov (0.11.0) + docile (~> 1.1.0) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) spring (1.5.0) sprockets (3.4.1) rack (> 1, < 3) @@ -181,6 +187,7 @@ DEPENDENCIES rspec-rails sass-rails (~> 5.0) sdoc (~> 0.4.0) + simplecov spring sqlite3 turbolinks diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index fe653d0393..9879143a46 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -15,13 +15,13 @@ end end - # describe "GET 'edit'" do - # it "renders edit view" do - # movie = Movie.create(title:"Schindler's List 2", director: "Steven Spielberg") - # get :edit, movie - # expect(subject).to render_template :edit, movie - # end - # end + describe "GET 'edit'" do + it "renders edit view" do + movie = Movie.create(title:"Schindler's List 2", director: "Steven Spielberg") + get :edit, id: movie.id + expect(subject).to render_template :edit + end + end describe "GET 'show'" do let(:new_movie) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61e27385c3..c1697e0176 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,6 @@ +require 'simplecov' +SimpleCov.start 'rails' + # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause From 614348fff6e3a0753a296399891fa8eae4ffce2b Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 16:12:57 -0800 Subject: [PATCH 35/60] create test for upvote --- spec/controllers/movies_controller_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 9879143a46..b3edfd00a8 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -80,7 +80,11 @@ end describe "POST 'upvote'" do - + it "redirects to show page" do + movie = Movie.create(title: "Schindler's List", director: "Steven Spielberg") + post :upvote, id: movie.id + expect(subject).to redirect_to movie_path(movie.id) + end end From 2c58eaa59880c069f3d32472a185c94adda86a36 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 16:14:27 -0800 Subject: [PATCH 36/60] create delete path --- spec/controllers/movies_controller_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index b3edfd00a8..746b73217a 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -76,7 +76,11 @@ end describe "DELETE 'destroy'" do - + it "redirects to index page" do + movie = Movie.create(title: "Schindler's List", director: "Steven Spielberg") + delete :destroy, id: movie.id + expect(subject).to redirect_to movies_path + end end describe "POST 'upvote'" do From d169cb0bf946ebd01a98c90d384ea935d616d9dd Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 16:39:40 -0800 Subject: [PATCH 37/60] create tests for books controller --- app/controllers/books_controller.rb | 4 +- spec/controllers/books_controller_spec.rb | 65 +++++++++++++++++++- spec/controllers/homepage_controller_spec.rb | 8 +++ spec/controllers/movies_controller_spec.rb | 3 + 4 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 spec/controllers/homepage_controller_spec.rb diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 46889ff321..f418380518 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -23,8 +23,8 @@ def update end def create - Book.create(book_params[:book]) - redirect_to books_path + book = Book.create(book_params[:book]) + book.save ? (redirect_to book_path(book)) : (render :new) end def edit diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index 62e6cc060e..9dbcd0dedc 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -15,25 +15,84 @@ end describe "GET 'edit'" do + it "renders edit view" do + book = Book.create(title: "The Sound and the Fury", author: "William Faulkner") + get :edit, id: book.id + expect(subject).to render_template :edit + end end describe "GET 'show'" do - + it "renders show view" do + book = Book.create(title: "The Sound and the Fury", author: "William Faulkner") + get :show, id: book.id + expect(subject).to render_template :show, id: book.id + end end describe "POST 'create'" do + let(:good_params) do + { + book: { + title: "The Sound and the Fury", + author: "William Faulkner" + } + } + end + let(:bad_params) do + { + book: { + title: "The Sound and the Fury" + } + } + end + it "redirects to show view on success" do + post :create, good_params + new_book = Book.last + expect(subject).to redirect_to book_path(new_book.id) + end + + it "renders new view on fail" do + post :create, bad_params + expect(subject).to render_template :new + end end describe "PATCH 'update'" do + let(:book) do + Book.create(title: "The Sound and the Fury", author: "William Faulkner") + end + it "redirects to show page on success" do + good_params = { + id: book.id, + book: { + title: "The Sound and the Fury", + author: "William Faulkner", + description: "Challenging read but worth the effort." + } + } + patch :update, good_params + expect(subject).to redirect_to book_path(book.id) + end + it "renders edit page on fail" do + end end describe "DELETE 'destroy'" do - + it "redirects to index page" do + book = Book.create(title: "The Sound and the Fury", author: "William Faulkner") + delete :destroy, id: book.id + expect(subject).to redirect_to books_path + end end describe "POST 'upvote'" do - + it "redirects to show page" do + book = Book.create(title: "The Sound and the Fury", author: "William Faulkner") + post :upvote, id: book.id + expect(subject).to redirect_to book_path(book.id) + end end end diff --git a/spec/controllers/homepage_controller_spec.rb b/spec/controllers/homepage_controller_spec.rb new file mode 100644 index 0000000000..f2c8d060de --- /dev/null +++ b/spec/controllers/homepage_controller_spec.rb @@ -0,0 +1,8 @@ +require 'rails_helper' + +RSpec.describe HomepageController, type: :controller do + describe "GET 'index'" do + + end + +end diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 746b73217a..adce1b3e0e 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -73,6 +73,9 @@ patch :update, update_params expect(subject).to redirect_to movie_path(movie.id) end + it "redirects to edit page on fail" do + + end end describe "DELETE 'destroy'" do From 352e939193bcec24f7ad6fcf26cf49ab3a474801 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Tue, 1 Dec 2015 16:59:24 -0800 Subject: [PATCH 38/60] create most tests for albums controller --- app/controllers/albums_controller.rb | 4 +-- spec/controllers/albums_controller_spec.rb | 38 ++++++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index b2e0024737..64c05190df 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -22,8 +22,8 @@ def update end def create - Album.create(album_params[:album]) - redirect_to albums_path + album = Album.new(album_params[:album]) + album.save ? (redirect_to album_path(album.id)) : (render :new) end def edit diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 669847e8a0..2f55a6a4a2 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -7,16 +7,48 @@ expect(response.status).to eq 200 end end - + describe "GET 'edit'" do + it "renders edit page" do + album = Album.create(title: "Ray of Light", artist: "Madonna") + get :edit, id: album.id + expect(subject).to render_template :edit + end end describe "GET 'show'" do - + it "renders show page" do + album = Album.create(title: "Ray of Light", artist: "Madonna") + get :show, id: album.id + expect(subject).to render_template :show, id: album.id + end end describe "POST 'create'" do - + let(:good_params) do + { + album: { + title: "The Sound and the Fury", + artist: "William Faulkner" + } + } + end + let(:bad_params) do + { + album: { + title: "The Sound and the Fury" + } + } + end + it "redirects to show on success" do + post :create, good_params + new_album = Album.last + expect(subject).to redirect_to album_path(new_album.id) + end + it "renders new on fail" do + post :create, bad_params + expect(subject).to render_template :new + end end describe "PATCH 'update'" do From 2298a4ff5838993da4e872fcefd93e0a42a533ce Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 08:22:28 -0800 Subject: [PATCH 39/60] create tests for albums controller --- spec/controllers/albums_controller_spec.rb | 42 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 2f55a6a4a2..f3b4208e2b 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -8,6 +8,13 @@ end end + describe "GET 'new'" do + it "renders the new page" do + get :new + expect(subject).to render_template :new + end + end + describe "GET 'edit'" do it "renders edit page" do album = Album.create(title: "Ray of Light", artist: "Madonna") @@ -52,14 +59,45 @@ end describe "PATCH 'update'" do + it "redirects to album on success" do + album = Album.create(title: "Ray of Light", artist: "Madonna") + update_params = { + id: album.id, + album: { + title: "Ray of Light", + artist: "Madonna", + description: "Good beats" } + } + patch :update, update_params + expect(subject).to redirect_to album_path(album.id) + end + + it "renders edit template on fail" do + # album = Album.create(title: "Ray of Light", artist: "Madonna") + # update_params = { + # id: album.id, + # album: { + # artist: "Madonna", + # description: "Good beats" } + # } + + end end describe "DELETE 'destroy'" do - + it "redirects to index on delete" do + album = Album.create(title: "Ray of Light", artist: "Madonna") + delete :destroy, id: album.id + expect(subject).to redirect_to albums_path + end end describe "POST 'upvote'" do - + it "redirects to show page" do + album = Album.create(title: "Ray of Light", artist: "Madonna") + post :upvote, id: album.id + expect(subject).to redirect_to album_path(album.id) + end end end From c415c4dfbeab50f25b5af70b76710a3a631f17eb Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 08:23:28 -0800 Subject: [PATCH 40/60] create test for homepage --- spec/controllers/homepage_controller_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/controllers/homepage_controller_spec.rb b/spec/controllers/homepage_controller_spec.rb index f2c8d060de..624830e492 100644 --- a/spec/controllers/homepage_controller_spec.rb +++ b/spec/controllers/homepage_controller_spec.rb @@ -2,7 +2,10 @@ RSpec.describe HomepageController, type: :controller do describe "GET 'index'" do - + it "renders the index template" do + get :index + expect(subject).to render_template :index + end end end From cee3119c29f2a5d6dc79c7265cd70406375cf28f Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 09:17:38 -0800 Subject: [PATCH 41/60] add pry rails to gemfile --- Gemfile | 1 + Gemfile.lock | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/Gemfile b/Gemfile index e38bc8f054..b0521a3b47 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ end group :development, :test do gem 'byebug' gem 'rspec-rails' + gem 'pry-rails' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 18a5cd5e56..484d23f1ae 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -79,6 +79,7 @@ GEM nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) + method_source (0.8.2) mime-types (2.99) mini_portile2 (2.0.0) minitest (5.8.3) @@ -86,6 +87,12 @@ GEM nokogiri (1.6.7) mini_portile2 (~> 2.0.0.rc2) pg (0.18.4) + pry (0.10.3) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-rails (0.3.4) + pry (>= 0.9.10) rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) @@ -147,6 +154,7 @@ GEM 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) rack (> 1, < 3) @@ -183,6 +191,7 @@ DEPENDENCIES jbuilder (~> 2.0) jquery-rails pg + pry-rails rails (= 4.2.5) rspec-rails sass-rails (~> 5.0) From 5506d4207a73930ab0a8eaf9e614400618317e51 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 09:17:56 -0800 Subject: [PATCH 42/60] style header and other css --- app/assets/images/owl.jpg | Bin 0 -> 13218 bytes app/assets/stylesheets/application.scss | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 app/assets/images/owl.jpg diff --git a/app/assets/images/owl.jpg b/app/assets/images/owl.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b3ded309503e7f923da57cb00fa145fbf656ae56 GIT binary patch literal 13218 zcmbVy2UrtJ_xD0*f`TX=1q4I{DJn&31O-H;OD_>26zNR@gyafR1OWj-MF9Z;ktQAK zy(mSxbP}o*NvHu5@-5!`dhh)|@AI|Ev%9}NbLPxBXJ*cs-3|FWc?LLnTU}EfprD`t zZh=35jHRvAym14jtFNQ3c~=dr007z#*6!}klzaf-;_B_Guc69kVrs@mI|@(&oB#vB z1u$6Kc)6?S>fQywa>RRd{dd_J20%#wFd+8d>;KLDKkgW8;a)ZXKtTu6-E6&VTtJKf z0BUC&cTaBspqT^d*L=O*K}>rF#4Mhmf*_VW!uEgSn@9M;pV;IV&prJcAkUGmj5ZF| zwjf4=_|k)a(Cz<$|I`8G0Oe@FUE!XNHhf3E(Dih)b99FPs`&Htf2jTk=l>46IQxJ$ z|0+D-`M8&p!5#1_d}O6WrW%MZftbg^=hk2HA-BCA8644n$?~s4q}Hq|M!1_b(kFORmn^M}2|zQZd54e%T1hge-YG+ym$7QClh*Z_j&w zwWTt%b5z&-iy!Ik{A(_Px>3FN^wB@k4U|vy&Dv8<1H_;lstvfS;gR1!OwD0yee=k- z;viNAj3}%DIN%060M9mnD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shzU>TCo_hH3OWXKd|6Yqbn0BSg+6_T$r!?c`irKv(F;89!8+C zicJ4u#e=I2jZFJ7Y^EJ=PZu%V-+%6m?z<&c4azcy^t#7_F>mOF(_hg|3a3@+T|dew z6yQO5Iz%YR){rXx+3_TggY4{CD=|D%gOwyc`)Ph!DIU>>6y|5}u|MN1_^5MYRA1Ki zKA=sT>F3v`z#P(C^~#?yZ|nBO%zC4#r{dN10@dQpdWDv%Wro^H=30jgM$Ns06aD2OvUM=UWhVkcck<4g86H61xP2Qi6V>@~tGL1G{m84>NvN3Bju+gd7ww^VX zn$X>5Ti&Lc`1TaWzDvsI5NJ$l(50@il8$_I;N@x2j@fx5C00FOIbGm~W&1Ov95|nR zTT>YD*f19sp`cqn zxFxEj+Gbc;`Z)w1p|jOy3neXFS*`S~Uo|=yR~V+OObFH)I#l?v zbGbx|CJG3}wLg35$U4cAg1OFX0Mkd_!N299C71{1mZ-a#_!%)59c)U@;;c*#=y43t z;9ai5Rq**>LVXi4wPTPg&;dp4@h+Q_<^{<>jYcNw4%QiOntTy{O)yiqeXO@rZR+xN zys=e^{nA^yPkVueudtKp(8y5F5YnYz~ek z)b8MEt7jZ+tw>YcZlf|gAr)6P^Wtk7pi$+V_(@m$#>NLVQnkJLDi6Fo2Lbo77jC7Zt>ktzGsSO7in z;0b-_Ru9IH^oZ-o_4M&Z@b76u=XU+bP?dZ0m5Ym7aSU$)p}`H-O+ zA)Y2Pdbyj!NARRdV|oNJ<02T*c)&*knCM~l)BYB?c zl%{Q`u6+~vFm?@a7tKtMAn{%x10ETN9EZ0EtIee4Y(naSd!6Ed_nJ=gF!QomU}72< ztfk|naIM-QD?VRXcAC_fN{_(KFzuagCK^Jw=Au);z#03tzL|-{ ZFR+vzabUC16e0W$Ojvqq0Gd4dzW|J{wv7M) literal 0 HcmV?d00001 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 2eb37b4e7c..54c75b4474 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -14,3 +14,20 @@ @import "bootstrap-sprockets"; @import "bootstrap"; + +.page-header { + background-image: image-url("owl.jpg"); + // background: image-url(owl.jpg); + background-repeat: no-repeat; + padding-bottom: 9px; + margin: 40px 0 20px; + border-bottom: 1px solid #eee; +} + +.page-header h1 { + margin-left: 150px; +} + +thead td { + font-weight: bold; +} From 8b719dd264e5939aac3b46e73964aedcf1bcba13 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 09:27:53 -0800 Subject: [PATCH 43/60] create footer --- app/views/layouts/application.html.erb | 4 ++-- app/views/shared/_footer.html.erb | 8 ++++++++ app/views/{layouts => shared}/_header.html.erb | 0 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 app/views/shared/_footer.html.erb rename app/views/{layouts => shared}/_header.html.erb (100%) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2b0c71d4f2..6770deb36a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,10 +8,10 @@
- <%= render 'layouts/header' %> + <%= render 'shared/header' %> <%= yield %>
- + <%= render 'shared/footer' %> diff --git a/app/views/shared/_footer.html.erb b/app/views/shared/_footer.html.erb new file mode 100644 index 0000000000..8c3069aa0a --- /dev/null +++ b/app/views/shared/_footer.html.erb @@ -0,0 +1,8 @@ +
+
+
+
+

Copyright © <%= link_to "Jennie Buechner", "https://www.linkedin.com/in/jenniebuechner" %> <%= Time.now.year %>

+
+
+
diff --git a/app/views/layouts/_header.html.erb b/app/views/shared/_header.html.erb similarity index 100% rename from app/views/layouts/_header.html.erb rename to app/views/shared/_header.html.erb From 5baefb6471d2707276d39d1da6ed5a476b09723e Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 09:35:58 -0800 Subject: [PATCH 44/60] try to refactor album create test --- spec/controllers/albums_controller_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index f3b4208e2b..1785c59fb1 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -32,6 +32,7 @@ end describe "POST 'create'" do + let(:good_params) do { album: { @@ -48,6 +49,15 @@ } end it "redirects to show on success" do + # subject { post :create, :new_album => { + # album: { + # title: "The Sound and the Fury", + # artist: "William Faulkner" + # } + # }} + # binding.pry + # expect(subject).to redirect_to album_path(assigns(:new_album)) + post :create, good_params new_album = Album.last expect(subject).to redirect_to album_path(new_album.id) From 2a8c503e6f566c21df53da7421b949e26131364c Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 09:40:30 -0800 Subject: [PATCH 45/60] refactor update books controller --- app/controllers/books_controller.rb | 3 +-- spec/controllers/books_controller_spec.rb | 11 ++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index f418380518..cdf5dc7dd8 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -18,8 +18,7 @@ def destroy end def update - @book.update(book_params[:book]) - redirect_to book_path(@book) + @book.update(book_params[:book]) ? (redirect_to book_path(@book)) : (render :edit) end def create diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index 9dbcd0dedc..d1608ac949 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -67,8 +67,6 @@ good_params = { id: book.id, book: { - title: "The Sound and the Fury", - author: "William Faulkner", description: "Challenging read but worth the effort." } } @@ -76,7 +74,14 @@ expect(subject).to redirect_to book_path(book.id) end it "renders edit page on fail" do - + bad_params = { + id: book.id, + book: { + title: "", + } + } + patch :update, bad_params + expect(subject).to render_template :edit end end From 3065a0dafbc4b6e800acd2f8713c91ddf85480a7 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 09:45:13 -0800 Subject: [PATCH 46/60] change update controllers for failed updates --- app/controllers/albums_controller.rb | 3 +-- app/controllers/movies_controller.rb | 3 +-- spec/controllers/albums_controller_spec.rb | 20 ++++++++++---------- spec/controllers/movies_controller_spec.rb | 14 +++++++++++--- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 64c05190df..a84f7bd712 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -17,8 +17,7 @@ def destroy end def update - @album.update(album_params[:album]) - redirect_to album_path(@album) + @album.update(album_params[:album]) ? (redirect_to album_path(@album)) : (render :edit) end def create diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 8b825b3632..bbce171121 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -24,8 +24,7 @@ def destroy end def update - @movie.update(movie_params[:movie]) - redirect_to movie_path(@movie) + @movie.update(movie_params[:movie]) ? (redirect_to movie_path(@movie)) : (render :edit) end def edit diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 1785c59fb1..66f8991465 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -69,8 +69,10 @@ end describe "PATCH 'update'" do + let (:album) do + Album.create(title: "Ray of Light", artist: "Madonna") + end it "redirects to album on success" do - album = Album.create(title: "Ray of Light", artist: "Madonna") update_params = { id: album.id, album: { @@ -81,16 +83,14 @@ patch :update, update_params expect(subject).to redirect_to album_path(album.id) end - it "renders edit template on fail" do - # album = Album.create(title: "Ray of Light", artist: "Madonna") - # update_params = { - # id: album.id, - # album: { - # artist: "Madonna", - # description: "Good beats" } - # } - + bad_params = { + id: album.id, + album: { + artist: "",} + } + patch :update, bad_params + expect(subject).to render_template (:edit) end end diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index adce1b3e0e..3f6b6b8e51 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -61,12 +61,13 @@ end describe "PATCH 'update'" do + let(:movie) do + Movie.create(title: "Schindler's List", director: "Steven Spielberg") + end it "redirects to show page on success" do - movie = Movie.create(title: "Schindler's List", director: "Steven Spielberg") update_params = { movie: { title: "Schindler's List 2", - director: "Steven Spielberg" }, id: movie.id } @@ -74,7 +75,14 @@ expect(subject).to redirect_to movie_path(movie.id) end it "redirects to edit page on fail" do - + bad_params = { + movie: { + title: "", + }, + id: movie.id + } + patch :update, bad_params + expect(subject).to render_template :edit end end From a7f552bc8fb5f2f0b15e541b60885f559a32b449 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 09:49:18 -0800 Subject: [PATCH 47/60] add error messages to form --- app/views/shared/_form.html.erb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/views/shared/_form.html.erb b/app/views/shared/_form.html.erb index a112f9c665..025b324510 100644 --- a/app/views/shared/_form.html.erb +++ b/app/views/shared/_form.html.erb @@ -1,3 +1,14 @@ +<% if !media.errors.nil? %> +

Error in submitting the form:

+
    + <% media.errors.each do |column, message| %> +
  • + <%= column.capitalize %><%= message %> +
  • + <% end %> +
+<% end %> +

<%= yield(:title) %>

From b590558a6d923e43620d9e0b0a46ec6a7655620e Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 10:15:06 -0800 Subject: [PATCH 48/60] add error output for form and maximum length for title --- app/controllers/albums_controller.rb | 7 ++++++- app/controllers/books_controller.rb | 7 ++++++- app/controllers/movies_controller.rb | 7 ++++++- app/models/album.rb | 2 +- app/models/book.rb | 2 +- app/models/movie.rb | 2 +- app/views/shared/_form.html.erb | 10 ++++------ 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index a84f7bd712..5e0d0f868d 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -22,7 +22,12 @@ def update def create album = Album.new(album_params[:album]) - album.save ? (redirect_to album_path(album.id)) : (render :new) + if album.save + redirect_to album_path(album.id) + else + @album = album + render :new + end end def edit diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index cdf5dc7dd8..e1fe81c2bc 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -23,7 +23,12 @@ def update def create book = Book.create(book_params[:book]) - book.save ? (redirect_to book_path(book)) : (render :new) + if book.save + redirect_to book_path(book) + else + @book = book + render :new + end end def edit diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index bbce171121..7b8d5e0f80 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -11,7 +11,12 @@ def new def create movie = Movie.new(movie_params[:movie]) - movie.save ? (redirect_to movie_path(movie)) : (render :new) + if movie.save + redirect_to movie_path(movie) + else + @movie = movie + render :new + end end diff --git a/app/models/album.rb b/app/models/album.rb index 4b630eebc5..f57268abba 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -1,4 +1,4 @@ class Album < ActiveRecord::Base - validates :title, presence: true + validates :title, presence: true, length: { maximum: 25 } validates :artist, presence: true end diff --git a/app/models/book.rb b/app/models/book.rb index 4bcc056a96..8d9dc4cee3 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,4 +1,4 @@ class Book < ActiveRecord::Base - validates :title, presence: true + validates :title, presence: true, length: { maximum: 25 } validates :author, presence: true end diff --git a/app/models/movie.rb b/app/models/movie.rb index f3946488b0..c87bfd9447 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,4 +1,4 @@ class Movie < ActiveRecord::Base - validates :title, presence: true + validates :title, presence: true, length: { maximum: 25 } validates :director, presence: true end diff --git a/app/views/shared/_form.html.erb b/app/views/shared/_form.html.erb index 025b324510..5f6bcf49cd 100644 --- a/app/views/shared/_form.html.erb +++ b/app/views/shared/_form.html.erb @@ -1,10 +1,8 @@ -<% if !media.errors.nil? %> -

Error in submitting the form:

+<% if media.errors.any? %> +

The form has <%=pluralize(media.errors.count, "error") %>:

    - <% media.errors.each do |column, message| %> -
  • - <%= column.capitalize %><%= message %> -
  • + <% media.errors.full_messages.each do |message| %> +
  • <%= message %>
  • <% end %>
<% end %> From a99f2840a7cd65e2785c97b632febfc65428753d Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 10:16:25 -0800 Subject: [PATCH 49/60] clean out excess comments --- spec/controllers/albums_controller_spec.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 66f8991465..11f1e2290e 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -49,15 +49,6 @@ } end it "redirects to show on success" do - # subject { post :create, :new_album => { - # album: { - # title: "The Sound and the Fury", - # artist: "William Faulkner" - # } - # }} - # binding.pry - # expect(subject).to redirect_to album_path(assigns(:new_album)) - post :create, good_params new_album = Album.last expect(subject).to redirect_to album_path(new_album.id) From 26156f010f2cc30011162c0c25fc2dcdec6afd85 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 10:36:06 -0800 Subject: [PATCH 50/60] create shared method concern for controller --- app/controllers/albums_controller.rb | 7 +------ app/controllers/books_controller.rb | 8 +------- app/controllers/concerns/shared_methods.rb | 13 +++++++++++++ app/controllers/movies_controller.rb | 8 +------- 4 files changed, 16 insertions(+), 20 deletions(-) create mode 100644 app/controllers/concerns/shared_methods.rb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 5e0d0f868d..02392d77af 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,4 +1,5 @@ class AlbumsController < ApplicationController + include SharedMethods before_action :get_album, only:[:show, :destroy, :update, :edit, :upvote] def index @albums = Album.all.order(:upvotes).reverse @@ -8,9 +9,6 @@ def new @album = Album.new end - def show - end - def destroy @album.destroy redirect_to albums_path @@ -30,9 +28,6 @@ def create end end - def edit - end - def upvote @album.upvotes += 1 @album.save diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index e1fe81c2bc..d6ab830f59 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,4 +1,5 @@ class BooksController < ApplicationController + include SharedMethods before_action :get_book, only:[:show, :destroy, :update, :edit, :upvote] def index @books = Book.all.order(:upvotes).reverse @@ -8,10 +9,6 @@ def new @book = Book.new end - - def show - end - def destroy @book.destroy redirect_to books_path @@ -31,9 +28,6 @@ def create end end - def edit - end - def upvote @book.upvotes += 1 @book.save diff --git a/app/controllers/concerns/shared_methods.rb b/app/controllers/concerns/shared_methods.rb new file mode 100644 index 0000000000..6825064153 --- /dev/null +++ b/app/controllers/concerns/shared_methods.rb @@ -0,0 +1,13 @@ +module SharedMethods + extend ActiveSupport::Concern + + module ClassMethods + def edit + end + + def show + end + + end + +end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 7b8d5e0f80..3983334212 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,4 +1,5 @@ class MoviesController < ApplicationController + include SharedMethods before_action :get_movie, only:[:show, :destroy, :update, :edit, :upvote] def index @@ -19,10 +20,6 @@ def create end end - - def show - end - def destroy @movie.destroy redirect_to movies_path @@ -32,9 +29,6 @@ def update @movie.update(movie_params[:movie]) ? (redirect_to movie_path(@movie)) : (render :edit) end - def edit - end - def upvote @movie.upvotes += 1 @movie.save From 7bb2249fa630fe383ac59bd7993b57f81fa1b158 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 11:12:17 -0800 Subject: [PATCH 51/60] dry up tests using shared tests --- spec/controllers/albums_controller_spec.rb | 13 +------------ spec/controllers/books_controller_spec.rb | 13 +------------ spec/controllers/movies_controller_spec.rb | 16 ++-------------- spec/shared_examples/shared_tests.rb | 16 ++++++++++++++++ spec/spec_helper.rb | 2 ++ 5 files changed, 22 insertions(+), 38 deletions(-) create mode 100644 spec/shared_examples/shared_tests.rb diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 11f1e2290e..b4dc96802f 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -1,19 +1,8 @@ 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 'new'" do - it "renders the new page" do - get :new - expect(subject).to render_template :new - end - end + it_behaves_like 'shared_tests' describe "GET 'edit'" do it "renders edit page" do diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index d1608ac949..af2f8ed54c 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -1,18 +1,7 @@ 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 'new'" do - it "renders new view" do - get :new - expect(subject).to render_template :new - end - end + it_behaves_like 'shared_tests' describe "GET 'edit'" do it "renders edit view" do diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index 3f6b6b8e51..b2ba6fe75e 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -1,20 +1,8 @@ require 'rails_helper' RSpec.describe MoviesController, type: :controller do - describe "GET 'index'" do - it "is successful" do - get :index - expect(response.status).to eq 200 - end - end - - describe "GET 'new'" do - it "renders new view" do - get :new - expect(subject).to render_template :new - end - end - + it_behaves_like 'shared_tests' + describe "GET 'edit'" do it "renders edit view" do movie = Movie.create(title:"Schindler's List 2", director: "Steven Spielberg") diff --git a/spec/shared_examples/shared_tests.rb b/spec/shared_examples/shared_tests.rb new file mode 100644 index 0000000000..81b6127559 --- /dev/null +++ b/spec/shared_examples/shared_tests.rb @@ -0,0 +1,16 @@ +shared_examples_for 'shared_tests' do + + describe "GET 'index'" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end + end + + describe "GET 'new'" do + it "renders the new page" do + get :new + expect(subject).to render_template :new + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c1697e0176..c082c7942a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,8 @@ require 'simplecov' SimpleCov.start 'rails' +Dir["./spec/shared_examples/**/*.rb"].sort.each { |f| require f} + # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause From e6c2b34fbf5d690d17842f2f1557a67d05064f5c Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 11:18:32 -0800 Subject: [PATCH 52/60] remove extra whitespace --- spec/controllers/albums_controller_spec.rb | 3 --- spec/controllers/movies_controller_spec.rb | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index b4dc96802f..2867b13eab 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -1,7 +1,6 @@ require 'rails_helper' RSpec.describe AlbumsController, type: :controller do - it_behaves_like 'shared_tests' describe "GET 'edit'" do @@ -21,7 +20,6 @@ end describe "POST 'create'" do - let(:good_params) do { album: { @@ -72,7 +70,6 @@ patch :update, bad_params expect(subject).to render_template (:edit) end - end describe "DELETE 'destroy'" do diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index b2ba6fe75e..c79c853cf3 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -2,7 +2,7 @@ RSpec.describe MoviesController, type: :controller do it_behaves_like 'shared_tests' - + describe "GET 'edit'" do it "renders edit view" do movie = Movie.create(title:"Schindler's List 2", director: "Steven Spielberg") @@ -90,5 +90,4 @@ end end - end From e0d522d2fa45cae2f8027b5481f6978e9a244639 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 14:38:23 -0800 Subject: [PATCH 53/60] add padding to upvote button --- app/assets/stylesheets/application.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 54c75b4474..8c4607833a 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -31,3 +31,7 @@ thead td { font-weight: bold; } + +form .btn-primary { + margin-bottom: 10px; +} From 6df3c069e6ccf58a413e6c86c1a93cc4530edc9a Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Wed, 2 Dec 2015 14:40:33 -0800 Subject: [PATCH 54/60] change color of links --- app/assets/stylesheets/application.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 8c4607833a..842313ac80 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -35,3 +35,7 @@ thead td { form .btn-primary { margin-bottom: 10px; } + +a { + color: #428bca; +} From f44ec289ec7e35ebb5d1c66bef0581613cd9a6fc Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Thu, 3 Dec 2015 10:05:37 -0800 Subject: [PATCH 55/60] rename columns to creator --- app/models/album.rb | 2 +- app/models/book.rb | 2 +- app/models/movie.rb | 2 +- .../20151203180116_change_column_names.rb | 7 ++ db/schema.rb | 8 +-- db/seeds.rb | 64 +++++++++---------- 6 files changed, 46 insertions(+), 39 deletions(-) create mode 100644 db/migrate/20151203180116_change_column_names.rb diff --git a/app/models/album.rb b/app/models/album.rb index f57268abba..9e24ea3301 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -1,4 +1,4 @@ class Album < ActiveRecord::Base validates :title, presence: true, length: { maximum: 25 } - validates :artist, presence: true + validates :creator, presence: true end diff --git a/app/models/book.rb b/app/models/book.rb index 8d9dc4cee3..3a3c3f5b63 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,4 +1,4 @@ class Book < ActiveRecord::Base validates :title, presence: true, length: { maximum: 25 } - validates :author, presence: true + validates :creator, presence: true end diff --git a/app/models/movie.rb b/app/models/movie.rb index c87bfd9447..0676b9cdf1 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,4 +1,4 @@ class Movie < ActiveRecord::Base validates :title, presence: true, length: { maximum: 25 } - validates :director, presence: true + validates :creator, presence: true end diff --git a/db/migrate/20151203180116_change_column_names.rb b/db/migrate/20151203180116_change_column_names.rb new file mode 100644 index 0000000000..2abff072b1 --- /dev/null +++ b/db/migrate/20151203180116_change_column_names.rb @@ -0,0 +1,7 @@ +class ChangeColumnNames < ActiveRecord::Migration + def change + rename_column(:movies, :director, :creator) + rename_column(:albums, :artist, :creator) + rename_column(:books, :author, :creator) + end +end diff --git a/db/schema.rb b/db/schema.rb index fb60605b14..e354f28051 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,11 +11,11 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151201000941) do +ActiveRecord::Schema.define(version: 20151203180116) do create_table "albums", force: :cascade do |t| t.string "title" - t.string "artist" + t.string "creator" t.string "description" t.integer "upvotes", default: 0 t.datetime "created_at", null: false @@ -24,7 +24,7 @@ create_table "books", force: :cascade do |t| t.string "title" - t.string "author" + t.string "creator" t.string "description" t.integer "upvotes", default: 0 t.datetime "created_at", null: false @@ -33,7 +33,7 @@ create_table "movies", force: :cascade do |t| t.string "title" - t.string "director" + t.string "creator" t.string "description" t.integer "upvotes", default: 0 t.datetime "created_at", null: false diff --git a/db/seeds.rb b/db/seeds.rb index 6be36e1eee..1baac02291 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,86 +7,86 @@ # Mayor.create(name: 'Emanuel', city: cities.first) albums = [{title: "Thriller", - artist: "Michael Jackson"}, + creator: "Michael Jackson"}, {title: "Nevermind", - artist: "Nirvana"}, + creator: "Nirvana"}, {title: "Abbey Road", - artist: "The Beatles"}, + creator: "The Beatles"}, {title: "Kind of Blue", - artist: "Miles Davis"}, + creator: "Miles Davis"}, {title: "Blonde on Blonde", - artist: "Bob Dylan"}, + creator: "Bob Dylan"}, {title: "Blue", - artist: "Joni Mitchell"}, + creator: "Joni Mitchell"}, {title: "What's Going On", - artist: "Marvin Gay"}, + creator: "Marvin Gay"}, {title: "The Doors", - artist: "The Doors"}, + creator: "The Doors"}, {title: "Like a Virgin", - artist: "Madonna"}, + creator: "Madonna"}, {title: "Legend", - artist: "Bob Marley and the Wailers"}, + creator: "Bob Marley and the Wailers"}, {title: "My Life", - artist: "Mary J. Blige"}, + creator: "Mary J. Blige"}, ] movies = [{title: "The Shawshank Redemption", - director: "Frank Darabont", + creator: "Frank Darabont", description: "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency."}, {title: "The Godfather", - director: "Francis Ford Coppola", + creator: "Francis Ford Coppola", description: "The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son."}, {title: "The Dark Knight", - director: "Christopher Nolan", + creator: "Christopher Nolan", description: "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice."}, {title: "12 Angry Men", - director: "Sidney Lumet", + creator: "Sidney Lumet", description: "A dissenting juror in a murder trial slowly manages to convince the others that the case is not as obviously clear as it seemed in court."}, {title: "Schindler's List", - director: "Steven Spielberg", + creator: "Steven Spielberg", description: "In Poland during World War II, Oskar Schindler gradually becomes concerned for his Jewish workforce after witnessing their persecution by the Nazis."}, {title: "Pulp Fiction", - director: "Quentin Tarantino", + creator: "Quentin Tarantino", description: "The lives of two mob hit men, a boxer, a gangster's wife, and a pair of diner bandits intertwine in four tales of violence and redemption."}, {title: "The Good, the Bad, and the Ugly", - director: "Sergio Leone", + creator: "Sergio Leone", description: "A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery."}, {title: "The Lord of the Rings: Return of the King", - director: "Peter Jackson", + creator: "Peter Jackson", description: "Gandalf and Aragorn lead the World of Men against Sauron's army to draw his gaze from Frodo and Sam as they approach Mount Doom with the One Ring."}, {title: "Fight Club", - director: "David Fincher", + creator: "David Fincher", description: "An insomniac office worker, looking for a way to change his life, crosses paths with a devil-may-care soap maker, forming an underground fight club that evolves into something much, much more..."}, {title: "Star Wars Episode V: The Empire Strikes Back", - director: "Irvin Kershner", + creator: "Irvin Kershner", description: "After the rebels have been brutally overpowered by the Empire on their newly established base, Luke Skywalker takes advanced Jedi training with Master Yoda, while his friends are pursued by Darth Vader as part of his plan to capture Luke."}, {title: "Forrest Gump", - director: "Robert Zemeckis", + creator: "Robert Zemeckis", description: "Forrest Gump, while not intelligent, has accidentally been present at many historic moments, but his true love, Jenny Curran, eludes him."}, {title: "The Goonies", - director: "Richard Donner", + creator: "Richard Donner", description: "In order to save their home from foreclosure, a group of misfits set out to find a pirate's ancient treasure."}, ] books = [{title: "Ulysses", - author: "James Joyce"}, + creator: "James Joyce"}, {title: "The Great Gatsby", - author: "F. Scott Fitzgerald"}, + creator: "F. Scott Fitzgerald"}, {title: "Lolita", - author: "Vladimir Nabokov"}, + creator: "Vladimir Nabokov"}, {title: "Brave New World", - author: "Aldous Huxley"}, + creator: "Aldous Huxley"}, {title: "The Sound and the Fury", - author: "William Faulkner"}, + creator: "William Faulkner"}, {title: "Bridget Jones's Diary", - author: "Helen Fielding"}, + creator: "Helen Fielding"}, {title: "Catch-22", - author: "Joseph Heller"}, + creator: "Joseph Heller"}, {title: "Invisible Man", - author: "Ralph Ellison"}, + creator: "Ralph Ellison"}, {title: "Practical Object-Oriented Design in Ruby (POODR)", - author: "Sandi Metz"}, + creator: "Sandi Metz"}, ] albums.each do |album| From 85c1efc519305e7aadc2b4438e1520cf39582a1c Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Thu, 3 Dec 2015 10:29:29 -0800 Subject: [PATCH 56/60] refactor seed file --- db/seeds.rb | 204 +++++++++++++++++++++++++--------------------------- 1 file changed, 99 insertions(+), 105 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 1baac02291..a3ab2aacbe 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,108 +1,102 @@ -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). -# -# Examples: -# -# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) -# Mayor.create(name: 'Emanuel', city: cities.first) +album = { + type: "Album", + objects: [ + {title: "Thriller", + creator: "Michael Jackson"}, + {title: "Nevermind", + creator: "Nirvana"}, + {title: "Abbey Road", + creator: "The Beatles"}, + {title: "Kind of Blue", + creator: "Miles Davis"}, + {title: "Blonde on Blonde", + creator: "Bob Dylan"}, + {title: "Blue", + creator: "Joni Mitchell"}, + {title: "What's Going On", + creator: "Marvin Gay"}, + {title: "The Doors", + creator: "The Doors"}, + {title: "Like a Virgin", + creator: "Madonna"}, + {title: "Legend", + creator: "Bob Marley and the Wailers"}, + {title: "My Life", + creator: "Mary J. Blige"}, + ] +} -albums = [{title: "Thriller", - creator: "Michael Jackson"}, - {title: "Nevermind", - creator: "Nirvana"}, - {title: "Abbey Road", - creator: "The Beatles"}, - {title: "Kind of Blue", - creator: "Miles Davis"}, - {title: "Blonde on Blonde", - creator: "Bob Dylan"}, - {title: "Blue", - creator: "Joni Mitchell"}, - {title: "What's Going On", - creator: "Marvin Gay"}, - {title: "The Doors", - creator: "The Doors"}, - {title: "Like a Virgin", - creator: "Madonna"}, - {title: "Legend", - creator: "Bob Marley and the Wailers"}, - {title: "My Life", - creator: "Mary J. Blige"}, - ] +movie = { + type: "Movie", + objects: [ + {title: "The Shawshank Redemption", + creator: "Frank Darabont", + description: "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency."}, + {title: "The Godfather", + creator: "Francis Ford Coppola", + description: "The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son."}, + {title: "The Dark Knight", + creator: "Christopher Nolan", + description: "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice."}, + {title: "12 Angry Men", + creator: "Sidney Lumet", + description: "A dissenting juror in a murder trial slowly manages to convince the others that the case is not as obviously clear as it seemed in court."}, + {title: "Schindler's List", + creator: "Steven Spielberg", + description: "In Poland during World War II, Oskar Schindler gradually becomes concerned for his Jewish workforce after witnessing their persecution by the Nazis."}, + {title: "Pulp Fiction", + creator: "Quentin Tarantino", + description: "The lives of two mob hit men, a boxer, a gangster's wife, and a pair of diner bandits intertwine in four tales of violence and redemption."}, + {title: "The Good, the Bad, and the Ugly", + creator: "Sergio Leone", + description: "A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery."}, + {title: "The Lord of the Rings: Return of the King", + creator: "Peter Jackson", + description: "Gandalf and Aragorn lead the World of Men against Sauron's army to draw his gaze from Frodo and Sam as they approach Mount Doom with the One Ring."}, + {title: "Fight Club", + creator: "David Fincher", + description: "An insomniac office worker, looking for a way to change his life, crosses paths with a devil-may-care soap maker, forming an underground fight club that evolves into something much, much more..."}, + {title: "Star Wars Episode V: The Empire Strikes Back", + creator: "Irvin Kershner", + description: "After the rebels have been brutally overpowered by the Empire on their newly established base, Luke Skywalker takes advanced Jedi training with Master Yoda, while his friends are pursued by Darth Vader as part of his plan to capture Luke."}, + {title: "Forrest Gump", + creator: "Robert Zemeckis", + description: "Forrest Gump, while not intelligent, has accidentally been present at many historic moments, but his true love, Jenny Curran, eludes him."}, + {title: "The Goonies", + creator: "Richard Donner", + description: "In order to save their home from foreclosure, a group of misfits set out to find a pirate's ancient treasure."}, + ] + } -movies = [{title: "The Shawshank Redemption", - creator: "Frank Darabont", - description: "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency."}, - {title: "The Godfather", - creator: "Francis Ford Coppola", - description: "The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son."}, - {title: "The Dark Knight", - creator: "Christopher Nolan", - description: "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice."}, - {title: "12 Angry Men", - creator: "Sidney Lumet", - description: "A dissenting juror in a murder trial slowly manages to convince the others that the case is not as obviously clear as it seemed in court."}, - {title: "Schindler's List", - creator: "Steven Spielberg", - description: "In Poland during World War II, Oskar Schindler gradually becomes concerned for his Jewish workforce after witnessing their persecution by the Nazis."}, - {title: "Pulp Fiction", - creator: "Quentin Tarantino", - description: "The lives of two mob hit men, a boxer, a gangster's wife, and a pair of diner bandits intertwine in four tales of violence and redemption."}, - {title: "The Good, the Bad, and the Ugly", - creator: "Sergio Leone", - description: "A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery."}, - {title: "The Lord of the Rings: Return of the King", - creator: "Peter Jackson", - description: "Gandalf and Aragorn lead the World of Men against Sauron's army to draw his gaze from Frodo and Sam as they approach Mount Doom with the One Ring."}, - {title: "Fight Club", - creator: "David Fincher", - description: "An insomniac office worker, looking for a way to change his life, crosses paths with a devil-may-care soap maker, forming an underground fight club that evolves into something much, much more..."}, - {title: "Star Wars Episode V: The Empire Strikes Back", - creator: "Irvin Kershner", - description: "After the rebels have been brutally overpowered by the Empire on their newly established base, Luke Skywalker takes advanced Jedi training with Master Yoda, while his friends are pursued by Darth Vader as part of his plan to capture Luke."}, - {title: "Forrest Gump", - creator: "Robert Zemeckis", - description: "Forrest Gump, while not intelligent, has accidentally been present at many historic moments, but his true love, Jenny Curran, eludes him."}, - {title: "The Goonies", - creator: "Richard Donner", - description: "In order to save their home from foreclosure, a group of misfits set out to find a pirate's ancient treasure."}, - - ] - -books = [{title: "Ulysses", - creator: "James Joyce"}, - {title: "The Great Gatsby", - creator: "F. Scott Fitzgerald"}, - {title: "Lolita", - creator: "Vladimir Nabokov"}, - {title: "Brave New World", - creator: "Aldous Huxley"}, - {title: "The Sound and the Fury", - creator: "William Faulkner"}, - {title: "Bridget Jones's Diary", - creator: "Helen Fielding"}, - {title: "Catch-22", - creator: "Joseph Heller"}, - {title: "Invisible Man", - creator: "Ralph Ellison"}, - {title: "Practical Object-Oriented Design in Ruby (POODR)", - creator: "Sandi Metz"}, - ] - -albums.each do |album| - a = Album.create(album) - a.upvotes = rand(1..50) - a.save -end - -movies.each do |movie| - m = Movie.create(movie) - m.upvotes = rand(1..50) - m.save -end - -books.each do |book| - b = Book.create(book) - b.upvotes = rand(1..50) - b.save +book = { + type: "Book", + objects: [ + {title: "Ulysses", + creator: "James Joyce"}, + {title: "The Great Gatsby", + creator: "F. Scott Fitzgerald"}, + {title: "Lolita", + creator: "Vladimir Nabokov"}, + {title: "Brave New World", + creator: "Aldous Huxley"}, + {title: "The Sound and the Fury", + creator: "William Faulkner"}, + {title: "Bridget Jones's Diary", + creator: "Helen Fielding"}, + {title: "Catch-22", + creator: "Joseph Heller"}, + {title: "Invisible Man", + creator: "Ralph Ellison"}, + {title: "Practical Object-Oriented Design in Ruby (POODR)", + creator: "Sandi Metz"}, + ] +} +[album, movie, book].each do |medium_hash| + type = medium_hash[:type] + objects = medium_hash[:objects] + objects.each do |object| + new_obj = type.constantize.create(object) + new_obj.upvotes = rand(1..50) + new_obj.save + end end From 9885d5c40aafd9607c57eab5b6ad9c293e35a00e Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Thu, 3 Dec 2015 10:30:04 -0800 Subject: [PATCH 57/60] edit strong params method to match column rename --- app/controllers/albums_controller.rb | 2 +- app/controllers/books_controller.rb | 2 +- app/controllers/movies_controller.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 02392d77af..7db842ffd3 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -40,6 +40,6 @@ def get_album end def album_params - params.permit(album:[:id, :title, :artist, :description, :upvotes]) + params.permit(album:[:id, :title, :creator, :description, :upvotes]) end end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index d6ab830f59..fef581de8e 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -40,6 +40,6 @@ def get_book end def book_params - params.permit(book:[:id, :title, :author, :description, :upvotes]) + params.permit(book:[:id, :title, :creator, :description, :upvotes]) end end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 3983334212..a26c6d9a20 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -41,6 +41,6 @@ def get_movie end def movie_params - params.permit(movie:[:id, :title, :director, :description, :upvotes]) + params.permit(movie:[:id, :title, :creator, :description, :upvotes]) end end From 5aeeaa5247818fbe9038677f1b715d76ac7b5919 Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Thu, 3 Dec 2015 10:38:13 -0800 Subject: [PATCH 58/60] rename field to creator --- app/views/albums/show.html.erb | 2 +- app/views/books/show.html.erb | 2 +- app/views/movies/new.html.erb | 2 +- app/views/movies/show.html.erb | 2 +- app/views/shared/_form.html.erb | 2 +- app/views/shared/_show.html.erb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index d2d3c41923..50c98fb2e7 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -1,2 +1,2 @@ <% provide(:who_by, "Recorded by:") %> -<%= render partial: 'shared/show', locals: {object: @album, by: @album.artist} %> +<%= render partial: 'shared/show', locals: {object: @album} %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index cf97506c8c..fe61bcc62a 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -1,2 +1,2 @@ <% provide(:who_by, "Written by:") %> -<%= render partial: 'shared/show', locals: {object: @book, by: @book.author} %> +<%= render partial: 'shared/show', locals: {object: @book} %> diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb index 59b42e84bd..f3c8436d18 100644 --- a/app/views/movies/new.html.erb +++ b/app/views/movies/new.html.erb @@ -1,2 +1,2 @@ <% provide(:title, "New Movie")%> -<%= render partial: 'shared/form', locals: {media: @movie, who_by: "director"} %> +<%= render partial: 'shared/form', locals: {media: @movie} %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 6844e20d61..feaba9b75c 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -1,2 +1,2 @@ <% provide(:who_by, "Directed by:") %> -<%= render partial: 'shared/show', locals: {object: @movie, by: @movie.director} %> +<%= render partial: 'shared/show', locals: {object: @movie} %> diff --git a/app/views/shared/_form.html.erb b/app/views/shared/_form.html.erb index 5f6bcf49cd..2a3d3cd20c 100644 --- a/app/views/shared/_form.html.erb +++ b/app/views/shared/_form.html.erb @@ -14,7 +14,7 @@ <%= f.label :title %> <%= f.text_field :title, class: 'form-control', :required => true %> <%= f.label who_by %> - <%= f.text_field who_by, class: 'form-control', :required => true %> + <%= f.text_field :creator, class: 'form-control', :required => true %> <%= f.label :description %> <%= f.text_area :description, class: 'form-control' %> <%= f.submit value: "Save", class: "btn btn-default"%> diff --git a/app/views/shared/_show.html.erb b/app/views/shared/_show.html.erb index 30b12e1330..5f7b4e00e3 100644 --- a/app/views/shared/_show.html.erb +++ b/app/views/shared/_show.html.erb @@ -1,6 +1,6 @@
-

<%= object.title %> <%= yield(:who_by) %> <%= by %>

+

<%= object.title %> <%= yield(:who_by) %> <%= object.creator %>

Upvotes: <%= object.upvotes %>

<%= object.description %>

<%= button_to "Upvote", polymorphic_path([:upvote, object]), method: :post, class: "btn btn-primary" %> From 6a9bb1c815f2be4742d86dbd807154a73514ab0d Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Thu, 3 Dec 2015 11:10:56 -0800 Subject: [PATCH 59/60] refactor rspec controller tests --- spec/controllers/albums_controller_spec.rb | 87 +-------------------- spec/shared_examples/shared_tests.rb | 88 ++++++++++++++++++++++ 2 files changed, 90 insertions(+), 85 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 2867b13eab..0fb9e3d981 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -1,90 +1,7 @@ require 'rails_helper' +MODEL = "Album".constantize + RSpec.describe AlbumsController, type: :controller do it_behaves_like 'shared_tests' - - describe "GET 'edit'" do - it "renders edit page" do - album = Album.create(title: "Ray of Light", artist: "Madonna") - get :edit, id: album.id - expect(subject).to render_template :edit - end - end - - describe "GET 'show'" do - it "renders show page" do - album = Album.create(title: "Ray of Light", artist: "Madonna") - get :show, id: album.id - expect(subject).to render_template :show, id: album.id - end - end - - describe "POST 'create'" do - let(:good_params) do - { - album: { - title: "The Sound and the Fury", - artist: "William Faulkner" - } - } - end - let(:bad_params) do - { - album: { - title: "The Sound and the Fury" - } - } - end - it "redirects to show on success" do - post :create, good_params - new_album = Album.last - expect(subject).to redirect_to album_path(new_album.id) - end - it "renders new on fail" do - post :create, bad_params - expect(subject).to render_template :new - end - end - - describe "PATCH 'update'" do - let (:album) do - Album.create(title: "Ray of Light", artist: "Madonna") - end - it "redirects to album on success" do - update_params = { - id: album.id, - album: { - title: "Ray of Light", - artist: "Madonna", - description: "Good beats" } - } - patch :update, update_params - expect(subject).to redirect_to album_path(album.id) - end - it "renders edit template on fail" do - bad_params = { - id: album.id, - album: { - artist: "",} - } - patch :update, bad_params - expect(subject).to render_template (:edit) - end - end - - describe "DELETE 'destroy'" do - it "redirects to index on delete" do - album = Album.create(title: "Ray of Light", artist: "Madonna") - delete :destroy, id: album.id - expect(subject).to redirect_to albums_path - end - end - - describe "POST 'upvote'" do - it "redirects to show page" do - album = Album.create(title: "Ray of Light", artist: "Madonna") - post :upvote, id: album.id - expect(subject).to redirect_to album_path(album.id) - end - end end diff --git a/spec/shared_examples/shared_tests.rb b/spec/shared_examples/shared_tests.rb index 81b6127559..a24444fb42 100644 --- a/spec/shared_examples/shared_tests.rb +++ b/spec/shared_examples/shared_tests.rb @@ -1,4 +1,33 @@ shared_examples_for 'shared_tests' do + let(:good_params) do + { + album: { + title: "Hello, World!", + creator: "Jennie" + } + } + end + let(:bad_params) do + { + album: { + title: "Hello, World!" + } + } + end + let(:update_params) do + { + id: new_medium.id, + album: { + description: "Great product!" } + } + end + let(:bad_update_params) do + { + id: new_medium.id, + album: { + title: "" } + } + end describe "GET 'index'" do it "is successful" do @@ -13,4 +42,63 @@ expect(subject).to render_template :new end end + + describe "GET 'edit'" do + it "renders edit page" do + new_medium = MODEL.create(title: "Hello, World!", creator: "Jennie") + get :edit, id: new_medium.id + expect(subject).to render_template :edit + end + end + + describe "GET 'show'" do + it "renders show page" do + new_medium = MODEL.create(title: "Hello, World!", creator: "Jennie") + get :show, id: new_medium.id + expect(subject).to render_template :show, id: new_medium.id + end + end + + describe "POST 'create'" do + it "redirects to show on success" do + post :create, good_params + new_medium = MODEL.last + expect(subject).to redirect_to album_path(new_medium.id) # need to fix this path + end + it "renders new on fail" do + post :create, bad_params + expect(subject).to render_template :new + end + end + + describe "PATCH 'update'" do + let (:new_medium) do + MODEL.create(title: "Hello, World!", creator: "Jennie") + end + it "redirects to album on success" do + patch :update, update_params + expect(subject).to redirect_to album_path(new_medium.id) # need to fix this path + end + it "renders edit template on fail" do + patch :update, bad_update_params + expect(subject).to render_template (:edit) + end + end + + describe "DELETE 'destroy'" do + it "redirects to index on delete" do + new_medium = MODEL.create(title: "Hello, World!", creator: "Jennie") + delete :destroy, id: new_medium.id + expect(subject).to redirect_to albums_path # need to fix this path + end + end + + describe "POST 'upvote'" do + it "redirects to show page" do + new_medium = MODEL.create(title: "Hello, World!", creator: "Jennie") + post :upvote, id: new_medium.id + expect(subject).to redirect_to album_path(new_medium.id) # need to fix this path + end + end + end From 4f6ddee5ddc7459276ddc49f8743343e032a637a Mon Sep 17 00:00:00 2001 From: Jennie Buechner Date: Thu, 3 Dec 2015 11:58:18 -0800 Subject: [PATCH 60/60] refactor rspec --- spec/controllers/albums_controller_spec.rb | 34 ++++++- spec/controllers/books_controller_spec.rb | 107 +++++--------------- spec/controllers/movies_controller_spec.rb | 108 +++++---------------- spec/models/album_spec.rb | 6 +- spec/models/book_spec.rb | 6 +- spec/models/movie_spec.rb | 6 +- spec/shared_examples/shared_tests.rb | 53 +++------- spec/spec_helper.rb | 5 +- 8 files changed, 110 insertions(+), 215 deletions(-) diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 0fb9e3d981..4156158bee 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -1,7 +1,37 @@ require 'rails_helper' -MODEL = "Album".constantize - RSpec.describe AlbumsController, type: :controller do + let(:good_params) do + { + album: { + title: "Hello, World!", + creator: "Jennie" + } + } + end + let(:bad_params) do + { + album: { + title: "Hello, World!" + } + } + end + let(:update_params) do + { + id: new_medium.id, + album: { + description: "Great product!" } + } + end + let(:bad_update_params) do + { + id: new_medium.id, + album: { + title: "" } + } + end + let(:model) do + "Album".constantize + end it_behaves_like 'shared_tests' end diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb index af2f8ed54c..83eb556c63 100644 --- a/spec/controllers/books_controller_spec.rb +++ b/spec/controllers/books_controller_spec.rb @@ -1,92 +1,37 @@ require 'rails_helper' RSpec.describe BooksController, type: :controller do - it_behaves_like 'shared_tests' - - describe "GET 'edit'" do - it "renders edit view" do - book = Book.create(title: "The Sound and the Fury", author: "William Faulkner") - get :edit, id: book.id - expect(subject).to render_template :edit - end - end - - describe "GET 'show'" do - it "renders show view" do - book = Book.create(title: "The Sound and the Fury", author: "William Faulkner") - get :show, id: book.id - expect(subject).to render_template :show, id: book.id - end + let(:model) do + "Book".constantize end - - describe "POST 'create'" do - let(:good_params) do - { - book: { - title: "The Sound and the Fury", - author: "William Faulkner" - } - } - end - let(:bad_params) do - { - book: { - title: "The Sound and the Fury" - } + let(:good_params) do + { + book: { + title: "Hello, World!", + creator: "Jennie" } - end - it "redirects to show view on success" do - post :create, good_params - new_book = Book.last - expect(subject).to redirect_to book_path(new_book.id) - end - - it "renders new view on fail" do - post :create, bad_params - expect(subject).to render_template :new - end - + } end - - describe "PATCH 'update'" do - let(:book) do - Book.create(title: "The Sound and the Fury", author: "William Faulkner") - end - it "redirects to show page on success" do - good_params = { - id: book.id, - book: { - description: "Challenging read but worth the effort." - } - } - patch :update, good_params - expect(subject).to redirect_to book_path(book.id) - end - it "renders edit page on fail" do - bad_params = { - id: book.id, - book: { - title: "", - } + let(:bad_params) do + { + book: { + title: "Hello, World!" } - patch :update, bad_params - expect(subject).to render_template :edit - end + } end - - describe "DELETE 'destroy'" do - it "redirects to index page" do - book = Book.create(title: "The Sound and the Fury", author: "William Faulkner") - delete :destroy, id: book.id - expect(subject).to redirect_to books_path - end + let(:update_params) do + { + id: new_medium.id, + book: { + description: "Great product!" } + } end - - describe "POST 'upvote'" do - it "redirects to show page" do - book = Book.create(title: "The Sound and the Fury", author: "William Faulkner") - post :upvote, id: book.id - expect(subject).to redirect_to book_path(book.id) - end + let(:bad_update_params) do + { + id: new_medium.id, + book: { + title: "" } + } end + it_behaves_like 'shared_tests' end diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb index c79c853cf3..f0a79bd4e0 100644 --- a/spec/controllers/movies_controller_spec.rb +++ b/spec/controllers/movies_controller_spec.rb @@ -1,93 +1,37 @@ require 'rails_helper' RSpec.describe MoviesController, type: :controller do - it_behaves_like 'shared_tests' - - describe "GET 'edit'" do - it "renders edit view" do - movie = Movie.create(title:"Schindler's List 2", director: "Steven Spielberg") - get :edit, id: movie.id - expect(subject).to render_template :edit - end - end - - describe "GET 'show'" do - let(:new_movie) do - Movie.create(title:"Schindler's List 2", director: "Steven Spielberg") - end - it "renders show view" do - get :show, id: new_movie.id - expect(subject).to render_template :show - end + let(:model) do + "Movie".constantize end - - describe "POST 'create'" do - let(:good_params) do - { - movie: { - title: "Schindler's List 2", - director: "Steven Spielberg" - } - } - end - let(:bad_params) do - { - movie: { - title: "Schindler's List 2", - } + let(:good_params) do + { + movie: { + title: "Hello, World!", + creator: "Jennie" } - end - it "redirects to show page on success" do - post :create, good_params - new_movie = Movie.last - expect(subject).to redirect_to movie_path(new_movie.id) - end - it "renders new page on fail" do - post :create, bad_params - expect(subject).to render_template :new - end + } end - - describe "PATCH 'update'" do - let(:movie) do - Movie.create(title: "Schindler's List", director: "Steven Spielberg") - end - it "redirects to show page on success" do - update_params = { - movie: { - title: "Schindler's List 2", - }, - id: movie.id - } - patch :update, update_params - expect(subject).to redirect_to movie_path(movie.id) - end - it "redirects to edit page on fail" do - bad_params = { - movie: { - title: "", - }, - id: movie.id + let(:bad_params) do + { + movie: { + title: "Hello, World!" } - patch :update, bad_params - expect(subject).to render_template :edit - end + } end - - describe "DELETE 'destroy'" do - it "redirects to index page" do - movie = Movie.create(title: "Schindler's List", director: "Steven Spielberg") - delete :destroy, id: movie.id - expect(subject).to redirect_to movies_path - end + let(:update_params) do + { + id: new_medium.id, + movie: { + description: "Great product!" } + } end - - describe "POST 'upvote'" do - it "redirects to show page" do - movie = Movie.create(title: "Schindler's List", director: "Steven Spielberg") - post :upvote, id: movie.id - expect(subject).to redirect_to movie_path(movie.id) - end + let(:bad_update_params) do + { + id: new_medium.id, + movie: { + title: "" } + } end - + it_behaves_like 'shared_tests' end diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index 1135e1f5df..db25f555f9 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -3,9 +3,9 @@ RSpec.describe Album, type: :model do describe ".validates" do it "must have a title and an artist" do - expect(Album.new(title: "a", artist: nil)).to_not be_valid - expect(Album.new(title: nil, artist: "a")).to_not be_valid - expect(Album.new(title: "a", artist: "a")).to be_valid + expect(Album.new(title: "a", creator: nil)).to_not be_valid + expect(Album.new(title: nil, creator: "a")).to_not be_valid + expect(Album.new(title: "a", creator: "a")).to be_valid end end end diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb index 6d262c903a..230387dcc1 100644 --- a/spec/models/book_spec.rb +++ b/spec/models/book_spec.rb @@ -3,9 +3,9 @@ RSpec.describe Book, type: :model do describe ".validates" do it "must have a title and an author" do - expect(Book.new(title: "a", author: nil)).to_not be_valid - expect(Book.new(title: nil, author: "a")).to_not be_valid - expect(Book.new(title: "a", author: "a")).to be_valid + expect(Book.new(title: "a", creator: nil)).to_not be_valid + expect(Book.new(title: nil, creator: "a")).to_not be_valid + expect(Book.new(title: "a", creator: "a")).to be_valid end end end diff --git a/spec/models/movie_spec.rb b/spec/models/movie_spec.rb index 87b7e907ff..81b40bdb5d 100644 --- a/spec/models/movie_spec.rb +++ b/spec/models/movie_spec.rb @@ -3,9 +3,9 @@ RSpec.describe Movie, type: :model do describe ".validates" do it "must have a title and a director" do - expect(Movie.new(title: "a", director: nil)).to_not be_valid - expect(Movie.new(title: nil, director: "a")).to_not be_valid - expect(Movie.new(title: "a", director: "a")).to be_valid + expect(Movie.new(title: "a", creator: nil)).to_not be_valid + expect(Movie.new(title: nil, creator: "a")).to_not be_valid + expect(Movie.new(title: "a", creator: "a")).to be_valid end end end diff --git a/spec/shared_examples/shared_tests.rb b/spec/shared_examples/shared_tests.rb index a24444fb42..866d37fb76 100644 --- a/spec/shared_examples/shared_tests.rb +++ b/spec/shared_examples/shared_tests.rb @@ -1,33 +1,8 @@ +require 'rails_helper' + + shared_examples_for 'shared_tests' do - let(:good_params) do - { - album: { - title: "Hello, World!", - creator: "Jennie" - } - } - end - let(:bad_params) do - { - album: { - title: "Hello, World!" - } - } - end - let(:update_params) do - { - id: new_medium.id, - album: { - description: "Great product!" } - } - end - let(:bad_update_params) do - { - id: new_medium.id, - album: { - title: "" } - } - end + describe "GET 'index'" do it "is successful" do @@ -45,7 +20,7 @@ describe "GET 'edit'" do it "renders edit page" do - new_medium = MODEL.create(title: "Hello, World!", creator: "Jennie") + new_medium = model.create(title: "Hello, World!", creator: "Jennie") get :edit, id: new_medium.id expect(subject).to render_template :edit end @@ -53,7 +28,7 @@ describe "GET 'show'" do it "renders show page" do - new_medium = MODEL.create(title: "Hello, World!", creator: "Jennie") + new_medium = model.create(title: "Hello, World!", creator: "Jennie") get :show, id: new_medium.id expect(subject).to render_template :show, id: new_medium.id end @@ -62,8 +37,8 @@ describe "POST 'create'" do it "redirects to show on success" do post :create, good_params - new_medium = MODEL.last - expect(subject).to redirect_to album_path(new_medium.id) # need to fix this path + new_medium = model.last + expect(subject).to redirect_to polymorphic_path(new_medium) # need to fix this path end it "renders new on fail" do post :create, bad_params @@ -73,11 +48,11 @@ describe "PATCH 'update'" do let (:new_medium) do - MODEL.create(title: "Hello, World!", creator: "Jennie") + model.create(title: "Hello, World!", creator: "Jennie") end it "redirects to album on success" do patch :update, update_params - expect(subject).to redirect_to album_path(new_medium.id) # need to fix this path + expect(subject).to redirect_to polymorphic_path(new_medium) # need to fix this path end it "renders edit template on fail" do patch :update, bad_update_params @@ -87,17 +62,17 @@ describe "DELETE 'destroy'" do it "redirects to index on delete" do - new_medium = MODEL.create(title: "Hello, World!", creator: "Jennie") + new_medium = model.create(title: "Hello, World!", creator: "Jennie") delete :destroy, id: new_medium.id - expect(subject).to redirect_to albums_path # need to fix this path + expect(subject).to redirect_to polymorphic_path(model.name.downcase.pluralize) # need to fix this path end end describe "POST 'upvote'" do it "redirects to show page" do - new_medium = MODEL.create(title: "Hello, World!", creator: "Jennie") + new_medium = model.create(title: "Hello, World!", creator: "Jennie") post :upvote, id: new_medium.id - expect(subject).to redirect_to album_path(new_medium.id) # need to fix this path + expect(subject).to redirect_to polymorphic_path(new_medium) # need to fix this path end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c082c7942a..1c863ed5af 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,6 @@ require 'simplecov' SimpleCov.start 'rails' - -Dir["./spec/shared_examples/**/*.rb"].sort.each { |f| require f} +require 'rails_helper' # 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`. @@ -22,6 +21,8 @@ # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| + Dir["./spec/shared_examples/**/*.rb"].sort.each { |f| require f} + config.include Rails.application.routes.url_helpers # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer.