Skip to content

Stacy's Media Ranker submission - #45

Open
StacyLundquist wants to merge 27 commits into
Ada-C14:masterfrom
StacyLundquist:master
Open

Stacy's Media Ranker submission#45
StacyLundquist wants to merge 27 commits into
Ada-C14:masterfrom
StacyLundquist:master

Conversation

@StacyLundquist

Copy link
Copy Markdown

Media Ranker

Congratulations! You're submitting your assignment!

Reflection//Comprehension Questions

Question Answer
Describe a custom model method you wrote. In the work model I created a (currently non-working) method to change the vote button to a remove vote if the person had already voted.
Describe how you approached testing that model method. What edge cases did you come up with? The idea was to test what happens when the user isn't logged in, or when the vote is nil.
What are session and flash? What is the difference between them? Session is the browsing session, and is connected to a particular user. Flash is a message that lasts for a cycle.
What was one thing that you gained more clarity on through this assignment? Ummmm, I gained more confusion of a lot of things! I gained clarity on exactly how much coffee I can drink in a day and how to generate models and controllers.
What is the Heroku URL of your deployed application? http://adiec14-media-ranker.herokuapp.com/

Assignment Submission: Media Ranker

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

@CheezItMan CheezItMan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Media Ranker

Functional Requirements: Manual Testing

Criteria yes/no
Before logging in --
1. On index page, there are at most 10 pieces of media on three lists, and a Media Spotlight ✔️, mostly, you don't have a movie category. I'm uncertain as to why.
2. Can go into a work's show page ✔️
3. Verify unable to vote on a work, and get a flash message ✔️, I just can't vote if I'm not logged in.
4. Can edit this work successfully, and get a flash message ✔️
5. Can go to "View all media" page and see three lists of works, sorted by vote ✔️, I can see the 2 categories you have
6. Verify unable to create a new work when the form is empty, and details about the validation errors are visible to the user through a flash message ✔️, you have front-end validations, nice, but I can't test the flash notice. See my works controller notes.
7. Can create a new work successfully. Note the URL for this work's show page ✔️
8. Can delete this work successfully ⚠️ I can't delete a work!
9. Going back to the URL of this deleted work's show page produces a 404 or some redirect behavior (and does not try to produce a broken view) ✔️
10. Verify that the "View all users" page lists no users ✔️
Log in --
11. Logging in with a valid name changes the UI to "Logged in as" and "Logout" buttons ✔️
12. Your username is listed in "View all users" page ✔️
13. Verify that number of votes determines the Media Spotlight ✔️
14. Voting on several different pieces of media affects the "Votes" tables shown in the work's show page and the user's show page ✔️
15. Voting on the same work twice produces an error and flash message, and there is no extra vote ✔️, you don't present the vote button, but you have the validation as well.
Log out --
16. Logging out showed a flash message and changed the UI ✔️
17. Logging in as a new user creates a new user ✔️
18. Logging in as an already existing user has a specific flash message ✔️

Major Learning Goals/Code Review

Criteria yes/no
1. Sees the full development cycle including deployment, and the app is deployed to Heroku ✔️
2. Practices full-stack development and fulfilling story requirements: the styling, look, and feel of the app is similar to the original Media Ranker ⚠️ Not quite there although you have a good start on it
3. Practices git with at least 25 small commits and meaningful commit messages ✔️

Previous Rails learning, Building Complex Model Logic, DRYing up Rails Code

Criteria yes/no
4. Routes file uses resources for works ✔️
5. Routes file shows intention in limiting routes for voting, log-in functionality, and users ✔️, one minor note
6. The homepage view, all media view, and new works view use semantic HTML ✔️
7. The homepage view, all media view, and new works view use partials when appropriate ⚠️, you have partials for forms but no others. You can use partials to dry up the repeated lists of works you have in several views.
8. The model for media (likely named work.rb) has_many votes ✔️
9. The model for media has methods to describe business logic, specifically for top ten and top media, possibly also for getting works by some category ✔️, You have it, but you waaay overcomplicated the methods required.
10. Some controller, likely the ApplicationController, has a controller filter for finding a logged in user ✔️
11. Some controller, likely the WorksController, has a controller filter for finding a work ✔️
12. The WorksController uses strong params ✔️
13. The WorksController's code style is clean, and focused on working with requests, responses, params, session, flash ⚠️ Some improvement in the error handling and use of flash, and the destroy action.

