Sha256: f89ecd355feaa231ce03356018234c6971f92e78b2a909bff3575c73e7c82a7a

Contents?: true

Size: 1.99 KB

Versions: 26

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

describe Locomotive::Membership do

  it 'should have a valid factory' do
    FactoryGirl.build(:membership, account: FactoryGirl.build(:account)).should be_valid
  end

  it 'should validate presence of account' do
    membership = FactoryGirl.build(:membership, account: nil)
    membership.should_not be_valid
    membership.errors[:account].should == ["can't be blank"]
  end

  it 'should assign account from email' do
    Locomotive::Account.stubs(:where).returns([FactoryGirl.build(:account)])
    Locomotive::Account.stubs(:find).returns(FactoryGirl.build(:account))
    membership = FactoryGirl.build(:membership, account: nil)
    membership.email = 'bart@simpson.net'
    membership.account.should_not be_nil
    membership.account.name.should == 'Bart Simpson'
  end

  describe 'next action to take' do

    before(:each) do
      @membership = FactoryGirl.build(:membership, site: FactoryGirl.build(:site))
      @account = FactoryGirl.build(:account)
      @account.stubs(:save).returns(true)
      Locomotive::Account.stubs(:where).returns([@account])
      Locomotive::Account.stubs(:find).returns(@account)
    end

    it 'should tell error' do
      @membership.process!.should == :error
    end

    it 'should tell we need to create a new account' do
      Locomotive::Account.stubs(:where).returns([])
      @membership.email = 'homer@simpson'
      @membership.process!.should == :create_account
    end

    it 'should tell nothing to do' do
      @membership.email = 'bart@simpson.net'
      @membership.site.stubs(:memberships).returns([self.build_membership(@account), self.build_membership])
      @membership.process!.should == :already_created
    end

    it 'should tell membership has to be saved' do
      @membership.email = 'bart@simpson.net'
      @membership.process!.should == :save_it
    end

    def build_membership(account = nil)
      FactoryGirl.build(:membership, site: FactoryGirl.build(:site), account: account || FactoryGirl.build(:account))
    end

  end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
locomotive_cms-2.5.7 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.6 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.6.rc2 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.6.rc1 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.5 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.4 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.3 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.2 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.1 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.0 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.0.rc3 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.0.rc2 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.5.0.rc1 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.4.1 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.4.0 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.3.1 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.3.0 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.2.3 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.2.2 spec/models/locomotive/membership_spec.rb
locomotive_cms-2.2.1 spec/models/locomotive/membership_spec.rb