Question: New to TDD here, d'oh!

Here's what I want to test ([ruby library](https://www.twilio.com/docs/ruby/install)), in brief:

```
 account = Twilio::RestAccount.new(ACCOUNT_SID, ACCOUNT_TOKEN)
    resp = account.request(
        "/#{API_VERSION}/Accounts/#{ACCOUNT_SID}/SMS/Messages",
        'POST',
        smsInfo
    )

```

And here's test code attempt:

```
describe Text do
  it "should call the Twilio API with credentials" do
    #pending "mocking api although not passed in.."
    t = mock(Twilio::RestAccount)
    twapi = mock("new twapi").should_receive(:request).and_return(Net::HTTPSuccess)
    t.stub(:new).and_return(twapi)

    Twilio::RestAccount.should_receive(:new)

    sms = Factory.create(:boring_sms)
    sms.send_sms
  end
end

```

which generates the error: undefined method `request' for nil:NilClass

Am I taking the right approach? thanks!

Answer: 
Use database relations. Your three tables are `concept`, `idea`, and `comment`. Each concept has many ideas, and each idea has many comments (though I find it more intuitive so say "each idea is related to one concept, each comment is related to one idea").

Your tables will look something like:

```
concept: id timestamp title user_id
idea: id timestamp ip text concept_id user_id
comment: id text idea_id comment_id
user: id username ....

```

Your id fields are primary auto\_incrementing keys (you can set this in phpMyAdmin). So for example, your idea\_id in the comment table will relate a comment to an idea. To select all comments for idea `10`: `SELECT * FROM comment WHERE idea_id=10`

You can use [SQL join queries](http://www.tizag.com/sqlTutorial/sqljoin.php) to do more complicated stuff.
You're looking for "foreign key references." You will likely find yourself with three tables: questions, answers, and comments on answers. Answers will have a field referencing the id of the question it's responding to, and likewise you will have a field in the comments table referencing the id of the answer it's responding to. I hope these links can be helpful:

[Wikipedia](http://en.wikipedia.org/wiki/Foreign_key)

[w3c](http://www.w3schools.com/sql/sql_foreignkey.asp)

This is an important area of database design that requires some heavier reading than it sounds like you're expecting.