diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000..d23c735138
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,22 @@
+# See https://help.github.com/articles/ignoring-files for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile '~/.gitignore_global'
+
+# Ignore bundler config.
+/.bundle
+
+# Ignore all logfiles and tempfiles.
+/log/*
+/tmp/*
+!/log/.keep
+!/tmp/.keep
+
+/node_modules
+/yarn-error.log
+
+.byebug_history
+
+.env
+coverage
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000000..9a75ab29bd
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,71 @@
+source 'https://rubygems.org'
+
+git_source(:github) do |repo_name|
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
+ "https://github.com/#{repo_name}.git"
+end
+gem 'pry'
+#simplecov
+gem 'simplecov', :require => false, :group => :test
+# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
+gem 'rails', '~> 5.1.4'
+# Use postgresql as the database for Active Record
+gem 'pg', '~> 0.18'
+# Use Puma as the app server
+gem 'puma', '~> 3.7'
+# Use SCSS for stylesheets
+gem 'sass-rails', '~> 5.0'
+# Use Uglifier as compressor for JavaScript assets
+gem 'uglifier', '>= 1.3.0'
+# See https://github.com/rails/execjs#readme for more supported runtimes
+# gem 'therubyracer', platforms: :ruby
+gem 'jquery-rails'
+# Use CoffeeScript for .coffee assets and views
+# gem 'coffee-rails', '~> 4.2'
+# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
+gem 'turbolinks', '~> 5'
+# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
+gem 'jbuilder', '~> 2.5'
+# Use Redis adapter to run Action Cable in production
+# gem 'redis', '~> 3.0'
+# Use ActiveModel has_secure_password
+# gem 'bcrypt', '~> 3.1.7'
+gem 'omniauth'
+gem 'omniauth-github'
+# Use Capistrano for deployment
+# gem 'capistrano-rails', group: :development
+
+group :development, :test do
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
+ gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
+ # Adds support for Capybara system testing and selenium driver
+ gem 'dotenv-rails'
+ gem 'capybara', '~> 2.13'
+ gem 'selenium-webdriver'
+end
+
+group :development do
+ # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
+ gem 'web-console', '>= 3.3.0'
+ gem 'listen', '>= 3.0.5', '< 3.2'
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
+ gem 'rails_layout'
+ gem 'spring'
+ gem 'spring-watcher-listen', '~> 2.0.0'
+end
+
+# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
+gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
+gem 'jquery-turbolinks'
+gem 'foundation-rails', '6.4.1.2'
+
+group :development do
+ gem 'better_errors'
+ gem 'pry-rails'
+ gem 'binding_of_caller'
+end
+
+group :test do
+ gem 'minitest-rails'
+ gem 'minitest-reporters'
+end
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000000..d83ba0babf
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,273 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actioncable (5.1.4)
+ actionpack (= 5.1.4)
+ nio4r (~> 2.0)
+ websocket-driver (~> 0.6.1)
+ actionmailer (5.1.4)
+ actionpack (= 5.1.4)
+ actionview (= 5.1.4)
+ activejob (= 5.1.4)
+ mail (~> 2.5, >= 2.5.4)
+ rails-dom-testing (~> 2.0)
+ actionpack (5.1.4)
+ actionview (= 5.1.4)
+ activesupport (= 5.1.4)
+ rack (~> 2.0)
+ rack-test (>= 0.6.3)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
+ actionview (5.1.4)
+ activesupport (= 5.1.4)
+ builder (~> 3.1)
+ erubi (~> 1.4)
+ rails-dom-testing (~> 2.0)
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
+ activejob (5.1.4)
+ activesupport (= 5.1.4)
+ globalid (>= 0.3.6)
+ activemodel (5.1.4)
+ activesupport (= 5.1.4)
+ activerecord (5.1.4)
+ activemodel (= 5.1.4)
+ activesupport (= 5.1.4)
+ arel (~> 8.0)
+ activesupport (5.1.4)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
+ i18n (~> 0.7)
+ minitest (~> 5.1)
+ tzinfo (~> 1.1)
+ addressable (2.5.2)
+ public_suffix (>= 2.0.2, < 4.0)
+ ansi (1.5.0)
+ arel (8.0.0)
+ babel-source (5.8.35)
+ babel-transpiler (0.7.0)
+ babel-source (>= 4.0, < 6)
+ execjs (~> 2.0)
+ better_errors (2.4.0)
+ coderay (>= 1.0.0)
+ erubi (>= 1.0.0)
+ rack (>= 0.9.0)
+ bindex (0.5.0)
+ binding_of_caller (0.7.3)
+ debug_inspector (>= 0.0.1)
+ builder (3.2.3)
+ byebug (9.1.0)
+ capybara (2.15.4)
+ addressable
+ mini_mime (>= 0.1.3)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ xpath (~> 2.0)
+ childprocess (0.8.0)
+ ffi (~> 1.0, >= 1.0.11)
+ coderay (1.1.2)
+ concurrent-ruby (1.0.5)
+ crass (1.0.2)
+ debug_inspector (0.0.3)
+ docile (1.1.5)
+ dotenv (2.2.1)
+ dotenv-rails (2.2.1)
+ dotenv (= 2.2.1)
+ railties (>= 3.2, < 5.2)
+ erubi (1.7.0)
+ execjs (2.7.0)
+ faraday (0.12.2)
+ multipart-post (>= 1.2, < 3)
+ ffi (1.9.18)
+ foundation-rails (6.4.1.2)
+ railties (>= 3.1.0)
+ sass (>= 3.3.0, < 3.5)
+ sprockets-es6 (>= 0.9.0)
+ globalid (0.4.1)
+ activesupport (>= 4.2.0)
+ hashie (3.5.6)
+ i18n (0.9.1)
+ concurrent-ruby (~> 1.0)
+ jbuilder (2.7.0)
+ activesupport (>= 4.2.0)
+ multi_json (>= 1.2)
+ jquery-rails (4.3.1)
+ rails-dom-testing (>= 1, < 3)
+ railties (>= 4.2.0)
+ thor (>= 0.14, < 2.0)
+ jquery-turbolinks (2.1.0)
+ railties (>= 3.1.0)
+ turbolinks
+ json (2.1.0)
+ jwt (1.5.6)
+ listen (3.1.5)
+ rb-fsevent (~> 0.9, >= 0.9.4)
+ rb-inotify (~> 0.9, >= 0.9.7)
+ ruby_dep (~> 1.2)
+ loofah (2.1.1)
+ crass (~> 1.0.2)
+ nokogiri (>= 1.5.9)
+ mail (2.7.0)
+ mini_mime (>= 0.1.1)
+ method_source (0.9.0)
+ mini_mime (0.1.4)
+ mini_portile2 (2.3.0)
+ minitest (5.10.3)
+ minitest-rails (3.0.0)
+ minitest (~> 5.8)
+ railties (~> 5.0)
+ minitest-reporters (1.1.18)
+ ansi
+ builder
+ minitest (>= 5.0)
+ ruby-progressbar
+ multi_json (1.12.2)
+ multi_xml (0.6.0)
+ multipart-post (2.0.0)
+ nio4r (2.1.0)
+ nokogiri (1.8.1)
+ mini_portile2 (~> 2.3.0)
+ oauth2 (1.4.0)
+ faraday (>= 0.8, < 0.13)
+ jwt (~> 1.0)
+ multi_json (~> 1.3)
+ multi_xml (~> 0.5)
+ rack (>= 1.2, < 3)
+ omniauth (1.7.1)
+ hashie (>= 3.4.6, < 3.6.0)
+ rack (>= 1.6.2, < 3)
+ omniauth-github (1.3.0)
+ omniauth (~> 1.5)
+ omniauth-oauth2 (>= 1.4.0, < 2.0)
+ omniauth-oauth2 (1.4.0)
+ oauth2 (~> 1.0)
+ omniauth (~> 1.2)
+ pg (0.21.0)
+ pry (0.11.2)
+ coderay (~> 1.1.0)
+ method_source (~> 0.9.0)
+ pry-rails (0.3.6)
+ pry (>= 0.10.4)
+ public_suffix (3.0.0)
+ puma (3.10.0)
+ rack (2.0.3)
+ rack-test (0.7.0)
+ rack (>= 1.0, < 3)
+ rails (5.1.4)
+ actioncable (= 5.1.4)
+ actionmailer (= 5.1.4)
+ actionpack (= 5.1.4)
+ actionview (= 5.1.4)
+ activejob (= 5.1.4)
+ activemodel (= 5.1.4)
+ activerecord (= 5.1.4)
+ activesupport (= 5.1.4)
+ bundler (>= 1.3.0)
+ railties (= 5.1.4)
+ sprockets-rails (>= 2.0.0)
+ rails-dom-testing (2.0.3)
+ activesupport (>= 4.2.0)
+ nokogiri (>= 1.6)
+ rails-html-sanitizer (1.0.3)
+ loofah (~> 2.0)
+ rails_layout (1.0.41)
+ railties (5.1.4)
+ actionpack (= 5.1.4)
+ activesupport (= 5.1.4)
+ method_source
+ rake (>= 0.8.7)
+ thor (>= 0.18.1, < 2.0)
+ rake (12.2.1)
+ rb-fsevent (0.10.2)
+ rb-inotify (0.9.10)
+ ffi (>= 0.5.0, < 2)
+ ruby-progressbar (1.9.0)
+ ruby_dep (1.5.0)
+ rubyzip (1.2.1)
+ sass (3.4.25)
+ sass-rails (5.0.6)
+ railties (>= 4.0.0, < 6)
+ sass (~> 3.1)
+ sprockets (>= 2.8, < 4.0)
+ sprockets-rails (>= 2.0, < 4.0)
+ tilt (>= 1.1, < 3)
+ selenium-webdriver (3.7.0)
+ childprocess (~> 0.5)
+ rubyzip (~> 1.0)
+ simplecov (0.15.1)
+ docile (~> 1.1.0)
+ json (>= 1.8, < 3)
+ simplecov-html (~> 0.10.0)
+ simplecov-html (0.10.2)
+ spring (2.0.2)
+ activesupport (>= 4.2)
+ spring-watcher-listen (2.0.1)
+ listen (>= 2.7, < 4.0)
+ spring (>= 1.2, < 3.0)
+ sprockets (3.7.1)
+ concurrent-ruby (~> 1.0)
+ rack (> 1, < 3)
+ sprockets-es6 (0.9.2)
+ babel-source (>= 5.8.11)
+ babel-transpiler
+ sprockets (>= 3.0.0)
+ sprockets-rails (3.2.1)
+ actionpack (>= 4.0)
+ activesupport (>= 4.0)
+ sprockets (>= 3.0.0)
+ thor (0.20.0)
+ thread_safe (0.3.6)
+ tilt (2.0.8)
+ turbolinks (5.0.1)
+ turbolinks-source (~> 5)
+ turbolinks-source (5.0.3)
+ tzinfo (1.2.4)
+ thread_safe (~> 0.1)
+ uglifier (3.2.0)
+ execjs (>= 0.3.0, < 3)
+ web-console (3.5.1)
+ actionview (>= 5.0)
+ activemodel (>= 5.0)
+ bindex (>= 0.4.0)
+ railties (>= 5.0)
+ websocket-driver (0.6.5)
+ websocket-extensions (>= 0.1.0)
+ websocket-extensions (0.1.2)
+ xpath (2.1.0)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ better_errors
+ binding_of_caller
+ byebug
+ capybara (~> 2.13)
+ dotenv-rails
+ foundation-rails (= 6.4.1.2)
+ jbuilder (~> 2.5)
+ jquery-rails
+ jquery-turbolinks
+ listen (>= 3.0.5, < 3.2)
+ minitest-rails
+ minitest-reporters
+ omniauth
+ omniauth-github
+ pg (~> 0.18)
+ pry
+ pry-rails
+ puma (~> 3.7)
+ rails (~> 5.1.4)
+ rails_layout
+ sass-rails (~> 5.0)
+ selenium-webdriver
+ simplecov
+ spring
+ spring-watcher-listen (~> 2.0.0)
+ turbolinks (~> 5)
+ tzinfo-data
+ uglifier (>= 1.3.0)
+ web-console (>= 3.3.0)
+
+BUNDLED WITH
+ 1.16.0
diff --git a/README.md b/README.md
index 6d792f05ce..7db80e4ca1 100644
--- a/README.md
+++ b/README.md
@@ -1,102 +1,24 @@
-# Media Ranker
+# README
-## Introduction
+This README would normally document whatever steps are necessary to get the
+application up and running.
-In this project, you will build a webapp where users can vote for their favorite pieces of media.
+Things you may want to cover:
-In contrast to previous projects, instead of implementing a pre-defined spec you will be imitating an existing site: http://media-ranker-2-0.herokuapp.com. Your job is to match the functionality and styling of this site as closely as possible.
+* Ruby version
-This is an individual, [stage 2](https://github.com/Ada-Developers-Academy/pedagogy/blob/master/rule-of-three.md) project.
+* System dependencies
-## Learning Goals
+* Configuration
-The purpose of this assignment is to reinforce the following concepts:
+* Database creation
-- Previous Rails learning, including MVC, RESTful routing, and the request cycle
-- Testing Rails applications
-- Building complex model logic
-- Using `session` and `flash` to track data between requests
-- DRYing up Rails code
-- Working with a CSS framework
-- Styling a page based on an existing design
+* Database initialization
-## Before You Begin
+* How to run the test suite
-### Provided Files
+* Services (job queues, cache servers, search engines, etc.)
-- `db/media_seeds.csv`: Some starter media to work with
-- `app/assets/images/owl.jpg`: The owl picture from the site
+* Deployment instructions
-### Regarding the Word "Media"
-
-The Rails inflector considers "media" to be the plural of "medium", which is not really what we mean here. You may want to choose a different word to represent "a book, movie or album" internally. The instructor-proved example site uses the word "work".
-
-## Project Requirements
-
-### Core Requirements
-
-Regardless of how you choose to implement this project or how much of it gets done, you should exhibit
-
-- Squeaky-clean **git hygiene**, including
- - A fresh branch for each new feature
- - Regular commits
- - Descriptive commit messages
-- Fanatical devotion to **test-driven development**
- - Pseudocode first, then write the tests, then write code to make them pass
-- Steadfast adherence to **agile development practices**
- - User stories should be listed and prioritized using a Trello board
- - The finished application should be deployed to Heroku (deploy early, deploy often)
-- Unrelenting use of **semantic HTML**
-
-### Baseline
-
-We will begin with some in-class work, exploring the site and pondering implementation details. Before you start writing _any_ code, you should:
-
-- Explore the existing Media Ranker site to become familiar with the necessary functionality
-- Create a Trello board to manage user stories
-- Create an ERD for the models
-
-Then, once you have a solid plan for how to structure your project:
-
-- Fork and clone the repo
-- Use `rails new .` to generate a new Rails project in the cloned directory
- - Verify that the changes we've made to Rails' defaults (postgres as the DB, spec-style testing) have been applied
-- `git add .` and `git commit -m "Initial Rails setup"`
-
-### Wave 1
-
-Mimic the site's basic functionality around Media, without worrying (yet) about Users or Votes:
-- Build a main page, with a list of the top 10 media of each category, as well as a spotlight section for the top media overall
-- Build an index page with a list of all works for each category
-- Allow users to add new works
-- Build a details page for each piece of media
-- Allow users to edit and delete works
-- Make sure any models and controllers you've built so far are well-tested
-
-### Wave 2
-
-Mimic the site's functionality around Users and Voting:
-- Allow users to "log in" to the site, and use the `session` to keep track of which user is currently logged in for a given browser
-- Allow users to vote for media, and sort media by vote count whenever a list of media is displayed
-- Add a list of voting users to the details page for each media
-- Don't allow a user to vote for the same media more than once
-- Add a page for each user, as well as a page showing a summary of all users
-- Make sure any models and controllers you've built so far are well-tested
-
-#### A note on logging in
-
-Passwords and security are tricky! We'll talk about that sort of thing a little in the coming weeks, but for now you don't need to provide any sort of security. The user gives you a username, and your site should just trust them.
-
-### Wave 3
-
-Use Foundation and CSS to style the site to match the example. The layout as well as the look and feel should match as close as possible.
-
-### Optional Enhancement Ideas
-
-Once your test coverage is comprehensive, your HTML is semantic, your user stories have all been moved to the `Done` column and your application has been deployed to Heroku, you may consider the following enhancements.
-
-1. DRY up your code as much as you can! Techniques worth investigating:
- - Helper methods
- - Controller filters
-1. Build category-specific pages for `index` and `new` (e.g. `/books` or `/movies/new`). These should be as DRY as possible. You might be interested in investigating _polymorphic routes_.
-1. Add a [recommendation system](https://www.toptal.com/algorithms/predicting-likes-inside-a-simple-recommendation-engine) that suggests media to a user based on what they have previously voted for.
+* ...
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000000..e85f913914
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,6 @@
+# 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.
+
+require_relative 'config/application'
+
+Rails.application.load_tasks
diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js
new file mode 100644
index 0000000000..b16e53d6d5
--- /dev/null
+++ b/app/assets/config/manifest.js
@@ -0,0 +1,3 @@
+//= link_tree ../images
+//= link_directory ../javascripts .js
+//= link_directory ../stylesheets .css
diff --git a/app/assets/images/.keep b/app/assets/images/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
new file mode 100644
index 0000000000..08ac36014d
--- /dev/null
+++ b/app/assets/javascripts/application.js
@@ -0,0 +1,19 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
+// vendor/assets/javascripts directory can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// compiled file. JavaScript code in this file should be added after the last require_* statement.
+//
+// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
+// about supported directives.
+//
+//= require rails-ujs
+//= require foundation
+//= require turbolinks
+//= require_tree .
+//= require foundation
+$(document).foundation();
+$(function(){ $(document).foundation(); });
diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js
new file mode 100644
index 0000000000..739aa5f022
--- /dev/null
+++ b/app/assets/javascripts/cable.js
@@ -0,0 +1,13 @@
+// Action Cable provides the framework to deal with WebSockets in Rails.
+// You can generate new channels where WebSocket features live using the `rails generate channel` command.
+//
+//= require action_cable
+//= require_self
+//= require_tree ./channels
+
+(function() {
+ this.App || (this.App = {});
+
+ App.cable = ActionCable.createConsumer();
+
+}).call(this);
diff --git a/app/assets/javascripts/channels/.keep b/app/assets/javascripts/channels/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js
new file mode 100644
index 0000000000..dee720facd
--- /dev/null
+++ b/app/assets/javascripts/main.js
@@ -0,0 +1,2 @@
+// Place all the behaviors and hooks related to the matching controller here.
+// All this logic will automatically be available in application.js.
diff --git a/app/assets/javascripts/media_instance.js b/app/assets/javascripts/media_instance.js
new file mode 100644
index 0000000000..dee720facd
--- /dev/null
+++ b/app/assets/javascripts/media_instance.js
@@ -0,0 +1,2 @@
+// Place all the behaviors and hooks related to the matching controller here.
+// All this logic will automatically be available in application.js.
diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js
new file mode 100644
index 0000000000..dee720facd
--- /dev/null
+++ b/app/assets/javascripts/user.js
@@ -0,0 +1,2 @@
+// Place all the behaviors and hooks related to the matching controller here.
+// All this logic will automatically be available in application.js.
diff --git a/app/assets/javascripts/vote.js b/app/assets/javascripts/vote.js
new file mode 100644
index 0000000000..dee720facd
--- /dev/null
+++ b/app/assets/javascripts/vote.js
@@ -0,0 +1,2 @@
+// Place all the behaviors and hooks related to the matching controller here.
+// All this logic will automatically be available in application.js.
diff --git a/app/assets/stylesheets/MediaRanker.htm b/app/assets/stylesheets/MediaRanker.htm
new file mode 100644
index 0000000000..158ba8cf31
--- /dev/null
+++ b/app/assets/stylesheets/MediaRanker.htm
@@ -0,0 +1,80 @@
+
+
+
+<% end %>
diff --git a/app/views/users/_login_form.html.erb b/app/views/users/_login_form.html.erb
new file mode 100644
index 0000000000..37556fc0e5
--- /dev/null
+++ b/app/views/users/_login_form.html.erb
@@ -0,0 +1,5 @@
+<%= form_tag do %>
+<%= collection_select(:user, :user_id, User.all, :id, :email) %>
+<%= submit_tag "Log in as User" , data: { confirm: 'Are you sure this is you?' } %>
+<%= link_to "New User", new_user_path %>
+<% end %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb
new file mode 100644
index 0000000000..c332bbaef3
--- /dev/null
+++ b/app/views/users/edit.html.erb
@@ -0,0 +1,4 @@
+
Edit User Details
+
+<%= render partial: "form" %>
+
diff --git a/app/views/users/login.html.erb b/app/views/users/login.html.erb
new file mode 100644
index 0000000000..a8fe969a37
--- /dev/null
+++ b/app/views/users/login.html.erb
@@ -0,0 +1,3 @@
+
+<%= render partial: "login_form" %>
+
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb
new file mode 100644
index 0000000000..758eff9eb5
--- /dev/null
+++ b/app/views/users/new.html.erb
@@ -0,0 +1,6 @@
+
+
New User
+
+ <%= render partial: "form" %>
+
+
diff --git a/bin/bundle b/bin/bundle
new file mode 100755
index 0000000000..66e9889e8b
--- /dev/null
+++ b/bin/bundle
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+load Gem.bin_path('bundler', 'bundle')
diff --git a/bin/rails b/bin/rails
new file mode 100755
index 0000000000..5badb2fde0
--- /dev/null
+++ b/bin/rails
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+APP_PATH = File.expand_path('../config/application', __dir__)
+require_relative '../config/boot'
+require 'rails/commands'
diff --git a/bin/rake b/bin/rake
new file mode 100755
index 0000000000..d87d5f5781
--- /dev/null
+++ b/bin/rake
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path('../spring', __FILE__)
+rescue LoadError => e
+ raise unless e.message.include?('spring')
+end
+require_relative '../config/boot'
+require 'rake'
+Rake.application.run
diff --git a/bin/setup b/bin/setup
new file mode 100755
index 0000000000..78c4e861dc
--- /dev/null
+++ b/bin/setup
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+require 'pathname'
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a starting point to setup your application.
+ # Add necessary setup steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ # Install JavaScript dependencies if using Yarn
+ # system('bin/yarn')
+
+
+ # puts "\n== Copying sample files =="
+ # unless File.exist?('config/database.yml')
+ # cp 'config/database.yml.sample', 'config/database.yml'
+ # end
+
+ puts "\n== Preparing database =="
+ system! 'bin/rails db:setup'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/bin/spring b/bin/spring
new file mode 100755
index 0000000000..fb2ec2ebb4
--- /dev/null
+++ b/bin/spring
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+# This file loads spring without using Bundler, in order to be fast.
+# It gets overwritten when you run the `spring binstub` command.
+
+unless defined?(Spring)
+ require 'rubygems'
+ require 'bundler'
+
+ lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
+ spring = lockfile.specs.detect { |spec| spec.name == "spring" }
+ if spring
+ Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
+ gem 'spring', spring.version
+ require 'spring/binstub'
+ end
+end
diff --git a/bin/update b/bin/update
new file mode 100755
index 0000000000..a8e4462f20
--- /dev/null
+++ b/bin/update
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+require 'pathname'
+require 'fileutils'
+include FileUtils
+
+# path to your application root.
+APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+
+def system!(*args)
+ system(*args) || abort("\n== Command #{args} failed ==")
+end
+
+chdir APP_ROOT do
+ # This script is a way to update your development environment automatically.
+ # Add necessary update steps to this file.
+
+ puts '== Installing dependencies =='
+ system! 'gem install bundler --conservative'
+ system('bundle check') || system!('bundle install')
+
+ puts "\n== Updating database =="
+ system! 'bin/rails db:migrate'
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! 'bin/rails log:clear tmp:clear'
+
+ puts "\n== Restarting application server =="
+ system! 'bin/rails restart'
+end
diff --git a/bin/yarn b/bin/yarn
new file mode 100755
index 0000000000..c2bacef836
--- /dev/null
+++ b/bin/yarn
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+VENDOR_PATH = File.expand_path('..', __dir__)
+Dir.chdir(VENDOR_PATH) do
+ begin
+ exec "yarnpkg #{ARGV.join(" ")}"
+ rescue Errno::ENOENT
+ $stderr.puts "Yarn executable was not detected in the system."
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
+ exit 1
+ end
+end
diff --git a/config.ru b/config.ru
new file mode 100644
index 0000000000..f7ba0b527b
--- /dev/null
+++ b/config.ru
@@ -0,0 +1,5 @@
+# This file is used by Rack-based servers to start the application.
+
+require_relative 'config/environment'
+
+run Rails.application
diff --git a/config/application.rb b/config/application.rb
new file mode 100644
index 0000000000..98b4ee1bce
--- /dev/null
+++ b/config/application.rb
@@ -0,0 +1,25 @@
+require_relative 'boot'
+
+require 'rails/all'
+
+# Require the gems listed in Gemfile, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(*Rails.groups)
+
+module MediaRanker
+ class Application < Rails::Application
+ config.generators do |g|
+ # Force new test files to be generated in the minitest-spec style
+ g.test_framework :minitest, spec: true
+
+ # Always use .js files, never .coffee
+ g.javascript_engine :js
+ end
+ # Initialize configuration defaults for originally generated Rails version.
+ config.load_defaults 5.1
+
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+ end
+end
diff --git a/config/boot.rb b/config/boot.rb
new file mode 100644
index 0000000000..30f5120df6
--- /dev/null
+++ b/config/boot.rb
@@ -0,0 +1,3 @@
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
+
+require 'bundler/setup' # Set up gems listed in the Gemfile.
diff --git a/config/cable.yml b/config/cable.yml
new file mode 100644
index 0000000000..3a27f13933
--- /dev/null
+++ b/config/cable.yml
@@ -0,0 +1,10 @@
+development:
+ adapter: async
+
+test:
+ adapter: async
+
+production:
+ adapter: redis
+ url: redis://localhost:6379/1
+ channel_prefix: MediaRanker_production
diff --git a/config/database.yml b/config/database.yml
new file mode 100644
index 0000000000..0bd2511123
--- /dev/null
+++ b/config/database.yml
@@ -0,0 +1,85 @@
+# PostgreSQL. Versions 9.1 and up are supported.
+#
+# Install the pg driver:
+# gem install pg
+# On OS X with Homebrew:
+# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
+# On OS X with MacPorts:
+# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
+# On Windows:
+# gem install pg
+# Choose the win32 build.
+# Install PostgreSQL and put its /bin directory on your path.
+#
+# Configure Using Gemfile
+# gem 'pg'
+#
+default: &default
+ adapter: postgresql
+ encoding: unicode
+ # For details on connection pooling, see Rails configuration guide
+ # http://guides.rubyonrails.org/configuring.html#database-pooling
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
+
+development:
+ <<: *default
+ database: MediaRanker_development
+
+ # The specified database role being used to connect to postgres.
+ # To create additional roles in postgres see `$ createuser --help`.
+ # When left blank, postgres will use the default role. This is
+ # the same name as the operating system user that initialized the database.
+ #username: MediaRanker
+
+ # The password associated with the postgres role (username).
+ #password:
+
+ # Connect on a TCP socket. Omitted by default since the client uses a
+ # domain socket that doesn't need configuration. Windows does not have
+ # domain sockets, so uncomment these lines.
+ #host: localhost
+
+ # The TCP port the server listens on. Defaults to 5432.
+ # If your server runs on a different port number, change accordingly.
+ #port: 5432
+
+ # Schema search path. The server defaults to $user,public
+ #schema_search_path: myapp,sharedapp,public
+
+ # Minimum log levels, in increasing order:
+ # debug5, debug4, debug3, debug2, debug1,
+ # log, notice, warning, error, fatal, and panic
+ # Defaults to warning.
+ #min_messages: notice
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ <<: *default
+ database: MediaRanker_test
+
+# As with config/secrets.yml, you never want to store sensitive information,
+# like your database password, in your source code. If your source code is
+# ever seen by anyone, they now have access to your database.
+#
+# Instead, provide the password as a unix environment variable when you boot
+# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
+# for a full rundown on how to provide these environment variables in a
+# production deployment.
+#
+# On Heroku and other platform providers, you may have a full connection URL
+# available as an environment variable. For example:
+#
+# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
+#
+# You can use this database configuration with:
+#
+# production:
+# url: <%= ENV['DATABASE_URL'] %>
+#
+production:
+ <<: *default
+ database: MediaRanker_production
+ username: MediaRanker
+ password: <%= ENV['MEDIARANKER_DATABASE_PASSWORD'] %>
diff --git a/config/environment.rb b/config/environment.rb
new file mode 100644
index 0000000000..426333bb46
--- /dev/null
+++ b/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require_relative 'application'
+
+# Initialize the Rails application.
+Rails.application.initialize!
diff --git a/config/environments/development.rb b/config/environments/development.rb
new file mode 100644
index 0000000000..5187e22186
--- /dev/null
+++ b/config/environments/development.rb
@@ -0,0 +1,54 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Do not eager load code on boot.
+ config.eager_load = false
+
+ # Show full error reports.
+ config.consider_all_requests_local = true
+
+ # Enable/disable caching. By default caching is disabled.
+ if Rails.root.join('tmp/caching-dev.txt').exist?
+ config.action_controller.perform_caching = true
+
+ config.cache_store = :memory_store
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
+ }
+ else
+ config.action_controller.perform_caching = false
+
+ config.cache_store = :null_store
+ end
+
+ # Don't care if the mailer can't send.
+ config.action_mailer.raise_delivery_errors = false
+
+ config.action_mailer.perform_caching = false
+
+ # Print deprecation notices to the Rails logger.
+ config.active_support.deprecation = :log
+
+ # Raise an error on page load if there are pending migrations.
+ config.active_record.migration_error = :page_load
+
+ # Debug mode disables concatenation and preprocessing of assets.
+ # This option may cause significant delays in view rendering with a large
+ # number of complex assets.
+ config.assets.debug = true
+
+ # Suppress logger output for asset requests.
+ config.assets.quiet = true
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+
+ # Use an evented file watcher to asynchronously detect changes in source code,
+ # routes, locales, etc. This feature depends on the listen gem.
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+end
diff --git a/config/environments/production.rb b/config/environments/production.rb
new file mode 100644
index 0000000000..d242dac65c
--- /dev/null
+++ b/config/environments/production.rb
@@ -0,0 +1,91 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Code is not reloaded between requests.
+ config.cache_classes = true
+
+ # Eager load code on boot. This eager loads most of Rails and
+ # your application in memory, allowing both threaded web servers
+ # and those relying on copy on write to perform better.
+ # Rake tasks automatically ignore this option for performance.
+ config.eager_load = true
+
+ # Full error reports are disabled and caching is turned on.
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
+ # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
+ # `config/secrets.yml.key`.
+ config.read_encrypted_secrets = true
+
+ # Disable serving static files from the `/public` folder by default since
+ # Apache or NGINX already handles this.
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
+
+ # Compress JavaScripts and CSS.
+ config.assets.js_compressor = :uglifier
+ # config.assets.css_compressor = :sass
+
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
+ config.assets.compile = false
+
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ # config.action_controller.asset_host = 'http://assets.example.com'
+
+ # Specifies the header that your server uses for sending files.
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
+
+ # Mount Action Cable outside main process or domain
+ # config.action_cable.mount_path = nil
+ # config.action_cable.url = 'wss://example.com/cable'
+ # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # Use the lowest log level to ensure availability of diagnostic information
+ # when problems arise.
+ config.log_level = :debug
+
+ # Prepend all log lines with the following tags.
+ config.log_tags = [ :request_id ]
+
+ # Use a different cache store in production.
+ # config.cache_store = :mem_cache_store
+
+ # Use a real queuing backend for Active Job (and separate queues per environment)
+ # config.active_job.queue_adapter = :resque
+ # config.active_job.queue_name_prefix = "MediaRanker_#{Rails.env}"
+ config.action_mailer.perform_caching = false
+
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation cannot be found).
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners.
+ config.active_support.deprecation = :notify
+
+ # Use default logging formatter so that PID and timestamp are not suppressed.
+ config.log_formatter = ::Logger::Formatter.new
+
+ # Use a different logger for distributed setups.
+ # require 'syslog/logger'
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
+ logger = ActiveSupport::Logger.new(STDOUT)
+ logger.formatter = config.log_formatter
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
+ end
+
+ # Do not dump schema after migrations.
+ config.active_record.dump_schema_after_migration = false
+end
diff --git a/config/environments/test.rb b/config/environments/test.rb
new file mode 100644
index 0000000000..8e5cbde533
--- /dev/null
+++ b/config/environments/test.rb
@@ -0,0 +1,42 @@
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Do not eager load code on boot. This avoids loading your whole application
+ # just for the purpose of running a single test. If you are using a tool that
+ # preloads Rails for running tests, you may have to set it to true.
+ config.eager_load = false
+
+ # Configure public file server for tests with Cache-Control for performance.
+ config.public_file_server.enabled = true
+ config.public_file_server.headers = {
+ 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
+ }
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates.
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment.
+ config.action_controller.allow_forgery_protection = false
+ config.action_mailer.perform_caching = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Print deprecation notices to the stderr.
+ config.active_support.deprecation = :stderr
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
+end
diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb
new file mode 100644
index 0000000000..89d2efab2b
--- /dev/null
+++ b/config/initializers/application_controller_renderer.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+# ActiveSupport::Reloader.to_prepare do
+# ApplicationController.renderer.defaults.merge!(
+# http_host: 'example.org',
+# https: false
+# )
+# end
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
new file mode 100644
index 0000000000..790ac905bb
--- /dev/null
+++ b/config/initializers/assets.rb
@@ -0,0 +1,15 @@
+# Be sure to restart your server when you modify this file.
+
+# Version of your assets, change this if you want to expire all your assets.
+Rails.application.config.assets.version = '1.0'
+
+# Add additional assets to the asset load path.
+# Rails.application.config.assets.paths << Emoji.images_path
+# Add Yarn node_modules folder to the asset load path.
+Rails.application.config.assets.paths << Rails.root.join('node_modules')
+
+# Precompile additional assets.
+# application.js, application.css, and all non-JS/CSS in the app/assets
+# folder are already added.
+# Rails.application.config.assets.precompile += %w( admin.js admin.css )
+Rails.application.config.assets.precompile += %w( vendor/modernizr.js )
diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb
new file mode 100644
index 0000000000..59385cdf37
--- /dev/null
+++ b/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb
new file mode 100644
index 0000000000..5a6a32d371
--- /dev/null
+++ b/config/initializers/cookies_serializer.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Specify a serializer for the signed and encrypted cookie jars.
+# Valid options are :json, :marshal, and :hybrid.
+Rails.application.config.action_dispatch.cookies_serializer = :json
diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb
new file mode 100644
index 0000000000..4a994e1e7b
--- /dev/null
+++ b/config/initializers/filter_parameter_logging.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Configure sensitive parameters which will be filtered from the log file.
+Rails.application.config.filter_parameters += [:password]
diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb
new file mode 100644
index 0000000000..ac033bf9dc
--- /dev/null
+++ b/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.acronym 'RESTful'
+# end
diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb
new file mode 100644
index 0000000000..dc1899682b
--- /dev/null
+++ b/config/initializers/mime_types.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb
new file mode 100644
index 0000000000..fd4416122a
--- /dev/null
+++ b/config/initializers/omniauth.rb
@@ -0,0 +1,3 @@
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email"
+end
diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb
new file mode 100644
index 0000000000..bbfc3961bf
--- /dev/null
+++ b/config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json]
+end
+
+# To enable root element in JSON for ActiveRecord objects.
+# ActiveSupport.on_load(:active_record) do
+# self.include_root_in_json = true
+# end
diff --git a/config/locales/en.yml b/config/locales/en.yml
new file mode 100644
index 0000000000..decc5a8573
--- /dev/null
+++ b/config/locales/en.yml
@@ -0,0 +1,33 @@
+# Files in the config/locales directory are used for internationalization
+# and are automatically loaded by Rails. If you want to use locales other
+# than English, add the necessary files in this directory.
+#
+# To use the locales, use `I18n.t`:
+#
+# I18n.t 'hello'
+#
+# In views, this is aliased to just `t`:
+#
+# <%= t('hello') %>
+#
+# To use a different locale, set it with `I18n.locale`:
+#
+# I18n.locale = :es
+#
+# This would use the information in config/locales/es.yml.
+#
+# The following keys must be escaped otherwise they will not be retrieved by
+# the default I18n backend:
+#
+# true, false, on, off, yes, no
+#
+# Instead, surround them with single quotes.
+#
+# en:
+# 'true': 'foo'
+#
+# To learn more, please read the Rails Internationalization guide
+# available at http://guides.rubyonrails.org/i18n.html.
+
+en:
+ hello: "Hello world"
diff --git a/config/puma.rb b/config/puma.rb
new file mode 100644
index 0000000000..1e19380dcb
--- /dev/null
+++ b/config/puma.rb
@@ -0,0 +1,56 @@
+# Puma can serve each request in a thread from an internal thread pool.
+# The `threads` method setting takes two numbers: a minimum and maximum.
+# Any libraries that use thread pools should be configured to match
+# the maximum value specified for Puma. Default is set to 5 threads for minimum
+# and maximum; this matches the default thread size of Active Record.
+#
+threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
+threads threads_count, threads_count
+
+# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
+#
+port ENV.fetch("PORT") { 3000 }
+
+# Specifies the `environment` that Puma will run in.
+#
+environment ENV.fetch("RAILS_ENV") { "development" }
+
+# Specifies the number of `workers` to boot in clustered mode.
+# Workers are forked webserver processes. If using threads and workers together
+# the concurrency of the application would be max `threads` * `workers`.
+# Workers do not work on JRuby or Windows (both of which do not support
+# processes).
+#
+# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
+
+# Use the `preload_app!` method when specifying a `workers` number.
+# This directive tells Puma to first boot the application and load code
+# before forking the application. This takes advantage of Copy On Write
+# process behavior so workers use less memory. If you use this option
+# you need to make sure to reconnect any threads in the `on_worker_boot`
+# block.
+#
+# preload_app!
+
+# If you are preloading your application and using Active Record, it's
+# recommended that you close any connections to the database before workers
+# are forked to prevent connection leakage.
+#
+# before_fork do
+# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
+# end
+
+# The code in the `on_worker_boot` will be called if you are using
+# clustered mode by specifying a number of `workers`. After each worker
+# process is booted, this block will be run. If you are using the `preload_app!`
+# option, you will want to use this block to reconnect to any threads
+# or connections that may have been created at application boot, as Ruby
+# cannot share connections between processes.
+#
+# on_worker_boot do
+# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
+# end
+#
+
+# Allow puma to be restarted by `rails restart` command.
+plugin :tmp_restart
diff --git a/config/routes.rb b/config/routes.rb
new file mode 100644
index 0000000000..958e488f3f
--- /dev/null
+++ b/config/routes.rb
@@ -0,0 +1,27 @@
+Rails.application.routes.draw do
+ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
+ resources :users, except:[:show, :index]
+
+ # post '/login', to:'users#login'
+ get '/logout', to: 'users#logout'
+
+
+
+ resources :media_instances do
+ resources :users, only: [:index] do
+ resources :votes, only: [ :create, :destroy]
+ end
+ end
+
+ resources :media_instances, constraints: { media_type: /book|movie|music/ } , :path => 'media_instances/:media_type'
+
+ get '/movies', to: 'media_instances#get_movies'
+ get '/books', to: 'media_instances#get_books'
+ get '/music', to: 'media_instances#get_music'
+
+ get '/auth/:provider/callback', to: 'users#login', as: 'login'
+ root 'main#index'
+
+ # get '/login', to: 'users#new', as: 'login'
+
+end
diff --git a/config/secrets.yml b/config/secrets.yml
new file mode 100644
index 0000000000..137e0f5c23
--- /dev/null
+++ b/config/secrets.yml
@@ -0,0 +1,32 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key is used for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+# You can use `rails secret` to generate a secure secret key.
+
+# Make sure the secrets in this file are kept private
+# if you're sharing your code publicly.
+
+# Shared secrets are available across all environments.
+
+# shared:
+# api_key: a1B2c3D4e5F6
+
+# Environmental secrets are only available for that specific environment.
+
+development:
+ secret_key_base: 46cd181c8b832fc350397bad283dd40671d4a9798c3bc12070ae710c0e013a125b59671bd6fa9817639588f920d61e18288ba5ad5b54d38c5d24251004f21fae
+
+test:
+ secret_key_base: ed7545ee9079e2dd9cb96a73d8993445927cf367ec0e397f5e9e1b238c5a7f4ab6216a311032563d86e03cb63235f9dd75be2fe924a2292da65ee3f8d16f7136
+
+# Do not keep production secrets in the unencrypted secrets file.
+# Instead, either read values from the environment.
+# Or, use `bin/rails secrets:setup` to configure encrypted secrets
+# and move the `production:` environment over there.
+
+production:
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
diff --git a/config/spring.rb b/config/spring.rb
new file mode 100644
index 0000000000..c9119b40c0
--- /dev/null
+++ b/config/spring.rb
@@ -0,0 +1,6 @@
+%w(
+ .ruby-version
+ .rbenv-vars
+ tmp/restart.txt
+ tmp/caching-dev.txt
+).each { |path| Spring.watch(path) }
diff --git a/db/media_seeds.csv b/db/media_seeds.csv
index b5101408d0..305f8609a7 100644
--- a/db/media_seeds.csv
+++ b/db/media_seeds.csv
@@ -1,27 +1,44 @@
-category,title,creator,publication_year,description
-album,Can't Buy a Thrill,Steely Dan,1972,
-album,Countdown to Ecstasy,Steely Dan,1973,
-album,Pretzel Logic,Steely Dan,1974,
-album,Katy Lied,Steely Dan,1975,
-album,The Royal Scam,Steely Dan,1976,
-album,Aja,Steely Dan,1977,
-album,Gaucho,Steely Dan,1980,
-album,Silence Yourself,Savages,2013,
-album,Adore Life,Savages,2016,
-album,NVM,Tacocat,2014,
-album,Lost Time,Tacocat,2016,
-album,No Regrets,Chastity Belt,2013,
-album,Time to Go Home,Chastity Belt,2015,
-album,Sleater-Kinney,Sleater-Kinney,1995,
-album,Call the Doctor,Sleater-Kinney,1996,
-album,Dig Me Out,Sleater-Kinney,1997,
-album,The Hot Rock,Sleater-Kinney,1999,
-album,All Hands on the Bad One,Sleater-Kinney,2000,
-album,One Beat,Sleater-Kinney,2002,
-album,The Woods,Sleater-Kinney,2005,
-album,No Cities to Love,Sleater-Kinney,2015,
+media_type,title,creator,pub_yr,description
+music,Can't Buy a Thrill,Steely Dan,1972,
+music,Countdown to Ecstasy,Steely Dan,1973,
+music,Pretzel Logic,Steely Dan,1974,
+music,Katy Lied,Steely Dan,1975,
+music,The Royal Scam,Steely Dan,1976,
+music,Aja,Steely Dan,1977,
+music,Gaucho,Steely Dan,1980,
+music,Silence Yourself,Savages,2013,
+music,Adore Life,Savages,2016,
+music,NVM,Tacocat,2014,
+music,Lost Time,Tacocat,2016,
+music,No Regrets,Chastity Belt,2013,
+music,Time to Go Home,Chastity Belt,2015,
+music,Sleater-Kinney,Sleater-Kinney,1995,
+music,Call the Doctor,Sleater-Kinney,1996,
+music,Dig Me Out,Sleater-Kinney,1997,
+music,The Hot Rock,Sleater-Kinney,1999,
+music,All Hands on the Bad One,Sleater-Kinney,2000,
+music,One Beat,Sleater-Kinney,2002,
+music,The Woods,Sleater-Kinney,2005,
+music,No Cities to Love,Sleater-Kinney,2015,
book,Hidden Figures,Margot Lee Shetterly,2016,Good book that came before the movie
book,Practical Object-Oriented Design in Ruby,Sandi Metz,2012,Good programming book
book,Kindred,Octavia E. Butler,1979,Good sci-fi book
book,Parable of the Sower,Octavia E. Butler,1993,
-book,A Wizard of Earthsea,Ursula K. Leguin,1968,
\ No newline at end of file
+book,A Wizard of Earthsea,Ursula K. Leguin,1968,
+music, Help, The Beatles, 1965,
+music, Hey You, Pink Floyd, 1979,
+music, Mack the Knife, Bobby Darin, 1959,
+music, Like a Rolling Stone, Bob Dylan, 1965,
+music, Keep Ya Head Up, Tupak Shakur, 1993,
+music, Riders on the Storm, The Doors, 1971,
+music, Somebody to Love, Jefferson Airplane, 1967,
+music, Purple Haze, Jimi Hendrix, 1967,
+movie, The Shawshank Redemption, Frank Darabont , 1994,
+movie, The Godfather, Francis Ford Coppola, 1972,
+movie, Schindler's List, Steven Spielberg, 1993,
+movie, Pulp Fiction,Quentin Tarantino, 1994,
+movie, The Good the Bad and the Ugly, Sergio Leone, 1966,
+movie, Fight Club , David Fincher, 1999,
+movie, The Lord of the Rings: The Fellowship of the Ring, Peter Jackson, 2001,
+movie, Forrest Gump,Robert Zemeckis, 1994,
+movie, Star Wars: Episode V - The Empire Strikes Back, Irvin Kershner, 1980
diff --git a/db/migrate/20171010222606_create_media_instances.rb b/db/migrate/20171010222606_create_media_instances.rb
new file mode 100644
index 0000000000..4629425838
--- /dev/null
+++ b/db/migrate/20171010222606_create_media_instances.rb
@@ -0,0 +1,13 @@
+class CreateMediaInstances < ActiveRecord::Migration[5.1]
+ def change
+ create_table :media_instances do |t|
+ t.string :media_type
+ t.string :title
+ t.string :creator
+ t.integer :pub_yr
+ t.string :description
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20171010223933_create_users.rb b/db/migrate/20171010223933_create_users.rb
new file mode 100644
index 0000000000..e8018b0a99
--- /dev/null
+++ b/db/migrate/20171010223933_create_users.rb
@@ -0,0 +1,10 @@
+class CreateUsers < ActiveRecord::Migration[5.1]
+ def change
+ create_table :users do |t|
+ t.string :name
+ t.string :email
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20171010224118_create_votes.rb b/db/migrate/20171010224118_create_votes.rb
new file mode 100644
index 0000000000..9ee05c2cda
--- /dev/null
+++ b/db/migrate/20171010224118_create_votes.rb
@@ -0,0 +1,10 @@
+class CreateVotes < ActiveRecord::Migration[5.1]
+ def change
+ create_table :votes do |t|
+ t.references :user, foreign_key: true
+ t.references :media_instance, foreign_key: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20171028232659_add_oauth_uid_and_provider.rb b/db/migrate/20171028232659_add_oauth_uid_and_provider.rb
new file mode 100644
index 0000000000..f367792149
--- /dev/null
+++ b/db/migrate/20171028232659_add_oauth_uid_and_provider.rb
@@ -0,0 +1,6 @@
+class AddOauthUidAndProvider < ActiveRecord::Migration[5.1]
+ def change
+ add_column :users, :oauth_uid, :string
+ add_column :users, :oauth_provider, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 0000000000..a396cab1d1
--- /dev/null
+++ b/db/schema.rb
@@ -0,0 +1,48 @@
+# 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: 20171028232659) do
+
+ # These are extensions that must be enabled in order to support this database
+ enable_extension "plpgsql"
+
+ create_table "media_instances", force: :cascade do |t|
+ t.string "media_type"
+ t.string "title"
+ t.string "creator"
+ t.integer "pub_yr"
+ t.string "description"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "users", force: :cascade do |t|
+ t.string "name"
+ t.string "email"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "oauth_uid"
+ t.string "oauth_provider"
+ end
+
+ create_table "votes", force: :cascade do |t|
+ t.bigint "user_id"
+ t.bigint "media_instance_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["media_instance_id"], name: "index_votes_on_media_instance_id"
+ t.index ["user_id"], name: "index_votes_on_user_id"
+ end
+
+ add_foreign_key "votes", "media_instances"
+ add_foreign_key "votes", "users"
+end
diff --git a/db/seeds.rb b/db/seeds.rb
new file mode 100644
index 0000000000..eec93f41ef
--- /dev/null
+++ b/db/seeds.rb
@@ -0,0 +1,15 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
+#
+# Examples:
+#
+# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
+# Character.create(name: 'Luke', movie: movies.first)
+require 'csv'
+media_file = Rails.root.join('db', 'media_seeds.csv')
+
+CSV.foreach(media_file, headers: true, header_converters: :symbol, converters: :all) do |row|
+ data = Hash[row.headers.zip(row.fields)]
+ puts data
+ MediaInstance.create!(data)
+end
diff --git a/lib/assets/.keep b/lib/assets/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/lib/tasks/.keep b/lib/tasks/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/log/.keep b/log/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/package.json b/package.json
new file mode 100644
index 0000000000..625900f9d8
--- /dev/null
+++ b/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "MediaRanker",
+ "private": true,
+ "dependencies": {}
+}
diff --git a/public/404.html b/public/404.html
new file mode 100644
index 0000000000..2be3af26fc
--- /dev/null
+++ b/public/404.html
@@ -0,0 +1,67 @@
+
+
+
+ The page you were looking for doesn't exist (404)
+
+
+
+
+
+
+
+
+
The page you were looking for doesn't exist.
+
You may have mistyped the address or the page may have moved.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/422.html b/public/422.html
new file mode 100644
index 0000000000..c08eac0d1d
--- /dev/null
+++ b/public/422.html
@@ -0,0 +1,67 @@
+
+
+
+ The change you wanted was rejected (422)
+
+
+
+
+
+
+
+
+
The change you wanted was rejected.
+
Maybe you tried to change something you didn't have access to.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/500.html b/public/500.html
new file mode 100644
index 0000000000..78a030af22
--- /dev/null
+++ b/public/500.html
@@ -0,0 +1,66 @@
+
+
+
+ We're sorry, but something went wrong (500)
+
+
+
+
+
+
+
+
+
We're sorry, but something went wrong.
+
+
If you are the application owner check the logs for more information.
+
+
+
diff --git a/public/apple-touch-icon-precomposed.png b/public/apple-touch-icon-precomposed.png
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/favicon.ico b/public/favicon.ico
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/robots.txt b/public/robots.txt
new file mode 100644
index 0000000000..37b576a4a0
--- /dev/null
+++ b/public/robots.txt
@@ -0,0 +1 @@
+# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb
new file mode 100644
index 0000000000..d19212abd5
--- /dev/null
+++ b/test/application_system_test_case.rb
@@ -0,0 +1,5 @@
+require "test_helper"
+
+class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
+ driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
+end
diff --git a/test/controllers/.keep b/test/controllers/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/controllers/main_controller_test.rb b/test/controllers/main_controller_test.rb
new file mode 100644
index 0000000000..33c8140433
--- /dev/null
+++ b/test/controllers/main_controller_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+describe MainController do
+ # it "must be a real test" do
+ # flunk "Need real tests"
+ # end
+end
diff --git a/test/controllers/media_instances_controller_test.rb b/test/controllers/media_instances_controller_test.rb
new file mode 100644
index 0000000000..a537815576
--- /dev/null
+++ b/test/controllers/media_instances_controller_test.rb
@@ -0,0 +1,245 @@
+require "test_helper"
+
+describe "MediaInstancesController" do
+ # it "must be a real test" do
+ # flunk "Need real tests"
+ # end
+ describe "index" do
+ it "returns a success status for all media_instances" do
+ get media_instances_path :media_type => "music"
+ must_respond_with :success
+ end
+
+ it "returns a success status when there are no media_instances" do
+ MediaInstance.destroy_all
+
+ get media_instances_path :media_type => "music"
+ must_respond_with :success
+ end
+
+ it "returns a success status when given a valid user_id and media_type" do
+ get media_instance_path(:id => MediaInstance.first.id, :media_type =>MediaInstance.first.media_type)
+ must_respond_with :success
+ end
+
+ it "returns something when given a bogus user_id" do
+ bad_user_id = User.last.id + 1
+ get media_instances_path(id: bad_user_id, media_type: "book")
+ must_respond_with :not_found
+ end
+ end
+
+ describe "new" do
+ it "works with an user id" do
+ binding.pry
+ get new_media_instance_path({title: "The Giver", media_type: "book", user: User.first.id})
+ must_respond_with :success
+ end
+
+ it "works without an user id" do
+ get new_media_instance_path({title: "The Giver", media_type: "book"})
+ must_respond_with :success
+ end
+ end
+
+ describe "create" do
+ it "adds the media_instance to the DB and redirects when the media_instance data is valid" do
+ # Arrange
+ media_instance_data = {
+ media_instance: {
+ media_type: "Test media_instance",
+ title: "a title"
+ }
+ }
+
+ # Test data should result in a valid media_instance, otherwise
+ # the test is broken
+
+ MediaInstance.new(media_instance_data[:media_instance]).must_be :valid?
+ start_media_instance_count = MediaInstance.count
+
+
+ # Act
+ post media_instances_path, params: media_instance_data
+
+ # Assert
+ must_respond_with :redirect
+ must_redirect_to media_instances_path
+
+ MediaInstance.count.must_equal start_media_instance_count + 1
+ end
+
+ it "sends bad_request when the media_instance data is bogus" do
+ # Arrange
+ invalid_media_instance_data = {
+ media_instance: {
+ media_type: "book",
+ # NO TITLE!!!
+ user_id: User.first.id
+ }
+ }
+ # Double check the data is truly invalid
+ MediaInstance.new(invalid_media_instance_data[:media_instance]).wont_be :valid?
+
+ start_media_instance_count = MediaInstance.count
+
+ # Act
+ post media_instances_path, params: invalid_media_instance_data
+
+ # Assert
+ must_respond_with :bad_request
+ # Vanilla rails doesn't provide any way to do this
+ # assert_template :new
+ MediaInstance.count.must_equal start_media_instance_count
+ end
+ end
+
+ describe "show" do
+ it "returns success when given a valid media_instance ID" do
+ # Arrange
+ media_instance_id = MediaInstance.first.id
+
+ # Act
+ get media_instance_path(:id => media_instance_id, :media_type => "book")
+
+ # Assert
+ must_respond_with :success
+ end
+
+ it "returns not_found when given an invalid media_instance ID" do
+ invalid_media_instance_id = MediaInstance.last.id + 1
+ get media_instance_path(:id => invalid_media_instance_id, :media_type => "book")
+ must_respond_with :not_found
+ end
+ end
+
+ describe "edit" do
+ it "returns success when given a valid media_instance ID" do
+ # Arrange
+ media_instance_id = MediaInstance.first.id
+ # media_instance_type = MediaInstance.first.media_type
+# binding.pry
+
+ # Act
+ get edit_media_instance_path(:id => media_instance_id, :media_type => "book")
+
+ # Assert
+ must_respond_with :success
+ end
+
+ it "returns not_found when given an invalid media_instance ID" do
+ invalid_media_instance_id = MediaInstance.last.id + 1
+ get edit_media_instance_path(:id => invalid_media_instance_id, :media_type => "book")
+ must_respond_with :not_found
+ end
+ end
+
+ describe "update" do
+ it "returns success if the media_instance ID is valid and the change is valid" do
+ media_instance = MediaInstance.first
+ media_instance_data = {
+ media_instance: {
+ title: "Changed title",
+ media_type: "book",
+ user_id: media_instance.user_id
+ }
+ }
+ media_instance.update_attributes(media_instance_data[:media_instance])
+ media_instance.must_be :valid?
+
+ patch media_instance_path(id: media_instance, media_type: media_instance.media_type), params: media_instance_data
+
+ must_respond_with :redirect
+ must_redirect_to media_instance_path(media_instance)
+
+ # Check that the change went through
+ media_instance.reload
+ media_instance.title.must_equal media_instance_data[:media_instance][:title]
+ end
+
+ it "returns not_found if the media_instance ID is invalid" do
+ invalid_media_instance_id = MediaInstance.last.id + 1
+ media_instance_data = {
+ media_instance: {
+ title: "Changed title",
+ media_type: "book",
+ user_id: User.first.id
+ }
+ }
+
+ patch media_instance_path(invalid_media_instance_id, media_instance_data[:media_instance][:media_type]), params: media_instance_data
+
+ must_respond_with :not_found
+ end
+
+ it "returns bad_request if the change is invalid" do
+ media_instance = MediaInstance.first
+ invalid_media_instance_data = {
+ media_instance: {
+ title: ""
+ }
+ }
+ # Check that the update is actually invalid
+ media_instance.update_attributes(invalid_media_instance_data[:media_instance])
+ media_instance.wont_be :valid?
+
+ patch media_instance_path(media_instance, media_type: "book"), params: invalid_media_instance_data
+
+ must_respond_with :bad_request
+
+ media_instance.reload
+ media_instance.title.wont_equal invalid_media_instance_data[:media_instance][:title]
+ end
+ end
+
+ describe "destroy" do
+ it "returns success and destroys the media_instance when given a valid media_instance ID" do
+ # Arrange
+ media_instance_id = MediaInstance.first.id
+ media_instance_type = MediaInstance.first.media_type
+
+ # Act
+ delete media_instance_path(id: media_instance_id, media_type: media_instance_type)
+
+ # Assert
+ must_respond_with :redirect
+ must_redirect_to media_instances_path
+ media_instance.find_by(id: media_instance_id).must_be_nil
+ end
+
+ it "returns not_found when given an invalid media_instance ID" do
+ invalid_media_instance_id = MediaInstance.last.id + 1
+
+ start_media_instance_count = MediaInstance.count
+
+ delete media_instance_path(id: invalid_media_instance_id, media_type: "book")
+
+ must_respond_with :not_found
+ MediaInstance.count.must_equal start_media_instance_count
+ end
+ end
+
+ describe "get movies" do
+ it "works" do
+ get movies_path
+ must_respond_with :success
+ end
+ it "gives instances of movies" do
+ get movies_path
+ @movies
+ end
+ end
+
+ describe "get books" do
+ it "gives instances of books" do
+
+ end
+
+ end
+ describe "get music" do
+ it "gives instances of music" do
+
+ end
+ end
+
+end
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb
new file mode 100644
index 0000000000..c7c49c917f
--- /dev/null
+++ b/test/controllers/users_controller_test.rb
@@ -0,0 +1,156 @@
+require "test_helper"
+
+describe UsersController do
+
+ # describe "new" do
+ # it "works" do
+ # user = {
+ # user: {
+ # oauth_provider: "github",
+ # oauth_uid: "4883904",
+ # email: "some@somesite.com",
+ # name: "Someone"
+ # }
+ # }
+ # start_count = User.all.count
+ # User.new(user[:user]).must_be :valid?
+ # get new_user_path, params: user
+ # binding.pry
+ # flash[:status].must_equal :success
+ # flash[:message].must_include "Successfully created user"
+ # must_respond_with :redirect
+ # must_redirect_to root_path
+ # User.all.count.must_equal start_count + 1
+ # end
+ # end
+
+ describe "create" do
+ it "works" do
+ user = {
+ user: {
+ oauth_provider: "github",
+ oauth_uid: "4883904",
+ email: "some@somesite.com",
+ name: "Someone"
+ }
+ }
+ start_count = User.all.count
+ User.new(user[:user]).must_be :valid?
+ post users_path, params: user
+ flash[:status].must_equal :success
+ flash[:message].must_include "Successfully created user"
+ must_respond_with :redirect
+ must_redirect_to root_path
+ User.all.count.must_equal start_count + 1
+ end
+
+
+ it "re-renders form when the user data is invalid" do
+ user = {
+ user: {
+ oauth_provider: "github",
+ oauth_uid: "",
+ email: "somebodyelse@somesite.com",
+ name: "Somebody_else"
+ }
+ }
+ User.new(user[:user]).wont_be :valid?
+ start_count = User.count
+
+ post users_path, params: user
+
+ must_respond_with :bad_request
+ User.count.must_equal start_count
+ end
+ end
+
+ describe "update" do
+
+ it "returns success if the user ID is valid and the change is valid" do
+ user = User.first
+ user_data = {
+ user: {
+ name: "changed username",
+ email: user.email
+ }
+ }
+ user.update_attributes(user_data[:user])
+ user.must_be :valid?, "Test is invalid because the provided data will produce an invalid user"
+
+ patch user_path(user), params: user_data
+
+ must_respond_with :redirect
+ must_redirect_to root_path
+
+ # Check that the change went through
+ user.reload
+ user.name.must_equal user_data[:user][:name]
+ end
+ end
+
+
+ describe "edit" do
+ it "succeeds for an extant user ID" do
+ get edit_user_path(User.first)
+ must_respond_with :success
+ end
+ it "renders 404 not_found for a bogus user ID" do
+ bogus_user_id = User.last.id + 1
+ get edit_user_path(bogus_user_id)
+ must_respond_with :not_found
+ end
+ end
+
+ describe "logout" do
+ it "works" do
+ login_test_user
+ get logout_path
+ session[:user].must_equal nil
+ must_redirect_to root_path
+ end
+
+ end
+
+ describe "login" do
+ it "logs in an existing user and redirects to the root route" do
+ start_count = User.all.count
+
+ user = users(:one)
+ OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user))
+
+ get login_path(:github)
+
+ must_redirect_to root_path
+
+ session[:user][:id].must_equal user.id
+
+ User.all.count.must_equal start_count
+ end
+
+ it "creates new user with new info" do
+
+ start_count = User.all.count
+ new_user = User.new(oauth_provider: 'github',oauth_uid: "adlgkcl",email: 'mail@mail.com', name: 'Mr. New')
+ OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(new_user))
+ get login_path(:github)
+ must_redirect_to root_path
+ User.count.must_equal start_count + 1
+ session[:user][:id].must_equal User.last.id
+ # flash[:result_text].must_equal "Successfully created new user "
+ # flash[:status].must_equal :success
+ end
+
+ it "generates failure with no info" do
+ start_count = User.all.count
+ OmniAuth.config.mock_auth[:github] = nil
+ get login_path(:github)
+ User.count.must_equal start_count
+ flash[:result_text].must_equal "Not logged in"
+ flash[:status].must_equal :failure
+ flash[:messages].must_include :email
+ flash[:messages].must_include :name
+ must_redirect_to root_path
+ end
+ end
+
+end
diff --git a/test/controllers/votes_controller_test.rb b/test/controllers/votes_controller_test.rb
new file mode 100644
index 0000000000..cf4d03935f
--- /dev/null
+++ b/test/controllers/votes_controller_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+describe VotesController do
+ # it "must be a real test" do
+ # flunk "Need real tests"
+ # end
+end
diff --git a/test/fixtures/.keep b/test/fixtures/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/fixtures/media_instances.yml b/test/fixtures/media_instances.yml
new file mode 100644
index 0000000000..67bfe75a62
--- /dev/null
+++ b/test/fixtures/media_instances.yml
@@ -0,0 +1,15 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ media_type: music
+ title: MyString
+ creator: MyString
+ pub_yr: 1986
+ description: MyString
+
+two:
+ media_type: book
+ title: MyString
+ creator: MyString
+ pub_yr: 1873
+ description: MyString
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
new file mode 100644
index 0000000000..1af93e4a6a
--- /dev/null
+++ b/test/fixtures/users.yml
@@ -0,0 +1,13 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ name: name one
+ email: MyString_one@mystring.com
+ oauth_uid: 1
+ oauth_provider: github
+
+two:
+ name: name two
+ email: MyString_two@mystring.com
+ oauth_uid: 2
+ oauth_provider: github
diff --git a/test/fixtures/votes.yml b/test/fixtures/votes.yml
new file mode 100644
index 0000000000..b14d84bd6d
--- /dev/null
+++ b/test/fixtures/votes.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ user: one
+ media_instance: one
+
+two:
+ user: two
+ media_instance: two
diff --git a/test/helpers/.keep b/test/helpers/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/integration/.keep b/test/integration/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/mailers/.keep b/test/mailers/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/models/.keep b/test/models/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/models/media_instance_test.rb b/test/models/media_instance_test.rb
new file mode 100644
index 0000000000..22c39b3fce
--- /dev/null
+++ b/test/models/media_instance_test.rb
@@ -0,0 +1,44 @@
+require "test_helper"
+
+describe MediaInstance do
+ describe "validations" do
+ let(:media_instance) { MediaInstance.new }
+ it "must reject if there is no title" do
+ media_instance.errors.messages.include? :title
+ end
+ it "must reject if there is no media type" do
+ media_instance.errors.messages.include? :media_type
+ end
+
+ it "must be valid" do
+ media_instances(:one).must_be :valid?
+ end
+ end
+
+ describe "relationships" do
+ it "must_respond_to votes" do
+ media_instances(:one).must_respond_to :votes
+ end
+ end
+
+ describe "ten_by_type" do
+ it "must be an array" do
+ example = MediaInstance.ten_by_type("music")
+ example.must_be_kind_of Array
+ end
+
+ it "must be an array of media instances" do
+ example = MediaInstance.ten_by_type("music")
+ example.each do |model|
+ model.must_be_kind_of MediaInstance
+ end
+ end
+
+ it "must get the correct media type" do
+ example = MediaInstance.ten_by_type("Music")
+ example.each do |model|
+ model.media_type.must_equal "music"
+ end
+ end
+ end
+end
diff --git a/test/models/user_test.rb b/test/models/user_test.rb
new file mode 100644
index 0000000000..b985dc3cdf
--- /dev/null
+++ b/test/models/user_test.rb
@@ -0,0 +1,90 @@
+require "test_helper"
+
+describe User do
+ describe "validations" do
+ let(:user) { User.new }
+
+ it "must be valid with correct validations" do
+ users(:one).must_be :valid?
+ users(:one).must_be_kind_of User
+ end
+
+ it "must only accept a user with email formatting" do
+ g = User.new(name: "Joe", email: "an email", oauth_uid: "4", oauth_provider: "github")
+ start_count = User.all.length
+ g.wont_be :valid?
+ g.errors.messages.must_include :email
+ g[:email] = "joeschmoe@somemail.com"
+ g.must_be :valid?
+ g.save
+ start_count.must_equal User.all.length - 1
+ end
+
+ it "requires the user to have oauth information" do
+ g = User.new(name: "Mary", email: "eeeee@mail.com")
+ start_count = User.all.length
+ g.wont_be :valid?
+ g.errors.messages.must_include :oauth_uid
+ g.errors.messages.must_include :oauth_provider
+
+ g[:oauth_uid] = "557"
+ g[:oauth_provider] = "github"
+ g.must_be :valid?
+ g.save
+
+ start_count.must_equal User.all.length - 1
+ end
+ end
+
+ describe "relationships" do
+ it "has many votes" do
+ one = users(:one)
+ one.must_respond_to :votes
+ one.votes.each do |vote|
+ vote.must_be_kind_of Vote
+ end
+ end
+ end
+
+ describe "self.by_auth_hash(auth_hash)" do
+ it "has an instance of user" do
+ auth_hash = {
+ 'provider' => "github",
+ 'uid' => "12345",
+ 'info' => {'email' => "somebody@somesite.com",
+ 'nickname' => "Somebody"}
+ }
+ user_auth = User.by_auth_hash auth_hash
+ user_auth.must_be_kind_of User
+ end
+
+ it "responds to the proper keys" do
+ auth_hash = {
+ 'provider' => "github",
+ 'uid' => "12345",
+ 'info' => {'email' => "somebody@somesite.com",
+ 'nickname' => "Somebody"}
+ }
+ user_auth = User.by_auth_hash auth_hash
+ user_auth.must_respond_to :oauth_provider
+ user_auth.must_respond_to :oauth_uid
+ user_auth.must_respond_to :email
+ user_auth.must_respond_to :name
+ end
+
+ it "has the correct values for user from auth_hash" do
+ auth_hash = {
+ 'provider' => "github",
+ 'uid' => "12345",
+ 'info' => {'email' => "somebody@somesite.com",
+ 'nickname' => "Somebody"}
+ }
+ user_auth = User.by_auth_hash auth_hash
+ user_auth.oauth_provider.must_equal "github"
+ user_auth.oauth_uid.must_equal "12345"
+ user_auth.email.must_equal "somebody@somesite.com"
+ user_auth.name.must_equal "Somebody"
+ end
+ end
+
+end
diff --git a/test/models/vote_test.rb b/test/models/vote_test.rb
new file mode 100644
index 0000000000..2c007a9ac8
--- /dev/null
+++ b/test/models/vote_test.rb
@@ -0,0 +1,17 @@
+require "test_helper"
+
+describe Vote do
+ let(:vote) { Vote.new }
+
+ it "will not be valid if the proper information isn't given" do
+ vote.wont_be :valid?
+ end
+ it "will give an error message for not having media_instance_id nor user_id" do
+ vote.errors.messages.include? :media_instance_id
+ vote.errors.messages.include? :user_id
+ end
+
+ it "must be valid" do
+ votes(:one).must_be :valid?
+ end
+end
diff --git a/test/system/.keep b/test/system/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/test_helper.rb b/test/test_helper.rb
new file mode 100644
index 0000000000..51f19c5628
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,51 @@
+require 'simplecov'
+SimpleCov.start
+ENV["RAILS_ENV"] = "test"
+require File.expand_path("../../config/environment", __FILE__)
+require "rails/test_help"
+require "minitest/rails"
+require "minitest/reporters" # for Colorized output
+
+# For colorful output!
+Minitest::Reporters.use!(
+ Minitest::Reporters::SpecReporter.new,
+ ENV,
+ Minitest.backtrace_filter
+)
+
+
+# To add Capybara feature tests add `gem "minitest-rails-capybara"`
+# to the test group in the Gemfile and uncomment the following:
+# require "minitest/rails/capybara"
+
+# Uncomment for awesome colorful output
+# require "minitest/pride"
+
+class ActiveSupport::TestCase
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
+ fixtures :all
+ def setup
+ # Once you have enabled test mode, all requests
+ # to OmniAuth will be short circuited to use the mock authentication hash.
+ # A request to /auth/provider will redirect immediately to /auth/provider/callback.
+ OmniAuth.config.test_mode = true
+ end
+
+ def mock_auth_hash(user)
+ return {
+ provider: user.oauth_provider,
+ uid: user.oauth_uid,
+ info: {
+ email: user.email,
+ nickname: user.name
+ }
+ }
+ end
+
+ def login_test_user
+ user = users(:one)
+ OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(user))
+ get login_path(:github)
+ end
+ # Add more helper methods to be used by all tests here...
+end
diff --git a/tmp/.keep b/tmp/.keep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/vendor/.keep b/vendor/.keep
new file mode 100644
index 0000000000..e69de29bb2