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

Audrey's final MediaRanker #28

Open
wants to merge 45 commits into
base: ald/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
821d9b7
Adding controllers complete with crud actions and views for each action.
Dreedle Nov 30, 2015
030cf4f
Adding models for book, movie, album and home
Dreedle Nov 30, 2015
9cd2a63
Adding home#index as the root, and movies, books and albums as resour…
Dreedle Nov 30, 2015
865cc69
Adding prelim html to application layout (header)
Dreedle Nov 30, 2015
6adfe0a
Wrote in seed.rb so can seed the database
Dreedle Nov 30, 2015
5ef28c9
On home index, showing all books, albums, and movies (not limited to …
Dreedle Nov 30, 2015
644245e
On home index, media are limited to top ten ranked
Dreedle Nov 30, 2015
a39ae30
Adding strong params to each of the model's controllers
Dreedle Nov 30, 2015
890c6b0
Upvote button works on movies
Dreedle Nov 30, 2015
481daf3
Adding upvote action to all controllers
Dreedle Nov 30, 2015
1a6d662
Upvote works for show on all three mvcs
Dreedle Nov 30, 2015
b6f6a51
Can now access edit pages and delete objects from show views
Dreedle Nov 30, 2015
9a63984
Crud set up on show page for an album. Buttons have classes in prepar…
Dreedle Dec 1, 2015
a2f1e19
All three models have links with bootstrap classes on their show page…
Dreedle Dec 1, 2015
7044e70
Adding /movies /books/ /albums indices
Dreedle Dec 1, 2015
8510d06
In the midst of working on new form for albums
Dreedle Dec 1, 2015
154f907
Adding rspec and spec files for all models and controllers
Dreedle Dec 1, 2015
326f7ef
Adding validations to each model
Dreedle Dec 1, 2015
f0dfb7e
Adding some spec tests for album models
Dreedle Dec 1, 2015
1d1aacf
Can add a new album an redirect to show
Dreedle Dec 1, 2015
f0f145f
Can make a new object of each of the three models
Dreedle Dec 1, 2015
ba9f55f
Can edit any one of the models
Dreedle Dec 1, 2015
52af368
Only title and ranking are validated in model
Dreedle Dec 1, 2015
674ec6a
Made it so that the value of ranking must be zero on creation, for album
Dreedle Dec 1, 2015
d82dbaa
Adding validations for ranking to book and movie
Dreedle Dec 1, 2015
d9ea6b0
Have rspec tests for getting each of the views for album
Dreedle Dec 1, 2015
a0c2335
JK wave 1 wasn't done. Just made it so that album returns to new form…
Dreedle Dec 2, 2015
5c2a967
Made it so all objects, if not saved from new form, go back to the ne…
Dreedle Dec 2, 2015
b512930
After changing behavior on failed form submissions, I think wave 1 is…
Dreedle Dec 2, 2015
1f0d599
Adding simplecov
Dreedle Dec 2, 2015
665876c
Adding owl
Dreedle Dec 2, 2015
6b92cf5
Putting left margin on h1 header
Dreedle Dec 2, 2015
f5a6099
Wave 3 appears to be finished before wave 2 (since added bootstrap cl…
Dreedle Dec 2, 2015
e3e7c48
finished 'upvote' test for album controller
Dreedle Dec 2, 2015
e0f9603
Have rspec for album#create
Dreedle Dec 2, 2015
c736eb7
Got albums#update tests working
Dreedle Dec 2, 2015
876dbab
Finished rspec for album#delete
Dreedle Dec 2, 2015
729dd69
Added tests to controllers for books and movies
Dreedle Dec 2, 2015
d31d06c
Constructing shared examples. Left off just before 'update'
Dreedle Dec 3, 2015
38ac0ad
Shared examples tests are working for albums controller
Dreedle Dec 3, 2015
ea02238
Using shared examples for all specs now
Dreedle Dec 3, 2015
347dd4e
Adding space after ranked on each medium's index page
Dreedle Dec 4, 2015
9de29be
Making before_action methods in home controller into private methods
Dreedle Dec 4, 2015
6f8221a
Adding shared spec file for models. Tidying up indentations in all files
Dreedle Dec 4, 2015
ccd4f0c
Close call- almost used 'post' for upvote by accident! Changed it to …
Dreedle 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
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
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use SCSS for stylesheets
gem 'bootstrap-sass', '~> 3.3.6'
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
Expand Down Expand Up @@ -36,6 +37,9 @@ group :development, :test do
gem 'sqlite3'
gem 'better_errors'
gem 'binding_of_caller'
gem 'rspec-rails'
gem 'simplecov'
gem 'pry'
end

group :development do
Expand Down
40 changes: 40 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 All @@ -73,12 +81,17 @@ GEM
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.99)
mini_portile2 (2.0.0)
minitest (5.8.3)
multi_json (1.11.2)
nokogiri (1.6.7)
mini_portile2 (~> 2.0.0.rc2)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -113,6 +126,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 @@ -124,6 +154,12 @@ 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)
rack (> 1, < 3)
Expand Down Expand Up @@ -154,15 +190,19 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
hirb
jbuilder (~> 2.0)
jquery-rails
pry
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/bookowl.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/home.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/
15 changes: 0 additions & 15 deletions app/assets/stylesheets/application.css

