Sha256: 64a72a689aab61aee64ad3c0a3c7b3593f9aaca44ee18657340f2f13cbd38b29

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../../../test/test_helper'

class SettingsTest < Test::Unit::TestCase
  
	def setup
		Settings.create(:var => 'test',  :value => 'foo')
		Settings.create(:var => 'test2', :value => 'bar')
	end
	
  def test_defaults
    Settings.defaults[:foo] = 'default foo'
    
    assert_nil Settings.object(:foo)
    assert_equal 'default foo', Settings.foo
    
    Settings.foo = 'bar'
    assert_equal 'bar', Settings.foo
    assert_not_nil Settings.object(:foo)
  end
  
	def test_get
		assert_setting 'foo', :test
		assert_setting 'bar', :test2
	end
	
	def test_update
		assert_assign_setting '321', :test
	end
	
	def test_create
    assert_assign_setting '123', :onetwothree
	end
  
  def test_complex_serialization
    complex = [1, '2', {:three => true}]
    Settings.complex = complex
    assert_equal complex, Settings.complex
  end
  
  def test_serialization_of_float
    Settings.float = 0.01
    Settings.reload
    assert_equal 0.01, Settings.float
    assert_equal 0.02, Settings.float * 2
  end
  
  private
    def assert_setting(value, key)
      key = key.to_sym
      assert_equal value, eval("Settings.#{key}")
      assert_equal value, Settings[key.to_sym]
      assert_equal value, Settings[key.to_s]
    end
    
    def assert_assign_setting(value, key)
      key = key.to_sym
      assert_equal value, eval("Settings.#{key} = value")
      assert_setting value, key
      eval("Settings.#{key} = nil")
      
      assert_equal value, (Settings[key] = value)
      assert_setting value, key
      Settings[key] = nil
      
      assert_equal value, (Settings[key.to_s] = value)
      assert_setting value, key
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails-settings-1.0.0 test/settings_test.rb