Sha256: 17585dff6c5de43295e7590eaf01c6766749bd96dbcf348a068823a40e62b721

Contents?: true

Size: 1.99 KB

Versions: 9

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

describe User do
  before(:all) do
    @user = FactoryGirl.build(:default_user)
  end
  
  it "should create a new instance given valid attributes" do
    @user.save!
  end
    
  context "validations" do
    it "should not be valid with empty name" do
      @user.name = nil
      @user.should_not be_valid
    end
    
    it "should not be valid with empty email" do
      @user.email = nil
      @user.should_not be_valid
    end
    
    it "should not be valid with invalid email" do
      @user.email = 'wrong'
      @user.should_not be_valid
    end
    
    it "should not be valid with invalid password" do
      @user.password = '123'
      @user.should_not be_valid
    end
  end
  
  context "after create" do
    before(:each) do
      @user = FactoryGirl.create(:default_user)
    end
    
    it 'should search users by email' do
      User.with_email(@user.email.split(/@/).first).first.should == @user
    end
    
    it "should search users by role" do
      User.with_role(::RoleType.default.id).all.should include(@user)
    end
    
    it "export users in csv format" do
      User.to_csv.should include([@user.id,@user.email,@user.name,@user.current_sign_in_ip].join(','))
    end
    
    it "export users in csv format with custom columns" do
      options = { :columns => [:id, :email, :confirmed_at, :created_at ] }
      User.to_csv(options).should include([@user.id,@user.email,@user.confirmed_at,@user.created_at].join(','))
    end
    
    it "should set default role" do
      @user.role_type_id.should == RoleType.default.id
      @user.role_symbol.should == RoleType.default.code
    end
    
    it 'should return default avatar image' do
      @user.avatar_small_url.should == "/images/manage/user_pic_small.gif"
    end
    
    it "should return current user events" do
      @user.confirmed_at = nil
      @user.lock_access!
      
      @user.events_for_current_state.should include('unlock')
      @user.events_for_current_state.should include('activate')
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sunrise-cms-0.4.2 spec/models/user_spec.rb
sunrise-cms-0.4.1 spec/models/user_spec.rb
sunrise-cms-0.4.0 spec/models/user_spec.rb
sunrise-cms-0.3.3 spec/models/user_spec.rb
sunrise-cms-0.3.2 spec/models/user_spec.rb
sunrise-cms-0.3.1 spec/models/user_spec.rb
sunrise-cms-0.3.0 spec/models/user_spec.rb
sunrise-cms-0.3.0.rc2 spec/models/user_spec.rb
sunrise-cms-0.3.0.rc spec/models/user_spec.rb