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

Time - Emily #46

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

Time - Emily #46

wants to merge 11 commits into from

Conversation

snowistaken
Copy link

Media Ranker

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Describe a custom model method you wrote. One custom model method that I wrote was for finding the spotlight work. This method is in the work model.
Describe how you approached testing that model method. What edge cases did you come up with? Some edge cases that I came up with were ensuring that a work was still returned if there were no voted works, as well as ensuring that the first work is selected if there is a tie.
What are session and flash? What is the difference between them? Session is a hash like object that persists through the user's visit to the site. This information is stored in the cookies in their browser. This allows us to know whether or not they are logged in, as well as to log them in when they attempt to do so. Flash is a tool that allows us to notify the user of something when they make a request.
What was one thing that you gained more clarity on through this assignment? Relationships and model methods are two things that I gained clarity on in this project. Understanding where to put methods and which ones to have makes the overall workflow of the project a lot more efficient.
What is the Heroku URL of your deployed application? I forgot to deploy my most recent version! Will update this with link at the same time that I fix tests.

My model tests are not currently complete. I'll be updating my PR with the completed tests this evening. Thanks :)

@CheezItMan
Copy link

Media Ranker

Functional Requirements: Manual Testing

Criteria yes/no
Before logging in --
1. On index page, there are at most 10 pieces of media on three lists, and a Media Spotlight ✔️
2. Can go into a work's show page ✔️
3. Verify unable to vote on a work, and get a flash message ⚠, This doesn't work see my notes, you forgot to redirect after setting the flash notice.
4. Can edit this work successfully, and get a flash message ⚠, no flash notice presented
5. Can go to "View all media" page and see three lists of works, sorted by vote ✔️
6. Verify unable to create a new work when the form is empty, and details about the validation errors are visible to the user through a flash message ⚠, no validation errors presented.
7. Can create a new work successfully. Note the URL for this work's show page ✔️
8. Can delete this work successfully ✔️
9. Going back to the URL of this deleted work's show page produces a 404 or some redirect behavior (and does not try to produce a broken view) ✔️
10. Verify that the "View all users" page lists no users ✔️
Log in --
11. Logging in with a valid name changes the UI to "Logged in as" and "Logout" buttons ✔️
12. Your username is listed in "View all users" page ✔️
13. Verify that number of votes determines the Media Spotlight ✔️
14. Voting on several different pieces of media affects the "Votes" tables shown in the work's show page and the user's show page ✔️
15. Voting on the same work twice produces an error and flash message, and there is no extra vote ⚠, No flash notice here
Log out --
16. Logging out showed a flash message and changed the UI ⚠ changed the UI, but didn't show a flash notice
17. Logging in as a new user creates a new user ✔️
18. Logging in as an already existing user has a specific flash message ⚠ no flash notice provided

Major Learning Goals/Code Review

Criteria yes/no
1. Sees the full development cycle including deployment, and the app is deployed to Heroku ⚠ no Deployment at present
2. Practices full-stack development and fulfilling story requirements: the styling, look, and feel of the app is similar to the original Media Ranker ⚠ The styling is minimal. However the functionality is mostly the same.
3. Practices git with at least 25 small commits and meaningful commit messages ⚠ Only a few commits. For a project like MediaRanker, I would expect at least 30 commits

Previous Rails learning, Building Complex Model Logic, DRYing up Rails Code

Criteria yes/no
4. Routes file uses resources for works ✔️
5. Routes file shows intention in limiting routes for voting, log-in functionality, and users ✔️
6. The homepage view, all media view, and new works view use semantic HTML ⚠ You're using a lot of div tags and improperly using the body tag.
7. The homepage view, all media view, and new works view use partials when appropriate ⚠ you're only using partials in forms, there are a few other places to use one.
8. The model for media (likely named work.rb) has_many votes ✔️
9. The model for media has methods to describe business logic, specifically for top ten and top media, possibly also for getting works by some category ✔️
10. Some controller, likely the ApplicationController, has a controller filter for finding a logged in user ⚠ Not there
11. Some controller, likely the WorksController, has a controller filter for finding a work ⚠ Not there
12. The WorksController uses strong params ✔️
13. The WorksController's code style is clean, and focused on working with requests, responses, params, session, flash ✔️, See my notes on flash.

Testing Rails Apps

