On Wed, Dec 31, 2008 at 3:52 AM, Jesse C. firstname.lastname@example.org
Good new and good news.
First, I’m starting from the floor up. (The groundwork is still past my
anxiety threshhold.) I’ve saved all the preexisting work to a
refactor_me file in the rails_root; starting over:
Assuming this is a controller spec, you’re going to want to stub
controller.current_user, not User.current user:
== application code
== Was expecting
Not sure why you’re expecting “A” here. In before(:each) the #puts
statement prints the id of User.first (which is 1) and the login of
that same user (which is “quentin”). The “F” is for a failing example
and there should be another one somewhere in the output (or a “.” if
one is passing).
[Item, Auction, User, Charity].each(&:delete_all)
If you use transactional_fixtures, this should not be necessary.
transactional_fixtures is the wrong name - it really means
transactional examples - each example is run in a transaction that is
rolled back. So if you start w/ a truncated db, each example fires up
a transaction, loads up fixtures, runs the example, rolls back the
transaction. Make sense?
u.pref_charity_three_id = 3
u.credits = 10
Activate non-admin user
You can keep these lines in the block - I would, though I wouldn’t
populate fixture data in a custom rake task like this.
If you’re using fixtures, just make this a fixture in
But I would recommend using something other than fixtures for sample
data. There are several problems with fixtures, some of which have
been resolved by the rails team over time, but the one that still
remains is that you have to look at another file to understand your
There are several libraries that help with this problem by letting you
set up default model builders that know how to build a valid model
with reasonable (what reasonable means is up to you - they are user
defined) defaults, but then override those defaults in your examples.
Take a look at these:
All three are very popular, work well, and offer different approaches
to setting up the default data, but all three let you override that
data in your code examples. Take a look at their READMEs and see if
this makes sense. Feel free to post back if you have questions.