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

Media Ranker #44

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

Media Ranker #44

wants to merge 15 commits into from

Conversation

sheland
Copy link

@sheland sheland commented Oct 15, 2018

Media Ranker

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Describe a custom model method you wrote. I created custom routes for my session controller. For example post 'users/login', to: 'sessions#login', as: 'login' creates a user by having them log in into session. Because of this I did not need to create a route for Users#create.
Describe how you approached testing that model method I first created the tests and then tried to make them pass. If it failed because I didn't add add a validation, I added it, then ran the rest again.
. What edge cases did you come up with? Incomplete users fields, saving nil valued variables,
What are session and flash? What is the difference between them? session is used to login a user, session keeps the user's data in cookies until they logout. Their data is then destroyed. Flash is a one-time message that the user gets to see after the controller successfully or successfully completes an action.
Describe a controller filter you wrote. It dries up your code be reducing repetitive lines of codes and saving it in a method.
What was one thing that you gained more clarity on through this assignment? I gained more clarity about model's relationships, how they connect to each other by creating references which then lets you use many dot.methods to retrieve interesting data.
What is the Heroku URL of your deployed application?
Do you have any recommendations on how we could improve this project for the next cohort? perhaps more time to complete it.

@dHelmgren
Copy link

Media Ranker

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene Good
Comprehension questions Good
General
Rails fundamentals (RESTful routing, use of named paths) yes
Views are well-organized (DRY, use of semantic HTML, use of partials) Good, see comments for further improvements!
Errors are reported to the user No, see comments
Business logic lives in the models Yes
Models are thoroughly tested, including relations, validations and any custom logic See comments
Wave 1 - Media
Splash page shows the three media categories Yes
Basic CRUD operations on media are present and functional Yes, with caveats, see comments
Wave 2 - Users and Votes
Users can log in and log out yes
The ID of the current user is stored in the session no
A user cannot vote for the same media more than once No, see comments
All media lists are ordered by vote count No, see comments
Splash page contains a media spotlight No
Wave 3 - Users and Votes
Media pages contain lists of voting users Yes
Individual user pages and the user list are present Yes
Optional - Styling
Bootstrap is used appropriately Yes
Look and feel is similar to the original yes
Overall While I think there are a lot of things working in favor of this project, I don't think it's completely meeting the learning goals we set out. Specifically, I see there are a variety of errors around your CRUD actions that don't break cleanly, you aren't properly utilizing session via the sessions controller, and your validations aren't implemented properly and at time contribute to your errors. That said, I think there are a lot of things you did well too: your view partials are excellent, you made good use of categories, and your model methods are working correctly on their own. It all needs to come together though, and unfortunately here it didn't quite.


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

Choose a reason for hiding this comment

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

Nice work limiting the routes for users to be just the ones you need!

<% flash.each do |name, message| %>
<% if message.class == Array %>
<div class="alert-warning">
<% message.each do |msg| %>

Choose a reason for hiding this comment

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

I might move this flash block outside of the nav. 1) it doesn't actually affect navigation, but 2) it's placement is not easy to read.

<%= render partial: "top_ten", locals: { #render top albums from _top_ten.html.erb
work_category: "album",
data: @albums
}

Choose a reason for hiding this comment

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

Nice job using view partials here, but can you think of a way to further DRY this code?

<section class="spotlight">
<h2 class="spotlight__header">
<span class="spotlight__header--prefix">Media Spotlight</span>
<%= link_to @best_work.title, work_path(@best_work), class: "spotlight__link-to" %> by <%= @best_work.creator %>

Choose a reason for hiding this comment

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

You don't define a @best_work, so this ERB doesn't run. The place to do this would be in the controller that directs the user to the main page.

@@ -0,0 +1,5 @@
class Vote < ApplicationRecord
belongs_to :user
belongs_to :work

Choose a reason for hiding this comment

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

You can't delete a work that has votes! This is because you've created a link between the two tables at the database level, and deleting the work would leave behind invalid votes. You might want to check out the dependent argument to has_many.

def upvote(user)
@vote = Vote.new #create a new vote
@vote.work_id = self.id #a work's id is assigned vote's foreign key, work_id
@vote.user_id = user.id #a user's id is assigned to vote's foreign key, user_id

Choose a reason for hiding this comment

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

This method doesn't validate whether or not the user is valid, which means if you try to upvote without validating the user, this method breaks!


#Assert
expect(vote).must_be_instance_of User
expect(user.id).must_equal vote.user_id

Choose a reason for hiding this comment

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

I would be trying to break the uniqueness property here rather than in the tests for works. 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

#Assert
expect(@vote).must_equal false
expect(work.errors.messages).wont_include: user_id

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 interesting test cases for your custom Work methods missing here. For your category and top ten methods, 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?

# end

def self.highest_albums #call self.top_10 method for album category
top_ten("album") #displays up to 10 albums

Choose a reason for hiding this comment

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

You should use symbols instead of strings here because your categories don't show up properly when they aren't capitalized the same way. That is, you have "albums" here and "Albums" in your seeds, so some of your work never shows up.

unless @vote.valid? #if vote is not valid...
puts "#{@vote.errors.messages}" #display error messages
end
@vote.save #save vote so user cannot duplicate vote for a work

Choose a reason for hiding this comment

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

This method should add votes to list of votes for a work. Your vote count doesn't get updated properly, so your sorts never work.

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