Permalink
Browse files

Refactoring: Migrate object_type_lookup_test.rb to RSpec

  • Loading branch information...
Ryan Lue authored and znuny-robo committed Feb 11, 2019
1 parent 107fd5e commit 7639ef46d3f4ba2c262da3f35eaf21bf5d975fd5
@@ -0,0 +1,5 @@
FactoryBot.define do
factory :object_lookup do
name { (ApplicationModel.descendants.map(&:name) - ObjectLookup.pluck(:name)).sample }
end
end
@@ -11,7 +11,7 @@
.dig([:base, []])
.merge(TypeLookup.pluck(:name))

Faker::Verb.unique.base
Faker::Verb.unique.past_participle
end
end
end
@@ -0,0 +1,51 @@
require 'rails_helper'

RSpec.describe ObjectLookup, type: :model do
describe '.by_name' do
context 'with name matching an existing ObjectLookup record' do
subject(:object_lookup) { create(:object_lookup) }

it 'returns its id' do
expect(ObjectLookup.by_name(object_lookup.name))
.to eq(object_lookup.id)
end
end

context 'with name not matching any ObjectLookup records' do
let(:name) { 'FooBar' }

it 'creates a new one with that name' do
expect { ObjectLookup.by_name(name) }
.to change { ObjectLookup.count }.by(1)

expect(ObjectLookup.last.name).to eq(name)
end

it 'returns its id' do
expect(ObjectLookup.by_name(name))
.to eq(ObjectLookup.last.id)
end

context 'for names not in strict CamelCase' do
let(:name) { 'Foo_Bar' }

it 'does not modify the format' do
ObjectLookup.by_name(name)

expect(ObjectLookup.last.name).to eq(name)
end
end
end
end

describe '.by_id' do
context 'with number matching an existing ObjectLookup#id' do
subject(:object_lookup) { create(:object_lookup) }

it 'returns its name' do
expect(ObjectLookup.by_id(object_lookup.id))
.to eq(object_lookup.name)
end
end
end
end
@@ -0,0 +1,51 @@
require 'rails_helper'

RSpec.describe TypeLookup, type: :model do
describe '.by_name' do
context 'with name matching an existing TypeLookup record' do
subject(:type_lookup) { create(:type_lookup) }

it 'returns its id' do
expect(TypeLookup.by_name(type_lookup.name))
.to eq(type_lookup.id)
end
end

context 'with name not matching any TypeLookup records' do
let(:name) { 'FooBar' }

it 'creates a new one with that name' do
expect { TypeLookup.by_name(name) }
.to change { TypeLookup.count }.by(1)

expect(TypeLookup.last.name).to eq(name)
end

it 'returns its id' do
expect(TypeLookup.by_name(name))
.to eq(TypeLookup.last.id)
end

context 'for names not in strict CamelCase' do
let(:name) { 'Foo_Bar' }

it 'does not modify the format' do
TypeLookup.by_name(name)

expect(TypeLookup.last.name).to eq(name)
end
end
end
end

describe '.by_id' do
context 'with number matching an existing TypeLookup#id' do
subject(:type_lookup) { create(:type_lookup) }

it 'returns its name' do
expect(TypeLookup.by_id(type_lookup.id))
.to eq(type_lookup.name)
end
end
end
end

This file was deleted.

Oops, something went wrong.

0 comments on commit 7639ef4

Please sign in to comment.