diff --git a/Gemfile b/Gemfile index fa992da0..cfab931f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,5 @@ source 'https://rubygems.org' -ruby '2.4.0' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") diff --git a/Gemfile.lock b/Gemfile.lock index ac73d272..76eb2ff8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GEM tzinfo (~> 1.1) ansi (1.5.0) arel (7.1.4) - autoprefixer-rails (8.2.0) + autoprefixer-rails (8.3.0) execjs babel-source (5.8.35) babel-transpiler (0.7.0) @@ -62,7 +62,7 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.0.5) - crass (1.0.3) + crass (1.0.4) erubi (1.7.1) erubis (2.7.0) execjs (2.7.0) @@ -117,7 +117,7 @@ GEM method_source (~> 0.9.0) pry-rails (0.3.6) pry (>= 0.10.4) - puma (3.11.3) + puma (3.11.4) rack (2.0.4) rack-test (0.6.3) rack (>= 1.0) @@ -175,14 +175,14 @@ GEM thor (0.20.0) thread_safe (0.3.6) tilt (2.0.8) - turbolinks (5.1.0) + turbolinks (5.1.1) turbolinks-source (~> 5.1) turbolinks-source (5.1.0) tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (4.1.8) + uglifier (4.1.9) execjs (>= 0.3.0, < 3) - web-console (3.5.1) + web-console (3.6.0) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) @@ -219,8 +219,5 @@ DEPENDENCIES uglifier (>= 1.3.0) web-console (>= 3.3.0) -RUBY VERSION - ruby 2.4.0p0 - BUNDLED WITH - 1.15.4 + 1.16.1 diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 5bce99e6..20667450 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -4,6 +4,7 @@ def login_form def login username = params[:username] + # binding.pry if username and user = User.find_by(username: username) session[:user_id] = user.id flash[:status] = :success diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index d2c5cfbb..64252ee0 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -1,5 +1,46 @@ require 'test_helper' describe UsersController do + describe 'Index' do + it "succeeds when there are users" do + # Act + get users_path + + # Assert + must_respond_with :success + end + it "succeeds when there are no users" do + # Arrange + Work.destroy_all + User.destroy_all + assert User.all.empty? + + # Act + get users_path + + # Assert + must_respond_with :success + end + end + + describe 'Show' do + it 'succeds with an existing id' do + # Act + get user_path(users(:dan).id) + + # Assert + must_respond_with :success + end + + it "renders 404 not_found for a wrong user ID" do + # Act + get user_path("wrong id") + + # Assert + must_respond_with :missing + end + + + end end diff --git a/test/controllers/works_controller_test.rb b/test/controllers/works_controller_test.rb index 0945ca47..b8fb6007 100644 --- a/test/controllers/works_controller_test.rb +++ b/test/controllers/works_controller_test.rb @@ -1,19 +1,30 @@ require 'test_helper' +require 'pry' describe WorksController do + let(:album) { works(:album) } + describe "root" do it "succeeds with all media types" do # Precondition: there is at least one media of each category - + get root_path + must_respond_with :success end it "succeeds with one media type absent" do # Precondition: there is at least one media in two of the categories - + proc { + album.destroy + }.must_change 'Work.count', -1 + get root_path + must_respond_with :success end it "succeeds with no media" do - + Work.destroy_all + assert Work.all.empty? + get root_path + must_respond_with :success end end @@ -22,16 +33,23 @@ describe "index" do it "succeeds when there are works" do + get works_path + must_respond_with :success end it "succeeds when there are no works" do - + Work.destroy_all + assert Work.all.empty? + get works_path + must_respond_with :success end end describe "new" do it "succeeds" do + get new_work_path + must_respond_with :success end end @@ -39,78 +57,179 @@ describe "create" do it "creates a work with valid data for a real category" do + proc { + post works_path, params: { + work: { + title: "New Work", + category: "album" + } + } + }.must_change 'Work.count', 1 + + # Assert + must_respond_with :redirect + must_redirect_to work_path(Work.last.id) + + end - it "renders bad_request and does not update the DB for bogus data" do + it "renders not_found and does not update the DB for bogus data" do + proc { + post works_path, params: { + work: { + title: "New work" + # missing category + } + } + }.must_change 'Work.count', 0 + must_respond_with :error end it "renders 400 bad_request for bogus categories" do + proc { + post works_path, params: { + work: { + title: "New work", + category: "wrong category" + } + } + }.must_change 'Work.count', 0 + must_respond_with 400 end end describe "show" do it "succeeds for an extant work ID" do + get work_path(works(:album).id) + + must_respond_with :success end it "renders 404 not_found for a bogus work ID" do + get work_path("wrong id") + must_respond_with :missing end end describe "edit" do it "succeeds for an extant work ID" do + get edit_work_path(works(:album).id) + must_respond_with :success end it "renders 404 not_found for a bogus work ID" do + get edit_work_path("wrong id") + must_respond_with :missing # 404 end end describe "update" do it "succeeds for valid data and an extant work ID" do + patch work_path(works(:album).id), params: { + work: { + title: "Update title" + } + } + + must_respond_with :redirect + must_redirect_to work_path(works(:album).id) end it "renders bad_request for bogus data" do + patch work_path(works(:album).id), params: { + work: { + doesnt_exists: "Update title" + } + } + + must_respond_with :redirect end it "renders 404 not_found for a bogus work ID" do + patch work_path("wrong id") + must_respond_with :missing # 404 end end describe "destroy" do it "succeeds for an extant work ID" do + proc { + delete work_path(works(:album).id) + }.must_change 'Work.count', -1 + must_respond_with :redirect end it "renders 404 not_found and does not update the DB for a bogus work ID" do + proc { + delete work_path('bad id') + }.must_change 'Work.count', 0 + must_respond_with 404 end end describe "upvote" do it "redirects to the work page if no user is logged in" do + post upvote_path(works(:album).id) + must_respond_with :redirect + must_redirect_to work_path(works(:album).id) end it "redirects to the work page after the user has logged out" do + post login_path, params: {user: "dee"} + # binding.pry + # it is not logging in tho + + post logout_path + # ? is this the right way to do this? + + post upvote_path(works(:album).id) + + must_respond_with :redirect + must_redirect_to work_path(works(:album).id) end it "succeeds for a logged-in user and a fresh user-vote pair" do + post login_path, ({ + username: (users :dan).username}) + # ? + proc { + post upvote_path((works :album).id) + binding.pry + }.must_change 'Vote.count', 1 + + + must_respond_with :redirect + must_redirect_to work_path(works(:album).id) end it "redirects to the work page if the user has already voted for that work" do + post login_path + # ? is this the right way to do this? + + post upvote_path(works(:album).id) + + proc { + post upvote_path(works(:album).id) + }.must_change "Work.count", 0 + must_respond_with :redirect + must_redirect_to work_path(works(:album).id) end end end