Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I test for belongs_to and has_many in Rails?

I'm using rspec and I'm trying to test whether or not my model y has many x. I've tried all sorts of things, including looping through the methods array, and can't seem to find a good method online. So what should I use?

like image 770
Brian Hicks Avatar asked Sep 12 '10 23:09

Brian Hicks


1 Answers

Without much hacking you could use remarkable gem: http://github.com/carlosbrando/remarkable

Taken from remarkable docs:

    describe Post do
      it { should belong_to(:user) }
      it { should have_many(:comments) }
      it { should have_and_belong_to_many(:tags) }
    end
like image 53
Tumas Avatar answered Sep 29 '22 12:09

Tumas