Sha256: 31dbb7b1d36f7e7b62561792aa79f87af9b13da26e2e9f20536dd0938cee60a4

Contents?: true

Size: 1.93 KB

Versions: 3

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'

describe User do
  before(:all) do
    @user = Factory.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 = Factory.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
    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

3 entries across 3 versions & 1 rubygems

Version Path
sunrise-core-0.2.2 spec/models/user_spec.rb
sunrise-core-0.2.1 spec/models/user_spec.rb
sunrise-core-0.2.0 spec/models/user_spec.rb