diff --git a/Gemfile b/Gemfile index 13d617ca23..827c360d22 100644 --- a/Gemfile +++ b/Gemfile @@ -35,12 +35,16 @@ gem 'sdoc', '~> 0.4.0', group: :doc group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' - gem 'better_errors' +end + +group :test do + gem 'minitest-reporters' end group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' + gem 'better_errors' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' diff --git a/Gemfile.lock b/Gemfile.lock index 2516d4acd5..8605f91ef5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,11 +36,17 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + ansi (1.5.0) arel (6.0.3) + 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) builder (3.2.2) byebug (9.0.6) + coderay (1.1.1) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) @@ -72,6 +78,11 @@ GEM mime-types-data (3.2016.0521) mini_portile2 (2.1.0) minitest (5.9.1) + minitest-reporters (1.1.11) + ansi + builder + minitest (>= 5.0) + ruby-progressbar multi_json (1.12.1) nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) @@ -105,6 +116,7 @@ GEM rake (11.3.0) rdoc (4.2.2) json (~> 1.4) + ruby-progressbar (1.8.1) sass (3.4.22) sass-rails (5.0.6) railties (>= 4.0.0, < 6) @@ -145,10 +157,12 @@ PLATFORMS ruby DEPENDENCIES + better_errors byebug coffee-rails (~> 4.1.0) jbuilder (~> 2.0) jquery-rails + minitest-reporters rails (= 4.2.7) sass-rails (~> 5.0) sdoc (~> 0.4.0) diff --git a/app/assets/images/owl.jpg b/app/assets/images/owl.jpg new file mode 100644 index 0000000000..b3ded30950 Binary files /dev/null and b/app/assets/images/owl.jpg differ diff --git a/app/assets/javascripts/albums.coffee b/app/assets/javascripts/albums.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/albums.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/books.coffee b/app/assets/javascripts/books.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/books.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/homes.coffee b/app/assets/javascripts/homes.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/homes.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/movies.coffee b/app/assets/javascripts/movies.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/movies.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/albums.scss b/app/assets/stylesheets/albums.scss new file mode 100644 index 0000000000..684cc4c17f --- /dev/null +++ b/app/assets/stylesheets/albums.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Albums controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/books.scss b/app/assets/stylesheets/books.scss new file mode 100644 index 0000000000..9fab565c8d --- /dev/null +++ b/app/assets/stylesheets/books.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Books controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/homes.scss b/app/assets/stylesheets/homes.scss new file mode 100644 index 0000000000..06b5a4714a --- /dev/null +++ b/app/assets/stylesheets/homes.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Homes controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/movies.scss b/app/assets/stylesheets/movies.scss new file mode 100644 index 0000000000..b86dfedb53 --- /dev/null +++ b/app/assets/stylesheets/movies.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Movies controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb new file mode 100644 index 0000000000..e53d80af63 --- /dev/null +++ b/app/controllers/albums_controller.rb @@ -0,0 +1,59 @@ +class AlbumsController < ApplicationController + def index + @albums = Album.all + @albums_by_rank = Album.order(:rank).reverse + + end + + def new + @album = Album.new + end + + def create + @album = Album.new(album_params) + if @album.save + redirect_to albums_path + else + render :new + end + end + + def edit + @album = Album.find(params[:id]) + end + + def update + @album = Album.find(params[:id]) + if @album.update(album_params) + redirect_to albums_path + else + render :edit + end + + end + + def destroy + @album = Album.find(params[:id]) + @album.destroy + redirect_to album_path + end + + def show + @album = Album.find(params[:id]) + end + + def upvote + @album = Album.find(params[:id]) + @album.rank += 1 + @album.save + redirect_to :back + end + + private + + def album_params + params.require(:album).permit(:name, :artist, :description) #do i want :rank ? + end + + +end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000000..2c148170e1 --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,57 @@ +class BooksController < ApplicationController + def index + @books = Book.all + @books_by_rank = Book.order(:rank).reverse + end + + def new + @book = Book.new + end + + def create + @book = Book.new(book_params) + if @book.save + redirect_to books_path + else + render :new + end + end + + def edit + @book = Book.find(params[:id]) + end + + def update + @book = Book.find(params[:id]) + if @book.update(book_params) + redirect_to books_path + else + render :edit + end + end + + def destroy + @book = Book.find(params[:id]) + @book.destroy + redirect_to book_path + end + + def show + @book = Book.find(params[:id]) + end + + def upvote + @book = Book.find(params[:id]) + @book.rank += 1 + @book.save + redirect_to :back + end + + private + + def book_params + params.require(:book).permit(:name, :author, :description) #do i want :rank ? + end + + +end diff --git a/app/controllers/homes_controller.rb b/app/controllers/homes_controller.rb new file mode 100644 index 0000000000..1121c2bbc0 --- /dev/null +++ b/app/controllers/homes_controller.rb @@ -0,0 +1,7 @@ +class HomesController < ApplicationController + def index + @movies_by_rank = Movie.order(:rank).reverse + @books_by_rank = Book.order(:rank).reverse + @albums_by_rank = Album.order(:rank).reverse + end +end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 0000000000..03c6dced82 --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -0,0 +1,60 @@ +class MoviesController < ApplicationController + def index + @movies = Movie.all + @movies_by_rank = Movie.order(:rank).reverse + + end + + def new + @movie = Movie.new + end + + def create + @movie = Movie.new(movie_params) + if @movie.save + redirect_to movies_path + else + render :new + end + end + + def edit + @movie = Movie.find(params[:id]) + end + + def update + @movie = Movie.find(params[:id]) + if @movie.update(movie_params) + redirect_to movies_path + else + render :edit + end + + end + + def destroy + @movie = Movie.find(params[:id]) + @movie.destroy + redirect_to movie_path + end + + def show + @movie = Movie.find(params[:id]) + end + + def upvote + @movie = Movie.find(params[:id]) + @movie.rank += 1 + @movie.save + + redirect_to :back + end + + + private + + def movie_params + params.require(:movie).permit(:name, :director, :description) #do i want :rank ? + end + +end diff --git a/app/helpers/albums_helper.rb b/app/helpers/albums_helper.rb new file mode 100644 index 0000000000..d976b7cef8 --- /dev/null +++ b/app/helpers/albums_helper.rb @@ -0,0 +1,2 @@ +module AlbumsHelper +end diff --git a/app/helpers/books_helper.rb b/app/helpers/books_helper.rb new file mode 100644 index 0000000000..4b9311e0be --- /dev/null +++ b/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/app/helpers/homes_helper.rb b/app/helpers/homes_helper.rb new file mode 100644 index 0000000000..2a8ce49d58 --- /dev/null +++ b/app/helpers/homes_helper.rb @@ -0,0 +1,2 @@ +module HomesHelper +end diff --git a/app/helpers/movies_helper.rb b/app/helpers/movies_helper.rb new file mode 100644 index 0000000000..493eee555f --- /dev/null +++ b/app/helpers/movies_helper.rb @@ -0,0 +1,2 @@ +module MoviesHelper +end diff --git a/app/models/album.rb b/app/models/album.rb new file mode 100644 index 0000000000..253ea39f93 --- /dev/null +++ b/app/models/album.rb @@ -0,0 +1,6 @@ +class Album < ActiveRecord::Base + + validates :name, presence: true + validates :artist, presence: true + +end diff --git a/app/models/book.rb b/app/models/book.rb new file mode 100644 index 0000000000..b5819f18c3 --- /dev/null +++ b/app/models/book.rb @@ -0,0 +1,6 @@ +class Book < ActiveRecord::Base + + validates :name, presence: true + validates :author, presence: true + +end diff --git a/app/models/movie.rb b/app/models/movie.rb new file mode 100644 index 0000000000..08ffa94347 --- /dev/null +++ b/app/models/movie.rb @@ -0,0 +1,6 @@ +class Movie < ActiveRecord::Base + + validates :name, presence: true + validates :director, presence: true + +end diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb new file mode 100644 index 0000000000..672fb7accf --- /dev/null +++ b/app/views/albums/_form.html.erb @@ -0,0 +1,20 @@ +<% if @album.errors.any? %> + +<% end %> + +<%= form_for @album, method: action_name do |f| %> +<%= f.label :name %> +<%= f.text_field :name %> +<%= f.label :artist %> +<%= f.text_field :artist %> +<%= f.label :description %> +<%= f.text_field :description %> +<%= f.submit "Submit!" %> +<% end %> diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb new file mode 100644 index 0000000000..0b41a370e5 --- /dev/null +++ b/app/views/albums/edit.html.erb @@ -0,0 +1 @@ +<%= render partial: "form", locals: {action_name: :patch} %> diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb new file mode 100644 index 0000000000..02cdd7a71a --- /dev/null +++ b/app/views/albums/index.html.erb @@ -0,0 +1,17 @@ + + + + + + + <% @albums_by_rank.each do |album| %> + + + + + + <% end %> +
RankingNameUpvote
<%= " #{album.rank}" %><%= link_to "#{album.name}", album_path(album.id)%><%= button_to "Upvote", upvote_album_path(album), method: :patch %>
+ +

