Family Tree Relation Conversion

The existing code works, but it looks very repetitive and inelegant. I would love to see a much more elegant and DRY solution.

Test Suite
                  context 'when user is male' do
    let(:u1) { create(:user, gender: 0) }
    let(:ft) { create(:family_tree, user: u1) }
    let(:u2) { create(:user, gender: 0) }
    let(:ft2) { create(:family_tree, user: u2) }
    let(:mem1) { create(:membership, invited: u2, relation: rel1, inviter: u1, family_tree: ft) }
    let(:mem2) { create(:membership, invited: u1, relation: rel2, inviter: u2, family_tree: ft2) }

    it "should convert the relation from 'son' to 'dad'" do
      rel1 = "son"
      rel2 = "dad"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'daughter' to 'dad'" do
      rel1 = "daughter"
      rel2 = "dad"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'mom' to 'son'" do
      rel1 = "mom"
      rel2 = "son"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'dad' to 'son'" do
      rel1 = "dad"
      rel2 = "son"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'grandfather' to 'grandson'" do
      rel1 = "grandfather"
      rel2 = "grandson"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'grandmother' to 'grandson'" do
      rel1 = "grandmother"
      rel2 = "grandson"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'great_grandfather' to 'great_grandson'" do
      rel1 = "great_grandfather"
      rel2 = "great_grandson"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'great_grandmother' to 'great_grandson'" do
      rel1 = "great_grandmother"
      rel2 = "great_grandson"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'niece' to 'uncle'" do
      rel1 = "niece"
      rel2 = "uncle"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'nephew' to 'uncle'" do
      rel1 = "nephew"
      rel2 = "uncle"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'aunt' to 'nephew'" do
      rel1 = "aunt"
      rel2 = "nephew"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'uncle' to 'nephew'" do
      rel1 = "uncle"
      rel2 = "nephew"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'sister' to 'brother'" do
      rel1 = "sister"
      rel2 = "brother"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'brother' to 'brother'" do
      rel1 = "brother"
      rel2 = "brother"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'wife' to 'husband'" do
      rel1 = "wife"
      rel2 = "husband"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'husband' to 'husband'" do
      rel1 = "husband"
      rel2 = "husband"
      expect(u1.convert_relation(rel1)).to eq rel2
    end

    it "should convert the relation from 'cousin' to 'cousin'" do
      rel1 = "cousin"
      rel2 = "cousin"
      expect(u1.convert_relation(rel1)).to eq rel2
    end
  end
                
Me bio pic
Language:

0 Suggestions