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

Ricky final media ranker #27

Open
wants to merge 45 commits into
base: ricky/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0ad887e
generate movies, albums, books controllers
hougland Nov 30, 2015
f04d922
generate album, book, movie models
hougland Nov 30, 2015
fb74d4b
create seed data
hougland Nov 30, 2015
17ac202
add contents to root view
hougland Nov 30, 2015
0922379
add index for movies with table showing all movies
hougland Nov 30, 2015
e6f10ce
working on layout for movies, now starting on books
hougland Nov 30, 2015
cd61aa7
add destroy function
hougland Nov 30, 2015
348c2c5
add upvote function for movies
hougland Nov 30, 2015
ef951c5
copy and pasting controller methods from movies to books and albums
hougland Nov 30, 2015
038ee47
add partial for index pages for all resources
hougland Nov 30, 2015
1b2d1b9
add views for other controllers
hougland Nov 30, 2015
e633fc5
copy and paste from movie show view to books and albums
hougland Dec 1, 2015
2bc22e3
shortened how I was ordering media by ranking
hougland Dec 1, 2015
45eefa1
create partial for show views
hougland Dec 1, 2015
0370957
create partial form for new and edit for all controllers
hougland Dec 1, 2015
4833112
add spec folder and blank necessary files
hougland Dec 1, 2015
901ea3c
add default info to rails_helper and spec_helper, plus tests for mode…
hougland Dec 1, 2015
40eb52f
add first tests for each controller, ensuring get index is successful
hougland Dec 1, 2015
d9d5862
add tests for get new form for all 3 controllers
hougland Dec 1, 2015
3caf884
add get show tests and error keys for modles to include name
hougland Dec 1, 2015
da3d4f6
improve show test and add post create test for albums controller
hougland Dec 1, 2015
c20958d
add test for delete
hougland Dec 1, 2015
92f012e
add test for upvote and update for album controller
hougland Dec 1, 2015
1402b96
add test for unsuccessful create attempt wihtout name
hougland Dec 1, 2015
dfeac1b
add test for unsucessful update of albums
hougland Dec 1, 2015
d825093
tweaking tests
hougland Dec 1, 2015
7045e6a
copy and paste tests for movie and book controllers, and run simplecov
hougland Dec 2, 2015
2db2508
switch upvote from post to patch
hougland Dec 2, 2015
2164ee8
switch buttons to links
hougland Dec 2, 2015
b5a556d
add one small test to upvote
hougland Dec 2, 2015
38f0509
add bootstrap gem
hougland Dec 2, 2015
34f454f
bootstrap format _index
hougland Dec 2, 2015
e9b58c5
bootstrap
hougland Dec 2, 2015
cddfea7
bootstrap
hougland Dec 2, 2015
1895ed7
bootstrap
hougland Dec 2, 2015
dacc948
add http status tests
hougland Dec 2, 2015
c8be616
shared examples for models
hougland Dec 3, 2015
d9b7f3f
DRY up tests for for create and edit
hougland Dec 3, 2015
d1f61a7
DRY patch update tests
hougland Dec 3, 2015
65a9d98
DRY upvote tests
hougland Dec 3, 2015
56b2e4d
DRY up code
hougland Dec 12, 2015
5f4e277
make header display correct text when editing or creating new media
hougland Dec 12, 2015
ee0b124
revise upvote paths
hougland Dec 13, 2015
ca2fa70
add to gitignore file
hougland Dec 13, 2015
f594ef8
add rspec tests
hougland Dec 13, 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
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source 'https://rubygems.org'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
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 +36,10 @@ 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 'binding_of_caller'
gem 'pry'
gem 'simplecov'
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 @@ -72,12 +80,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 @@ -112,6 +125,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 +153,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 @@ -153,14 +189,18 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
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/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/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,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
*/
// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap-sprockets";
@import "bootstrap";

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

.page-header {
background-image: url(/assets/owl.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/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/
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
def index
@media = Album.order(ranking: :desc)
end

def show
@media = 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.

We can DRY this out a bit by making this line into a before_action, because it is used to setup the @media variable the same way in multiple controller actions.

end

def new
@media = Album.new
end

def create
@media = Album.new(strong_params)
Copy link

Choose a reason for hiding this comment

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

We could also do:

@media = Album.create(strong_params) do |album|
  album.ranking = 0
end
if @media.persisted?
  # ...
end

@media.ranking = 0
if @media.save
redirect_to album_path(@media.id)
else
render "new"
end
end

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

def update
@media = Album.find(params[:id])
@media.attributes = strong_params
if @media.save
render "show"
Copy link

Choose a reason for hiding this comment

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

What are the trade-offs between using render "show" here to directly display the show template, versus redirecting to albumPath(@media.id) (as we did in the create action)?

else
render "edit"
end
end

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

def upvote
@media = Album.find(params[:id])
@media.ranking += 1
@media.save
render "show"
end

private

def strong_params
params.require(:album).permit(:name, :artist, :description, :ranking)
end
end
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

def index
@movies = Movie.order(ranking: :desc).limit(2)
@books = Book.order(ranking: :desc).limit(2)
@albums = Album.order(ranking: :desc).limit(2)
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
def index
@media = Book.order(ranking: :desc)
end

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

def new
@media = Book.new
end

def create
@media = Book.new(strong_params)
@media.ranking = 0
if @media.save
redirect_to book_path(@media.id)
else
render "new"
end
end

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

def update
@media = Book.find(params[:id])
@media.attributes = strong_params
if @media.save
render "show"
else
render "edit"
end
end

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

def upvote
@media = Book.find(params[:id])
@media.ranking += 1
@media.save
render "show"
end

private

def strong_params
params.require(:book).permit(:name, :author, :description, :ranking)
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
def index
@media = Movie.order(ranking: :desc)
end

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

def new
@media = Movie.new
end

def create
@media = Movie.new(strong_params)
@media.ranking = 0
if @media.save
redirect_to movie_path(@media.id)
else
render "new"
end
end

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

def update
@media = Movie.find(params[:id])
@media.attributes = strong_params
if @media.save
render "show"
else
render "edit"
end
end

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

def upvote
@media = Movie.find(params[:id])
@media.ranking += 1
@media.save
render "show"
end

private

def strong_params
params.require(:movie).permit(:name, :director, :description, :ranking)
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
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
1 change: 1 addition & 0 deletions app/views/albums/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'form' %>
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: "index", locals: { class_type: Album } %>
1 change: 1 addition & 0 deletions app/views/albums/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'form' %>
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: "show", locals: { header: "Recorded by", name: @media.artist } %>
Loading