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
|
2011-08-25 21:28:56 +00:00
|
|
|
FactoryGirl.build(:membership, :account => FactoryGirl.build(:account)).should be_valid
|
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 validate presence of account' do
|
2011-08-25 21:28:56 +00:00
|
|
|
membership = FactoryGirl.build(:membership, :account => nil)
|
2010-05-10 22:39:52 +00:00
|
|
|
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
|
2011-08-25 21:28:56 +00:00
|
|
|
Account.stubs(:where).returns([FactoryGirl.build(:account)])
|
|
|
|
Account.stubs(:find).returns(FactoryGirl.build(:account))
|
|
|
|
membership = FactoryGirl.build(:membership, :account => nil)
|
2010-05-10 22:39:52 +00:00
|
|
|
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
|
2011-08-25 21:28:56 +00:00
|
|
|
@membership = FactoryGirl.build(:membership, :site => FactoryGirl.build(:site))
|
|
|
|
@account = FactoryGirl.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'
|
2011-07-05 16:30:12 +00:00
|
|
|
@membership.site.stubs(:memberships).returns([self.build_membership(@account), self.build_membership])
|
|
|
|
@membership.process!.should == :already_created
|
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
|
2011-07-05 16:30:12 +00:00
|
|
|
|
|
|
|
def build_membership(account = nil)
|
2011-08-25 21:28:56 +00:00
|
|
|
FactoryGirl.build(:membership, :site => FactoryGirl.build(:site), :account => account || FactoryGirl.build(:account))
|
2011-07-05 16:30:12 +00:00
|
|
|
end
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|