Reflection to Tealeaf Course3 Week4
Three kinds of BDD
In week 4 beginning, we got a brief intro for 3 kinds of BDD:
meet in the middle
I think this should be the popular one for modern development. The front-end engineer build the pages from mockups, then back-end developer connect UI with controllers and models.
inside out
It develops from models to controllers till views and integrations. It’s hard to decide what models you really need in the beginning.
outside in
It devlops from integrations to controllers and models. It start from a big vision, and close to what user’s need. But for developer, it’s hard to code from this big vision, especially for integration test in the development beginning.
Self Referential Associations
We can use self referential association to let user track other users. For example:
1 | # t.integer :follower_id, :leader_id |
Then, model User
can have these virtual attributes:
1 | has_many :following_relationships, class_name: 'Relationship', foreign_key: :follower_id |
Sending Emails
Rails also offer ActionMailer
for sending emails.
- create files in
app/mailers/app_mailer.rb
1 | class AppMailer < ActionMailer::Base |
View
template inapp/views/app_mailers/send_welcome_email
:
1 | %html(lang='en-US') |
- Config for
config/environments/development.rb
1 | config.action_mailer.delivery_method = :letter_opener |
And
1 | group :development do |
This is only for
development
setting, we also need to set fortest
andproduction
independent
Handling Sensitive Account Info
It’s dangerous to upload config setting file to github or other public storage, there is someone update AWS key to GitHub and got a unbelievable credit bill.
Use ENV
to protect secret data, we can use gem Figaro
.
Figara is the simplest way to keep our key value safe.
There are two posts talking about this topic:
Update: Tealeaf also have a post about Managing Environment Configuration Variables in Rails
Test Email sending
Remember to clear email deliveries before test:
1 | before { ActionMailer::Base.deliveries.clear } |
Then we can validate email in the test by this
1 | post :create |
Update database, use rake tasks
An advice from TA Tomtomecek, I update existing data in model User, and he suggest me to use custom rake tasks to do that. I’ve not taste that yet, just leave a memo here to remember.