Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ab0206a
Seeds Database with Videos
Feb 20, 2014
6ce4d36
Building Home Page
Feb 20, 2014
dc4d06d
Creates Home View
Feb 20, 2014
83787e6
Builds Homepage
Feb 20, 2014
938f182
Building Video Show
Feb 20, 2014
9826c9c
Building Video View
Feb 20, 2014
6bc0883
Fixing Bug in Video Show
Feb 20, 2014
4b230a7
Fixes Bug
Feb 20, 2014
920125e
Fixing Image to Match its Object
Feb 20, 2014
3ee7e5d
builds home page
Feb 21, 2014
0293c4b
Creating Category and Seeding Database
Feb 21, 2014
fbd364c
Creates Category Functionality and Improves Image to Object Programming
Feb 21, 2014
7dc0dc4
Works on Category Show view
Feb 21, 2014
decd5cd
Works on Category Show
Feb 21, 2014
100400d
Creates Videos Per Category Pages
Feb 22, 2014
89a0d05
Creates Category View For Each Category
Feb 22, 2014
f437d7a
Successfully Shows All Movies Per Category In a DRY Way
Feb 22, 2014
ce22440
DRYs up my code
Feb 22, 2014
b57bab8
tests video model's ability to save
Feb 23, 2014
52f646f
tests model associations for video and category
Feb 23, 2014
fec30df
tests for models
Feb 23, 2014
4079674
Debugs Tests in category_spec
Feb 23, 2014
019e44c
Cleans up code after kevin's code review
Feb 24, 2014
9c5436a
Uses Shoulda Matchers in Specs
Feb 25, 2014
4826a39
Refactors Preassignment Code According to TA Comments
Feb 25, 2014
92eca76
Trying to create 4 tests cases for video search method
Feb 26, 2014
75647c8
Tests Pass for Search by video's title function
Feb 26, 2014
668172f
improves tests for search by title functionality
Feb 27, 2014
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 .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ group :production do
gem 'rails_12factor'
end

group :development, :test do
gem 'rspec-rails', '~> 3.0.0.beta'
end

group :test do
gem 'shoulda-matchers'
end

25 changes: 25 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ GEM
coffee-script-source (1.6.3)
daemons (1.1.9)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
erubis (2.7.0)
eventmachine (1.0.0)
execjs (2.0.2)
Expand Down Expand Up @@ -98,11 +99,33 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.0)
rspec-collection_matchers (0.0.3)
rspec-expectations (>= 2.99.0.beta1)
rspec-core (3.0.0.beta2)
rspec-support (= 3.0.0.beta2)
rspec-expectations (3.0.0.beta2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (= 3.0.0.beta2)
rspec-mocks (3.0.0.beta2)
rspec-support (= 3.0.0.beta2)
rspec-rails (3.0.0.beta2)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-collection_matchers
rspec-core (= 3.0.0.beta2)
rspec-expectations (= 3.0.0.beta2)
rspec-mocks (= 3.0.0.beta2)
rspec-support (= 3.0.0.beta2)
rspec-support (3.0.0.beta2)
sass (3.2.12)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10)
sprockets-rails (~> 2.0.0)
shoulda-matchers (2.5.0)
activesupport (>= 3.0.0)
slop (3.4.7)
sprockets (2.10.0)
hike (~> 1.2)
Expand Down Expand Up @@ -145,7 +168,9 @@ DEPENDENCIES
pry-nav
rails
rails_12factor
rspec-rails (~> 3.0.0.beta)
sass-rails
shoulda-matchers
sqlite3
thin
uglifier
5 changes: 5 additions & 0 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class CategoriesController < ApplicationController
def show
@category = Category.find(params[:id])
end
end
11 changes: 11 additions & 0 deletions app/controllers/videos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class VideosController < ApplicationController

def index
@categories = Category.all
end

def show
@video = Video.find(params[:id])
end

end
3 changes: 3 additions & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Category < ActiveRecord::Base
has_many :videos, -> { order('title') }
end
10 changes: 10 additions & 0 deletions app/models/video.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Video < ActiveRecord::Base
belongs_to :category

