2010-05-10 22:39:52 +00:00
|
|
|
require 'spec_helper'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
describe Membership do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
it 'should have a valid factory' do
|
|
|
|
Factory.build(:membership, :account => Factory.build(:account)).should be_valid
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
it 'should validate presence of account' do
|
|
|
|
membership = Factory.build(:membership, :account => nil)
|
|
|
|
membership.should_not be_valid
|
|
|
|
membership.errors[:account].should == ["can't be blank"]
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
it 'should assign account from email' do
|
|
|
|
Account.stubs(:where).returns([Factory.build(:account)])
|
|
|
|
Account.stubs(:find).returns(Factory.build(:account))
|
|
|
|
membership = Factory.build(:membership, :account => nil)
|
|
|
|
membership.email = 'bart@simpson.net'
|
|
|
|
membership.account.should_not be_nil
|
|
|
|
membership.account.name.should == 'Bart Simpson'
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
describe 'next action to take' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
before(:each) do
|
2010-05-10 22:39:52 +00:00
|
|
|
@membership = Factory.build(:membership, :site => Factory.build(:site))
|
|
|
|
@account = Factory.build(:account)
|
2010-07-13 20:01:40 +00:00
|
|
|
@account.stubs(:save).returns(true)
|
2010-05-10 22:39:52 +00:00
|
|
|
Account.stubs(:where).returns([@account])
|
|
|
|
Account.stubs(:find).returns(@account)
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
it 'should tell error' do
|
2010-07-13 20:01:40 +00:00
|
|
|
@membership.process!.should == :error
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
it 'should tell we need to create a new account' do
|
|
|
|
Account.stubs(:where).returns([])
|
|
|
|
@membership.email = 'homer@simpson'
|
2010-07-13 20:01:40 +00:00
|
|
|
@membership.process!.should == :create_account
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
it 'should tell nothing to do' do
|
|
|
|
@membership.email = 'bart@simpson.net'
|
|
|
|
@membership.site.stubs(:memberships).returns([@membership, @membership])
|
2010-07-13 20:01:40 +00:00
|
|
|
@membership.process!.should == :nothing
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
it 'should tell membership has to be saved' do
|
|
|
|
@membership.email = 'bart@simpson.net'
|
2010-07-13 20:01:40 +00:00
|
|
|
@membership.process!.should == :save_it
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|