A new week has started, and of course, we had breakfast together. First it was time to revise the expected objectives that we had last week, see if we had achieved them or not and then set this weeks goals.
Also among us, we had new people, the next couple of weeks we have new hackers in residence 🙂
After breakfast a couple of pending things, first one to check comments on one of the previous post done by a friend (@jaimeiniesta) , after reading it was time to modifying things.
One that I keep forgetting, before commiting into github make sure that .gitignore has at least the basics things configured, like not commiting your database.yml file, and your secret_token that is in config/initializers!!!
So, for that I had to remove my files from the remote repo but I didn’t want to lose them in the local repo, so copy the database to /tmp and
git rm config/database.yml
when going to do the push, I included in the commit things that I didn’t want so I had to come to the previous commit, to do this
git reset "HEAD^"
and you go back one commit 🙂 with every ^ you go back one commit 🙂 … in case you messed around too much.
Then we had a new session of Rails Q&A, this time testing and testing associations 🙂
Learning about FactoryGirl,in the factories, factory is inheritance, it can just inherit from 1 class while trait is composition , it gets methods from several classes, so you can have something like this, that look similar but are different
factory :with_comments do
after_create do |post|
FactoryGirl.create(:comments, :post => post)
end
trait :with_comments do
after_create do |post|
FactoryGirl.create(:comments, :post => post)
end
Until now I’ve been doing the testing using the “should” syntax but it seems that is going to get deprecated so now switching to rspec expectation syntax
Back to associations, what happens if you have an event but its location or organizers are deleted? I can happen that once a event is created its organizer disappears or the location
that host it is not anymore there, so we would delete the organizer and/or the location but we want to keep the event, so we could make it dependent :nullify so that the events will be kept on the DB, but their organizer_id and/or location_id will be set to nil.
has_many :events, dependent: :nullify
Sometimes I find difficult to verbalize what test I want to do, so I have to keep in mind the very basics and perhaps write it a hundred times 😛
#do the setup
#describe the action
#write the expectation
The day went on, we had some drinks to get to know better the hackers in residence, cool people!! and to wrap up some of us just decided to go to the cinema, nice to change activity too.
Time to start week 3 #hackership http://t.co/LguLegtlIx