validates_presence_of :title, :description

def self.search_by_title(search_term)
return [] if search_term.blank?
where("title LIKE ?", "%#{search_term}%")
end
end
6 changes: 6 additions & 0 deletions app/views/categories/_section.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%article.video_category
%header
%h3= "#{video.title}"
.videos.row
.video.col-sm-2
= link_to image_tag("#{video.small_cover}"), video_path(video)
3 changes: 3 additions & 0 deletions app/views/categories/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- @category.videos.each do |video|
= render 'categories/section', video: video

9 changes: 9 additions & 0 deletions app/views/videos/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- @categories.each do |category|
%article.video_category
%header
%h3
= link_to "#{category.name}", category_path(category)
.videos.row
- category.videos.first(6).each do |a|
.video.col-sm-2
= link_to image_tag("#{a.small_cover}"), video_path(a)
50 changes: 50 additions & 0 deletions app/views/videos/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
%article.video
.container
.row
.video_large_cover.col-sm-7.col-sm-offset-1
= image_tag("#{@video.large_cover}")
.video_info.col-sm-3
%header
%h3
= @video.title
%span Rating: 4.5/5.0
%p
= @video.description
.actions
%a.btn.btn-primary(href="") Watch Now
%a.btn.btn-default(href="") + My Queue

%section.reviews.container
.row
.col-sm-10.col-sm-offset-1
%form
%fieldset
.form-group
%label Rate this video
.row
.col-sm-3
%select.form-control(name="")
%option(value="5") 5 Stars
%option(value="4") 4 Stars
%option(value="3") 3 Stars
%option(value="2") 2 Stars
%option(value="1") 1 Star
.form-group
%label Write Review
.row
.col-sm-8
%textarea.form-control(name="" rows="6")
%fieldset.form-group.actions.clearfix
%input(type="submit" value="Submit" class="btn")
%a(href="") Cancel
%header
%h3 User Reviews (253)
%ul
- 8.times do
%article.review
%li.row
.col-sm-2
%span Rating: 5 / 5
%p by <a href="">John A. Zoidberg</a>
.col-sm-8
%p In my opinion, this is one of the best shows ever made. It's not only funny, but despite being so frequently silly, it's very smart as well. Math, science, history, all get referenced. The best parts of the show are the subtle things, those little things in the background or just on screen for a couple of seconds that just make you laugh out loud if you were paying attention. The writers even appear to have been thinking ahead, because if you play close attention to the first episode, you can see a literal shadow of an event revealed seasons later.
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Myflix::Application.routes.draw do
resources :videos
resources :categories
get 'ui(/:action)', controller: 'ui'
end
11 changes: 11 additions & 0 deletions db/migrate/20140220001555_create_videos_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateVideosTable < ActiveRecord::Migration
def change
create_table :videos do |t|
t.string :title
t.string :description
t.binary :small_cover
t.binary :large_cover
t.timestamps
end
end
end
8 changes: 8 additions & 0 deletions db/migrate/20140221174123_create_categories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateCategories < ActiveRecord::Migration
def change
create_table :categories do |t|
t.string :name
t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140221174726_add_column_category_to_videos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddColumnCategoryToVideos < ActiveRecord::Migration
def change
add_column :videos, :category, :integer
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameColumnVideosCategoryCategoryId < ActiveRecord::Migration
def change
rename_column :videos, :category, :category_id
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ChangeColumnVideosLargeSmallCoverString < ActiveRecord::Migration
def change
change_column :videos, :large_cover, :string
change_column :videos, :small_cover, :string
end
end
32 changes: 32 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140221184632) do

create_table "categories", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "videos", force: true do |t|
t.string "title"
t.string "description"
t.string "small_cover"
t.string "large_cover"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "category_id"
end

end
16 changes: 16 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,19 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)

Video.destroy_all

