Sha256: a27ea3d6d8c3adbaf3b1322d4c65ac26c506ef5eb561f9d94717570dd2d5ff37

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

describe 'AppConfig' do
  before :all do
    establish_connection
    init_custom_table
    
    Item.create(:name => 'foo', :data => 'bar', :fmt => 'string')
  end
  
  it 'should raise InvalidSource error if source model is not defined' do
    AppConfig.configure
    proc { AppConfig.load }.should raise_error AppConfig::InvalidSource
  end
  
  it 'should raise InvalidSource error if source model was not found' do
    AppConfig.configure(:model => FakeModel)
    proc { AppConfig.load }.should raise_error AppConfig::InvalidSource
  end
  
  it 'should validate custom source fields' do
    AppConfig.configure(
      :model  => Item,
      :key    => 'name',
      :value  => 'data',
      :format => 'fmt'
    )
    
    proc { AppConfig.load }.should_not raise_error AppConfig::InvalidSource
    
    AppConfig.configure(
      :model  => Item,
      :key    => 'fake_field',
      :value  => 'data',
      :format => 'fmt'
    )
    
    proc { AppConfig.load }.should raise_error AppConfig::InvalidSource
  end
  
  it 'should load data from custom model' do
    
    AppConfig.configure(
      :model  => Item,
      :key    => 'name',
      :value  => 'data',
      :format => 'fmt'
    )
    
    AppConfig.load
    AppConfig.exist?('foo').should == true
    AppConfig.foo.should == 'bar'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
app-config-0.1.2 spec/source_spec.rb
app-config-0.1.1 spec/source_spec.rb