Sha256: 00c8d8d42ea37993b4bf601c8baf28752f7d0b3a4387615cfff4cfe8abc5fe67

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

describe UserAlias do

  describe ".taken?(alias)" do
    subject { UserAlias.taken?("j.doe") }
    describe "for the alias not being taken" do
      it { should be_false }
    end
    describe "for the alias being taken" do
      before { @user = create(:user, :alias => "j.doe" ) }
      it { should_not be_false }
      it { should == @user }
    end
  end

  describe "#taken?" do
    subject { UserAlias.new("foo").taken? }
    describe "for the alias not being taken" do
      it { should == false }
    end
    describe "for the alias being taken" do
      before { @user = create(:user, :alias => "foo") }
      it { should_not be_false }
      it { should == @user }
    end
  end

  describe ".generate_for(user)" do
    before do
      @user = create(:user, first_name: "John", last_name: "Doe")
    end
    subject { UserAlias.generate_for(@user) }
    describe "for no other user with the same last name existing" do
      it { should == "doe" }
    end
    describe "for a user with the same last name existing" do
      before { create(:user, first_name: "Otto", last_name: "Doe") }
      it { should == "j.doe" }
    end
    describe "for a user with the same last name and a first name with the same initial existing" do
      before { create(:user, first_name: "Jane", last_name: "Doe") }
      it { should == "john.doe" }
    end
    describe "for a user with the same first and last names existing" do
      before { create(:user, first_name: "John", last_name: "Doe", :alias => "some_other_alias") }
      describe "for the user having a date of birth given" do
        before { @user.date_of_birth = "1986-01-01".to_date }
        it { should == "john.doe.1986" }
      end
      describe "for the user having no date of birth given" do
        it { should == nil }
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
your_platform-1.0.1 spec/models/user_alias_spec.rb
your_platform-1.0.0 spec/models/user_alias_spec.rb
your_platform-0.0.2 spec/models/user_alias_spec.rb