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: 
> 
> each concept would also have a table
> 
> 
> 

tables are not meant to be dynamic elements. of course they can be, but seriously.

a relational database structure has a static amount of tables.

please read about the [fundamentals of relational database design](http://www.deeptraining.com/litwin/dbdesign/FundamentalsOfRelationalDatabaseDesign.aspx)

the question whether you combine different entities in one table, and add a field to distinguish them, is very valid one. 

in the end i think it comes down to the application. it can seriously speed up things but also slow down. i prefer seperate tables because you save one index and may have it easier with sharding in fugure. UNION statements are cheap.

that being said. start with fixed objects, create tables for them.

create a table for "concepts" one for "ideas" one for "comments" one for "users" etc...

comments get a field for "idea" which idea they belong to etc.
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.