Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 90 additions & 21 deletions spec/lib/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,106 @@ def mock_column(name, type, options = {})
double('Column', stubs)
end

it { expect(AnnotateModels.quote(nil)).to eql('NULL') }
it { expect(AnnotateModels.quote(true)).to eql('TRUE') }
it { expect(AnnotateModels.quote(false)).to eql('FALSE') }
it { expect(AnnotateModels.quote(25)).to eql('25') }
it { expect(AnnotateModels.quote(25.6)).to eql('25.6') }
it { expect(AnnotateModels.quote(1e-20)).to eql('1.0e-20') }
it { expect(AnnotateModels.quote(BigDecimal('1.2'))).to eql('1.2') }
it { expect(AnnotateModels.quote([BigDecimal('1.2')])).to eql(['1.2']) }

describe '#parse_options' do
describe '.quote' do
subject do
AnnotateModels.quote(value)
end

context 'when the argument is nil' do
let(:value) { nil }
it 'returns string "NULL"' do
is_expected.to eq('NULL')
end
end

context 'when the argument is true' do
let(:value) { true }
it 'returns string "TRUE"' do
is_expected.to eq('TRUE')
end
end

context 'when the argument is false' do
let(:value) { false }
it 'returns string "FALSE"' do
is_expected.to eq('FALSE')
end
end

context 'when the argument is an integer' do
let(:value) { 25 }
it 'returns the integer as a string' do
is_expected.to eq('25')
end
end

context 'when the argument is a float number' do
context 'when the argument is like 25.6' do
let(:value) { 25.6 }
it 'returns the float number as a string' do
is_expected.to eq('25.6')
end
end

context 'when the argument is like 1e-20' do
let(:value) { 1e-20 }
it 'returns the float number as a string' do
is_expected.to eq('1.0e-20')
end
end
end

context 'when the argument is a BigDecimal number' do
let(:value) { BigDecimal('1.2') }
it 'returns the float number as a string' do
is_expected.to eq('1.2')
end
end

context 'when the argument is an array' do
let(:value) { [BigDecimal('1.2')] }
it 'returns an array of which elements are converted to string' do
is_expected.to eq(['1.2'])
end
end
end

describe '.parse_options' do
let(:options) do
{
root_dir: '/root',
model_dir: 'app/models,app/one, app/two ,,app/three'
}
end

it 'sets @root_dir' do
before :each do
AnnotateModels.send(:parse_options, options)
expect(AnnotateModels.instance_variable_get(:@root_dir)).to eq('/root')
end

it 'sets @model_dir separated with a comma' do
AnnotateModels.send(:parse_options, options)
expected = [
'app/models',
'app/one',
'app/two',
'app/three'
]
expect(AnnotateModels.instance_variable_get(:@model_dir)).to eq(expected)
describe '@root_dir' do
subject do
AnnotateModels.instance_variable_get(:@root_dir)
end

it 'sets @root_dir' do
expect(AnnotateModels.instance_variable_get(:@root_dir)).to eq('/root')
end
end

describe '@model_dir' do
subject do
AnnotateModels.instance_variable_get(:@model_dir)
end

it 'separates option "model_dir" with commas and sets @model_dir as an array of string' do
expected = [
'app/models',
'app/one',
'app/two',
'app/three'
]
expect(subject).to eq(expected)
end
end
end

Expand Down