<%= link_to "Add an Album", new_album_path %> <%= link_to "View All Media", homes_index_path%> +

diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb new file mode 100644 index 0000000000..9f454a45f9 --- /dev/null +++ b/app/views/albums/new.html.erb @@ -0,0 +1 @@ +<%= render partial: "form", locals: {action_name: :post} %> diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb new file mode 100644 index 0000000000..63b4ab7ebc --- /dev/null +++ b/app/views/albums/show.html.erb @@ -0,0 +1,25 @@ +

<%= "#{@album.name} Recorded by: #{@album.artist}" %>

+ +

<%= "Ranked: #{@album.rank}" %>

+

<%= "#{@album.description}" %>

+ + +<%= button_to "Upvote", upvote_album_path(@album), method: :patch %> + + + +<%= link_to "Edit #{@album.name}", edit_album_path %> + + + + +<%= link_to "DELETE", album_path(@album), method: :destroy, +data: {confirm: "Are you really, really sure?"}%> + + + +<%= link_to "View All Albums", albums_path %> + + + +<%= link_to "View All Media", homes_index_path %> diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb new file mode 100644 index 0000000000..7c1375d00b --- /dev/null +++ b/app/views/books/_form.html.erb @@ -0,0 +1,20 @@ +<% if @book.errors.any? %> + +<% end %> + +<%= form_for @book, method: action_name do |f| %> +<%= f.label :name %> +<%= f.text_field :name %> +<%= f.label :author %> +<%= f.text_field :author %> +<%= f.label :description %> +<%= f.text_field :description %> +<%= f.submit "Submit!" %> +<% end %> diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb new file mode 100644 index 0000000000..0b41a370e5 --- /dev/null +++ b/app/views/books/edit.html.erb @@ -0,0 +1 @@ +<%= render partial: "form", locals: {action_name: :patch} %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb new file mode 100644 index 0000000000..06bcfe9941 --- /dev/null +++ b/app/views/books/index.html.erb @@ -0,0 +1,16 @@ + + + + + + + <% @books_by_rank.each do |book| %> + + + + + + <% end %> +
RankingNameUpvote
<%= " #{book.rank}" %><%= link_to "#{book.name}", book_path(book.id)%><%= button_to "Upvote", upvote_book_path(book), method: :patch %>
+ +