Testing Rails Apps

Criteria yes/no
14. There are valid fixtures files used for users, votes, and works ⚠️
15. User model has tests with sections on validations (valid and invalid) and relationships (has votes) ⚠️, no real tests
16. Vote model has tests with sections on validations (valid and invalid) and relationships (belongs to a user, belongs to a vote) ⚠️ Very little testing
17. Work model has tests with sections on validations (valid and invalid) and relationships (has votes) ⚠, Some errors here especially around validations
18. Work model has tests with a section on all business logic methods in the model, including their edge cases ⚠️ Missing tests

Overall Feedback

Overall Feedback Criteria yes/no
Red (Not at Standard) 0-10 in Code Review or 0-11 in Functional Reqs, or assignment is breaking/doesn’t run with less than 5 minutes of debugging, or the instructor judges that this project needs special attention ♥️

Code Style Bonus Awards

Was the code particularly impressive in code style for any of these reasons (or more...?)

Quality Yes?
Perfect Indentation
Elegant/Clever

Summary

Yes, I'm labeling this Red, but you are closer than you think to Green. Most of your issues relate to testing. I've left extensive comments in the code. Take a look. You have a lot of the functionality in place.

Areas to improve on include:

  1. Writing Validation and custom method tests for models
  2. Simplifying your custom model methods. You overcomplicated your life with the work.rb file. See my inline notes here.
  3. Practice debugging in Rails and asking for help. I suspect your sharp brain let you do more with less help than other students in regular Ruby, but Rails is a bit bigger and you seemed to have run into a bug and moved on without calling out for help. I'm happy to sit with you and review this project at some point and practice some debugging skills.

As time allows doing practice with controller tests as well.

Areas you did well:

  1. Controller filters! Awesome! Well done.
  2. Complicated validations, really clever ones
  3. Front-end Validations
  4. Lots of clever front-end things like hiding the vote button when I can't vote.
  5. Pretty clean routes.rb file.

Due to the rubric this is a red, but you're actually pretty close to Green. If testing had been done, I think it would have been Green.

Comment thread test/models/work_test.rb Outdated
end

describe "validations" do
let work = works(:test_book)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This isn't how a let is written

Suggested change
let work = works(:test_book)
let (:work) { works(:test_book) }

it "can get the new user" do

# Act
get new_user_path

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This test is failing because in routes.rb you don't have the route given a nickname.

Comment thread config/routes.rb Outdated
end

resources :users, only: [:index, :show]
get '/signup', to: 'users#new'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
get '/signup', to: 'users#new'
get '/signup', to: 'users#new', as: "new_user"

