The status feed: Add a failing test that microposts of my followed user should be included in my feed
The status feed: Implement the User#feed method using a not yet existing method 'Micropost.from_users_followed_by(self)'

Now more cases failed because we break the User#feed method
A first feed implementation (not scale well): Get all tests green by implementing Micropost.from_users_followed_by class method

Techniques:
The code is quite intricate:
  def self.from_users_followed_by
    followed_user_ids = user.followed_user_ids
    where("user_id IN (?) OR user_id = ?", followed_user_ids, user)
  end
To understand it we need to build it one piece a time:

1. We once write in User class:
  Micropost.where("user_id = ?", id)
This inspires us to write similarly in Micropost class:
  where("user_id in (?) OR user_id = ?", following_ids, user)
1) Here we omit the leading Micropost because the method live in Micropost class itself
2) Also note that 'followed_user_ids' should be a string with comma seperated user ids, according to SQL syntax

>>> Note <<<
We use the 'IN' syntax of SQL. However such SQL might have bad performance (the term is 'scalability'), or even break with some database provider, if the 'following_ids' contains say, 5,000 ids.
>>> end <<<

2. To build the string 'followed_user_ids' we could write something like:

  User.first.followed_users.map{ |i| i.to_s }.join(', ')

Which could be simplified using Ruby shorthand notation: If the same method (e.g. 'to_s') gets called on each element, we could use an ampersand and a symbol correspond to that method

  User.first.followed_users.map(&:id).join(', ')

3. Rails provides such common contructions by default: By appending '_ids' Rails will do the same thing for us

  User.first.followed_user_ids.join(', ')

>>> Note <<<
Here the 'followed_user_ids' method is synthesized by Active Record based on the has_many :followed_users association
>>> end <<<

When used in SQL, the "join(', ')" could be omitted, which will be like:

  User.first.followed_user_ids
Subselects (a better implementation): Use SQL subselect to implement Micropost.from_users_followed_by method

Techniques:
1. It's better if we could query like:
  SELECT * FROM microposts
  WHERE user_id IN (SELECT followed_id FROM relationships
                    WHERE follower_id = 1)
        OR user_id = 1
instead of:
  SELECT * FROM microposts
  WHERE user_id IN (2, 3, 4, 5, 6, 7, ...)
        OR user_id = 1

2. To achieve this we first replace:
  where("user_id IN (?) OR user_id = ?", followed_user_ids, user)
with:
  where("user_id IN (:followed_user_ids) OR user_id = :user_id",
      followed_user_ids: followed_user_ids, user_id: user)
They are equivalent. But if 'followed_user_ids' is inserted more than once, the latter is better.

3. We replace:
  followed_user_ids = user.followed_user_ids
with:
  followed_user_ids = "SELECT followed_id FROM relationships
                       WHERE follower_id = :user_id"

4. We use string interpolation to build the final result:
def self.from_users_followed_by
  followed_user_ids = "SELECT followed_id FROM relationships
                       WHERE follower_id = :user_id"
  where("user_id IN (#{followed_user_ids}) OR user_id = :user_id",
        user_id: user.id)
end