Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0b30e9
commit cd97ea0
Showing
5 changed files
with
173 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
require 'rubygems' | ||
|
||
desc 'Default: run unit tests.' | ||
task :default => :test | ||
|
||
desc 'Test the fleximage plugin.' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.pattern = 'test/*_test.rb' | ||
t.verbose = true | ||
end | ||
|
||
|
||
desc 'Generate documentation for the rails-settings plugin.' | ||
Rake::RDocTask.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'Rails Settings' | ||
rdoc.options << '--line-numbers' << '--inline-source' | ||
rdoc.rdoc_files.include('README.rdoc') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
|
||
begin | ||
require 'jeweler' | ||
Jeweler::Tasks.new do |gem| | ||
gem.name = "rails-settings" | ||
gem.summary = <<EOF | ||
Settings is a plugin that makes managing a table of global key, value pairs | ||
easy. Think of it like a global Hash stored in your database, that uses simple | ||
ActiveRecord like methods for manipulation. Keep track of any global setting | ||
that you don't want to hard code into your rails app. You can store any kind | ||
of object. Strings, numbers, arrays, or any serializable object. | ||
EOF | ||
gem.description = <<EOF | ||
Settings is a plugin that makes managing a table of global key, value pairs | ||
easy. | ||
EOF | ||
gem.email = "ruby@beautifulpixel.com" | ||
gem.homepage = "http://github.com/Squeegy/rails-settings" | ||
gem.authors = `git log --pretty=format:"%an"`.split("\n").uniq.sort | ||
gem.add_development_dependency "rails", ">=2.0.1" | ||
end | ||
Jeweler::GemcutterTasks.new | ||
rescue LoadError | ||
puts "Jeweler (or a dependency) not available." | ||
puts "Install it with: gem install jeweler" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
require 'settings' | ||
require File.expand_path(File.join(File.dirname(__FILE__), %w(lib settings))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Generated by jeweler | ||
# DO NOT EDIT THIS FILE DIRECTLY | ||
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command | ||
# -*- encoding: utf-8 -*- | ||
|
||
Gem::Specification.new do |s| | ||
s.name = %q{rails-settings} | ||
s.version = "1.0.0" | ||
|
||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | ||
s.authors = ["Alex Wayne", "Joshua Clayton", "squeegy"] | ||
s.date = %q{2009-12-24} | ||
s.description = %q{Settings is a plugin that makes managing a table of global key, value pairs | ||
easy. | ||
} | ||
s.email = %q{ruby@beautifulpixel.com} | ||
s.extra_rdoc_files = [ | ||
"README.rdoc" | ||
] | ||
s.files = [ | ||
"MIT-LICENSE", | ||
"README.rdoc", | ||
"generators/settings_migration/USAGE", | ||
"generators/settings_migration/settings_migration_generator.rb", | ||
"generators/settings_migration/templates/migration.rb", | ||
"init.rb", | ||
"lib/settings.rb", | ||
"test/settings_test.rb" | ||
] | ||
s.homepage = %q{http://github.com/Squeegy/rails-settings} | ||
s.rdoc_options = ["--charset=UTF-8"] | ||
s.require_paths = ["lib"] | ||
s.rubygems_version = %q{1.3.5} | ||
s.summary = %q{Settings is a plugin that makes managing a table of global key, value pairs easy. Think of it like a global Hash stored in your database, that uses simple ActiveRecord like methods for manipulation. Keep track of any global setting that you don't want to hard code into your rails app. You can store any kind of object. Strings, numbers, arrays, or any serializable object.} | ||
s.test_files = [ | ||
"test/settings_test.rb" | ||
] | ||
|
||
if s.respond_to? :specification_version then | ||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION | ||
s.specification_version = 3 | ||
|
||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then | ||
s.add_development_dependency(%q<rails>, [">= 2.0.1"]) | ||
else | ||
s.add_dependency(%q<rails>, [">= 2.0.1"]) | ||
end | ||
else | ||
s.add_dependency(%q<rails>, [">= 2.0.1"]) | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
#!/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 | ||
#!/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 |