10.times do
Video.create!(title: "Futurama", description: "An awesome, nerdy spin off of the Simpsons ...", category_id: 1, small_cover: "/tmp/futurama.jpg", large_cover: "/tmp/monk_large.jpg")
#Video.create!(title: "South Park", description: "A show with crude language and dark surreal humor...", category_id: 1, small_cover: "/tmp/south_park.jpg", large_cover: "/tmp/monk_large.jpg")
#Video.create!(title: "Family Guy", description: "A cartoon that exhibits much of its humor in the form of cutaway gags...", category_id: 1, small_cover: "/tmp/family_guy.jpg", large_cover: "/tmp/monk_large.jpg")

#Video.create!(title: "Futurama", description: "An awesome, nerdy spin off of the Simpsons ...", category_id: 2, small_cover: "/tmp/futurama.jpg", large_cover: "/tmp/monk_large.jpg")
Video.create!(title: "South Park", description: "A show with crude language and dark surreal humor...", category_id: 2, small_cover: "/tmp/south_park.jpg", large_cover: "/tmp/monk_large.jpg")
#Video.create!(title: "Family Guy", description: "A cartoon that exhibits much of its humor in the form of cutaway gags...", category_id: 2, category_id: 1, small_cover: "/tmp/family_guy.jpg", large_cover: "/tmp/monk_large.jpg")

#Video.create!(title: "Futurama", description: "An awesome, nerdy spin off of the Simpsons ...", category_id: 3, small_cover: "/tmp/futurama.jpg", large_cover: "/tmp/monk_large.jpg")
#Video.create!(title: "South Park", description: "A show with crude language and dark surreal humor...", category_id: 3, small_cover: "/tmp/south_park.jpg", large_cover: "/tmp/monk_large.jpg")
Video.create!(title: "Family Guy", description: "A cartoon that exhibits much of its humor in the form of cutaway gags...", category_id: 3, small_cover: "/tmp/family_guy.jpg", large_cover: "/tmp/monk_large.jpg")
end
6 changes: 6 additions & 0 deletions spec/models/category_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

describe Category do

it { should have_many(:videos) }
end
45 changes: 45 additions & 0 deletions spec/models/video_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'spec_helper'

describe Video do

it { should belong_to(:category) }
it { should validate_presence_of(:title) }
it { should validate_presence_of(:description) }

describe ".search_by_title(search_term)" do

it "should return an empty array if the user submits no parameters" do
family_guy = Video.create(title: "Family Guy", description: "A really twisted versino of the Simpsons")
south_park = Video.create(title: "South Park", description: "A funny video")
expect(Video.search_by_title("")).to eq([])
end

it "should return an empty array if it finds no videos" do
family_guy = Video.create(title: "Family Guy", description: "A really twisted versino of the Simpsons")
south_park = Video.create(title: "South Park", description: "A funny video")
expect(Video.search_by_title("test")).to eq([])
end

it "should return an array of one video if it is an exact match" do
family_guy = Video.create(title: "Family Guy", description: "A really twisted versino of the Simpsons")
south_park = Video.create(title: "South Park", description: "A funny video")
family_guy = Video.create(title: "Family Guy", description: "A really twisted versino of the Simpsons")
expect(Video.search_by_title("South Park")).to eq([south_park])
end

it "should return an array of one video for a partial match" do
family_guy = Video.create(title: "Family Guy", description: "A really twisted versino of the Simpsons")
south_park = Video.create(title: "South Park", description: "A funny video")
family_guy_2 = Video.create(title: "Family Guy", description: "A really twisted versino of the Simpsons")
expect(Video.search_by_title("Family Guy")).to eq([family_guy, family_guy_2])
end
it "should return an array of all matches oredered by created_at" do
family_guy = Video.create(title: "Family Guy", description: "A really twisted versino of the Simpsons", created_at: 1.day.ago)
south_park = Video.create(title: "South Park", description: "A funny video", created_at: 2.day.ago)
family_matters = Video.create(title: "Family Matters", description: "Steve Urkel...Yay!", created_at: 3.day.ago)
expect(Video.search_by_title("Family")).to eq([family_guy, family_matters])
end
end
end


41 changes: 41 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true

# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end