Sha256: c5981cee13f9190e00d98d951c7df620b2f366eed61d4c44db1497e1dd24eefe

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

require File.expand_path('../../spec_helper', __FILE__)

describe "Has Person Name" do
  before(:each) do
    clean_database!
  end

  describe "Automatic name assignment" do
    before(:each) do
      clean_database!
      @person = Person.new
    end

    it "should have an accessor for the defined name fields" do
      @person.should respond_to(:name)
    end

    it "should read active_record attributes" do
      @person.name_first_name = "Matthijs"
      @person.name.first_name.should == "Matthijs"

      @person.name_last_name = "Groen"
      @person.name.last_name.should == "Groen"

      @person.name.to_s.should == "Matthijs Groen"
    end

    it "should assign active_record attributes" do
      @person.name.first_name = "Matthijs"
      @person.name_first_name.should == "Matthijs"

      @person.name.last_name = "Groen"
      @person.name_last_name.should == "Groen"
    end

    it "should split up name parts and assign to correct fields" do
      test_fields = %w(prefix first_name middle_name intercalation last_name suffix)
      test_cases = [
        [nil, "Matthijs", nil, nil, "Groen", nil],
        [nil, "Matthijs", "Jacobus", nil, "Groen", nil],
        [nil, "Frans", nil, "van der", "Sluis", nil],
        [nil, "Maria", "Cornelia Hendrina", nil, "Damen-van Valenberg", nil],
        [nil, "Dirk", "Jan", "van de", "Abeele", nil],
        [nil, "Yolanthe", "Cabau", "van", "Kasbergen", nil],
      ]

      test_cases.each do |fields|
        string = fields.compact.join(" ")
        @person = Person.new
        @person.name = string

        test_fields.each_with_index do |field, index|
          @person.name.send(field).should == fields[index]
        end
      end
    end

    it "should remember corrections" do
      @person.name.first_name = "Yolanthe"
      @person.name.last_name = "Cabau van Kasbergen"

      @person.name = "Yolanthe Truuske Cabau van Kasbergen"
      @person.name.middle_name.should == "Truuske"
      @person.name.last_name.should == "Cabau van Kasbergen"
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
person-name-0.2.2 spec/person_name/has_person_name_spec.rb
person-name-0.2.1 spec/person_name/has_person_name_spec.rb