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

Leah - Water #52

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
26bf60e
Initial Rails Setup
scottzec Nov 11, 2020
b76497e
validations
scottzec Nov 15, 2020
78bcd84
views
scottzec Nov 15, 2020
fd197ff
validation tests added and passing
scottzec Nov 15, 2020
634df9d
prep for layout template
scottzec Nov 15, 2020
ec5c551
app and works#index html
scottzec Nov 15, 2020
bdacb6c
homepages#index html framework
scottzec Nov 15, 2020
c75a27b
works#index html framework
scottzec Nov 15, 2020
de97ac5
works form works show user show html base
scottzec Nov 15, 2020
66fefc5
css
scottzec Nov 15, 2020
48453dd
works listed by cat
scottzec Nov 16, 2020
052aa61
change works index html buttons to erb
scottzec Nov 16, 2020
4726c3c
works show
scottzec Nov 16, 2020
d568689
form with css new work
scottzec Nov 16, 2020
2e85acd
spotlight finally working
scottzec Nov 16, 2020
2096d79
css works on top 10
scottzec Nov 16, 2020
809618e
spotlight tests, 1 still not passing
scottzec Nov 16, 2020
91f3115
top 10 testing
scottzec Nov 16, 2020
99a1cef
added fixtures
scottzec Nov 16, 2020
e02eb02
rollback successful after migration disaster, saving schema
scottzec Nov 16, 2020
73cb04a
after updating fixtures to correct data type for publication_year, te…
scottzec Nov 16, 2020
1c68da9
edit with flash blank page
scottzec Nov 16, 2020
318c71e
delete with flash, same 404
scottzec Nov 16, 2020
e78f30c
edit and delete functioning again, flash to be resolved
scottzec Nov 16, 2020
3ca8905
added flash to view
scottzec Nov 16, 2020
3f04e2e
votes nested route
scottzec Nov 17, 2020
7109e8a
added session routes
scottzec Nov 17, 2020
e33113b
login routes, actions and views setup. still need logout button
scottzec Nov 17, 2020
13c6e8e
logout and current views all setup and running
scottzec Nov 17, 2020
16428bf
vote create action
scottzec Nov 17, 2020
75a7e20
migrations relating votes to user and work
scottzec Nov 17, 2020
07e59e8
upvote functionality working
scottzec Nov 17, 2020
b3f5485
added votes for views
scottzec Nov 17, 2020
862bfed
added filters to controllers
scottzec Nov 17, 2020
da23f4a
only 1 vote per user per work
scottzec Nov 17, 2020
f1be597
top 10, spotlight and works index all sorted by votes descending
scottzec Nov 17, 2020
7680e3e
current user tests
scottzec Nov 17, 2020
72e4aa6
vote fixtures
scottzec Nov 18, 2020
3b026ad
vote fixtures
scottzec Nov 18, 2020
8c34218
find_work controller working
scottzec Nov 18, 2020
0bb9076
relationship tests
scottzec Nov 18, 2020
5f3947d
user views complete with relation has many works thru votes
scottzec Nov 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
validation tests added and passing
scottzec committed Nov 15, 2020
commit fd197ff030d0e9747506826ec22c288fa1e554ce
35 changes: 34 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
class UsersController < ApplicationController

def index
@users = User.all
end

def show
user_id = params[:id]
@user = User.find_by(id: user_id)
if @user.nil?
# Change this to a 404 page
redirect_to root
end
end

def new
@user = User.new
end

def create
@user = User.new(user_params)
if @user.save
flash[:success] = "You have joined the ranker!"
# @user or @user.id ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either works, they do the same thing.

redirect_to user_path(@user.id)
return
else
flash.now[:error] = "There's been an error. We couldn't add you to the system."
render :new, status: :bad_request
return
end
end

private

# Strong Params: https://learn-2.galvanize.com/cohorts/2036/blocks/1006/content_files/intro-to-rails/strong-params.md
def user_params
return params.require(:user).permit(:user_name, :join_date)
end

end
26 changes: 21 additions & 5 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
class WorksController < ApplicationController

def index
@works = Work.all
end

def new
@work = Work.new
end

def show
work_id = params[:id]
@work = Work.find_by(id: work_id)
@@ -16,8 +13,27 @@ def show
end
end

def new
@work = Work.new
end

def create
@work = Work.new(work_params)
if @work.save # returns true if db insert succeeds
flash[:success] = "Your #{@work.category} has been added successfully to the ranker"
redirect_to work_path(@work.id) # @work or @work.id?
return
else
flash.now[:error] = "Something's gone awry. Your #{@work.category} hasn't been added"
render :new, status: :bad_request # look at bad_request
return
end
end

private

# Strong Params: https://learn-2.galvanize.com/cohorts/2036/blocks/1006/content_files/intro-to-rails/strong-params.md
def work_params
return params.require(:work).permit(:title, :category, :creator, :publication_year, :description)
end

end
2 changes: 0 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -2,6 +2,4 @@ class User < ApplicationRecord
has_many :votes

validates :user_name, presence: true
validates :category, presence: true
validates :creator, presence: true
end
1 change: 1 addition & 0 deletions app/models/work.rb
Original file line number Diff line number Diff line change
@@ -2,4 +2,5 @@ class Work < ApplicationRecord
has_many :votes

validates :title, presence: true
validates :category, presence: true
end
29 changes: 26 additions & 3 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
require "test_helper"

# Add Relations Tests in Wave 2
# Add Fixtures Later
# New? Create?

describe User do
# it "does a thing" do
# value(1+1).must_equal 2
# end
it "is valid when all required fields are present" do
# Arrange
@user = User.new(user_name: "me")

# Act
created_user = @user.valid?

# Assert
expect(created_user).must_equal true
end

it "is invalid without title" do
# Arrange
@user = User.new

#Act
created_user = @user.valid?

# Assert
expect(created_user).must_equal false
expect(@user.errors.messages).must_include :user_name
end
end
41 changes: 38 additions & 3 deletions test/models/work_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
require "test_helper"

# Add Relations Tests in Wave 2
# Add Fixtures Later
# New? Create?

describe Work do
# it "does a thing" do
# value(1+1).must_equal 2
# end
it "is valid when all required fields are present" do
# Arrange
@work = Work.new(title: "Long", category: "Movie")

# Act
created_work = @work.valid?

# Assert
expect(created_work).must_equal true
end

it "is invalid without title" do
# Arrange
@work = Work.new(category: "Movie")

#Act
created_work = @work.valid?

# Assert
expect(created_work).must_equal false
expect(@work.errors.messages).must_include :title
end

it "is invalid without category" do
# Arrange
@work = Work.new(title: "Long")

#Act
created_work = @work.valid?

# Assert
expect(created_work).must_equal false
expect(@work.errors.messages).must_include :category
end
end