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 - Jessica #29

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

Ports - Jessica #29

wants to merge 43 commits into from

Conversation

jessicacaley
Copy link

Media Ranker

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Describe a custom model method you wrote. Work.top returns the overall top work object based on how many votes they have.
Describe how you approached testing that model method. What edge cases did you come up with? I checked if it would return an object of media with the most votes, and as edge cases tested that it would return nil if there was no media at all and would only return one object if it was a tie (didn't matter which).
What are session and flash? What is the difference between them? Session is a persistent hash-like object that allows you to, in this case, track logged in users across time/pages. Flash is not persistent but is also a hash-like object that only exists for one request-response cycle.
What was one thing that you gained more clarity on through this assignment? I gained a lot of clarity on using test fixtures.
What is the Heroku URL of your deployed application? rankmedia.herokuapp.com
Do you have any recommendations on how we could improve this project for the next cohort? More project time during the week would be super helpful! Also, there were some things we learned for the first time in lecture, like testing session, and this project was our first chance to apply it, but the lecture and the code weren't the clearest thing in the world. I think that could be helped by just having more project time in the week where instructors are available to clarify things, because I got the sinking feeling working on this project that I was doing things wrong and reinforcing bad habits.

…isplay additional information as per example
@tildeee
Copy link

tildeee commented May 8, 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) x
Views are well-organized (DRY, use of semantic HTML, use of partials) x, great use of partials!
Errors are reported to the user x
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

Hi Jessica! Well done! Overall, I think your project was really clean, thorough (model tests!), and often times clever. Fantastic work! I have confidence that you hit the learning goals.

That being said, all of the comments I have are on the following things: ways to make your code style more consistent, and some small details that have an opportunity to be refactored.

Overall, good work. Well done!

flash[:success] = "Successfully logged in as existing user #{user.name}"
end

if user.id
Copy link

Choose a reason for hiding this comment

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

With our understanding of Rails, this if ... else checks on essentially user.nil?, which is covered above. It probably might feel more useful to bring this check on failure of saving inside of the first if after checking if user = User.create(name: name) succeeds or fails.

end

def logout
user = User.find_by(id: session[:user_id])
Copy link

Choose a reason for hiding this comment

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

This line gets repeated twice... Maybe this is a good use case for a helper method to be pulled out, or even a controller filter (before_action)?

class User < ApplicationRecord
has_many :votes
has_many :works, through: :votes

Copy link

Choose a reason for hiding this comment

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

There is one goofy edge case not accounted for: validating on the presence of name!

validates :title, presence: true

def self.top
Work.all.max_by do |work| work.votes.length end
Copy link

Choose a reason for hiding this comment

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

For the sake of consistency, I would recommend curly braces and an explicit return:

return Work.all.max_by { |work| work.votes.length }

def self.list_by_votes(category)
list = Work.where(category: category)
sorted_list = list.sort_by { |work| -work.votes.length }
return sorted_list
Copy link

Choose a reason for hiding this comment

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

This is very specifically a "bonus" refactoring: I think this will be fine with just:

return list.sort_by { |work| -work.votes.length }

@@ -0,0 +1,13 @@
Rails.application.routes.draw do
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.

Interesting, I'm not sure what this syntax does... Do we need it? A lot of the tests break if I comment this out... but maybe at those points you should use root_path?

root to: "homepages#index" # where do i want this to be
resources :users, only: [:show, :index]
resources :works do
resources :votes, only: [:create]
Copy link

Choose a reason for hiding this comment

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

Good call on nesting this one route in here -- you're right, votes are inherently tied to works!

get "/login", to: "users#login_form", as: "login"
post "/login", to: "users#login"
post "/logout", to: "users#logout", as: "logout"
get "/current", to: "users#current", as: "current_user"
Copy link

Choose a reason for hiding this comment

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

Is this being used?

has_many :works, through: :votes

# I added this before I decided to do a current user path. Do I need this, then?
def self.current(session)
Copy link

@tildeee tildeee May 8, 2019

Choose a reason for hiding this comment

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

From our spelunking: This method is only being used in the application layout file... which could be refactored to not use this method (called with User.current)

it "returns an array of all objects of type if less than 10 exist" do
all_movies = Work.where(category: "movie")
top_movies = Work.top_ten("movie")
assert top_movies.length < 10 # for sake of test, must be true
Copy link

Choose a reason for hiding this comment

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

This is not a high priority refactor, but for the sake of being consistent with non-assert style tests, this is the syntax for this:

expect(top_movies.length).must_be :<, 10

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