settler 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/helper.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'pp'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+
8
+ require 'FileUtils'
9
+
10
+ gem "activerecord"
11
+ require 'active_record'
12
+
13
+ require File.dirname(__FILE__) + '/../init.rb'
14
+
15
+ def load_schema
16
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
17
+ ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new(File.dirname(__FILE__) + "/debug.log")
18
+ db_adapter = ENV['DB']
19
+ # no db passed, try one of these fine config-free DBs before bombing.
20
+ db_adapter ||= begin
21
+ require 'rubygems'
22
+ require 'sqlite'
23
+ 'sqlite'
24
+ rescue MissingSourceFile
25
+ begin
26
+ require 'sqlite3'
27
+ 'sqlite3'
28
+ rescue MissingSourceFile
29
+ end
30
+ end
31
+
32
+ if db_adapter.nil?
33
+ raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
34
+ end
35
+ ActiveRecord::Base.establish_connection(config[db_adapter])
36
+ load(File.dirname(__FILE__) + "/schema.rb")
37
+ end
38
+
data/test/schema.rb ADDED
@@ -0,0 +1,11 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :settings, :force => true do |t|
3
+ t.string :key, :null => false
4
+ t.string :alt
5
+ t.text :value
6
+ t.boolean :editable
7
+ t.boolean :deletable
8
+ t.boolean :deleted
9
+ t.timestamps
10
+ end
11
+ end
data/test/settler.yml ADDED
@@ -0,0 +1,16 @@
1
+ settings:
2
+ google_analytics_key:
3
+ alt: Google analytics key
4
+ value: 'UA-xxxxxx-x'
5
+ editable: true
6
+ deletable: false
7
+ validations:
8
+ presence: true
9
+ search_algorithm:
10
+ alt: Default search engine
11
+ value: 'ferret'
12
+ editable: false
13
+ deletable: true
14
+ validations:
15
+ inclusion: [ 'ferret' , 'sphinx' ]
16
+
@@ -0,0 +1,68 @@
1
+ require 'helper'
2
+
3
+ class TestSettler < Test::Unit::TestCase
4
+ load_schema
5
+
6
+ def setup
7
+ Setting.without_default_scope{ Setting.delete_all }
8
+ Settler.source = File.dirname(__FILE__) + '/settler.yml'
9
+ Settler.namespace = 'settings'
10
+ Settler.load!
11
+ end
12
+
13
+ def test_should_load_settings
14
+ assert_equal ['google_analytics_key', 'search_algorithm'], Settler.settings
15
+ end
16
+
17
+ def test_should_find_setting_value
18
+ assert_equal 'ferret', Settler[:search_algorithm]
19
+ assert_equal 'ferret', Settler.search_algorithm.value
20
+ end
21
+
22
+ def test_should_get_validations_for_setting
23
+ assert_equal({'presence' => true}, Settler.validations_for(:google_analytics_key))
24
+ assert_equal({"inclusion"=>["ferret", "sphinx"]}, Settler.validations_for(:search_algorithm))
25
+ end
26
+
27
+ def test_should_not_create_instance
28
+ assert_raise NoMethodError do
29
+ Settler.new
30
+ end
31
+ end
32
+
33
+ def test_should_report_or_raise_missing
34
+ Settler.report_missing = true
35
+ Settler.raise_missing = true
36
+
37
+ assert_raise RuntimeError do
38
+ Settler.missing_setting
39
+ end
40
+ end
41
+
42
+ def test_should_not_destroy_undeletable_setting
43
+ assert !Settler.google_analytics_key.destroy
44
+ assert !Settler.google_analytics_key.deleted?
45
+ end
46
+
47
+ def test_should_destroy_setting
48
+ deletable_setting = Settler.search_algorithm
49
+ assert deletable_setting.deletable?
50
+ assert deletable_setting.destroy
51
+ assert_equal true, deletable_setting.deleted?
52
+ Settler.load!
53
+ assert_nil Settler.search_algorithm
54
+ end
55
+
56
+ def test_should_not_update_uneditable_setting
57
+ uneditable_setting = Settler.search_algorithm
58
+ assert !uneditable_setting.update_attributes(:value => 'new_value')
59
+ assert_equal 'ferret', Settler[:search_algorithm]
60
+ end
61
+
62
+ def test_should_update_editable_setting
63
+ editable_setting = Settler.google_analytics_key
64
+ assert editable_setting.update_attributes(:value => 'new_value')
65
+ assert_equal 'new_value', Settler[:google_analytics_key]
66
+ end
67
+
68
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: settler
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Reinier de Lange
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-23 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: This gem is a combination of the Squeegy's rails-settings and Binarylogic's settingslogic gem, meaning it reads its configuration from a YAML file, but stores all settings in the database as well for on the fly changes.
22
+ email: r.j.delange@nedforce.nl
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.rdoc
30
+ files:
31
+ - .document
32
+ - .gitignore
33
+ - LICENSE
34
+ - README.rdoc
35
+ - Rakefile
36
+ - VERSION
37
+ - generators/settler/settler_generator.rb
38
+ - generators/settler/templates/migration.rb
39
+ - generators/settler/templates/settler.yml
40
+ - init.rb
41
+ - lib/hash_extension.rb
42
+ - lib/setting.rb
43
+ - lib/settler.rb
44
+ - test/database.yml
45
+ - test/debug.log
46
+ - test/helper.rb
47
+ - test/schema.rb
48
+ - test/settler.yml
49
+ - test/test_settler.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/moiristo/settler
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Settler manages global application settings in Rails
80
+ test_files:
81
+ - test/helper.rb
82
+ - test/schema.rb
83
+ - test/test_settler.rb