Sha256: b6efbae688a831925dde64b66fac98fb05a74ce4df0424292e19ee577497a0b4

Contents?: true

Size: 906 Bytes

Versions: 2

Compression:

Stored size: 906 Bytes

Contents

require File.dirname(__FILE__) + '/spec_helper'

class User < ActiveRecord::Base
  attr_accessible :first_name, :last_name, :username
  suggestions_for :username
end

describe UsernameSuggester::UsernameSuggestions do
  before(:each) do
    @user = User.new(:first_name => "Jerry", :last_name => "Luk")
  end
  
  it "should able to suggest usernames" do
    suggestions = @user.username_suggestions
    suggestions.should_not be_blank
    suggestions.should include "jerry"
  end
  
  it "should able to suggest usernames that are not taken" do
    UsernameSuggester::Suggester.send(:define_method, :rand) { 1 }
    
    User.create!(:username => "jerry")
    1.upto(10) do |i|
      User.create!(:username => "jerry#{i}")
    end
    suggestions = @user.username_suggestions
    suggestions.should_not be_blank
    suggestions.should_not include "jerry"
    suggestions.should include "jerry11"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
username_suggester-0.2.1 spec/suggestions_for_spec.rb
username_suggester-0.2.0 spec/suggestions_for_spec.rb