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:
== test code
require File.dirname(__FILE__) + '/../spec_helper'
describe "bidding on an item" do
controller_name :items
before :each do
@user = User.first
User.stub!(:current_user).with(@user)
puts @user.id, @user.login
end
it "should require a credit" do
@user.credits = 0
@user.save
post 'bid', :bid => {:auction_id => 1, :user_id => @user, :point =>
1}
assigns[:bid].should_not be_new_record
end
it "should be allowed with a credit" do
@user.credits = 1
@user.save
post 'bid', :bid => {:auction_id => 1, :user_id => @user, :point =>
1}
assigns[:bid].should be_new_record
end
end
== application code
def bid
if can_bid?(current_user)
@bid = Bid.new(params[:bid])
@bid.save
end
end
def can_bid?(user)
user.credits > 0
end
== Errors
1
quentin
F1
quentin
== Was expecting
1
A
F1
A
(rather than the bort fixtures)
== auction_spec.rake
namespace :db do
desc "Erase and fill the test database for auction spec"
task :auction_spec => "test" do
require 'populator'
require 'faker'
[Item, Auction, User, Charity].each(&:delete_all)
.
.
.
# Create activated non-admin user
user = User.create do |u|
u.login = 'A'
u.password = u.password_confirmation = 'foobar'
u.email = '[email protected]'
u.pref_charity_one_id = 1
u.pref_charity_two_id = 2
u.pref_charity_three_id = 3
u.credits = 10
end
# Activate non-admin user
user.register!
user.activate!
.
.
.
end
end
==
I feel open to constructive criticism, now, as to the method of using
test records. Though I'm not sure what my question is..
Thanks in advance.
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users