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

India - Water #48

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open

India - Water #48

wants to merge 33 commits into from

Conversation

indiakato
Copy link

@indiakato indiakato commented Nov 17, 2020

Media Ranker

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Describe a custom model method you wrote. I wrote a model method that will find the media spotlight of the work with the most votes. I did this by ordering all of the works by votes and finding the first one.
Describe how you approached testing that model method. What edge cases did you come up with? I tested using my fixtures to make sure that the spotlight method would return the work that I made in my fixtures with the most votes.
What are session and flash? What is the difference between them? Session and flash uses hash like objects that allow data to persist between requests. Flash only preserves the data in one request response cycle while session data can persist through more than one cycle.
What was one thing that you gained more clarity on through this assignment? I gained more clarity on using session and flash. I also feel more comfortable creating new rails apps and really improved on my planning before I actually started coding.
What is the Heroku URL of your deployed application? I wasn't able to deploy to heroku

Assignment Submission: Media Ranker

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

Reflection

Prompt Response
What was a custom model method you wrote? What was it responsible for doing?
Describe how you approached testing that model method. What edge cases did you come up with?
What are session and flash? What is the difference between them?
What was one thing that you gained more clarity on through this assignment?
What is the Heroku URL of your deployed application?

Copy link

@beccaelenzil beccaelenzil left a comment

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

