require 'rails_helper' module Logistics module Core RSpec.describe UnitService do describe '#convert_unit' do it 'converts to quintal' do create(:unit, abbreviation: 'qt', name: 'Quintal', rate_to_base: 1) create(:unit, abbreviation: 'kg', name: 'Kilogram', rate_to_base: 5) unit_service = UnitService.new converted = unit_service.convert_unit(20, 'kg') expect(converted).to eq 4 end it 'converts from quintal' do create(:unit, abbreviation: 'qt', name: 'Quintal', rate_to_base: 1) create(:unit, abbreviation: 'kg', name: 'Kilogram', rate_to_base: 5) unit_service = UnitService.new converted = unit_service.convert_unit(6, 'kg', false) expect(converted).to eq 30 end end end end end