On 15 December 2010 12:23, Gareth Townsend <[email protected]> wrote:
> If you need to write to the DB in order to test, then don't test those things 
> in the specs.
>

For a lot of the model methods, there is some custom SQL with lots of
joins etc. going on and many of the model specs just test these
queries actually work... in fact, just about every non-trivial model
test requires some models to exist (users with certain permissions
etc.).. I'm guess we're just testing wrong, but I'm not sure how to
get around these cases:

(examples made up)

1) Testing queries

student = Factory(:student)
course = Factory(:course, :taken_by => student)
# ....
Classroom.student_scope.include?(student).should be_true

Imagine student_scope was a named_scope with a long/complex query I
wanted to test... how else could this be done?

2) Testing methods which create other models

student = Factory(:student)
student.send_email! # will create Email models...
Email.count.should == 1

# I suppose this could be done by mocking calls to Email#save! ?

etc.

I'm probably just doing it wrong... but it's amazing you manage to
have a test suite with no inserts at all!

Robert

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to