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

Branches-Sara #29

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

Branches-Sara #29

wants to merge 16 commits into from

Conversation

sarashahbaig
Copy link

Task List

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Describe in your own words what the Model is doing in Rails A model is like a class; it talks to the database, stores and validates data.
Describe in your own words what the Controller is doing in Rails Controller dos the work of analyzing user requests, data submissions, cookies and sessions.
Describe in your own words what the View is doing in Rails Views are what the user sees as HTML, CSS.
Describe an edge-case controller test you wrote get edit_task_path(-1) must_respond_with :redirect.
What is the purpose of using strong params? (i.e. the params method in the controller) Strong params helps protect against assignment to the model and gives us control to do so in the controller where it belongs.
How are Rails migrations related to Rails models? Requirements change all the time, and those changes often lead to database changes which are in Rails models.
Describe one area of Rails that are still unclear on Nothing in particular.

@tildeee
Copy link

tildeee commented Oct 14, 2019

Task List

What We're Looking For

Feature Feedback
Baseline
Appropriate Git Usage with no extraneous files checked in x
Answered comprehension questions x
Successfully handles: Index, Show x
Index & Show tests pass x
Successfully handles: New, Create x
New & Create tests pass x
Successfully handles: Edit, Update x
Tests for Edit & Update test valid & invalid task ids x
Successfully handles: Destroy, Task Complete x
Tests for Destroy & Task Complete include tests for valid and invalid task ids x, missing edge cases
Routes follow RESTful conventions could be improved
Uses named routes (like _path) x
Overall

Well done on this project, Sara! Your code generally looks good, and your tests generally look good.

However, you have a couple of places that I have some concern about for syntax, with possibly some concerns for understanding. I hope that when you read these comments, you'll have a better sense for ways to improve syntax, areas of concept to review, and questions for me or for any instructor.

  • routes
  • edge cases on tests for controllers
  • updating models using dot syntax (.)
  • using find_by to determine if a Task is missing

Let me know what questions you have! Keep up the hard work!

a {
font-size: 12px;
text-decoration: none;
color: white;
Copy link

Choose a reason for hiding this comment

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

Because of this style, which makes all links turn white, it was impossible for me to see the link to Mark Complete or Mark Incomplete, so I almost thought that this feature wasn't done! Watch out with your styles and think about what the user sees.

must_redirect_to root_path

expect( Task.find_by(id: id) ).must_be_nil
end
Copy link

Choose a reason for hiding this comment

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

What about a test for deleting a task that doesn't exist?

}
}
#Act
patch task_path(existing_task.id, params: update_task_from_data)
Copy link

Choose a reason for hiding this comment

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

This test doesn't use your complete_task_path route, and uses a completely different route/action here. In fact, it doesn't even go into the TasksController toggle_complete action here!


#Assert
expect( Task.find_by(id: existing_task.id).completed).wont_equal nil
end
Copy link

Choose a reason for hiding this comment

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

What happens if we try to toggle_complete on a task that doesn't exist? It would be awesome to have a test here on that.


# patch '/tasks/update/:id', to: 'tasks#update', as: 'task_update'

delete '/tasks/:id', to: 'tasks#destroy', as: 'task_delete'
Copy link

Choose a reason for hiding this comment

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

Hm, here you make a new route to delete a task. This is a route that can be generated with the resources, like the in line above with resources :tasks


# get '/tasks/:id/edit', to: 'tasks#edit', as: 'edit_task'

# patch '/tasks/update/:id', to: 'tasks#update', as: 'task_update'
Copy link

Choose a reason for hiding this comment

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

This file may be easier to work with if you delete the comments


delete '/tasks/:id', to: 'tasks#destroy', as: 'task_delete'

get '/tasks/complete/:id', to: 'tasks#toggle_complete', as: 'complete_task'
Copy link

Choose a reason for hiding this comment

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

What is the controller action tasks#toggle_complete (TasksController, toggle_complete action) supposed to do? It's supposed to change a task's data so that it's complete. Since it's going to change task data, instead of ask/query for data, we should think about the HTTP Verb for this route. The HTTP Verb you defined is get, which is usually associated with asking/querying for information. Since we're not querying, we should use the HTTP Verbs associated with changing information, like patch or put. Therefore, maybe the better version of this route may be patch '/tasks/complete/:id', to: 'tasks#toggle_complete', as: 'complete_task'

Of course, this will affect the link in the view that goes to this route.

@@ -0,0 +1,117 @@
class TasksController < ApplicationController
def index
@tasks = Task.all.order(:id)
Copy link

Choose a reason for hiding this comment

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

Nice detail to order and sort them!

@task = Task.find_by(id: task_id)

if task_id < 0
flash[:Error] = "Could not find task with id: -1"
Copy link

Choose a reason for hiding this comment

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

We haven't learned what flash is yet -- what are you doing here? :)


def update
id = params[:id].to_i
if id < 0
Copy link

Choose a reason for hiding this comment

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

Your conditional if id < 0 is to help determine if the task was not found. However, this is not a very solid way of approaching the problem. This logic works if params[:id] is equal to -1. What if params[:id] is equal to tacocat? Then id would equal 0. Also, what if params[:id] is equal to 999, which is a valid number, but there isn't a task with that ID number?

The better thing to do would be to check if Task.find_by gives back a task or if it gives back nil.

Let me know if you have questions, because this is really important

@task[:description] = params[:task][:description]
@task[:completed] = params[:task][:completed]

if @task.save
Copy link

@tildeee tildeee Oct 14, 2019

Choose a reason for hiding this comment

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

Instead of re-assigning each part of @task, it will be better practice to use strong params, so to change this method to

@task = Task.find_by(id: id)
if @task.update(task_params)

id = params[:id]
@task = Task.find_by(id: id)
if @task.completed == nil
@task[:completed] = "yes"
Copy link

Choose a reason for hiding this comment

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

Instead of using this syntax with the square brackets, the same thing can be accomplished with . and it is more Rails-y

@task.completed = "yes"

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