Criteria yes/no
14. There are valid fixtures files used for users, votes, and works ⚠ No fixtures
15. User model has tests with sections on validations (valid and invalid) and relationships (has votes) ✔️
16. Vote model has tests with sections on validations (valid and invalid) and relationships (belongs to a user, belongs to a vote) ✔️
17. Work model has tests with sections on validations (valid and invalid) and relationships (has votes) ✔️
18. Work model has tests with a section on all business logic methods in the model, including their edge cases ⚠ Missing

Overall Feedback

Overall Feedback Criteria yes/no
Yellow (Approaches Standards) 12+ in Functional Requirements: Manual Testing && 11+ in Code Review, or the instructor judges that this project needs special attention I judged this as yellow based on some parts only partially completed.

Code Style Bonus Awards

Was the code particularly impressive in code style for any of these reasons (or more...?)

Quality Yes?
Descriptive/Readable
Logical/Organized

Summary

You got the basic functionality completed Emily. See my comments in your code below. From this I think you need more practice with testing including fixtures, custom methods and controller tests. You also need more practice writing flash notices and styling. That said you have the relationships working and you have some custom validations and business logic methods. I'm glad you got this in and if you push any further commits and want my feedback just ping me in slack.


describe 'validations' do
before do
@vote = Vote.new(user_id: 1, work_id: 1)

Choose a reason for hiding this comment

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

This won't work because you can't guarantee that the test database will have a user and work with id 1.

Either:

  1. Create fixtures for your test database and use them or
  2. Do something like this
Suggested change
@vote = Vote.new(user_id: 1, work_id: 1)
@user = User.create(username: 'bob');
@user = User.create(username: 'bob');
@work = Work.create(category: 'book', title: 'Wizard of Oz', creator: 'Someone', publication_year: "1920", description: 'a book about a girl who got hit on the head')
@vote = Vote.new(user_id: @user.id, work_id: @work.id)

expect(result).must_equal true
end

it 'is invalid without a category' do

Choose a reason for hiding this comment

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

Just a note, that you can loop through the required fields, you don't have to make a test for each one.

  required_fields = [:category, :title, :creator, :publication_year]
  required_fields.each do |field|
    old_value = @work[field]
    @work[field] = nil
    expect(@work.valid?).must_equal false
    @work[field] = old_value
  end

end
end

describe 'work model methods' do

Choose a reason for hiding this comment

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

Just noting these aren't done yet.

end
end

# describe 'relations' do

Choose a reason for hiding this comment

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

Just noting these are missing.

Comment on lines +2 to +3
validates :user_id, presence: true
validates :work_id, presence: true

Choose a reason for hiding this comment

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

You don't need to have these, the relationships require them anyway.

However you do need a validation to prevent a duplicate combination user_id and work_id.

Suggested change
validates :user_id, presence: true
validates :work_id, presence: true
# Requires every combination work_id and user_id to be unique.
validates :user_id, uniqueness: {scope: :work_id}

@work = Work.find_by(id: params[:id])

if @work.nil?
head :not_found

Choose a reason for hiding this comment

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

Suggested change
head :not_found
flash[:notice] = "Work not found"
redirect_to root_path

head :not_found
return
elsif @work.update(work_params)
redirect_to work_path(@work.id)

Choose a reason for hiding this comment

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

I suggest adding a flash notice here.

end
end

def destroy

Choose a reason for hiding this comment

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

Flash notices would be good here.

Comment on lines +12 to +43
<header>
<div><h2 class="nav justify-content-center">Media Ranker | Ranking the Best of Everything</h2></div>
</header>

<ul class="nav justify-content-center">
<li class="nav-item">
<a><%= link_to "Top Media", root_path %> |</a>
</li>
<li class="nav-item">
<a><%= link_to "View all Media", works_path %> |</a>
</li>
<li class="nav-item">
<a><%= link_to "Add a New Work", new_work_path %> |</a>
</li>
<li class="nav-item">
<a><%= link_to "View All Users", users_path %> |</a>
</li>
<% if session[:user_id] == nil %>
<li class="nav-item">
<a><%= link_to "Log In |", login_path %></a>
</li>
<% else %>
<li class="nav-item">
<a>Logged in as: <%= User.find_by(id: session[:user_id]).username %> |</a>
</li>
<% end %>
<% if session[:user_id] %>
<li class="nav-item">
<a><%= link_to "Log Out", logout_path, method: :post%></a>
</li>
<% end %>
</ul>

Choose a reason for hiding this comment

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

This content should be in the body tag to be proper HTML.

@@ -0,0 +1,36 @@
<body>

Choose a reason for hiding this comment

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

The body tag is in the layout file and there should only be one body in the HTML document.

Perhaps you meant main

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