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

Completed Media Ranker #29

Open
wants to merge 64 commits into
base: KED/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
cda108c
create models
kedevlin Nov 30, 2015
4792c90
Create controllers
kedevlin Nov 30, 2015
c3d93d2
Add routes
kedevlin Nov 30, 2015
7febcc9
Create CRUD controller methods
kedevlin Nov 30, 2015
de26c24
Add movie index view and update controller method
kedevlin Nov 30, 2015
994b7cb
Fix movie index view, add book index view, update book index controller
kedevlin Nov 30, 2015
d4b318c
Add album index view and update index method in controller
kedevlin Nov 30, 2015
ecb205a
Create show views and update show method for all three controllers
kedevlin Nov 30, 2015
a790342
Create form and edit view files for all controllers, create form for …
kedevlin Nov 30, 2015
d5c74fd
Create form for movie and album
kedevlin Nov 30, 2015
3c9847e
Add redirect to update method of all 3 controllers
kedevlin Nov 30, 2015
a3aecd6
Create new views, add new button to index views
kedevlin Nov 30, 2015
14c38f3
Complete new and create methods for all three controllers
kedevlin Nov 30, 2015
1f3a49c
Complete destroy methods for all 3 controllers
kedevlin Nov 30, 2015
c94ac27
Create upvote method for movies
kedevlin Nov 30, 2015
6930d6b
Add upvote methods to books and albums
kedevlin Nov 30, 2015
01450e5
Create root route with list of 10 from each table
kedevlin Nov 30, 2015
02822b6
Order by rank on root page
kedevlin Nov 30, 2015
e360b69
order by ranked on show pages
kedevlin Nov 30, 2015
8fb8a13
Add links to index views on root view
kedevlin Dec 1, 2015
c89bcee
Add View All Media button to index pages
kedevlin Dec 1, 2015
b6d2764
Add Upvote button to index pages
kedevlin Dec 1, 2015
bc49cc2
Add links to index pages from show pages
kedevlin Dec 1, 2015
ad730c9
Add header, add validation to all 3 models
kedevlin Dec 1, 2015
80ac720
Add name validation for 3 models
kedevlin Dec 1, 2015
3cda762
Added before_action to all 3 controllers
kedevlin Dec 1, 2015
836d0af
Setup rspec and manually create files
kedevlin Dec 1, 2015
2a1b470
Add test to album spec
kedevlin Dec 1, 2015
78245b3
Add tests to movie and book specs
kedevlin Dec 1, 2015
a753812
Add GET index tests to controller specs
kedevlin Dec 1, 2015
f79af1e
Added album controller tests for GET new, POST create, and GET show
kedevlin Dec 1, 2015
77f0c52
add test for post create with bad params (album controller)
kedevlin Dec 1, 2015
cab896f
Add album controller tests for edit with good params
kedevlin Dec 1, 2015
1c0060f
complete album PATCH update tes
kedevlin Dec 1, 2015
392006d
Add album destroy test
kedevlin Dec 2, 2015
cfdf599
in albums test, defined album object via let before any of the class'…
kedevlin Dec 2, 2015
d23dd2b
Add book controller tests
kedevlin Dec 2, 2015
c46ed1a
Added controller tests for movie
kedevlin Dec 2, 2015
4ea084b
Add SimpleCov gem
kedevlin Dec 2, 2015
e79c849
Add bootstrap gem
kedevlin Dec 2, 2015
131373e
Style header
kedevlin Dec 2, 2015
c8c91a4
Add bootstrap styling to home page
kedevlin Dec 2, 2015
fcad9cb
Add bootstrap styling to movie index page
kedevlin Dec 2, 2015
464b1d4
Added some boostrap styling to movie show page
kedevlin Dec 3, 2015
ab3ec47
Style edit and new movie views with bootsrap
kedevlin Dec 3, 2015
e1c51e8
Finish styling movie show page with bootstrap
kedevlin Dec 3, 2015
6dee57c
Add bootstrap styling to all views of albums and books
kedevlin Dec 3, 2015
e833054
Add shared example for model specs
kedevlin Dec 3, 2015
0b63f4f
Add shared example test for 3 controllers for GET index
kedevlin Dec 3, 2015
79af199
Add shared examples for show and new tests
kedevlin Dec 3, 2015
25743dd
Add shared example test for POST create
kedevlin Dec 3, 2015
145af64
Add shared example GET edit
kedevlin Dec 3, 2015
8a0ba69
Add shared examples for PATCH update
kedevlin Dec 3, 2015
d102896
Add DELETE destroy shared example
kedevlin Dec 3, 2015
fac53c8
Add PATCH upvote shared tests
kedevlin Dec 3, 2015
eacd01e
Add partial for movie index view
kedevlin Dec 4, 2015
7c69b5b
Add reference to index partial in albums and movies index
kedevlin Dec 4, 2015
ae16f87
Added show partial and reference to it in movies show view
kedevlin Dec 4, 2015
fec3d5a
Add partials to books and albums show
kedevlin Dec 4, 2015
b88cc42
add partial for forms, reference in edit and new views and delete con…
kedevlin Dec 4, 2015
c7cf364
Add top list partial and reference it for each controller in welcome#…
kedevlin Dec 4, 2015
781903a
Add space in <title>
kedevlin Dec 4, 2015
85340db
setup factory girl
kedevlin Jan 13, 2016
54cb442
update rspec to include factories
kedevlin Jan 13, 2016
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
/log/*
!/log/.keep
/tmp
coverage
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
Copy link

Choose a reason for hiding this comment

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

It's not much of an issue to have this included in the project repo, although you could have put this .rspec file in your home directory and it would work for your local machine (across all projects).

--require spec_helper
5 changes: 5 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'
# 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 @@ -34,9 +36,12 @@ gem 'sdoc', '~> 0.4.0', group: :doc

gem 'rails-erd'

gem 'simplecov', :require => false, :group => :test

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'rspec-rails'
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 @@ -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)
Expand All @@ -131,6 +156,11 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
simplecov (0.11.1)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
spring (1.5.0)
sprockets (3.4.1)
Expand Down Expand Up @@ -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)
Expand All @@ -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
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 @@ -11,6 +11,7 @@
// about supported directives.
//
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require_tree .
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/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/javascripts/welcome.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,27 @@
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap-sprockets";
@import "bootstrap";

.page-header {
background: url(/assets/owl.jpg);
background-repeat: no-repeat;
padding-bottom: 9px;
margin: 40px 0 20px;
border-bottom: 1px solid #eee;
}

.page-header h1 {
margin-left: 150px;
}

a {
color: #428bca;
}

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/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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/welcome.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the welcome controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
56 changes: 56 additions & 0 deletions app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class AlbumsController < ApplicationController
before_action :get_album, only: [:show, :edit, :destroy, :upvote, :update]
Copy link

Choose a reason for hiding this comment

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

Excellent time to use a before_action!


def get_album
Copy link

Choose a reason for hiding this comment

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

Traditionally all methods used as before_actions are defined as private, along with the strong params methods.

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

def index
@albums = Album.order(ranked: :desc)
end

def show
end

def new
@album = Album.new
end

def create
@album = Album.create(album_params)
if @album.save
Copy link

Choose a reason for hiding this comment

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

Because Album.create already calls save as part of doing its thing, we don't need to call it again here. To check whether or not @album as saved to the database we can use if @album.persisted? instead.

redirect_to album_path(@album)
else
render "new"
end
end

def edit
end

def update
@album.update(album_params)
if @album.save
redirect_to album_path(@album)
else
render "edit"
end
end

def destroy
@album.destroy
redirect_to albums_path
end

def upvote
@album.ranked += 1
@album.save
redirect_to album_path(@album)
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.

I like that you did not include :ranked here -- this is the exact purpose of the strong params idea.

Because none of our routes intend for the user to directly modify the ranked attribute (even in upvote we just modify it ourselves), we should not permit that attribute to exist in our params. If we had allowed it, a malicious user could add that into the params hash directly and then Rails would be happy to let them set whatever value they wanted.

end
end
56 changes: 56 additions & 0 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class BooksController < ApplicationController
before_action :get_book, only: [:show, :edit, :destroy, :upvote, :update]

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

def index
@books = Book.order(ranked: :desc)
end

def show
end

def new
@book = Book.new
end

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

def edit
end

def update
@book.update(book_params)
if @book.save
redirect_to book_path(@book)
else
render "edit"
end
end

def destroy
@book.destroy
redirect_to books_path
end

def upvote
@book.ranked += 1
@book.save
redirect_to book_path(@book)
end

private

def book_params
params.require(:book).permit([:name, :author, :description])
end
end
56 changes: 56 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class MoviesController < ApplicationController
before_action :get_movie, only: [:show, :edit, :destroy, :upvote, :update]

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

def index
@movies = Movie.order(ranked: :desc)
end

def show
end

def new
@movie = Movie.new
end

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

def edit
end

def update
@movie.update(movie_params)
if @movie.save
redirect_to movie_path(@movie)
else
render "edit"
end
end

def destroy
@movie.destroy
redirect_to movies_path
end

def upvote
@movie.ranked += 1
@movie.save
redirect_to movie_path(@movie)
end

private

def movie_params
params.require(:movie).permit([:name, :director, :description])
end
end
7 changes: 7 additions & 0 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class WelcomeController < ApplicationController
def index
@movies = Movie.order(ranked: :desc).limit(10)
Copy link

Choose a reason for hiding this comment

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

Because we use order(ranked: :desc) here three times, and in each of the model-specific controllers, it might be a good idea to refactor these into class methods (or even better, scopes) on the associated model classes:

def Movie < ActiveRecord::Base
  # ...
  def self.by_rank
    return self.order(ranked: :desc)
  end
  # OR...
  scope :by_rank, -> { order(ranked: :desc) }
end

And then you can use it as: @movies = Movie.by_rank.limit(10).

@books = Book.order(ranked: :desc).limit(10)
@albums = Album.order(ranked: :desc).limit(10)
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/movies_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MoviesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/welcome_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module WelcomeHelper
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
end
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
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
end
2 changes: 2 additions & 0 deletions app/views/albums/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h2>Edit Album</h2>
<%= render partial: 'shared/form', locals: { medium: @album, creator_field: :artist } %>
1 change: 1 addition & 0 deletions app/views/albums/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: 'shared/index', locals: { media: @albums, name: "album" } %>
2 changes: 2 additions & 0 deletions app/views/albums/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h2>New Album</h2>
<%= render partial: 'shared/form', locals: { medium: @album, creator_field: :artist } %>
1 change: 1 addition & 0 deletions app/views/albums/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: 'shared/show', locals: { medium: @album, name: "album", creator: @album.artist, create_type: "Recorded" } %>
Copy link

Choose a reason for hiding this comment

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

So very, very DRY... like a strong Chardonnay, or this joke.

Also, I don't think the name variable is necessary for this partial. Everywhere that we're using name in there we could say medium.class instead, I believe. This would also avoid the need to use name.pluralize in certain cases.

2 changes: 2 additions & 0 deletions app/views/books/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h2>Edit Book</h2>
<%= render partial: 'shared/form', locals: { medium: @book, creator_field: :author } %>
Loading