Skip to content

Conversation

@dev-elle-up
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 The Model references the data in the database. I think the term Model is also used to refer to the database directly.
Describe in your own words what the Controller is doing in Rails The Controller receives requests from the router, then accesses the data (Model) and View files, and finally sends the data as a web page back to the user.
Describe in your own words what the View is doing in Rails The View provides the HTML that gets returned to the user. The .html.erb file can contain Ruby code, which gets evaluated and turned into HTML before being displayed.
Describe an edge-case controller test you wrote One test makes sure that the user is redirected if they try to edit a task that doesn't exist.
What is the purpose of using strong params? (i.e. the params method in the controller) For security purposes, controllers cannot pass parameters from a form directly into an instance of the controller (to the database). Rails uses strong parameters to give the controller actions access to updating an instance's parameters.
How are Rails migrations related to Rails models? Migrations are used to create and change models.
Describe one area of Rails that are still unclear on There are two areas that are unclear. The first is writing custom routes / making buttons work (I'm not sure I made the 'mark complete' button correctly). Writing tests is also still unclear. I love the concepts and I want to be really good at this. I think right now syntax and not knowing what the options are are both holding me back.

@tildeee
Copy link

tildeee commented Apr 22, 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 tests incomplete
Routes follow RESTful conventions x
Uses named routes (like _path) x
Overall

Great job with this project, Elle! Your project hits all the requirements I was looking for: following Rails best practices, RESTful routes, and CRUD. Also, I'm so happy you used strong params well!

The only thing I have to comment on is your controller tests, which I think you knew would happen.
I think fundamentally what was going on is your understanding of how to make controller tests test the controller-- I think you tried to do something closer to testing models. Don't forget-- the goal of the controller tests is to make the action controller execute. The only way to get to that controller action is through sending a request in the test! So controller tests will have code that's more like get tasks_path or post tasks_path, params: some_hash_representing_form_data. I have more comments in line, but let me know what other questions you have.

That being said, your project looks great! Even the mark complete functionality -- it looks good to me. Well done!

elsif this_task.completed == false
this_task.completed = true
this_task[:date_completed] = Time.now
end
Copy link

Choose a reason for hiding this comment

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

Great work on this logic! It's accurate and has the right functionality. It can probably be refactored to something a little more slim. Don't forget-- if this_task.completed == true is the same thing as if this_task.completed, and you could use an else instead of elsif ...!

# Arrange
change_task = Task.find_by(task_name: "Clean the bathroom")

change_task.update(params: new_task_hash)
Copy link

Choose a reason for hiding this comment

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

Instead of calling update on the task itself, you'll want to use routes to get to the controller action you are testing. The method update that's on the task itself doesn't take a params hash... but the controller update action does! That's why your other version makes sense-- you call patch task_path(id), params: new_task_hash

# }.must_change task_to_toggle[:completed], true

# Act
task_to_toggle2.toggle_completed
Copy link

Choose a reason for hiding this comment

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

Here, you are calling toggle_completed as if it were an instance method on the model task_to_toggle2. However, your model doesn't have a method by that name defined! Instead, your Act will be to execute the code in the TasksController in the action/method named toggle_compelted... And how do you get to that code? Through the router! Your act will be whatever is the route defined to get there... which will be put toggle_completed_action_path

I think fixing the rest of your incomplete tests will follow this same pattern:

  1. Determine which controller and controller action you are testing
  2. Determine which route will get to that controller and controller action (delete task_path, maybe?)
  3. Determine which info needs to go along with it:
    • Does it have route params?
    • Does it have form data?
  4. Write out the "Act" in this test using that route and that additional information

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