Skip to content

Instantly share code, notes, and snippets.

@erikpukinskis
Created April 2, 2010 20:05
Show Gist options
  • Save erikpukinskis/353636 to your computer and use it in GitHub Desktop.
Save erikpukinskis/353636 to your computer and use it in GitHub Desktop.
require 'authlogic'
require 'spec'
require 'active_record'
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => 'test.db')
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.validate_login_field = {:if => :active?}
c.validate_password_field = {:if => :active?}
c.validate_email_field = {:if => :active?}
end
def activate
@active = true
end
def active?
@active === true
end
end
describe "User for gradual engagement" do
before :all do
ActiveRecord::Migration.create_table :users do |t|
t.timestamps
t.string :login, :null => false
t.string :crypted_password, :null => false
t.string :password_salt, :null => false
t.string :persistence_token, :null => false
end
end
after :all do
ActiveRecord::Migration.drop_table :users
end
it "should be valid if we don't activate it" do
User.new.should be_valid
end
it "should be invalid if we activate it" do
u = User.new
u.activate
u.should_not be_valid
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment