Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete MediaRanker #42

Open
wants to merge 91 commits into
base: dfp/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
7a7b397
Generate movie model
dezshino Nov 30, 2015
4b81b42
Generate book model
dezshino Nov 30, 2015
dab484b
Generate album model
dezshino Nov 30, 2015
88d391c
Add controllers for books, movies, and albums
dezshino Nov 30, 2015
7a749a7
Create routes for albums, books, and movies
dezshino Nov 30, 2015
ef1da81
Generate a media controller, add an index method to it, add a root ro…
dezshino Nov 30, 2015
9da5b38
Add methods to BooksController, empty for now
dezshino Nov 30, 2015
e7d95e2
Add books to seeds
dezshino Nov 30, 2015
8178be3
Create an index view for books that shows all books
dezshino Nov 30, 2015
096e7be
Create books show page
dezshino Nov 30, 2015
4cbabaa
Add links to book index
dezshino Nov 30, 2015
ec13745
Add form to books new view
dezshino Nov 30, 2015
3e5dd1d
Create form for books works
dezshino Nov 30, 2015
34d2f0f
Put form into a partial, link to add a book from books index
dezshino Nov 30, 2015
dac12cd
Add edit/update form/function to books
dezshino Nov 30, 2015
32131e2
Link to books edit form
dezshino Nov 30, 2015
1008df3
Add link/ability to delete a book
dezshino Dec 1, 2015
923e5fc
Add upvote ability to books
dezshino Dec 1, 2015
30979ef
Add upvote button to books index page
dezshino Dec 1, 2015
28ceb15
Fill out more on home page, order media by their upvote amounts
dezshino Dec 1, 2015
ab2a52e
Update seeds
dezshino Dec 1, 2015
26026f1
Update media index page to show all media types
dezshino Dec 1, 2015
928cecf
Validate presence and uniqueness of book name
dezshino Dec 1, 2015
d48562c
generate ERD diagram
dezshino Dec 1, 2015
e881c8b
Add empty methods to albums and movies controller
dezshino Dec 1, 2015
026fccf
Add validation of presence and uniqueness for name in movie and album…
dezshino Dec 1, 2015
b0d94df
Rspec setup
dezshino Dec 1, 2015
c62d1dd
rspec setup
dezshino Dec 1, 2015
68d356f
Add tests for each model to test they each must have a name to be valid
dezshino Dec 1, 2015
1e2c1b0
Add test to books controller to check response status for index is ok
dezshino Dec 1, 2015
fa3325f
Add test to albums controller to check response status for index is o…
dezshino Dec 1, 2015
2cbb090
Add test for index response status ok for media
dezshino Dec 1, 2015
1d70ef0
Add index view to movies
dezshino Dec 1, 2015
91dda9a
Add response status test for movies index
dezshino Dec 1, 2015
e40a195
Add empty views to movies and albums
dezshino Dec 1, 2015
1d718d1
spec for book GET show/:id
dezshino Dec 1, 2015
947e4d1
Work in progress, started a shared partial for controller index pages
dezshino Dec 1, 2015
5efb398
Add index view for movies and upvote method and route
dezshino Dec 1, 2015
71c4ee6
Add show view to movies
dezshino Dec 1, 2015
3bee303
Fix header
dezshino Dec 1, 2015
a845fc1
Fix create method
dezshino Dec 1, 2015
073c88e
Add create and update abilities to movies
dezshino Dec 1, 2015
989f9ce
Add controller actions, views, route for albums
dezshino Dec 1, 2015
ac616ba
Fill out rest of links on media index page
dezshino Dec 1, 2015
f202f95
Fix white space and indents
dezshino Dec 1, 2015
bf9991a
Add specs for show view for movies and albums controllers
dezshino Dec 1, 2015
591c69a
add and require simplecov gem
dezshino Dec 2, 2015
99f77d2
Add spec for POST 'create' when good params
dezshino Dec 2, 2015
8c3fd91
refactor POST create test
dezshino Dec 2, 2015
e3f0af1
Add spec for errors
dezshino Dec 2, 2015
a87ff82
PATCH update spec for albums
dezshino Dec 2, 2015
d7d0c0a
Add destroy action to albums controller
dezshino Dec 2, 2015
4aebbf0
Add spec for albums controller destroy action
dezshino Dec 2, 2015
6808992
add spec for album controller post upvote action
dezshino Dec 2, 2015
66e2fbb
Setup bootstrap
dezshino Dec 2, 2015
c95a96c
Add owl image
dezshino Dec 2, 2015
1c95ec3
Bootstrap styling
dezshino Dec 2, 2015
9d091b5
Styling
dezshino Dec 2, 2015
a0e02f7
Made a index partial, applied it to moviesindex
dezshino Dec 2, 2015
f245288
Fixed index partial upvote method
dezshino Dec 3, 2015
b509d13
refactor
dezshino Dec 3, 2015
9454378
change amount the media index will show
dezshino Dec 3, 2015
cac2b1e
generate test coverage
dezshino Dec 3, 2015
dd1a0da
Fix index partial, update views to apply change, format albums index …
dezshino Dec 3, 2015
aac1445
Create a form partial in shared folder, replace movies forms with it
dezshino Dec 3, 2015
09a337f
Set up books to use form partial in shared folder
dezshino Dec 3, 2015
13c0988
Set up albums to use form partial in shared folder
dezshino Dec 3, 2015
5aa5f3d
Created a partial for show, applied it to movies
dezshino Dec 3, 2015
038042c
Apply show partial to books
dezshino Dec 3, 2015
e683bed
Apply shared show partial to albums
dezshino Dec 3, 2015
c6c9cbe
Update shared index partial to have proper grammar
dezshino Dec 3, 2015
96e0553
Add spec for album edit
dezshino Dec 3, 2015
be73f8f
Fix album update method to re render the edit form if params not valid
dezshino Dec 3, 2015
51ceb13
Add test for albums controller update with bad params
dezshino Dec 3, 2015
18610f5
Update books controller update method to re render the edit form if p…
dezshino Dec 3, 2015
1a2700f
Update movies controller update method to re render the edit form if …
dezshino Dec 3, 2015
c2276ae
Add specs
dezshino Dec 3, 2015
8e6b899
book specs
dezshino Dec 3, 2015
14e8db1
fix whitespace
dezshino Dec 3, 2015
6641959
Add specs to movies controller
dezshino Dec 3, 2015
09675a0
Refactor test, take out unneccessary params
dezshino Dec 3, 2015
78a7408
Take out unneccessary params from specs
dezshino Dec 4, 2015
752f46f
Take out unneccessary params from specs
dezshino Dec 4, 2015
9c2a358
Use shared spec for models
dezshino Dec 4, 2015
26b62fb
took out unneccessary lines
dezshino Dec 4, 2015
ace940c
Update wording
dezshino Dec 4, 2015
7dd3f96
fix indents
dezshino Dec 4, 2015
a521fdb
begin adding specs to medium_controller_spec to later DRY up specs code
dezshino Dec 4, 2015
31243ec
add specs to medium_controller_spec
dezshino Dec 4, 2015
5158568
add last specs to medium_controller_spec
dezshino Dec 4, 2015
32688a5
DRY up spec code using medium_controller_spec
dezshino Dec 4, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ source 'https://rubygems.org'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use bootstrap for styling
gem 'bootstrap-sass', '~> 3.3.6'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
Expand Down Expand Up @@ -35,6 +37,8 @@ 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'
gem 'simplecov'
end

group :development do
Expand Down
33 changes: 33 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -112,6 +120,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)
Expand All @@ -123,6 +148,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)
sprockets (3.4.1)
rack (> 1, < 3)
sprockets-rails (2.3.3)
Expand Down Expand Up @@ -152,14 +182,17 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
jquery-rails
rails (= 4.2.5)
rails-erd
rspec-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
simplecov
sqlite3
turbolinks
uglifier (>= 1.3.0)
Expand Down
Binary file added app/assets/images/owl.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/javascripts/albums.coffee
Original file line number Diff line number Diff line change
@@ -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/
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//= require bootstrap-sprockets
3 changes: 3 additions & 0 deletions app/assets/javascripts/books.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/javascripts/media.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/javascripts/movies.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/albums.scss
Original file line number Diff line number Diff line change
@@ -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/
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@
* 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;
}
a {
color: #428bca;
}
.row {
margin-right: -15px;
margin-left: -15px;
}
form .btn-primary {
margin-bottom: 10px;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/books.scss
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/media.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the media controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/movies.scss
Original file line number Diff line number Diff line change
@@ -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/
55 changes: 55 additions & 0 deletions app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class AlbumsController < ApplicationController

def index
@albums = Album.all.order(:upvotes).reverse
end

def show
@album = Album.find(params[:id])
end

def new
@album = Album.new
end

def edit
@album = Album.find(params[:id])
end

def create
@album = Album.new(album_params)
if @album.save
redirect_to album_path(@album.id)
else
render :new
end
end

def update
@album = Album.update(params[:id], album_params)
if @album.save
redirect_to album_path(@album.id)
else
render :edit
end
end

def destroy
Album.find(params[:id]).destroy
redirect_to albums_path
end

def upvote
album = Album.find(params[:id])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you search for this album in multiple methods. A possible way you could DRY up your code in a refactor would be to extract finding the album into its own private method and create a before_action that calls it before each method except: [:index, :new, :create].

album.upvotes += 1
album.save!
redirect_to album_path(params[:id])
end

private

def album_params
params.require(:album).permit(:name, :artist, :description)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of strong params! #security

end

end
54 changes: 54 additions & 0 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class BooksController < ApplicationController

def index
@books = Book.all.order(:upvotes).reverse
end

def show
@book = Book.find(params[:id])
end

def new
@book = Book.new
end

def edit
@book = Book.find(params[:id])
end

def create
@book = Book.new(book_params)
if @book.save
redirect_to book_path(@book.id)
else
render :new
end
end

def update
@book = Book.update(params[:id], book_params)
if @book.save
redirect_to book_path(@book.id)
else
render :edit
end
end

def destroy
Book.find(params[:id]).destroy
redirect_to books_path
end

def upvote
book = Book.find(params[:id])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same before_action concept could be used for finding your book in this controller 😄

book.upvotes += 1
book.save!
redirect_to book_path(params[:id])
end

private

def book_params
params.require(:book).permit(:name, :author, :description)
end
end
7 changes: 7 additions & 0 deletions app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class MediaController < ApplicationController
def index
@books = Book.all.order(:upvotes).reverse.take(10)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a good place to use a model scope.

Example in controller:
Book.best(10)

Example in the Book model:
scope :best, -> (total) { order('upvotes DESC').limit(total)}

@albums = Album.all.order(:upvotes).reverse.take(10)
@movies = Movie.all.order(:upvotes).reverse.take(10)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consider using a constant here to hold the number of media you want to display. That way if it changes later on, you only need to update it in one place instead of three.

end
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice clean controller!

55 changes: 55 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class MoviesController < ApplicationController

def index
@movies = Movie.all.order(:upvotes).reverse
end

def show
@movie = Movie.find(params[:id])
end

def new
@movie = Movie.new
end

def edit
@movie = Movie.find(params[:id])
end

def create
@movie = Movie.new(movie_params)
if @movie.save
redirect_to movie_path(@movie.id)
else
render :new
end
end

def update
@movie = Movie.update(params[:id], movie_params)
if @movie.save
redirect_to movie_path(@movie.id)
else
render :edit
end
end

def destroy
Movie.find(params[:id]).destroy
redirect_to movies_path
end

def upvote
movie = Movie.find(params[:id])
movie.upvotes += 1
movie.save!
redirect_to movie_path(params[:id])
end

private

def movie_params
params.require(:movie).permit(:name, :director, :description)
end

end
2 changes: 2 additions & 0 deletions app/helpers/albums_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AlbumsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/books_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module BooksHelper
end
2 changes: 2 additions & 0 deletions app/helpers/media_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MediaHelper
end
2 changes: 2 additions & 0 deletions app/helpers/movies_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MoviesHelper
end
3 changes: 3 additions & 0 deletions app/models/album.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Album < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be where you could add in those scopes mentioned in earlier comment.

Example:
scope :best, -> (total) { order('upvotes DESC').limit(total)}

3 changes: 3 additions & 0 deletions app/models/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Book < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
end
3 changes: 3 additions & 0 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Movie < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
end
5 changes: 5 additions & 0 deletions app/views/albums/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h2>Edit Album</h2>
<%= render partial: "shared/form", locals: {
media: @album,
creator: :artist
} %>
7 changes: 7 additions & 0 deletions app/views/albums/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= render partial: "shared/index", locals: {
medias: @albums,
media: "album",
upvote: "upvote_album_path",
new_media: "new_album_path",
one_media: "An Album"
} %>
5 changes: 5 additions & 0 deletions app/views/albums/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h2>New Album</h2>
<%= render partial: "shared/form", locals: {
media: @album,
creator: :artist
} %>
10 changes: 10 additions & 0 deletions app/views/albums/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= render partial: "shared/show", locals: {
media: @album,
type: "Albums",
creator: @album.artist,
creator_action: "Recorded",
upvote: "upvote_album_path",
edit_media: "edit_album_path",
media_path: "album_path",
medias_path: "albums_path"
} %>
Loading