<%= link_to "Add a Book", new_book_path %> <%= link_to "View All Media", homes_index_path %>

diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb new file mode 100644 index 0000000000..9f454a45f9 --- /dev/null +++ b/app/views/books/new.html.erb @@ -0,0 +1 @@ +<%= render partial: "form", locals: {action_name: :post} %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb new file mode 100644 index 0000000000..0873a3dadb --- /dev/null +++ b/app/views/books/show.html.erb @@ -0,0 +1,31 @@ +

<%= "#{@book.name} Recorded by: #{@book.author}" %>

+ +

<%= "Ranked: #{@book.rank}" %>

+

<%= "#{@book.description}" %>

+ + +<%= button_to "Upvote", upvote_book_path(@book), method: :patch %> + + + + + + + + + +<%= link_to "Edit #{@book.name}", edit_book_path %> + + + + +<%= link_to "DELETE", book_path(@book), method: :destroy, +data: {confirm: "Are you really, really sure?"}%> + + + +<%= link_to "View All Books", books_path %> + + + +<%= link_to "View All Media", homes_index_path %> diff --git a/app/views/homes/index.html.erb b/app/views/homes/index.html.erb new file mode 100644 index 0000000000..dbe3313ab8 --- /dev/null +++ b/app/views/homes/index.html.erb @@ -0,0 +1,32 @@ + + + + + + + <% 10.times do |i| %> + + + + + + + + <% end %> + + + + + +
Top MoviesTop BooksTop Albums
<%= link_to "#{@movies_by_rank[i].name}", movie_path(@movies_by_rank[i].id)%><%= " #{@movies_by_rank[i].rank}" %><%= link_to "#{@books_by_rank[i].name}", book_path(@books_by_rank[i].id)%><%= " #{@books_by_rank[i].rank}" %><%= link_to "#{@albums_by_rank[i].name}", album_path(@albums_by_rank[i].id)%><%= " #{@albums_by_rank[i].rank}" %>
+ <%= link_to "View More Movies", movies_path %> + + + <%= link_to "View More Books", books_path %> + + + <%= link_to "View More Albums", albums_path %> + +
+ + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2d02e8fbd4..1be6957af6 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,7 +8,20 @@ +
+ +
<%= yield %> + diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb new file mode 100644 index 0000000000..ed9ffe3862 --- /dev/null +++ b/app/views/movies/_form.html.erb @@ -0,0 +1,20 @@ +<% if @movie.errors.any? %> + +<% end %> + +<%= form_for @movie, method: action_name do |f| %> +<%= f.label :name %> +<%= f.text_field :name %> +<%= f.label :director %> +<%= f.text_field :director %> +<%= f.label :description %> +<%= f.text_field :description %> +<%= f.submit "Submit!" %> +<% end %> diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb new file mode 100644 index 0000000000..0b41a370e5 --- /dev/null +++ b/app/views/movies/edit.html.erb @@ -0,0 +1 @@ +<%= render partial: "form", locals: {action_name: :patch} %> diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb new file mode 100644 index 0000000000..8d63ea4478 --- /dev/null +++ b/app/views/movies/index.html.erb @@ -0,0 +1,16 @@ + + + + + + + <% @movies_by_rank.each do |movie| %> + + + + + + <% end %> +
RankingNameUpvote
<%= " #{movie.rank}" %><%= link_to "#{movie.name}", movie_path(movie.id)%><%= button_to "Upvote", upvote_movie_path(movie), method: :patch %>
+ +

