Skip to content

Commit

Permalink
Add major refactors for Rubocop compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisC0801 committed Jul 13, 2019
1 parent 0566059 commit 16d5150
Show file tree
Hide file tree
Showing 63 changed files with 575 additions and 286 deletions.
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ gem 'omniauth-google-oauth2'
gem 'will_paginate'
gem 'yt', '~> 0.29.1'

group :test do
gem 'webdrivers'
end

group :development, :test do
gem 'awesome_print'
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'capybara'
gem 'chromedriver-helper'
gem 'database_cleaner'
gem 'foundation-rails'
gem 'launchy'
gem 'pry'
gem 'rspec-rails'
gem 'rubocop'
gem 'selenium-webdriver'
gem 'shoulda-matchers'
gem 'simplecov'
gem 'vcr'
Expand Down
13 changes: 5 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ GEM
activerecord (~> 5.0)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
archive-zip (0.12.0)
io-like (~> 0.3.0)
arel (9.0.0)
ast (2.4.0)
awesome_print (1.8.0)
Expand All @@ -85,9 +83,6 @@ GEM
activesupport
childprocess (1.0.1)
rake (< 13.0)
chromedriver-helper (2.1.1)
archive-zip (~> 0.10)
nokogiri (~> 1.8)
coderay (1.1.2)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -151,7 +146,6 @@ GEM
httpclient (2.8.3)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
io-like (0.3.0)
jaro_winkler (1.5.3)
jbuilder (2.9.1)
activesupport (>= 4.2.0)
Expand Down Expand Up @@ -349,6 +343,10 @@ GEM
activemodel (>= 5.0)
bindex (>= 0.4.0)
railties (>= 5.0)
webdrivers (3.9.4)
nokogiri (~> 1.6)
rubyzip (~> 1.0)
selenium-webdriver (~> 3.0)
webmock (3.6.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
Expand Down Expand Up @@ -377,7 +375,6 @@ DEPENDENCIES
bootsnap (>= 1.1.0)
byebug
capybara
chromedriver-helper
coffee-rails (~> 4.2)
database_cleaner
factory_bot_rails
Expand All @@ -400,12 +397,12 @@ DEPENDENCIES
rspec-rails
rubocop
sass-rails (~> 5.0)
selenium-webdriver
shoulda-matchers
simplecov
tzinfo-data
vcr
web-console (>= 3.3.0)
webdrivers
webmock
webpacker (~> 3.5)
will_paginate
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ $ bundle exec rspec
* [webpacker](https://github.com/rails/webpacker)
* [vcr](https://github.com/vcr/vcr)
* [selenium-webdriver](https://www.seleniumhq.org/docs/03_webdriver.jsp)
* [chromedriver-helper](http://chromedriver.chromium.org/)

### Versions
* Ruby 2.4.1
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
# for example lib/tasks/capistrano.rake, and they will automatically be
# available to Rake.

require_relative 'config/application'

Expand Down
4 changes: 4 additions & 0 deletions app/controllers/api/v1/videos_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

class Api::V1::VideosController < ApplicationController
def index
render json: Video.all
end

def show
render json: Video.find(params[:id])
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def tutorial_name(id)
end

def four_oh_four
raise ActionController::RoutingError.new('Not Found')
raise ActionController::RoutingError, 'Not Found'
end
end
12 changes: 6 additions & 6 deletions app/controllers/github_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

class GithubController < ApplicationController
def create
token = auth_hash['credentials']['token']
current_user.token = Token.find_or_create_by(github_token: token)
current_user.update(html_url: auth_hash["info"]["urls"]["GitHub"])
redirect_to dashboard_path
end
def create
token = auth_hash['credentials']['token']
current_user.token = Token.find_or_create_by(github_token: token)
current_user.update(html_url: auth_hash['info']['urls']['GitHub'])
redirect_to dashboard_path
end

private

Expand Down
28 changes: 14 additions & 14 deletions app/controllers/tutorials_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

class TutorialsController < ApplicationController
def show
tutorial = Tutorial.find(params[:id])
if current_user == nil && !tutorial.non_classroom?
return four_oh_four
else
@facade = TutorialFacade.new(tutorial, params[:video_id])
end
end
tutorial = Tutorial.find(params[:id])
if current_user.nil? && !tutorial.non_classroom?
return four_oh_four
else
@facade = TutorialFacade.new(tutorial, params[:video_id])
end
end

def index
if current_user == nil
@tutorials = Tutorial.non_classroom
else
@tutorials = Tutorial.all
end
end
def index
@tutorials = if current_user.nil?
Tutorial.non_classroom
else
Tutorial.all
end
end
end
9 changes: 4 additions & 5 deletions app/facades/tutorial_facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ def initialize(tutorial, video_id = nil)
end

def current_video
if @video_id
if @video_id
videos.find(@video_id)
elsif
no_videos?
add_default_video
videos.first
elsif no_videos?
add_default_video
videos.first
else
videos.first
end
Expand Down
2 changes: 2 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

# base mailer from rails

class ApplicationMailer < ActionMailer::Base
default from: '[email protected]'
layout 'mailer'
Expand Down
1 change: 1 addition & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# base model that database models inherit from
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
1 change: 1 addition & 0 deletions app/models/friendship.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# friendship model as a self referental joins table to users
class Friendship < ApplicationRecord
belongs_to :user
belongs_to :friend, class_name: 'User'
Expand Down
1 change: 1 addition & 0 deletions app/models/github_user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# a model storing github login information
class GithubUser
attr_reader :login,
:html_url
Expand Down
1 change: 1 addition & 0 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# a repository model storing a name and URL of a github repository
class Repository
attr_reader :name, :html_url

Expand Down
1 change: 1 addition & 0 deletions app/models/token.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# an entry storing tokens for users
class Token < ApplicationRecord
belongs_to :user
end
36 changes: 19 additions & 17 deletions app/models/tutorial.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
# frozen_string_literal: true

# a tutorial model that has many videos and accepts tags
class Tutorial < ApplicationRecord
has_many :videos, -> { order(position: :ASC) }, dependent: :destroy
acts_as_taggable_on :tags, :tag_list
accepts_nested_attributes_for :videos
validates_presence_of :title
validates_presence_of :title

def self.non_classroom
where(classroom: false)
end
def self.non_classroom
where(classroom: false)
end

def non_classroom?
classroom == false
end
def no_videos?
videos.size == 0
end
def non_classroom?
classroom == false
end

def add_default_video
if no_videos?
title = "Tutorial Has No Videos"
description = ""
videos << Video.new(title: title, description: description)
end
end
def no_videos?
videos.empty?
end

def add_default_video
if no_videos?
title = 'Tutorial Has No Videos'
description = ''
videos << Video.new(title: title, description: description)
end
end
end
7 changes: 4 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# a user model that stores names, tokens, and friendships
class User < ApplicationRecord
has_one :token, dependent: :destroy
has_many :user_videos
Expand All @@ -15,8 +16,8 @@ class User < ApplicationRecord

def self.bookmarks(user)
Tutorial.includes(:videos)
.order(:position, :id)
.where("videos.id" => user.videos)
.references(:video)
.order(:position, :id)
.where('videos.id' => user.videos)
.references(:video)
end
end
1 change: 1 addition & 0 deletions app/models/user_video.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# a joins model between users and videos for bookmarking
class UserVideo < ApplicationRecord
belongs_to :video, foreign_key: 'video_id'
belongs_to :user, foreign_key: 'user_id'
Expand Down
8 changes: 4 additions & 4 deletions app/models/video.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# frozen_string_literal: true

# a video model containing youtube urls
class Video < ApplicationRecord
has_many :user_videos
has_many :users, through: :user_videos
belongs_to :tutorial

def default_video?
title == "Tutorial Has No Videos"
end
def default_video?
title == 'Tutorial Has No Videos'
end

validates_presence_of :position

end
9 changes: 6 additions & 3 deletions app/services/tutorial_sequencer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

# this service will change the position of videos if needed

class TutorialSequencer
def initialize(tutorial, sequenced_video_ids)
@tutorial = tutorial
Expand All @@ -20,11 +22,12 @@ def videos

def update_position_if_changed!
sequenced_video_ids.each.with_index(1) do |video_id, index|
video = videos.find do |video|
video_to_change = videos.find do |video|
video.id == video_id.to_i
end

video.update(position: index) if video.position != index
if video_to_change.position != index
video_to_change.update(position: index)
end
end
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace :api do
namespace :v1 do
resources :tutorials, only: %i[show index]
resources :videos, only: [:show]
resources :videos, only: %i[show index]
end
end

Expand Down
1 change: 1 addition & 0 deletions db/migrate/20180719194238_create_videos.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# creates a video table with description, video id, and thumbnail attributes
class CreateVideos < ActiveRecord::Migration[5.2]
def change
create_table :videos do |t|
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20180722204432_create_users.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# creates a users table with email, name, password, and role attributes
class CreateUsers < ActiveRecord::Migration[5.2]
def change
create_table :users do |t|
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20180723205733_create_tutorials.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# creates a tutorial table with title, description, thumbnail, playlist id, and classroom attributes
class CreateTutorials < ActiveRecord::Migration[5.2]
def change
create_table :tutorials do |t|
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20180723212101_add_tutorials_to_videos.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# adds a tutorial id reference to the video table
class AddTutorialsToVideos < ActiveRecord::Migration[5.2]
def change
add_reference :videos, :tutorial, index: true
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20180723214457_create_user_videos.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# creates a user video joins table with user id and video id attributes
class CreateUserVideos < ActiveRecord::Migration[5.2]
def change
create_table :user_videos do |t|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# creates a tags tables
# This migration comes from acts_as_taggable_on_engine (originally 1)
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]; end
Expand Down
Loading

0 comments on commit 16d5150

Please sign in to comment.