Feedback updated on 12/1 is in ()

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 (✔️) Voting functionality not implemented yet.
4. Can edit this work successfully, and get a flash message No flash message
5. Can go to "View all media" page and see three lists of works, sorted by vote (Not 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 (✔️ - details of validation errors are not shows, see in-line comment) create method missing
7. Can create a new work successfully. Note the URL for this work's show page (✔️) create method was not created
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 Incomplete
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 (✔️) Incomplete
13. Verify that number of votes determines the Media Spotlight (✔️) Voting functionality not implemented yet.
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 (✔️-- good work flashing the validation errors) Voting functionality not implemented yet.
15. Voting on the same work twice produces an error and flash message, and there is no extra vote Voting functionality not implemented yet.
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 Not deployed yet
2. Practices full-stack development and fulfilling story requirements: the styling, look, and feel of the app is similar to the original Media Ranker No styles added
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 ✔️
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 See in-line comment for suggestion.
8. The model for media (likely named work.rb) has_many votes (✔️) Voting functionality not implemented yet.
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 (✔️)No model methods
10. Some controller, likely the ApplicationController, has a controller filter for finding a logged in user (✔️)See in-line comment.
11. Some controller, likely the WorksController, has a controller filter for finding a work See in-line comment
12. The WorksController uses strong params ✔️
13. The WorksController's code style is clean, and focused on working with requests, responses, params, session, flash ✔️

Testing Rails Apps

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

Overall Feedback

(Great job working through this project. You've implemented the login/logout feature, upvote feature, fixtures, and model methods. I've left some in-line comment for suggestion on how to use partial views and controller filters to DRY up your code. Please let me know if you have any questions. Keep up the hard work!)

You are off to a good start with this project. It is great to see that you met the learning goal of implementing log-in / log-out, including working with session and flash, writing custom routes, and writing custom controller methods.

I tried to highlight places where you could make use of partial views, controller filters, and model methods with in-line comments. Please let me know if you have any questions about these.

Since you did not have the opportunity to practice some of the new Rails tools on this project, on the current project (bEtsy), I encourage you to play close attention to testing the model with fixtures, model validations, and the custom routes and methods that enable to adding to cart and checkout features. Again, please let me know if you have any questions.

Overall Feedback Criteria yes/no
Green (Meets/Exceeds Standards) 14+ in Functional Requirements: Manual Testing && 14+ in Code Review
Yellow (Approaches Standards) 12+ in Functional Requirements: Manual Testing && 11+ in Code Review, or the instructor judges that this project needs special attention
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
Descriptive/Readable
Logical/Organized


<h2>Top Albums</h2>
<ul>
<% top_ten = @albums.sample(10) %>

Choose a reason for hiding this comment

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

Consider moving this logic into a model method.

<% end %>
</ul>

<h2>Top Books</h2>

Choose a reason for hiding this comment

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

Note that this view code is almost identical to the code above for albums. You can use a loop or a partial view, combined with a model method that selects the work for a particular category, to DRY up this code.

<h1>Media Ranker</h1>

<h2>Media Spotlight</h2>
<% spotlight = @works.find_by(id: 1) %>

Choose a reason for hiding this comment

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

Good work having a place holder for this media spotlight.

Comment on lines 12 to 21
if ! user.save
flash[:error] = "Unable to login"
redirect_to root_path
return
end
flash[:welcome] = "Welcome #{user.username}"
else
#Existing User
flash[:welcome] = "Welcome back #{user.username}"
end

Choose a reason for hiding this comment

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

Good use of flash messages

Comment on lines +8 to +10
get "/login", to: "users#login_form", as: "login"
post "/login", to: "users#login"
post "/logout", to: "users#logout", as: "logout"

Choose a reason for hiding this comment

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

Good work creating these custom routes.

Comment on lines +24 to +29
@work = Work.find_by(id: params[:id])

if @work.nil?
redirect_to works_path
return
end

Choose a reason for hiding this comment

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

Consider adding this code to a controller filter like find_work to DRY up your code.

@indiakato indiakato changed the title India - Water (Incomplete project) India - Water Dec 1, 2020
Copy link

@beccaelenzil beccaelenzil left a comment

Choose a reason for hiding this comment

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

Great job working through the logic for this project - It is now Green 👍

<td><%= link_to book.title, work_path(book) %></td>
<td><%= book.creator %></td>
<td><%= book.publication_year %></td>
<td><%= link_to "Upvote", vote_path(book.id) %></td>

Choose a reason for hiding this comment

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

This link produces the error No route matches [GET] "/works/17/vote". The default method for link_to is get, so you need to specify the method.

Suggested change
<td><%= link_to "Upvote", vote_path(book.id) %></td>
<td><%= link_to "Upvote", vote_path(book.id), method: :post %></td>

Choose a reason for hiding this comment

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

With this change, the upvote button works!

flash[:message] = "Successfully created"
redirect_to work_path(@work)
else
flash[:error] = "Failed to create new media"

Choose a reason for hiding this comment

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

To show the specifics of the failed validations, access @work.errors.messages. You can do this in your view or iterate through the messages here and store them in the flash hash.

Work.all.order(vote_count: :desc).first
end

def self.top_ten_books

Choose a reason for hiding this comment

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

Consider using a single method for all categories that takes the category as a parameter to DRY up your code:self.top_ten(category). Then you can use the .find method to get all works from that category, and sort them.

@@ -0,0 +1,41 @@
<% books = @works.where(category: "book") %>

Choose a reason for hiding this comment

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

This is a great place to make use of the top_ten method from your model so you don't put logic in the view.

Comment on lines +32 to +40
<% albums.each do |album | %>
<tr>
<td><%= album.vote_count %></td>
<td><%= link_to album.title, work_path(album) %></td>
<td><%= album.creator %></td>
<td><%= album.publication_year %></td>
<td><%= link_to "Upvote", vote_path(album.id) %></td>
</tr>
<% end %>

Choose a reason for hiding this comment

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

Note that you have three blocks of code that are almost identical. Consider how you can use a partial view with the local variable being the category or a loop to dry up this code.

Comment on lines +8 to +13
@work = Work.find_by(id: params[:id])

if @work.nil?
head :not_found
return
end

Choose a reason for hiding this comment

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

Note this functionality is used in multiple methods. This is a great place for a controller filter find_work

@work = Work.find_by(id: params[:id])

if @work.nil?
head :not_found

Choose a reason for hiding this comment

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

Consider adding redirect behavior rather than head :not_found to redirect the user to a useful page.

description: this is work1
publication_year: 2020
category: album
vote_count: 1

Choose a reason for hiding this comment

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

Rather than adding a vote_count to the work fixture, it is best to rely on the relationship between works and votes, such that the way that a vote_count is increased is by a work having vote fixtures.

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