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.
I would use three different tables with foreign keys to link them. But you may also nest comments (or whatever) by having a 'parent'-row on the comment-table, which is a foreign-key to this tables primary key.

```
CREATE TABLE IF NOT EXISTS `comment` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `parent_comment` int(11) DEFAULT NULL COMMENT 'allows commenting on comments (annotations)',
  `user` int(11) NOT NULL,
  `headline` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `content` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_comment_parent` (`parent_comment`),
  KEY `fk_comment_user` (`user`)
);

ALTER TABLE `comment`
  ADD CONSTRAINT `fk_comment_parent` FOREIGN KEY (`parent_comment`) REFERENCES `comment` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_comment_user` FOREIGN KEY (`user`) REFERENCES `user` (`id`) ON UPDATE CASCADE;

```