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

Melissa : Edges :media Ranker #39

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

Conversation

melicious-dish
Copy link

Media Ranker

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Describe a custom model method you wrote. All amy methods are in the controllers, which I know isn't ideal because the models should hold all the business logic.
Describe how you approached testing that model method. What edge cases did you come up with? I tested the controller methods. And tested to make sure all title of media were unique
What are session and flash? What is the difference between them? Session is an object that is used to keep track of data throughout a users session on the browser. Sessions end when a user closes their browsers - unlike flash, the data stores will not go away after the next request-response cycle. . Flash is used to send a one time message from controllers to our views.
Describe a controller filter you wrote. I did a before_action controller filter to find logged in user in the application controller. Before each method in the application, this will run. It will find the user id by finding the session id
What was one thing that you gained more clarity on through this assignment? Using foreign keys and how to access info from one database through them. Also controller testing and how to use and write them.
What is the Heroku URL of your deployed application? https://media-stinker.herokuapp.com/
Do you have any recommendations on how we could improve this project for the next cohort?

@droberts-sea
Copy link

Media Ranker

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene yes
Comprehension questions yes
General
Rails fundamentals (RESTful routing, use of named paths) some - you have many routes that you're not using
Views are well-organized (DRY, use of semantic HTML, use of partials) some - see inline
Errors are reported to the user yes
Business logic lives in the models There's a lot of room for improvement here. I like that you used a validation to encode the logic of who can vote for what, but there are several places where you do complex database work in the controller, that really ought to be class methods in the model.
Models are thoroughly tested, including relations, validations and any custom logic see inline comments
Wave 1 - Media
Splash page shows the three media categories yes
Basic CRUD operations on media are present and functional yes
Wave 2 - Users and Votes
Users can log in and log out yes
The ID of the current user is stored in the session yes
A user cannot vote for the same media more than once yes
All media lists are ordered by vote count yes
Splash page contains a media spotlight yes
Wave 3 - Users and Votes
Media pages contain lists of voting users yes
Individual user pages and the user list are present yes - small bug: a user's page fails to show if they've voted for a work that has been deleted
Optional - Styling
Bootstrap is used appropriately some
Look and feel is similar to the original this is a good start
Overall

This is a good start. You were able to get the site working well, including logging in, voting and sorting media by votes, which is is impressive!

However, there is room for growth around working with models, both in terms of writing methods to handle business logic, and testing that logic to make sure it's correct. Those are both important learning goals for this project, and it's important to me that you feel comfortable with those techniques. Please read my inline comments around business logic and model tests, take the opportunity to practice them as you continue working on bEtsy, and let me know if you have any questions or want further guidance.

I do want to affirm that the weekend this project was assigned was very busy, and that the application you've submitted matches the functionality of our demo site pretty well. Even if there's improvements to be made, there's also a lot of good work here, and you should be proud of what you've accomplished.

belongs_to :user
belongs_to :work

validates :user_id, uniqueness: { scope: :work_id, message: "only one vote"}

Choose a reason for hiding this comment

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

Nice work getting this tricky validation figured out!

def homepage
works_albums = Work.left_joins(:votes).group(:id).order("category asc, count(votes.work_id) desc").where({ category: "album" }).limit(10)

works_books = Work.left_joins(:votes).group(:id).order("category asc, count(votes.work_id) desc").where({ category: "book" }).limit(10)
Copy link

@droberts-sea droberts-sea Oct 22, 2018

Choose a reason for hiding this comment

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

These long lines of database work would be great as model methods. That would help DRY out this code, and would allow you to break the work across multiple lines to make it easier to follow. Having it in a separate method would make the functionality simpler to test as well. Something like this:

class Work
  # ...
  def self.top_ten(category)
    works_by_votes = Work.left_joins(:votes).group(:id).order("category asc, count(votes.work_id) desc")
    works_for_category = works_by_votes.where(category: category)
    return works_for_category.first(10)
  end
end


@top_work = work.max_by { |w| w.votes.count }

@works = work.group_by(&:category)

Choose a reason for hiding this comment

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

Finding the top work would be another excellent model method.

def edit
if @work.nil?
head :not_found
end

Choose a reason for hiding this comment

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

You make this check many times in this controller. Why not add it to the find_work filter?

</head>
<title>Media Ranker</title>

<section>

Choose a reason for hiding this comment

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

This file would benefit from some general cleanup. For example, this <title> should be inside the <head>, and this <section> should be inside the <body>. You have several other dangling or unclosed tags, and it looks like you started to apply high-level sectioning elements (<header>, <main>, etc) but didn't follow through.

In the past your view organization and use of semantic HTML has been strong - what happened?

<% @works.each do |c, works| %> <!-- iterate over the works hash that was created in in index by group_by -->
<strong> Top </strong>
<strong><%= c.titleize.pluralize%></strong>

Choose a reason for hiding this comment

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

I like that you're looping over the categories here to avoid copy-pasting the same table code 3 times. Good work keeping things DRY.

@@ -0,0 +1,9 @@
class VotesController < ApplicationController

# do we need a votes controller? - asks Dan

Choose a reason for hiding this comment

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

Nope. You should remove this file.


resources :users
resources :votes
resources :works

Choose a reason for hiding this comment

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

There's a lot of extra routes defined in this file:

  • I don't think you're using the full set of RESTful routes for users, only :index and :show
  • Since you don't have anything in your VotesController, you don't need resources :votes at all

Make sure you're only generating the routes you need for your application.

describe Vote do
let(:vote) { votes(:vote_one) }

it "must be valid" do

Choose a reason for hiding this comment

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

You should be testing the uniqueness constraint here! Specific test cases I'd want to see:

  • A user can have votes for two different works
  • A work can have votes from two different users
  • A user cannot vote for the same work twice


describe Work do


Choose a reason for hiding this comment

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

You didn't put your business logic in the model, so it makes sense that you wouldn't have tests for it. However, if you were to follow the comments above, then you might end up with test cases like these.

For finding the media spotlight, I would wonder:

  • What happens if there are no works?
  • What happens if there are works but no votes?
  • What happens if two works have the same number of votes?

For finding the top ten works in a category, I would ask:

  • What if there are no works of that category?
  • What if there are less than 10 works?
  • What if there's a tie for last place, e.g. works 9, 10 and 11 all have 0 votes?

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