Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leticia Tran (Ampers) - MediaRankerRevisited #36

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -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?("/")
Expand Down
17 changes: 7 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions test/controllers/users_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
129 changes: 124 additions & 5 deletions test/controllers/works_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -22,95 +33,203 @@

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

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