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

Ports - Heather #27

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

Ports - Heather #27

wants to merge 51 commits into from

Conversation

piffer59
Copy link

Media Ranker

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Describe a custom model method you wrote. method that will return the top 10 works by category
Describe how you approached testing that model method. What edge cases did you come up with? In my yml file I created 11 albums and voted on them. I tested that the returned array contained 10. given more time. For edge cases, I tested that for categories of works that had fewer or no works, it returned the number of works that were in the yml files.
What are session and flash? What is the difference between them? flash will persist only for the duration of one request cycle, with session will last for the entire session that a user is logged in.
What was one thing that you gained more clarity on through this assignment? I am slowly starting to understand controller testing better.
What is the Heroku URL of your deployed application? https://good-media.herokuapp.com/
Do you have any recommendations on how we could improve this project for the next cohort? Do no have this due on the same weekend as an assessment.

piffer59 added 30 commits April 22, 2019 15:47
@tildeee
Copy link

tildeee commented May 5, 2019

Media Ranker

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene x
Comprehension questions x
General
Rails fundamentals (RESTful routing, use of named paths) well done!
Views are well-organized (DRY, use of semantic HTML, use of partials) well done!
Errors are reported to the user it seems like reporting errors on creating works doesn't show up, but otherwise looks good
Business logic lives in the models x
Models are thoroughly tested, including relations, validations and any custom logic x
Controllers are thoroughly tested, including the login/logout process and multi-step workflows like voting for a work x
Wave 1 - Media
Splash page shows the three media categories x
Basic CRUD operations on media are present and functional x
Wave 2 - Users and Votes
Users can log in and log out x
The ID of the current user is stored in the session x
A user cannot vote for the same media more than once x
All media lists are ordered by vote count x
Splash page contains a media spotlight x
Wave 3 - Users and Votes
Media pages contain lists of voting users x
Individual user pages and the user list are present x
Optional - Styling
Bootstrap is used appropriately x
Look and feel is similar to the original x
Overall

Well done on this, Heather! This project was huge and your submission is great.

Your controllers and controller tests are great! I have no complaints on those!

I'm really happy with the model code, the model tests, and all of the moving parts, too. Great job on hitting the learning goals.

All of my comments are really about the following things:

  • Your site has a very interesting bug! Whenever I RESTART the server, the first time I go to the home page, it has an error, but when refreshing, it renders just fine! Considering the following steps to reproduce:
  1. Restart the server
  2. Go to the homepage
  3. Observe: The view throws an error that @works is nil… which is weird, because Work.all should never be nil
  4. Refresh the page
  5. Observe: Upon refreshing the page, it works!

I actually figured out what was going on!

  • Secondly, there were some interesting moments of refactoring that I saw. While your code was functional (and well tested!), I thought I would use the opportunity to start helping you think of ways to refactor your code.

Also, overall, your indentation always got a little weird in the view code (see the nav element in the application layout and the tables).

That being said, great submission. Well done!

@@ -0,0 +1,7 @@
class HomepagesController < ApplicationController
def index
def index
Copy link

Choose a reason for hiding this comment

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

Hm?! Why is an index method defined inside of the index method?! Actually, this is what produced the really interesting bug!!

has_many :votes, dependent: :destroy

def self.top_ten(type)
array_by_type = self.where(category: type)
Copy link

Choose a reason for hiding this comment

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

I think these variables names could be better. If it were me, I would rename array_by_type to simply works or categorized_works, and array_by_votes to sorted_works

return array_by_votes[0..9]
end
else
return array_by_type
Copy link

Choose a reason for hiding this comment

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

Hm... array_by_type (since it comes from a where call) will always be an array... even an empty array. If that's the case, do we need the if ... else here? Consider the following refactor of the method:

def self.top_ten(type)
    array_by_type = self.where(category: type)
    array_by_votes = array_by_type.sort_by { |work| -work.votes.count }
    return array_by_votes[0..9]
end

The tests still pass! When you are ready, take some time to think about why this still works and is effectively the same thing as your current code

spotlight = sorted_works.first

return spotlight
end
Copy link

Choose a reason for hiding this comment

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

I like this code! It's concise and clean. How would you feel if you did the following refactor:

  def self.media_spotlight
    sorted_works = self.all.sort_by { |work| -work.votes.count }
    return sorted_works.first
  end

<%= link_to "Media Ranker", homepages_path %>
<small>Ranking the Best of Everything</small>
</h1>
<% if flash.count > 0 %>
Copy link

Choose a reason for hiding this comment

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

It probably would be way better to insert flash outside of the header tag to match the model website

<%= render partial: "indextable", locals: {
header_category: "Albums:",
category: "album"
} %>
Copy link

Choose a reason for hiding this comment

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

Fantastic use of partials! :D

Rails.application.routes.draw do
root to: "homepages#index"

get "homepages/index"
Copy link

Choose a reason for hiding this comment

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

Since you did resoures :homepages, only: [:index] below, you don't need this route. Also, it doesn't direct anyone anywhere! It's not quite the right syntax

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