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

Earth - Beauttie #38

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

Earth - Beauttie #38

wants to merge 36 commits into from

Conversation

beauttie
Copy link

@beauttie beauttie commented Nov 16, 2020

Media Ranker

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Describe a custom model method you wrote. I wrote a helper method that sorts all Work instances by vote count. Then I wrote a custom model method that gets all works in a category (passed in as a parameter) and calls that helper method to return the first 10 instances.
Describe how you approached testing that model method. What edge cases did you come up with? I tested three cases: when there are more than 10 works, less than 10, and no works.
What are session and flash? What is the difference between them? They both store data from a controller action. Data from flash hash is available until the next request cycle whereas data from session persists until the user quits the browser.
What was one thing that you gained more clarity on through this assignment? Test fixtures
What is the Heroku URL of your deployed application? https://work-of-art.herokuapp.com/

…tes, define indirect relations between users and works
Copy link

@CheezItMan CheezItMan 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

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 ✔️, but you're not using flash notices 😭
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) ✔, but you should provide a flash message
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 ✔️
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 ✔️
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 my inline note on partials
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 ✔️
10. Some controller, likely the ApplicationController, has a controller filter for finding a logged in user ⚠️, this filter isn't there
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 ✔️

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 ✔️

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
Descriptive/Readable
Concise
Logical/Organized

Summary

Nice work Beauttie! You hit the learning goals here. This is an outstanding submission. Well done.

The only area for improvement I can suggest is to make more use of partials, use flash notices to display error messages and use a controller filter to find the logged in user.

Comment on lines +2 to +11
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
get "/login", to: "users#login_form", as: "login"
post "/login", to: "users#login"
post "/logout", to: "users#logout", as: "logout"
post "/works/:id/upvote", to: "works#upvote", as: "upvote"

root to: "works#homepage"

resources :works
resources :users, only: [:index, :show]

Choose a reason for hiding this comment

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

This works!

Comment on lines +8 to +11
def self.sort_by_votes
# in descending order
return self.all.sort_by { |work| -work.votes.count }
end

Choose a reason for hiding this comment

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

This works, but it's better to use the database to sort with the order method. You can see a blog post on the subject to learn more.

belongs_to :work
belongs_to :user

validates :work_id, uniqueness: { scope: :user_id, message: "User has already voted for this work" }

Choose a reason for hiding this comment

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

👍

Comment on lines +18 to +28
<% @works.where(category: category).sort_by_votes.each do |medium| %>
<tr>
<td><%= medium.votes.count %></td>
<td><%= link_to medium.title, work_path(medium) %></td>
<td><%= medium.creator %></td>
<td><%= medium.publication_year %></td>
<td><%= link_to "Upvote",
upvote_path(medium),
method: :post, class: "btn btn-primary"%></td>
</tr>
<% end %>

Choose a reason for hiding this comment

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

Do you notice that you repeat this type of loop through a set of works over and over again... Maybe you could put this into a partial and dry up your code.

@@ -0,0 +1,91 @@
class WorksController < ApplicationController
before_action :find_work, only: [:show, :edit, :update, :destroy]

Choose a reason for hiding this comment

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

👍 Yeah controller filter!

Comment on lines +2 to +12
<section>
<% if @user.errors.any? %>
<div class="alert alert-warning">
<ul>
<% @user.errors.each do |column, message| %>
<li><strong><%= column %></strong> <%= message %></li>
<% end %>
</ul>
</div>
<% end %>
</section>

Choose a reason for hiding this comment

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

This should now be done with flash notices.

@@ -0,0 +1,55 @@
require "test_helper"

describe User do

Choose a reason for hiding this comment

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

👍

expect(sorted_media.last.votes.count).must_equal 0
end

it "returns an empty array if there are no works" do

Choose a reason for hiding this comment

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

👍 Good!

end
end

describe "top_10" do

Choose a reason for hiding this comment

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

👍 Well done

end
end

describe "spotlight" do

Choose a reason for hiding this comment

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

Good set of tests covering the edge cases.

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