This file was deleted.

16 changes: 16 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap-sprockets";
@import "bootstrap";

form .btn-primary {
margin-bottom: 10px;
}

.page-header {
background: url("bookowl.jpg");
background-repeat: no-repeat;
}

.page-header h1 {
margin-left: 150px;
}
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/home.scss
Original file line number Diff line number Diff line change
@@ -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/
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/
59 changes: 59 additions & 0 deletions app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class AlbumsController < ApplicationController

def index
@albums = Album.all
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.

Because we're setting the @album variable in the same with in multiple controller actions (upvote, show, edit, etc.) we should make this a before_action which happens on those specific actions.

@album.update_attribute(:ranking, @album.ranking + 1)
redirect_to action: :show
Copy link

Choose a reason for hiding this comment

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

We should use a route helper method for this, redirect_to album_path(@album.id), as we do in other places.

end

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

def new
@album = Album.new
end

def create
@album = Album.create(title: album_params[:album][:title],
Copy link

Choose a reason for hiding this comment

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

Because we're using the special "strong params" syntax to implement album_params we can actually pass its return value directly to create:

@album = Album.create(album_params[:album]) do |album|
  album.ranking = 0
end

That way, if we want to add more parameters to Album (and Movie or Book) we just need to add them into album_params and everything else will work itself out.

description: album_params[:album][:description],
artist: album_params[:album][:artist],
ranking: 0)
if @album.save
redirect_to album_path(@album.id)
else
render "new"
end
end

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

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

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

private

def album_params
params.permit(album:[:title, :description, :ranking, :artist])
Copy link

Choose a reason for hiding this comment

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

If we change this line to:

params.require(:album).permit(:title, :description, :ranking, :artist)

... we get slightly more security (params must have a sub-hash called :album to be valid), and on lines 22 and 41 we can just say Album.create(album_params) or @album.update(album_params) and not need to specify the :album sub-hash (because Rails knows it's required).

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

Choose a reason for hiding this comment

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

Basically the same comments from albums_controller.rb apply here.

def index
@books = Book.all
end

def upvote
@book = Book.find(params[:id])
@book.update_attribute(:ranking, @book.ranking + 1)
redirect_to action: :show
end

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

def new
@book = Book.new
end

def create
@book = Book.create(title: book_params[:book][:title],
description: book_params[:book][:description],
author: book_params[:book][:author],
ranking: 0)
if @book.save
redirect_to book_path(@book.id)
else
render "new"
end
end

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

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

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

private

def book_params
params.permit(book:[:title, :description, :ranking, :author])
end
end
22 changes: 22 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class HomeController < ApplicationController
before_action :get_movies
Copy link

Choose a reason for hiding this comment

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

Generally I like the use of before_action (as evidenced by my suggestion for albums_controller.rb), but here I'm not sure that we need it.
We've only got one action in HomeController, so the use of before_action is mostly just spreading out the lines that happen in the index method, without reducing code duplication.

before_action :get_books
before_action :get_albums

def index
end

private

def get_movies
@movies = Movie.all
end

def get_books
@books = Book.all
end

def get_albums
@albums = Album.all
end
end
58 changes: 58 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class MoviesController < ApplicationController
Copy link

Choose a reason for hiding this comment

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

Basically the same comments from albums_controller.rb apply here.

def index
@movies = Movie.all
end

def upvote
@movie = Movie.find(params[:id])
@movie.update_attribute(:ranking, @movie.ranking + 1)
redirect_to action: :show
end

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

def new
@movie = Movie.new
end

def create
@movie = Movie.create(title: movie_params[:movie][:title],
description: movie_params[:movie][:description],
director: movie_params[:movie][:director],
ranking: 0)
if @movie.save
redirect_to movie_path(@movie.id)
else
render "new"
end
end

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

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

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

private

def movie_params
params.permit(movie:[:title, :description, :ranking, :director])
end
end
Loading