93 lines
3.8 KiB
Ruby
93 lines
3.8 KiB
Ruby
require 'spec_helper'
|
|
|
|
# these tests avoid the use of ActiveRecord and FactoryGirl to do blackbox, non test-instrumented tests
|
|
describe UserManager do
|
|
|
|
|
|
before(:each) do
|
|
@user_manager = UserManager.new(:conn => @conn)
|
|
UserMailer.deliveries.clear
|
|
end
|
|
|
|
describe "signup" do
|
|
it "signup successfully" do
|
|
@user = @user_manager.signup("bob", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
|
|
|
@user.errors.any?.should be_false
|
|
@user.name.should == "bob"
|
|
@user.email.should == "bob@jamkazam.com"
|
|
@user.email_confirmed.should be_false
|
|
@user.city.should == "Austin"
|
|
@user.state.should == "TX"
|
|
@user.country.should == "USA"
|
|
@user.instruments.length.should == 0
|
|
@user.signup_token.should_not be_nil
|
|
|
|
UserMailer.deliveries.length.should == 1
|
|
end
|
|
|
|
it "signup successfully with instruments" do
|
|
@user = @user_manager.signup("bob", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA",
|
|
[{ :instrument_id => "electric guitar", :proficiency_level => 3, :priority => 0}], "http://localhost:3000/confirm" )
|
|
|
|
@user.errors.any?.should be_false
|
|
@user.instruments.length.should == 1
|
|
musician_instrument = @user.musician_instruments[0]
|
|
musician_instrument.instrument.should == Instrument.find("electric guitar")
|
|
musician_instrument.proficiency_level.should == 3
|
|
end
|
|
|
|
it "duplicate signup failure" do
|
|
@user = @user_manager.signup("bob", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
|
UserMailer.deliveries.length.should == 1
|
|
@user.errors.any?.should be_false
|
|
|
|
# exactly the same parameters; should dup on email, and send no email
|
|
@user = @user_manager.signup("bob", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
|
UserMailer.deliveries.length.should == 1
|
|
@user.errors.any?.should be_true
|
|
@user.errors[:email][0].should == "has already been taken"
|
|
|
|
# change email so that name appears dupped
|
|
@user = @user_manager.signup("bob", "bobbie@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
|
UserMailer.deliveries.length.should == 1
|
|
@user.errors.any?.should be_true
|
|
@user.errors[:name][0].should == "has already been taken"
|
|
end
|
|
|
|
it "fail on no username" do
|
|
@user = @user_manager.signup("", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
|
UserMailer.deliveries.length.should == 0
|
|
@user.errors.any?.should be_true
|
|
@user.errors[:name][0].should == "can't be blank"
|
|
end
|
|
|
|
it "fail on no username" do
|
|
@user = @user_manager.signup("murp", "", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
|
UserMailer.deliveries.length.should == 0
|
|
@user.errors.any?.should be_true
|
|
@user.errors[:email][0].should == "can't be blank"
|
|
end
|
|
end
|
|
|
|
describe "signup_confirm" do
|
|
it "fail on no username" do
|
|
@user = @user_manager.signup("bob", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" )
|
|
@user = @user_manager.signup_confirm(@user.signup_token)
|
|
@user.email_confirmed.should be_true
|
|
end
|
|
|
|
it "fail to confirm bogus signup token" do
|
|
expect { @user_manager.signup_confirm("murp") }.to raise_error ActiveRecord::RecordNotFound
|
|
end
|
|
|
|
it "fail to confirm empty signup token" do
|
|
expect { @user_manager.signup_confirm("") }.to raise_error ActiveRecord::RecordNotFound
|
|
end
|
|
|
|
it "fail to confirm nil signup token" do
|
|
expect { @user_manager.signup_confirm(nil) }.to raise_error ActiveRecord::RecordNotFound
|
|
end
|
|
end
|
|
end
|