Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'spec_helper'
- describe User do
- before(:each) do
- @attr = {
- :username => "kiba",
- :email => "hackerkiba@gmail.com",
- :password => "boo33",
- :password_confirmation => "boo33",
- :experience => 0
- }
- end
- it "should create a new instance given valid attributes" do
- success = User.new(@attr)
- success.should be_valid
- end
- it "should not create a new instance if name is not there" do
- noname = User.new(@attr.merge(:username => ""))
- noname.should_not be_valid
- end
- it "should not create a new instance if experience is not there" do
- noexp = User.new(@attr.merge(:experience => ""))
- noexp.should_not be_valid
- end
- it "should fail if experience is not numerical" do
- string = User.new(@attr.merge(:experience => "asdf"))
- string.should_not be_valid
- end
- describe "quests association" do
- before(:each) do
- @user = User.create(@attr)
- @q2 = Factory(:quest,:user => @user, :deadline => Date.tomorrow)
- @q1 = Factory(:quest,:user => @user, :deadline => Date.yesterday)
- @attr = Factory(:quest)
- end
- it "should have username and such" do
- @user.username.should == "kiba"
- end
- it "should have a quests attribute" do
- @user.should respond_to(:quests)
- end
- it "should have the quests in the right order" do
- @user.quests.should == [@q2,@q1]
- end
- it "should destory associated quests" do
- @user.destroy()
- [@q1,@q2].each do |quest|
- Quest.find_by_id(quest.id).should be_nil
- end
- end
- it "when completed should increase users experience" do
- @q1.complete()
- @q1.completed.should == true
- @user.quests[1].completed.should == true
- @user.calculate()
- @user.experience.should == 24
- end
- end
- end
Add Comment
Please, Sign In to add comment