describe "show" do
it "can get a valid user" do
# Act
get user_path(first.id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing The model class

Suggested change
get user_path(first.id)
get user_path(User.first.id)

end

def show
@user = User.find_by(id: params[:id])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You need to do something if the user doesn't exist. Otherwise @user.votes is nil.

Suggested change
@user = User.find_by(id: params[:id])
@user = User.find_by(id: params[:id])
if @user.nil?
redirect_to root_path
flash[:error] = "User not found"
return
end

Comment on lines +2 to +3
before_action :find_work, only: [:show, :edit, :update, :destroy]
before_action :find_work_votes, only: :show

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Awesome! Filters!

Comment on lines +45 to +50
flash.now[:error] = "Work edits not saved!"
@work.errors.messages.each do |field, messages|
flash[field] = messages
end
render :edit
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you're rendering use flash.now Also don't forget the status code!

Suggested change
flash.now[:error] = "Work edits not saved!"
@work.errors.messages.each do |field, messages|
flash[field] = messages
end
render :edit
end
flash.now[:error] = "Work edits not saved!"
@work.errors.messages.each do |field, messages|
flash.now[field] = messages
end
render :edit, status: :bad_request
end

Comment on lines +30 to +35
flash[:error] = "Work not created!"
@work.errors.messages.each do |field, messages|
flash[field] = messages
end
redirect_to new_work_path
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should instead render the new view.

Suggested change
flash[:error] = "Work not created!"
@work.errors.messages.each do |field, messages|
flash[field] = messages
end
redirect_to new_work_path
end
flash.now[:error] = "Work not created!"
@work.errors.messages.each do |field, messages|
flash.now[field] = messages
end
render :new, status: :bad_request
end

Comment thread app/controllers/works_controller.rb Outdated
Comment on lines +54 to +61
if @work.nil?
@deleted_work = @work.destroy
flash[:success] = "#{@work.title} deleted"
redirect_to root_path
else
flash[:failure] = "Work #{@work.title} not destroyed."
redirect_back fallback_location: root_path
end

@CheezItMan CheezItMan Nov 20, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you want to destroy a work if it's not nil.

Suggested change
if @work.nil?
@deleted_work = @work.destroy
flash[:success] = "#{@work.title} deleted"
redirect_to root_path
else
flash[:failure] = "Work #{@work.title} not destroyed."
redirect_back fallback_location: root_path
end
unless @work.nil?
@deleted_work = @work.destroy
flash[:success] = "#{@work.title} deleted"
redirect_to root_path
else
flash[:failure] = "Work #{params[:id]} not destroyed."
redirect_back fallback_location: root_path
end

Comment thread config/routes.rb
root to: 'works#home'

resources :works do
resources :votes, only: [:create, :destroy]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't know that you need to nest destroy

@CheezItMan CheezItMan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Media Ranker

Functional Requirements: Manual Testing

Criteria yes/no
Before logging in --
1. On index page, there are at most 10 pieces of media on three lists, and a Media Spotlight ✔️
2. Can go into a work's show page ✔️
3. Verify unable to vote on a work, and get a flash message ✔️
4. Can edit this work successfully, and get a flash message ✔️
5. Can go to "View all media" page and see three lists of works, sorted by vote ✔️
6. Verify unable to create a new work when the form is empty, and details about the validation errors are visible to the user through a flash message ✔️
7. Can create a new work successfully. Note the URL for this work's show page ✔️
8. Can delete this work successfully ✔️
9. Going back to the URL of this deleted work's show page produces a 404 or some redirect behavior (and does not try to produce a broken view) ✔️
10. Verify that the "View all users" page lists no users ✔️
Log in --
11. Logging in with a valid name changes the UI to "Logged in as" and "Logout" buttons ✔️
12. Your username is listed in "View all users" page ✔️
13. Verify that number of votes determines the Media Spotlight ✔️
14. Voting on several different pieces of media affects the "Votes" tables shown in the work's show page and the user's show page ✔️
15. Voting on the same work twice produces an error and flash message, and there is no extra vote ✔️, you don't present the vote button, but you have the validation as well.
Log out --
16. Logging out showed a flash message and changed the UI ✔️
17. Logging in as a new user creates a new user ✔️
18. Logging in as an already existing user has a specific flash message ✔️

Major Learning Goals/Code Review

Criteria yes/no
1. Sees the full development cycle including deployment, and the app is deployed to Heroku ✔️
2. Practices full-stack development and fulfilling story requirements: the styling, look, and feel of the app is similar to the original Media Ranker ✔️
3. Practices git with at least 25 small commits and meaningful commit messages ✔️

Previous Rails learning, Building Complex Model Logic, DRYing up Rails Code

Criteria yes/no
4. Routes file uses resources for works ✔️
5. Routes file shows intention in limiting routes for voting, log-in functionality, and users ✔️, one minor note
6. The homepage view, all media view, and new works view use semantic HTML ✔️
7. The homepage view, all media view, and new works view use partials when appropriate ⚠️, you have partials for forms but no others. You can use partials to dry up the repeated lists of works you have in several views.
8. The model for media (likely named work.rb) has_many votes ✔️
9. The model for media has methods to describe business logic, specifically for top ten and top media, possibly also for getting works by some category ✔️, You have it, but you waaay overcomplicated the methods required.
10. Some controller, likely the ApplicationController, has a controller filter for finding a logged in user ✔️
11. Some controller, likely the WorksController, has a controller filter for finding a work ✔️
12. The WorksController uses strong params ✔️
13. The WorksController's code style is clean, and focused on working with requests, responses, params, session, flash ⚠️ Some improvement in the error handling and use of flash, and the destroy action.

Testing Rails Apps

Criteria yes/no
14. There are valid fixtures files used for users, votes, and works ✔️
15. User model has tests with sections on validations (valid and invalid) and relationships (has votes) ✔️
16. Vote model has tests with sections on validations (valid and invalid) and relationships (belongs to a user, belongs to a vote) ✔️
17. Work model has tests with sections on validations (valid and invalid) and relationships (has votes) ✔️
18. Work model has tests with a section on all business logic methods in the model, including their edge cases ⚠️ Missing tests

Overall Feedback

Overall Feedback

Overall Feedback Criteria yes/no
Green (Meets/Exceeds Standards) 14+ in Functional Requirements: Manual Testing && 14+ in Code Review 💚

Code Style Bonus Awards

Was the code particularly impressive in code style for any of these reasons (or more...?)

Quality Yes?
Perfect Indentation
Elegant/Clever

Summary

This is green and it mostly works. You do have a broken user show path, but that's minor. I've also noted that your controller tests are a bit of a mess and tried to give some feedback there even though it wasn't in the assignment. It's good that you attempted them, but I would get one test working before moving to the next. Otherwise things tend to build like your last commit notes.

As I noted last time, I think you overthought some things about the project, particularly the upvoting and downvoting logic you were working on. Keep it simple.

@@ -1 +1 @@
VALID_CATEGORIES = %w[album book].freeze
VALID_CATEGORIES = %w[album book movie].freeze

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

end
end

describe "current" do

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What about users who are not logged in?

Comment thread test/test_helper.rb
Comment on lines +28 to +32
login_data = {
user: {
username: user.name,
},
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Notice that the form you use to log in doesn't nest username under a user hash. Also in your controller you are using "name" as the key and not "username".

So this should be:

Suggested change
login_data = {
user: {
username: user.name,
},
}
login_data = {
name: user.name,
}

Comment thread config/routes.rb

get '/signup', to: 'users#new'

get "/users/current", to: "users#current", as: "current_user"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You don't have this controller method.

perform_login(users(:second))

# Act
get current_user_path

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This crashes because you don't have a current method in the users controller.

post work_votes_path(work)
}.must_differ 'work.votes', 1

vote = Vote.find_by(user_id: user.id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you're creating a new user you'll also need to find them again in the DB since now they have an id number

Suggested change
vote = Vote.find_by(user_id: user.id)
user = User.find_by(name: user.name)
vote = Vote.find_by(user_id: user.id)

Comment on lines +77 to +79
expect {
delete work_vote_path(work_id: work_hash, vote_id: 1)
}.wont_differ 'work.votes'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is no work object here or vote for that matter and so it can't have votes. This test doesn't make much sense.

end
end

describe 'destroy' do

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For the destroy route, I don't think you need to use a nested route since you can identify the vote by it's id number.

Comment on lines +52 to +54
expect {
delete work_vote_path(work_id: work, vote_id: vote)
}.must_differ 'work.votes', -1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
expect {
delete work_vote_path(work_id: work, vote_id: vote)
}.must_differ 'work.votes', -1
expect {
delete work_vote_path(work_id: work, id: vote)
}.must_differ 'work.votes.count', -1

redirect_to work_path(params[:work_id])
end

def destroy

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think you need a destroy or "downvote" method.

I think you've overcomplicated this quite a bit. If you want to give them the abiltiy to downvote, you can check to see if the current user and work have a vote, if so remove it, otherwise add a vote.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants