Day 64 : Another pull request!

So. We just made another pull request! And the builds are passing! 😀

Remember our previous blog post in which we faced “NoMethodError: undefined method `with_indifferent_access’ for ..:Array” in our teams controller spec? Well, we went to Monika with this and she figured it out in no seconds. The association between team and project is a has_one. But in our spec, we were passing in an array of values of the name attribute of the project. So it was expecting many more project attributes which we weren’t passing in. Passing it as a hash, one key value pair, solved it!

And the next problem was that the project name wasn’t getting saved ( we assumed it wasn’t getting saved, you’ll know why, keep reading ) in the teams form inspite of us using the accepts nested attributes in the teams model and setting up the proper associations. We were drawing blanks everywhere! So, Pavan helped us out here. He suggested a cool awesome way to find out the bug! Write specs for how you would expect your code to behave. So he helped us write specs for the code we wanted to test. Turned out that the project name was in fact getting saved along with the team. Okay, works good. Next. Why weren’t we able to see the team name in the form after hitting save and going back to edit the same form, then? Hmmm, some bug in the controller. Test the controller. Write specs in the controller. Used the reload method to reload the form and then test if the project name comes up in the reloaded form. Nope! Aha, gotcha. So. We go to our edit method in the controller and then see what is happening. We used build_project. Which meant that each time the page is reloaded, this build method creates a new object in memory which the view takes and displays. We definitely don’t want object for the project everytime the page is reloaded! We just want this to happen only when a selected team is editing their form for the first time! Made some code changes there in the edit method and now it works!

Keeping fingers crossed and hoping our PR gets merged soon! 😀

Here’s our pull request

P.S. We HAD to create a new PR. Our previous WIP one, well, we made a lot of mistakes with git. Not saying anymore 😛



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s