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

Kay Media Ranker #37

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

Kay Media Ranker #37

wants to merge 60 commits into from

Conversation

kayxn23
Copy link

@kayxn23 kayxn23 commented Oct 15, 2018

Media Ranker

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Describe a custom model method you wrote.
In the Work model, I created a custom model self method (self.albums). It calls an active record finder method “.where” on Work to return an array of entries that have the category: album. Then I used the Arel gem method to convert a string of SQL to work in the model which arranges the works in order by the number of votes they have in descending order and their titles by ascending order.

Describe how you approached testing that model method. What edge cases did you come up with? |
In general checking what happens when there is nil, one or many. I actually need to write more edge cases :/

What are session and flash? What is the difference between them? |
Flash and Session are both hashes. Flash tells the user something happened(success or error), session stores a piece of information(in my app its the user_id) in the browser in the cookies file which persists as the user goes to different pages in a website, while everything else gets re-set.

Describe a controller filter you wrote. |
I didn’t incorporate any controller filters yet.

What was one thing that you gained more clarity on through this assignment? |
I gained more clarity about Rails in terms of how the the routes, model, view and controller work together practically and where to look when an error occurred, I felt very confused about it still while working on RideShareRails. I also gained more clarity on how to write tests for the model.

What is the Heroku URL of your deployed application? |
https://kay-media-ranker.herokuapp.com/main/index

Do you have any recommendations on how we could improve this project for the next cohort? |
I could have used more time for this project, I felt like it was the first project I really started to understand how Rails works. Maybe doing this project before RideShare with a partner would help because each person gets to take their time to do extra learning in areas that they don’t understand yet, whereas when you’re working on a pair project it is more rushed.

…dit method which finds the work that needs to be edited
…e and created user and vote models and controllers although i just realised vote doesn't need controller
…its category, and created vote validation so a user can only vote on a single work once
…ed from Works child model Votes..pretty sure its working
…otes belonging to works, did this by creating new migration to add votes_count column and added counter_cache option in votes belongs to relationship
@dHelmgren
Copy link

Media Ranker

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene Good
Comprehension questions I appreciate your thoughtful answers! Just a heads up, your PR formatting got messed up, and I recommend using the preview button on Github before actually submitting. :)
General
Rails fundamentals (RESTful routing, use of named paths) With the exception of using too many routes for :users, you handle RESTful routes well.
Views are well-organized (DRY, use of semantic HTML, use of partials) Generally yes, see comments!
Errors are reported to the user There is an error when upvoting when there is not a user logged in that produces a generic error page rather than giving the user a polite message.
Business logic lives in the models yes.
Models are thoroughly tested, including relations, validations and any custom logic See comments, there were some edge cases missed.
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 Some, the main page doesn't sort them by votes
Splash page contains a media spotlight No, see above
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 Some
Look and feel is similar to the original Workflow is similar but styling isn't, this is totally OK.
Overall On the whole, this is a strong submission. As you move forward, I'd make an effort to think about how best to DRY up your code, and where you can expand test coverage. You seem to be on the edge of a breakthrough with controller filters, so hopefully you get a chance to try those with bEtsy! I can see that you put a lot of hard work into this assignment.

belongs_to :user
belongs_to :work, counter_cache: true
#vote can only be created on the same work by the same user once aka #each user can only upvote a work once
validates :user_id, uniqueness: {scope: :work_id, message:"You can only vote once"}

Choose a reason for hiding this comment

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

Good work getting these validations and relations figured out; they're tricky!

class Work < ApplicationRecord
validates :title, presence: true
validates :title, uniqueness: { scope: :category }
validates_inclusion_of :category, in: %w(book album movie)

Choose a reason for hiding this comment

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

Good job figuring out validate_inclusion_of here, if you want to make it even more useful, consider putting those categories in a constant! That way, you can leverage the categories outside of this validation!


def self.movies
return Work.where(category: 'movie').order(Arel.sql('votes_count IS NULL, votes_count DESC'), title: :asc)
end

Choose a reason for hiding this comment

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

These are not particularly DRY, we are essentially doing the same set of operations with slightly different names for those categories. Consider using a method with a single parameter category that selects the works by that parameter.

One more suggestion: While they aren't technically necessary, using intermediate variables to help break up these search parameters would make it easier for the reader, rather than having to parse a single line of code with lots of stuff going on.

# def find_user
# @current_user = User.find_by(id: session[:user_id])
#this finds the current user in the session so i can display it where i need
# end

Choose a reason for hiding this comment

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

This is commented out, but I feel like it shouldn't be. You've created a way of doing the job of a controller filter, but the result is less readable and less DRY.

@books = Work.books
@movies = Work.movies

@current_user = User.find_by(id: session[:user_id])

Choose a reason for hiding this comment

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

This makes the display for a user inconsistent; we see "Welcome {Name}" on any page where we are fetching @current_user, but the majority of your routes don't display who is logged in.

Putting find_user in a controller filter (as it seems you originally may have intended) would be the better solution.


vote10:
user: user3
user: work5

Choose a reason for hiding this comment

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

This vote has 2 users!

end

describe 'Validations' 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

albums_array = Work.albums #array of works that are albums
albums_array2 = Work.albums.sort

compare = albums_array.zip(albums_array2).map {|album, album2| album == album2}

Choose a reason for hiding this comment

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

This is a nice way to make sure that you aren't missing anything, and that they are correctly sorted!

movies_array.each do |work|
expect(work.category).must_equal 'movie'
end
end

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. 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?

<% flash.each do |name, message| %>
<div class="alert"-<%=name %> <%=message %> </div>
<% end %>
</section>

Choose a reason for hiding this comment

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

Your auto-indenter is not catching ERB very well. Your job is to help other developers read your code when you aren't there to explain it, so checking indentation should be a mandate for any serious developer!

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