Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ce25711
Created movies model and controller with restful routes
CShekta Nov 30, 2015
5810d30
Added index and show pages and logic for movie EXCEPT for upvote
CShekta Nov 30, 2015
467f9b2
Added new and edit functionality plus some more links
CShekta Nov 30, 2015
f200a8e
Added delete functionality and link
CShekta Nov 30, 2015
b09f693
Added upvote method
CShekta Nov 30, 2015
e33df21
Added some more seed data and links
CShekta Dec 1, 2015
6f369e8
added album and book model and controllers
CShekta Dec 1, 2015
6318ea6
Updated routes and added application index
CShekta Dec 1, 2015
90e1347
Added some form partials
CShekta Dec 1, 2015
91c6f4d
added spec folder and files stub
CShekta Dec 1, 2015
da67f94
Fixing rspec gem install
CShekta Dec 1, 2015
db8415b
Added initial movie specs
CShekta Dec 1, 2015
e98a8e6
Added specs for get and show for movies
CShekta Dec 1, 2015
e58a5fa
Added _index partial and welcome controller
CShekta Dec 1, 2015
f936a2e
Added index partial and controller methods for books
CShekta Dec 1, 2015
e7d8bdf
Added how partials for all controllers and started edit
CShekta Dec 2, 2015
ebcdcfa
Added new and some show partials for all controllers
CShekta Dec 2, 2015
c6f643a
Added edit forms for controllers
CShekta Dec 2, 2015
ac06ce4
Refactored partials for movies to actually work correctly
CShekta Dec 2, 2015
6d5d18a
Partials to books
CShekta Dec 2, 2015
89f67a6
refactored albums as well
CShekta Dec 2, 2015
ce8bc89
Created correct home page and heading
CShekta Dec 2, 2015
859d7ce
refactored some controller methods
CShekta Dec 2, 2015
4e0073f
Installed bootstrap gem and corresponding scss file
CShekta Dec 2, 2015
346dd21
Added bootstrap stylings
CShekta Dec 2, 2015
c047b37
Added simplecov
CShekta Dec 2, 2015
a48c402
Finished specs for controllers, path and upvote need work
CShekta Dec 3, 2015
ce653e1
DRYed out model specs with medium partial
CShekta Dec 3, 2015
58db5fd
Tried to refactor rspec methods in books, post, update, and upvote ar…
CShekta Dec 3, 2015
798f340
DRYed out books controller spec
CShekta Dec 3, 2015
05d1ecf
fixed albums spec
CShekta Dec 3, 2015
afb713c
finished movies medium_controller_spec
CShekta Dec 3, 2015
cf6c1a8
dryed out books controller spec
CShekta Dec 3, 2015
c055237
Finished rspec
CShekta Dec 3, 2015
30640c8
last minute css fixes
CShekta Dec 3, 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
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ gem 'rails', '4.2.5'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'bootstrap-sass', '~> 3.3.6'

gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
Expand All @@ -31,9 +33,12 @@ gem 'sdoc', '~> 0.4.0', group: :doc
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

gem 'simplecov'

Choose a reason for hiding this comment

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

Recommend you add coverage to your .gitignore if you're going to use 'simplecov'


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)
coderay (1.1.0)
Expand All @@ -54,6 +60,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 @@ -107,6 +115,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)
sass (3.4.19)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
Expand All @@ -117,6 +142,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)
spring (1.5.0)
sprockets (3.4.1)
rack (> 1, < 3)
Expand Down Expand Up @@ -147,14 +177,17 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
jquery-rails
pg
rails (= 4.2.5)
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,30 @@
* 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;

Choose a reason for hiding this comment

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

Try to keep indentation consistent

border-bottom: 1px solid #eee;
}

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

a {
color: #428bca;
}

.btn-primary {
margin-top: 10px;
margin-right: 10px;
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/
52 changes: 52 additions & 0 deletions app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class AlbumsController < ApplicationController
before_action only: [:show, :edit, :update, :upvote] { @album = Album.find(params[:id]) }

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

def show
end

Choose a reason for hiding this comment

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

This is just a style guide (have you covered this?) thing: def show; end looks cleaner.


def new
@album = Album.new
end

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

def edit
end

def update
@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

def upvote
@album.rank += 1
@album.save
redirect_to album_path(@album.id)
end

private

def album_params

Choose a reason for hiding this comment

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

I really like that you made this method private

params.permit(album: [:name, :artist, :description, :rank])
end
end
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ 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

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

Choose a reason for hiding this comment

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

I like that your controllers are really clean and easy to read

before_action only: [:show, :edit, :update, :upvote] { @book = Book.find(params[:id])}

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

def show
end

def new
@book = Book.new
end

def create
@book = Book.create(book_params[:book])

if @book.save
redirect_to book_path(@book)
else
render "new"
end
end

def edit
end

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

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

def upvote
@book = Book.find(params[:id])
@book.rank += 1
@book.save
redirect_to book_path(@book)
end

private

def book_params
params.permit(book: [:name, :author, :description, :rank])
end
end
51 changes: 51 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class MoviesController < ApplicationController
before_action only: [:show, :edit, :update, :upvote] { @movie = Movie.find(params[:id]) }
def index
@movies = Movie.order(rank: :desc)
end

def show
end

def new
@movie = Movie.new
end

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

def edit
end

def update
@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.rank += 1
@movie.save
redirect_to movie_path(@movie)
end

private

def movie_params
params.permit(movie: [:name, :director, :description, :rank])
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(rank: :desc).limit(10)
@books = Book.order(rank: :desc).limit(10)
@albums = Album.order(rank: :desc).limit(10)

Choose a reason for hiding this comment

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

Have you discovered/learned about scopes yet? This would be good opportunity to check them out. Also recommend using a constant for the 10 here.

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
10 changes: 10 additions & 0 deletions app/views/albums/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= render partial: "application/edit",
locals: {
media: @album,
title: "Album",
singular_name: "album",
plur_name: "albums",
maker: "artist",
created_by: "Recorded by:",
}
%>
9 changes: 9 additions & 0 deletions app/views/albums/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= render partial: "application/index",
locals: {
media: @albums,
title: "Album",
singular_name: "album",
plur_name: "albums",
created_by: "Recorded by:",
}
%>
Loading