<%= link_to "Add a Movie", new_movie_path %> <%= link_to "View All Media", homes_index_path %>

diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb new file mode 100644 index 0000000000..9f454a45f9 --- /dev/null +++ b/app/views/movies/new.html.erb @@ -0,0 +1 @@ +<%= render partial: "form", locals: {action_name: :post} %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb new file mode 100644 index 0000000000..53290a84d8 --- /dev/null +++ b/app/views/movies/show.html.erb @@ -0,0 +1,27 @@ +

<%= "#{@movie.name} Recorded by: #{@movie.director}" %>

+ +

<%= "Ranked: #{@movie.rank}" %>

+

<%= "#{@movie.description}" %>

+ + + +<%= button_to "Upvote", upvote_movie_path(@movie), method: :patch %> + + + + +<%= link_to "Edit #{@movie.name}", edit_movie_path %> + + + + +<%= link_to "DELETE", movie_path(@movie), method: :destroy, +data: {confirm: "Are you really, really sure?"}%> + + + +<%= link_to "View All Movies", movies_path %> + + + +<%= link_to "View All Media", homes_index_path %> diff --git a/config/routes.rb b/config/routes.rb index 3f66539d54..49252ec785 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,15 @@ Rails.application.routes.draw do + get 'homes/index' + + resources :movies + resources :books + resources :albums + patch 'movies/:id/upvote', to: 'movies#upvote', as: 'upvote_movie' + patch 'books/:id/upvote', to: 'books#upvote', as: 'upvote_book' + patch 'albums/:id/upvote', to: 'albums#upvote', as: 'upvote_album' + root 'homes#index' + + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/db/migrate/20161011184704_create_movies.rb b/db/migrate/20161011184704_create_movies.rb new file mode 100644 index 0000000000..1c40a5f879 --- /dev/null +++ b/db/migrate/20161011184704_create_movies.rb @@ -0,0 +1,12 @@ +class CreateMovies < ActiveRecord::Migration + def change + create_table :movies do |t| + t.string :name + t.string :director + t.string :description + t.integer :rank + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161011184730_create_books.rb b/db/migrate/20161011184730_create_books.rb new file mode 100644 index 0000000000..12eb4ee8b2 --- /dev/null +++ b/db/migrate/20161011184730_create_books.rb @@ -0,0 +1,12 @@ +class CreateBooks < ActiveRecord::Migration + def change + create_table :books do |t| + t.string :name + t.string :author + t.string :description + t.integer :rank + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161011184757_create_albums.rb b/db/migrate/20161011184757_create_albums.rb new file mode 100644 index 0000000000..9f04354899 --- /dev/null +++ b/db/migrate/20161011184757_create_albums.rb @@ -0,0 +1,12 @@ +class CreateAlbums < ActiveRecord::Migration + def change + create_table :albums do |t| + t.string :name + t.string :artist + t.string :description + t.integer :rank + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161012222547_change_rank_to_zero.rb b/db/migrate/20161012222547_change_rank_to_zero.rb new file mode 100644 index 0000000000..f6ad8a4a60 --- /dev/null +++ b/db/migrate/20161012222547_change_rank_to_zero.rb @@ -0,0 +1,7 @@ +class ChangeRankToZero < ActiveRecord::Migration + def change + change_column :albums, :rank, :integer, default: 0 + change_column :movies, :rank, :integer, default: 0 + change_column :books, :rank, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..02dddd71f8 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,43 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20161012222547) do + + create_table "albums", force: :cascade do |t| + t.string "name" + t.string "artist" + t.string "description" + t.integer "rank", default: 0 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "books", force: :cascade do |t| + t.string "name" + t.string "author" + t.string "description" + t.integer "rank", default: 0 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "movies", force: :cascade do |t| + t.string "name" + t.string "director" + t.string "description" + t.integer "rank", default: 0 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/test/controllers/albums_controller_test.rb b/test/controllers/albums_controller_test.rb new file mode 100644 index 0000000000..07e6701275 --- /dev/null +++ b/test/controllers/albums_controller_test.rb @@ -0,0 +1,94 @@ +require 'test_helper' + +class AlbumsControllerTest < ActionController::TestCase + + # INDEX + test "should get index" do + get :index + assert_response :success + assert_template :index + end + + # NEW + test "should get new form" do + get :new + assert_response :success + assert_template partial: '_form' + assert_template :new + end + + # CREATE + test "add a new album" do + post_params = {album: {name: "Yolo", artist: "Yates"} } + assert_difference("Album.count", 1) do + post :create, post_params + end + assert_redirected_to albums_path + end + + test "won't add an invalid album" do + post_params = { album: { artist: "Yolo" } } + assert_no_difference('Album.count') do + post :create, post_params + end + assert_template :new + end + + # SHOW + test "should show the requested album" do + album = albums(:Robyn_one).id + get :show, { id: album } + assert_response :success + assert_template :show + yolo = assigns(:album) + assert_not_nil yolo + assert_equal yolo.id, album + end + + # EDIT + test "should get edit form" do + id = albums(:Britney_Spears_one).id + get :edit, { id: id } + assert_response :success + assert_template :edit + end + + # UPDATE + test "should update the album" do + id = albums(:Elton_one).id + patch :update, {id: id, album: {name: "Elton_one"} } + assert_equal "Elton_one", Album.find(id).name + assert_redirected_to albums_path + end + + test "update should not allow nil artist" do + id = albums(:Smashing_Pumpkins_one).id + patch :update, {id: id, album: {artist: nil} } + assert_equal "Smashing Pumpkins", Album.find(id).artist + assert_template :edit + end + + # DESTROY + test "destroy should delete the item" do + id = albums(:Phil_Collins_one).id + assert_difference("Album.count", -1) do + delete :destroy, {id: id} + end + assert_raises ActiveRecord::RecordNotFound do + Album.find(id) + end + assert_redirected_to album_path + end + + # UPVOTE + test "should add 1 to rank" do + album = albums(:Phil_Collins_one) + setup do + @request.env['HTTP_REFERER'] = 'http://localhost:3000/albums' + patch :upvote, id: album.id + end + album.upvote + assert_equal 1, album.rank + end + +end diff --git a/test/controllers/books_controller_test.rb b/test/controllers/books_controller_test.rb new file mode 100644 index 0000000000..560c65fd3c --- /dev/null +++ b/test/controllers/books_controller_test.rb @@ -0,0 +1,95 @@ +require 'test_helper' + +class BooksControllerTest < ActionController::TestCase + + # INDEX + test "should get index" do + get :index + assert_response :success + assert_template :index + end + + # NEW + test "should get new form" do + get :new + assert_response :success + assert_template partial: '_form' + assert_template :new + end + + # CREATE + test "add a new book" do + post_params = {book: {name: "Yolo", author: "Tina Fey"} } + assert_difference("Book.count", 1) do + post :create, post_params + end + assert_redirected_to books_path + end + + test "won't add an invalid book" do + post_params = { book: { author: "Yolo" } } + assert_no_difference('Book.count') do + post :create, post_params + end + assert_template :new + end + + # SHOW + test "should show the requested book" do + book = books(:HP_seven).id + get :show, { id: book } + assert_response :success + assert_template :show + yolo = assigns(:book) + assert_not_nil yolo + assert_equal yolo.id, book + end + + # EDIT + test "should get edit form" do + id = books(:HP_six).id + get :edit, { id: id } + assert_response :success + assert_template :edit + end + + # UPDATE + test "should update the book" do + id = books(:HP_two).id + patch :update, {id: id, book: {name: "HP_two"} } + assert_equal "HP_two", Book.find(id).name + assert_redirected_to books_path + end + + test "update should not allow nil author" do + id = books(:HP_three).id + patch :update, {id: id, book: {author: nil} } + assert_equal "J.K. Rowling", Book.find(id).author + assert_template :edit + end + + # DESTROY + test "destroy should delete the item" do + id = books(:HP_seven).id + assert_difference("Book.count", -1) do + delete :destroy, {id: id} + end + assert_raises ActiveRecord::RecordNotFound do + Book.find(id) + end + assert_redirected_to book_path + end + + + # UPVOTE + test "should add 1 to rank" do + book = books(:HP_four) + setup do + @request.env['HTTP_REFERER'] = 'http://localhost:3000/books' + patch :upvote, id: book.id + end + book.upvote + assert_equal 1, book.rank + end + +end diff --git a/test/controllers/homes_controller_test.rb b/test/controllers/homes_controller_test.rb new file mode 100644 index 0000000000..2ee8550d50 --- /dev/null +++ b/test/controllers/homes_controller_test.rb @@ -0,0 +1,12 @@ +require 'test_helper' + +class HomesControllerTest < ActionController::TestCase + + # INDEX + test "should get index" do + get :index + assert_response :success + assert_template :index + end + +end diff --git a/test/controllers/movies_controller_test.rb b/test/controllers/movies_controller_test.rb new file mode 100644 index 0000000000..26489711a7 --- /dev/null +++ b/test/controllers/movies_controller_test.rb @@ -0,0 +1,95 @@ +require 'test_helper' + +class MoviesControllerTest < ActionController::TestCase + + # INDEX + test "should go to index" do + get :index + assert_response :success + assert_template :index + end + + # NEW + test "should go to new form" do + get :new + assert_response :success + assert_template partial: '_form' + assert_template :new + end + + # CREATE + test "add a new movie" do + post_params = {movie: {name: "Yolo", director: "Nickelback"} } + assert_difference("Movie.count", 1) do + post :create, post_params + end + assert_redirected_to movies_path + end + + test "won't add an invalid movie" do + post_params = { movie: { director: "Yolo" } } + assert_no_difference('Movie.count') do + post :create, post_params + end + assert_template :new + end + + # SHOW + test "should show the requested movie" do + movie = movies(:Reservoir_Dogs).id + get :show, { id: movie } + assert_response :success + assert_template :show + yolo = assigns(:movie) + assert_not_nil yolo + assert_equal yolo.id, movie + end + + # EDIT + test "should get edit form" do + id = movies(:Uncle_Buck).id + get :edit, { id: id } + assert_response :success + assert_template :edit + end + + # UPDATE + test "should update the movie" do + id = movies(:Pulp_Fiction).id + patch :update, {id: id, movie: {name: "Pulp_Fiction"} } + assert_equal "Pulp_Fiction", Movie.find(id).name + assert_redirected_to movies_path + end + + test "update should not allow nil director" do + id = movies(:Uncle_Buck).id + patch :update, {id: id, movie: {director: nil} } + assert_equal "John Hughes", Movie.find(id).director + assert_template :edit + end + + # DESTROY + test "destroy should delete the item" do + id = movies(:Kill_Bill_vol_1).id + assert_difference("Movie.count", -1) do + delete :destroy, {id: id} + end + assert_raises ActiveRecord::RecordNotFound do + Movie.find(id) + end + assert_redirected_to movie_path + end + + # UPVOTE + test "should add 1 to rank" do + movie = movies(:Kill_Bill_vol_1) + setup do + @request.env['HTTP_REFERER'] = 'http://localhost:3000/movies' + patch :upvote, id: movie.id + end + movie.upvote + assert_equal 1, movie.rank + end + + +end diff --git a/test/fixtures/albums.yml b/test/fixtures/albums.yml new file mode 100644 index 0000000000..128ddc3318 --- /dev/null +++ b/test/fixtures/albums.yml @@ -0,0 +1,61 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +Elton_one: + name: + artist: Elton John + description: Awesome + +Elton_two: + name: Elton_two + artist: + description: Great + +Phil_Collins_one: + name: Phil_Collins_one + artist: Phil Collins + description: The best + +Phil_Collins_two: + name: Phil_Collins_two + artist: Phil Collins + description: woot + +Robyn_one: + name: Robyn_one + artist: Robyn + description: yeah + +Robyn_two: + name: Robyn_two + artist: Robyn + description: so good + +Britney_Spears_one: + name: Britney_Spears_one + artist: Britney Spears + description: So lucky + +Britney_Spears_two: + name: Britney_Spears_two + artist: Britney Spears + description: Toxic + +Nirvana_one: + name: Nirvana_one + artist: Nirvana + description: RIP Kurt + +Nirvana_two: + name: Nirvana_two + artist: Nirvana + description: teen spirit + +Smashing_Pumpkins_one: + name: Smashing_Pumpkins_one + artist: Smashing Pumpkins + description: today + +Smashing_Pumpkins_two: + name: Smashing_Pumpkins_two + artist: Smashing Pumpkins + description: the world is a vampire diff --git a/test/fixtures/books.yml b/test/fixtures/books.yml new file mode 100644 index 0000000000..08e0d046f0 --- /dev/null +++ b/test/fixtures/books.yml @@ -0,0 +1,61 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +HP_one: + name: HP_one + author: + description: Awesome + +HP_two: + name: + author: J.K. Rowling + description: Great + +HP_three: + name: HP_three + author: J.K. Rowling + description: Mysterious + +HP_four: + name: HP_four + author: J.K. Rowling + description: Wow + +HP_five: + name: HP_five + author: J.K. Rowling + description: Sad + +HP_six: + name: HP_six + author: J.K. Rowling + description: Sadder + +HP_seven: + name: HP_seven + author: J.K. Rowling + description: Best! + +ASOIAF_one: + name: ASOIAF_one + author: George R.R. Martin + description: RIP Ned! + +ASOIAF_two: + name: ASOIAF_two + author: George R.R. Martin + description: Woohoo + +ASOIAF_three: + name: ASOIAF_three + author: George R.R. Martin + description: RIP Robb! + +ASOIAF_four: + name: ASOIAF_four + author: George R.R. Martin + description: Where Dany at? + +ASOIAF_five: + name: ASOIAF_five + author: George R.R. Martin + description: YAS QUEEN diff --git a/test/fixtures/movies.yml b/test/fixtures/movies.yml new file mode 100644 index 0000000000..b0caadada4 --- /dev/null +++ b/test/fixtures/movies.yml @@ -0,0 +1,66 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +Pulp_Fiction: + name: + director: Quentin Tarantino + description: Blood + +Jackie_Brown: + name: Jackie_Brown + director: + description: more blood + +Inglorious_Basterds: + name: Inglorious_Basterds + director: Quentin Tarantino + description: even more blood + +Kill_Bill_vol_1: + name: Kill_Bill_vol_1 + director: Quentin Tarantino + description: so much blood + +Kill_Bill_vol_2: + name: Kill_Bill_vol_2 + director: Quentin Tarantino + description: literally buckets of blood + +Reservoir_Dogs: + name: Reservoir_Dogs + director: Quentin Tarantino + description: a fair amount of blood + +The_Breakfast_Club: + name: The_Breakfast_Club + director: John Hughes + description: molly ringwald + +Sixteen_Candles: + name: Sixteen_Candles + director: John Hughes + description: more molly ringwald + +Ferris_Buellers_Day_Off: + name: Ferris_Buellers_Day_Off + director: John Hughes + description: playing hookey = awesome + +Uncle_Buck: + name: Uncle_Buck + director: John Hughes + description: RIP John Candy + +Shes_Having_A_Baby: + name: Shes_Having_A_Baby + director: John Hughes + description: Six degrees of Kevin Bacon + +Spirited_Away: + name: Spirited_Away + director: Hayao Miyazaki + description: parents = pigs + +Ponyo: + name: Ponyo + director: Hayao Miyazaki + description: a better little mermaid diff --git a/test/models/album_test.rb b/test/models/album_test.rb new file mode 100644 index 0000000000..e599f66211 --- /dev/null +++ b/test/models/album_test.rb @@ -0,0 +1,39 @@ +require 'test_helper' + +class AlbumTest < ActiveSupport::TestCase + + test "validations: album name can't be blank" do + album = albums(:Elton_one) + assert_not album.valid? + assert album.errors.keys.include?(:name), "name is not in the errors hash" + end + + test "validations: album artist can't be blank" do + album = albums(:Elton_two) + assert_not album.valid? + assert album.errors.keys.include?(:artist), "artist is not in the errors hash" + end + + test "Create an album w/ valid data" do + album = albums(:Robyn_one) + assert album.valid? + end + + test "Create two albums with different titles" do + album1 = albums(:Britney_Spears_one) + album2 = albums(:Britney_Spears_two) + assert album2.valid? + end + + test "When a new album is created, rank is 0" do + album = albums(:Phil_Collins_one) + assert album.rank == 0 + end + + test "When a new album is created, rank isn't something besides 0" do + album = albums(:Smashing_Pumpkins_one) + assert_not album.rank == rand(1..2000) + assert_not album.rank == rand(-2000..-1) + end + +end diff --git a/test/models/book_test.rb b/test/models/book_test.rb new file mode 100644 index 0000000000..afe4ace8f0 --- /dev/null +++ b/test/models/book_test.rb @@ -0,0 +1,38 @@ +require 'test_helper' + +class BookTest < ActiveSupport::TestCase + test "validations: book name can't be blank" do + book = books(:HP_two) + assert_not book.valid? + assert book.errors.keys.include?(:name), "name is not in the errors hash" + end + + test "validations: book author can't be blank" do + book = books(:HP_one) + assert_not book.valid? + assert book.errors.keys.include?(:author), "author is not in the errors hash" + end + + test "Create an book w/ valid data" do + book = books(:HP_five) + assert book.valid? + end + + test "Create two books with different titles" do + book1 = books(:HP_three) + book2 = books(:HP_four) + assert book2.valid? + end + + test "When a new book is created, rank is 0" do + book = books(:HP_seven) + assert book.rank == 0 + end + + test "When a new book is created, rank isn't something besides 0" do + book = books(:HP_six) + assert_not book.rank == rand(1..2000) + assert_not book.rank == rand(-2000..-1) + end + +end diff --git a/test/models/movie_test.rb b/test/models/movie_test.rb new file mode 100644 index 0000000000..a5c1f5d8a9 --- /dev/null +++ b/test/models/movie_test.rb @@ -0,0 +1,38 @@ +require 'test_helper' + +class MovieTest < ActiveSupport::TestCase + + test "validations: movie name can't be blank" do + movie = movies(:Pulp_Fiction) + assert_not movie.valid? + assert movie.errors.keys.include?(:name), "name is not in the errors hash" + end + + test "validations: movie director can't be blank" do + movie = movies(:Jackie_Brown) + assert_not movie.valid? + assert movie.errors.keys.include?(:director), "director is not in the errors hash" + end + + test "Create an movie w/ valid data" do + movie = movies(:Reservoir_Dogs) + assert movie.valid? + end + + test "Create two movies with different titles" do + movie1 = movies(:Kill_Bill_vol_1) + movie2 = movies(:Kill_Bill_vol_2) + assert movie2.valid? + end + + test "When a new movie is created, rank is 0" do + movie = movies(:Inglorious_Basterds) + assert movie.rank == 0 + end + + test "When a new movie is created, rank isn't something besides 0" do + movie = movies(:The_Breakfast_Club) + assert_not movie.rank == rand(1..2000) + assert_not movie.rank == rand(-2000..-1) + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 92e39b2d78..f40803b101 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,10 +1,11 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' +require "minitest/reporters" class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all - + Minitest::Reporters.use! # Add more helper methods to be used by all tests here... end