+
+
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/users_controller_test.rb b/test/controllers/users_controller_test.rb
new file mode 100644
index 0000000000..3d861f2524
--- /dev/null
+++ b/test/controllers/users_controller_test.rb
@@ -0,0 +1,42 @@
+require "test_helper"
+
+describe UsersController do
+ describe "index" do
+ it "returns a success status" do
+ get users_path
+ must_respond_with :success
+ end
+
+ it "returns a success status when there are no users" do
+ User.destroy_all
+ get users_path
+ must_respond_with :success
+ end
+ end
+
+ describe "show" do
+ it "returns a success status when an existing user is selected" do
+ get user_path(User.first.id)
+ must_respond_with :success
+ end
+
+ it "returns an error message when given a bogus User id" do
+ get user_path(User.last.id + 1)
+ must_respond_with :not_found
+ end
+ end
+
+ #THis test won't work... doesn't recognize login as a method?!
+ # describe "login" do
+ # u = User.create!(name: "someone")
+ # user_data = {
+ # user: {
+ # name: u.name
+ # }
+ # }
+ # login
+ #
+ # must_redirect_to root_path
+ # must_respond_with :success
+ # end
+end
diff --git a/test/controllers/votes_controller_test.rb b/test/controllers/votes_controller_test.rb
new file mode 100644
index 0000000000..a91f8c8762
--- /dev/null
+++ b/test/controllers/votes_controller_test.rb
@@ -0,0 +1,41 @@
+require "test_helper"
+
+describe VotesController do
+ describe "new" do
+ it "returns a success status" do
+ get new_vote_path
+ must_respond_with :success
+ end
+ end
+
+ describe "create" do
+ it "adds the vote to the database when data given is valid" do
+ start_count = Vote.count
+ # u = User.create!(name: "someone")
+ u = users(:kamron)
+ # user_data = {
+ # user: {
+ # name: u.name
+ # }
+ # }
+ # u.login
+
+ vote_data = {
+ vote: {
+ user_id: u.id,
+ work_id: Work.first.id
+ }
+ }
+ # visit works_path
+ vote = Vote.new(vote_data[:vote]).must_be :valid?
+
+ #These tests don't work because I am redirecting to the page the user is on, and I do not know how to specify that in the test
+
+ post votes_path, params: vote_data
+ # must_respond_with :redirect
+ # must_redirect_to works_path
+ Vote.count.must_equal (start_count + 1)
+ end
+ end
+
+end
diff --git a/test/controllers/works_controller_test.rb b/test/controllers/works_controller_test.rb
new file mode 100644
index 0000000000..3766b049cc
--- /dev/null
+++ b/test/controllers/works_controller_test.rb
@@ -0,0 +1,167 @@
+require "test_helper"
+
+describe WorksController do
+ describe "index" do
+ it "returns a success status" do
+ get works_path
+ must_respond_with :success
+ end
+ end
+
+ describe "show" do
+ it "returns a success status when an existing work is selected" do
+ get work_path(Work.first)
+ must_respond_with :success
+ end
+
+ it "returns an error message when given a bogus work id" do
+ get work_path(Work.last.id + 1)
+ must_respond_with :not_found
+ end
+
+ it "returns a success status when there are no works" do
+ Work.destroy_all
+ get works_path
+ must_respond_with :success
+ end
+ end
+
+#failing to add the book to the database, why? Think I don't understand the test well rather than method not working.
+ describe "create" do
+ it "adds the Work to the database when data given is valid and redirects to Work#Index once done" do
+ start_count = Work.all.count
+ work_data = {
+ work: {
+ title: "this is a test",
+ category: "album",
+ creator: "Nobody"
+ }
+ }
+ Work.new(work_data[:work]).must_be :valid?
+
+
+ post works_path, params: work_data
+ must_respond_with :redirect
+ must_redirect_to works_path
+ Work.count.must_equal (start_count + 1)
+ end
+
+ it "if data given is invalid, it will render a new form and will not add the Work to the database" do
+ start_count = Work.all.count
+ invalid_work_data = {
+ work: {
+ #NO TITLE
+ category: "album"
+ }
+ }
+ Work.new(invalid_work_data[:work]).wont_be :valid?
+ post works_path, params: invalid_work_data
+ must_respond_with :bad_request
+
+ start_count.must_equal Work.all.count
+ end
+ end
+
+ describe "new" do
+ it "returns a success status" do
+ get new_work_path
+ must_respond_with :success
+ end
+ end
+
+ describe "edit" do
+ it "returns a success status when given a valid Work id" do
+ work = works(:cat_stevens)
+ get work_path(work)
+ must_respond_with :success
+ end
+
+ it "returns an error message when given a bogus work id" do
+ get work_path(Work.last.id + 1)
+ must_respond_with :not_found
+ end
+ end
+
+ describe "update" do
+ it "returns success if Work exists, change is valid, and db updated" do
+ work = Work.first
+
+ work_data = {
+ work: {
+ title: work.title,
+ category: work.category,
+ description: "changed description"
+ }
+ }
+
+ work.update_attributes(work_data[:work])
+ work.must_be :valid?, "Test is invalid because the provided data will produce an invalid work."
+
+ patch work_path(work), params: work_data
+ must_respond_with :redirect
+ must_redirect_to work_path(work)
+
+ #Check that the change went through
+ work.reload
+ work.title.must_equal work_data[:work][:title]
+ end
+
+ it "returns not_found if the work ID is invalid" do
+ invalid_work_id = Work.last.id + 1
+ work_data = {
+ work: {
+ title: "Title",
+ category: "book",
+ description: "changed description"
+ }
+ }
+ patch work_path(invalid_work_id), params: work_data
+ must_respond_with :not_found
+ end
+
+ it "returns bad_request if the change is invalid" do
+ work = Work.first
+ invalid_work_data = {
+ work: {
+ title: "",
+ category: "album"
+ }
+ }
+ # Check that the update is actually invalid
+ work.update_attributes(invalid_work_data[:work])
+ work.wont_be :valid?
+
+ patch work_path(work), params: invalid_work_data
+
+ must_respond_with :bad_request
+
+ work.reload
+ work.title.wont_equal invalid_work_data[:work][:title]
+ end
+
+ end
+
+ describe "destroy" do
+ it "returns success and destroys the work when given a valid work ID" do
+ work_id = Work.first.id
+
+ delete work_path(work_id)
+
+ must_respond_with :redirect
+ must_redirect_to works_path
+ Work.find_by(id: work_id).must_be_nil
+ end
+
+ it "returns not_found when given an invalid Work ID" do
+ invalid_work_id = Work.last.id + 1
+
+ start_work_count = Work.count
+
+ delete work_path(invalid_work_id)
+
+ must_respond_with :not_found
+ Work.count.must_equal start_work_count
+ end
+ 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/users.yml b/test/fixtures/users.yml
new file mode 100644
index 0000000000..526d3dd8f8
--- /dev/null
+++ b/test/fixtures/users.yml
@@ -0,0 +1,11 @@
+tanja:
+ name: Tanja
+kim:
+ name: Kim
+bianca:
+ name: Bianca
+dario:
+ name: Dario
+kamron:
+ name: Kamron
+
diff --git a/test/fixtures/votes.yml b/test/fixtures/votes.yml
new file mode 100644
index 0000000000..96ed9f55a5
--- /dev/null
+++ b/test/fixtures/votes.yml
@@ -0,0 +1,22 @@
+#albums
+vote1:
+ user: tanja
+ work: cat_stevens
+vote2:
+ user: kim
+ work: cat_stevens
+vote3:
+ user: dario
+ work: cat_stevens
+vote4:
+ user: bianca
+ work: cat_stevens
+vote5:
+ user: kim
+ work: florence
+vote6:
+ user: dario
+ work: florence
+vote7:
+ user: bianca
+ work: all_good
diff --git a/test/fixtures/works.yml b/test/fixtures/works.yml
new file mode 100644
index 0000000000..474a1b4cb7
--- /dev/null
+++ b/test/fixtures/works.yml
@@ -0,0 +1,68 @@
+#BOOKS
+poodr:
+ title: POODR
+ category: book
+ publication_year: 2000
+ creator: Sandi Metz
+ description: org your code
+
+winnie:
+ title: Winnie the Pooh
+ category: book
+ publication_year: 1891
+ creator: Christopher Robbin
+ description: fantastic adventures and philosophy
+
+nineteen_eighty_four:
+ title: "1984"
+ category: book
+ publication_year: 1950
+ creator: George Orwell
+ description: The future is here
+
+hitchhiker:
+ title: Hitchhiker's Guide
+ category: book
+ publication_year: 1980
+ creator: Douglas Adams
+ description: Guide to life, the universe, and really everything.
+
+#END OF BOOKS
+
+#ALBUMS
+cat_stevens:
+ title: Cats in the Cradle
+ category: album
+ publication_year: 1970
+ creator: Cat Stevens
+ description: great album
+
+all_good:
+ title: All Good
+ category: album
+ publication_year: 1979
+ creator: Beatles
+ description: wonderful
+
+florence:
+ title: Florence and the Machine
+ category: album
+ publication_year: 2017
+ creator: Florence
+ description: love it
+#End of ALBUMS
+
+#Movies
+wonder_woman:
+ title: Wonder Woman
+ category: movie
+ publication_year: 2017
+ creator: Jane Doe
+ description: awesome
+
+sound_of_music:
+ title: The Sound of Music
+ category: movie
+ publication_year: 1960
+ creator: Marry Poppins
+ description: lovely musical
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/user_test.rb b/test/models/user_test.rb
new file mode 100644
index 0000000000..d11f26824d
--- /dev/null
+++ b/test/models/user_test.rb
@@ -0,0 +1,26 @@
+require "test_helper"
+
+describe User do
+ describe "validations" do
+ it "can be created with a name" do
+ u = User.new(name: "Tanja")
+ u.valid?.must_equal true
+ end
+
+ it "must have a name" do
+ u = User.new
+ u.valid?.must_equal false
+ end
+ end
+
+ describe "relationships" do
+ it "can access votes" do
+ u = User.new(name: "Jones")
+ u.votes.count.must_equal 0
+ end
+ end
+
+ it "can access fixtures" do
+ users(:tanja).wont_be_nil
+ end
+end
diff --git a/test/models/vote_test.rb b/test/models/vote_test.rb
new file mode 100644
index 0000000000..16674d1362
--- /dev/null
+++ b/test/models/vote_test.rb
@@ -0,0 +1,68 @@
+require "test_helper"
+require 'date'
+#
+# describe Vote do
+# let(:vote) { Vote.new }
+#
+# it "must be valid" do
+# value(vote).must_be :valid?
+# end
+# end
+
+describe Vote do
+ before do
+ @u = users(:tanja)
+ @w = works(:cat_stevens)
+ end
+
+ describe "validations" do
+
+ it "can be created with a name and work" do
+ v = Vote.new(user_id: @u.id, work_id: @w.id)
+ v.valid?.must_equal true
+ end
+
+ it "must have a user_id" do
+ v = Vote.new(work_id: @w.id)
+ v.valid?.must_equal false
+ end
+
+ it "must have a work_id" do
+ v = Vote.new(user_id: @u.id)
+ v.valid?.must_equal false
+ end
+ end
+
+ describe "fixtures" do
+ it "can access fixtures" do
+ votes(:vote1).wont_be_nil
+ end
+ end
+
+ describe "created at" do
+ it "records and reports the correct date vote made" do
+ new_user = User.create!(name: "patrick")
+ new_vote = Vote.create!(user_id: new_user.id, work_id: @w.id)
+ new_vote.valid?
+ new_vote.created_at.to_date.must_equal DateTime.now.utc.to_date
+ end
+end
+
+ describe "votes_by_user" do
+ it "gives a list of votes for only the user specified" do
+ Vote.votes_by_user(@u).count.must_equal 1
+ end
+ it "works when user has no votes" do
+ new_user = User.create!(name: "jack")
+ new_user.valid?
+ Vote.votes_by_user(new_user).count.must_equal 0
+ end
+ it "reports the correct work title" do
+ work_id = Vote.votes_by_user(@u)[0].work_id
+ work = Work.find_by(id: work_id)
+ work.title.must_equal "Cats in the Cradle"
+ end
+
+ end
+
+end
diff --git a/test/models/work_test.rb b/test/models/work_test.rb
new file mode 100644
index 0000000000..216a8989b0
--- /dev/null
+++ b/test/models/work_test.rb
@@ -0,0 +1,146 @@
+require "test_helper"
+
+describe Work do
+ describe "validations"do
+
+ it "can be created with all fields" do
+ a = Work.new(title: "Test Title", category: "movie", publication_year: 2000, description: "whatever")
+
+ a.must_be :valid?
+ end
+
+ it "requires a title" do
+ a = Work.new(category: "movie", publication_year: 2000, creator: "J J")
+ is_valid = a.valid?
+ is_valid.must_equal false
+ a.errors.messages.must_include :title
+ end
+
+ it "requires a category" do
+ a = Work.new(title: "Whoot?!", publication_year: 2000, creator: " J J")
+ is_valid = a.valid?
+ is_valid.must_equal false
+ a.errors.messages.must_include :category
+ end
+
+ it "won't allow a description longer than 500 characters" do
+ description = "*" * 501
+ b = Work.new(title: "Test Title", category: "movie", description: description, creator: "J J")
+ b.wont_be :valid?
+ b.errors.messages.must_include :description
+ end
+
+ it "will allow a description less than 500 characters" do
+ work = works(:poodr)
+ work.must_be :valid?
+ a = Work.new(title: "Test Title", category: "book", description: "T", creator: "B N")
+ a.must_be :valid?
+ end
+
+ it "will allow no description" do
+ a = Work.new(title: "Test Title", category: "book", creator: "NO One")
+ a.must_be :valid?
+ end
+
+ end
+
+ # describe "creator" do # not working and this should probably be in the controller tests
+ # it "will assign the Creator as 'unknown' if no input is given" do
+ # a = Work.new(title: "Test Title", category: "book")
+ # a.must_be :valid?
+ # a.creator.must_equal "Unknown"
+ # end
+ # end
+
+ describe "self.all_albums" do
+ it "will return a list of all works that are categorized as 'album'" do
+ Work.all_albums.count.must_equal 3
+ end
+
+ it "will not include any works that are not albums" do
+ Work.all_albums.find_by(category: "book").must_equal nil
+
+ Work.all_albums.find_by(category: "movie").must_equal nil
+ end
+ end
+
+ describe "self.all_books" do
+ it "will return a list of all works categorized as 'book'" do
+ Work.all_books.count.must_equal 4
+ end
+
+ it "will not include any works that are not books" do
+ Work.all_books.find_by(category: "album").must_equal nil
+
+ Work.all_books.find_by(category: "movie").must_equal nil
+ end
+ end
+
+ describe "self.all_movies" do
+ it "will return a list of all works categorized as 'movie'" do
+ Work.all_movies.count.must_equal 2
+ end
+
+ it "will not include any works that are not movies" do
+ Work.all_movies.find_by(category: "album").must_equal nil
+
+ Work.all_movies.find_by(category: "book").must_equal nil
+ end
+ end
+
+ describe "self.top_ten_albums" do
+ it "will return the number of albums if the count is 10 or less" do
+ Work.top_ten_albums.count.must_equal 3
+ end
+
+ it "will not return more than 10 items" do
+ title = "Test"
+ category = "album"
+ creator = "No one"
+ 10.times do
+ Work.create!(title: title, category: category, creator: creator)
+ end
+ Work.top_ten_albums.count.must_equal 10
+ end
+ end
+
+ describe "self.top_ten" do
+ it "returns the correct number of elements" do
+ Work.top_ten("book").count.must_equal 4
+ end
+
+ it "first element is the one with most number of votes" do
+ work = Work.create!(title: "Vote Test", category: "album", creator: "No name")
+ 10.times do
+ name = rand(0..200).to_s
+ user = User.create!(name: name)
+ Vote.create!(user: user, work: work)
+ end
+ Work.top_ten("album").first.must_equal work
+ end
+
+ it "returns the elements in the correct order" do
+ work1 = works(:cat_stevens)
+ work2 = works(:florence)
+ work3 = works(:all_good)
+
+ Work.top_ten("album").first.must_equal work1
+ Work.top_ten("album")[1].must_equal work2
+ Work.top_ten("album")[2].must_equal work3
+ end
+
+ it "returns an empty list if no elements are present" do
+ Work.destroy_all
+ Work.top_ten("album").must_equal []
+ end
+
+ end
+
+ describe "self.top" do
+ it "returns the Work with the most votes" do
+ top_work = works(:cat_stevens)
+ Work.top.must_equal top_work
+ end
+ 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..10594a3248
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,26 @@
+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
+ # 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