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/.rspec b/.rspec new file mode 100644 index 0000000000..83e16f8044 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/Gemfile b/Gemfile index 69890fc981..922f613846 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.5' # Use sqlite3 as the database for Active Record - +gem 'bootstrap-sass', '~> 3.3.6' gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' @@ -33,6 +33,11 @@ gem 'sdoc', '~> 0.4.0', group: :doc group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + gem 'rspec-rails' +end + +group :test do + gem 'simplecov', require: false end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index dee2f0686a..801083d137 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,12 +37,18 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.3) + autoprefixer-rails (6.1.2) + execjs + json better_errors (2.1.1) coderay (>= 1.0.0) erubis (>= 2.6.6) rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) + bootstrap-sass (3.3.6) + autoprefixer-rails (>= 5.2.1) + sass (>= 3.3.4) builder (3.2.2) byebug (8.2.1) choice (0.2.0) @@ -55,6 +61,8 @@ GEM execjs 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) @@ -120,6 +128,23 @@ GEM thor (>= 0.18.1, < 2.0) rake (10.4.2) rdoc (4.2.0) + rspec-core (3.4.1) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-mocks (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-rails (3.4.0) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + railties (>= 3.0, < 4.3) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) ruby-graphviz (1.2.2) sass (3.4.19) sass-rails (5.0.4) @@ -131,6 +156,11 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + simplecov (0.11.0) + docile (~> 1.1.0) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) slop (3.6.0) spring (1.5.0) sprockets (3.4.1) @@ -162,6 +192,7 @@ PLATFORMS DEPENDENCIES better_errors binding_of_caller + bootstrap-sass (~> 3.3.6) byebug coffee-rails (~> 4.1.0) jbuilder (~> 2.0) @@ -170,8 +201,10 @@ DEPENDENCIES pry-rails rails (= 4.2.5) rails-erd + rspec-rails sass-rails (~> 5.0) sdoc (~> 0.4.0) + simplecov spring sqlite3 turbolinks 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/album.coffee b/app/assets/javascripts/album.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/album.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e07c5a830f..f91cae5d9b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -11,6 +11,7 @@ // about supported directives. // //= require jquery +//= require bootstrap-sprockets //= require jquery_ujs //= require turbolinks //= require_tree . diff --git a/app/assets/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/home.coffee b/app/assets/javascripts/home.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/home.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/movies.coffee b/app/assets/javascripts/movies.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/movies.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/album.scss b/app/assets/stylesheets/album.scss new file mode 100644 index 0000000000..2bb51d310f --- /dev/null +++ b/app/assets/stylesheets/album.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the album controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.scss similarity index 73% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index f9cd5b3483..f6a8e870fa 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.scss @@ -10,6 +10,20 @@ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new * file per style scope. * - *= require_tree . - *= require_self */ + +@import "bootstrap-sprockets"; +@import "bootstrap"; + +.page-header { + background-image: image-url("owl.jpg"); + background-repeat: no-repeat; +} + +.page-header h1 { + margin-left: 150px; +} + +form .btn-primary { + margin-bottom: 10px; +} diff --git a/app/assets/stylesheets/books.scss b/app/assets/stylesheets/books.scss new file mode 100644 index 0000000000..81379d103f --- /dev/null +++ b/app/assets/stylesheets/books.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the books controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/home.scss b/app/assets/stylesheets/home.scss new file mode 100644 index 0000000000..f0ddc6846a --- /dev/null +++ b/app/assets/stylesheets/home.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/movies.scss b/app/assets/stylesheets/movies.scss new file mode 100644 index 0000000000..70aaa8a9a4 --- /dev/null +++ b/app/assets/stylesheets/movies.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the movies controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb new file mode 100644 index 0000000000..957c2c1dfd --- /dev/null +++ b/app/controllers/albums_controller.rb @@ -0,0 +1,56 @@ +class AlbumsController < ApplicationController + + def index + @albums = Album.all.sort_by { |album| -album.rank } + end + + def upvote + album = Album.find(params[:id]) + album.rank += 1 + album.save + redirect_to album_path(album) + end + + def new + @album = Album.new + end + + def create + @album = Album.new(album_params[:album]) + if @album.save + redirect_to album_path(@album) + else + render "new" + end + end + + def show + @album = Album.find(params[:id]) + end + + def edit + @album = Album.find(params[:id]) + end + + def update + @album = Album.find(params[:id]) + @album.update( album_params[:album]) + if @album.save + redirect_to album_path(@album) + else + render "edit" + end + end + + def destroy + Album.destroy(params[:id]) + redirect_to albums_path + end + + private + + def album_params + params.permit(album:[:name, :artist, :description, :rank]) + end + +end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000000..a88afb2766 --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,57 @@ +class BooksController < ApplicationController + + def index + @books = Book.all.sort_by { |book| -book.rank } + end + + def upvote + book = Book.find(params[:id]) + book.rank += 1 + book.save + redirect_to book_path(book) + end + + def new + @book = Book.new + end + + def create + @book = Book.new(book_params) + if @book.save + redirect_to book_path(@book) + else + render "new" + end + end + + def show + @book = Book.find(params[:id]) + end + + def edit + @book = Book.find(params[:id]) + end + + def update + @book = Book.find(params[:id]) + @book.update( book_params ) + if @book.save + redirect_to book_path(@book) + else + render "edit" + end + end + + def destroy + Book.destroy(params[:id]) + redirect_to books_path + end + + private + + def book_params + params.require(:book).permit(:name, :author, :description, :rank) + end + + +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000000..6170b646cf --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,8 @@ +class HomeController < ApplicationController + + def index + @movies = Movie.all.sort_by { |movie| -movie.rank }.first(10) + @albums = Album.all.sort_by { |album| -album.rank }.first(10) + @books = Book.all.sort_by { |book| -book.rank }.first(10) + end +end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 0000000000..9774b91bb4 --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -0,0 +1,57 @@ +class MoviesController < ApplicationController + + def index + @movies = Movie.all.sort_by { |movie| -movie.rank } + end + + def new + @movie = Movie.new + end + + def create + @movie = Movie.new(movie_params[:movie]) + if @movie.save + redirect_to movie_path(@movie) + else + render "new" + end + end + + def show + @movie = Movie.find(params[:id]) + end + + def edit + @movie = Movie.find(params[:id]) + end + + def update + @movie = Movie.find(params[:id]) + @movie.update( movie_params[:movie]) + if @movie.save + redirect_to movie_path(@movie) + else + render "edit" + end + end + + def destroy + Movie.destroy(params[:id]) + redirect_to movies_path + end + + def upvote + movie = Movie.find(params[:id]) + movie.rank += 1 + movie.save + redirect_to movie_path(movie) + end + + private + + def movie_params + params.permit(movie:[:name, :director, :description, :rank]) + end + + +end diff --git a/app/helpers/album_helper.rb b/app/helpers/album_helper.rb new file mode 100644 index 0000000000..23ace66827 --- /dev/null +++ b/app/helpers/album_helper.rb @@ -0,0 +1,2 @@ +module AlbumHelper +end diff --git a/app/helpers/books_helper.rb b/app/helpers/books_helper.rb new file mode 100644 index 0000000000..4b9311e0be --- /dev/null +++ b/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000000..23de56ac60 --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/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..cbbf38bde0 --- /dev/null +++ b/app/models/album.rb @@ -0,0 +1,6 @@ +class Album < ActiveRecord::Base + validates :name, presence: true, length: { maximum: 100 } + validates :description, length: {maximum: 500 } + validates :artist, length: {maximum: 100 } + +end diff --git a/app/models/book.rb b/app/models/book.rb new file mode 100644 index 0000000000..c72e044a92 --- /dev/null +++ b/app/models/book.rb @@ -0,0 +1,6 @@ +class Book < ActiveRecord::Base + validates :name, presence: true, length: { maximum: 100 } + validates :description, length: {maximum: 500 } + validates :author, length: {maximum: 100 } + +end diff --git a/app/models/movie.rb b/app/models/movie.rb new file mode 100644 index 0000000000..11064ae833 --- /dev/null +++ b/app/models/movie.rb @@ -0,0 +1,6 @@ +class Movie < ActiveRecord::Base + validates :name, presence: true, length: { maximum: 100 } + validates :description, length: {maximum: 500 } + validates :director, length: {maximum: 100 } + +end diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb new file mode 100644 index 0000000000..42c50caa33 --- /dev/null +++ b/app/views/albums/edit.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/form', + locals:{ medium: @album, action: :update, title: "Edit Album", creator: :artist, rank_value: @album.rank} %> diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb new file mode 100644 index 0000000000..d65c78cecd --- /dev/null +++ b/app/views/albums/index.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/index', + locals:{media:@albums, media_type: :album } %> diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb new file mode 100644 index 0000000000..84f0f0a9f8 --- /dev/null +++ b/app/views/albums/new.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/form', + locals:{ medium: @album, action: :create, title: "New Album", creator: :artist, rank_value: 0} %> diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb new file mode 100644 index 0000000000..41ada7c2d4 --- /dev/null +++ b/app/views/albums/show.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/detail', + locals:{ medium: @album, creator: @album.artist, byline: "Recorded by: ", media_type: :albums} %> diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb new file mode 100644 index 0000000000..e52bb31153 --- /dev/null +++ b/app/views/books/edit.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/form', + locals:{ medium: @book, action: :update, title: "Edit Book", creator: :author, rank_value: @book.rank} %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb new file mode 100644 index 0000000000..4ecd01613f --- /dev/null +++ b/app/views/books/index.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/index', + locals:{media:@books, media_type: :book } %> diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb new file mode 100644 index 0000000000..a0813b365f --- /dev/null +++ b/app/views/books/new.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/form', + locals:{ medium: @book, action: :create, title: "New Book", creator: :author, rank_value: 0} %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb new file mode 100644 index 0000000000..848c96905a --- /dev/null +++ b/app/views/books/show.html.erb @@ -0,0 +1,2 @@ +<%= render partial:'shared/detail', + locals:{ medium: @book, creator: @book.author, byline: "Written by: ", media_type: :books} %> diff --git a/app/views/home/_list.html.erb b/app/views/home/_list.html.erb new file mode 100644 index 0000000000..c8dd9da734 --- /dev/null +++ b/app/views/home/_list.html.erb @@ -0,0 +1,11 @@ +