Permalink
Browse files

Add RSpec test.

  • Loading branch information...
1 parent 93fc39c commit 725ae77682eb9fbca56013c886827446901e306e @huacnlee committed Feb 9, 2012
View
1 .rspec
@@ -0,0 +1 @@
+--colour --format nested
View
@@ -0,0 +1,8 @@
+source "http://rubygems.org"
+
+gem 'rails'
+
+group :test do
+ gem 'rspec-rails'
+ gem 'sqlite3'
+end
View
@@ -0,0 +1,102 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.2.1)
+ actionpack (= 3.2.1)
+ mail (~> 2.4.0)
+ actionpack (3.2.1)
+ activemodel (= 3.2.1)
+ activesupport (= 3.2.1)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.1)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.1)
+ activesupport (= 3.2.1)
+ builder (~> 3.0.0)
+ activerecord (3.2.1)
+ activemodel (= 3.2.1)
+ activesupport (= 3.2.1)
+ arel (~> 3.0.0)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.1)
+ activemodel (= 3.2.1)
+ activesupport (= 3.2.1)
+ activesupport (3.2.1)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.0)
+ builder (3.0.0)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ journey (1.0.1)
+ json (1.6.5)
+ mail (2.4.1)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.17.2)
+ multi_json (1.0.4)
+ polyglot (0.3.3)
+ rack (1.4.1)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.2.1)
+ actionmailer (= 3.2.1)
+ actionpack (= 3.2.1)
+ activerecord (= 3.2.1)
+ activeresource (= 3.2.1)
+ activesupport (= 3.2.1)
+ bundler (~> 1.0)
+ railties (= 3.2.1)
+ railties (3.2.1)
+ actionpack (= 3.2.1)
+ activesupport (= 3.2.1)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ rspec-rails (2.8.1)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.8.0)
+ sprockets (2.1.2)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.5)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.31)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rails
+ rspec-rails
+ sqlite3
View
104 README.md
@@ -0,0 +1,104 @@
+# Settings Gem
+
+This is improved from rails-settings, added caching for all settings.
+Settings is a plugin that makes managing a table of global key, value pairs easy.
+Think of it like a global Hash stored in you database, that uses simple ActiveRecord
+like methods for manipulation. Keep track of any global setting that you dont want
+to hard code into your rails app. You can store any kind of object. Strings, numbers,
+arrays, or any object. Ported to Rails 3!
+
+
+## Setup
+
+Edit your Gemfile:
+
+ gem "rails-settings-cached"
+
+Generate your settings:
+
+ rails g settings <settings_name>
+
+Now just put that migration in the database with:
+
+ rake db:migrate
+
+
+## Usage
+
+You need create a class in `app/models/setting.rb` :
+
+ # app/models/setting.rb
+ # extension RailsSettings::CachedSettings
+ class Setting < RailsSettings::CachedSettings
+ end
+
+The syntax is easy. First, lets create some settings to keep track of:
+
+ Setting.admin_password = 'supersecret'
+ Setting.date_format = '%m %d, %Y'
+ Setting.cocktails = ['Martini', 'Screwdriver', 'White Russian']
+ Setting.foo = 123
+ Setting.credentials = { :username => 'tom', :password => 'secret' }
+
+Now lets read them back:
+
+ Setting.foo # returns 123
+
+Changing an existing setting is the same as creating a new setting:
+
+ Setting.foo = 'super duper bar'
+
+For changing an existing setting which is a Hash, you can merge new values with existing ones:
+
+ Setting.merge! :credentials, :password => 'topsecret'
+ Setting.credentials # returns { :username => 'tom', :password => 'topsecret' }
+
+Decide you dont want to track a particular setting anymore?
+
+ Setting.destroy :foo
+ Setting.foo # returns nil
+
+Want a list of all the settings?
+
+ Setting.all # returns {'admin_password' => 'super_secret', 'date_format' => '%m %d, %Y'}
+
+You need name spaces and want a list of settings for a give name space? Just choose your prefered named space delimiter and use Setting.all like this:
+
+ Setting['preferences.color'] = :blue
+ Setting['preferences.size'] = :large
+ Setting['license.key'] = 'ABC-DEF'
+ Setting.all('preferences.') # returns { 'preferences.color' => :blue, 'preferences.size' => :large }
+
+Set defaults for certain settings of your app. This will cause the defined settings to return with the
+Specified value even if they are not in the database. Make a new file in `config/initializers/default_settings.rb`
+with the following:
+
+ Setting.defaults[:some_setting] = 'footastic'
+
+Now even if the database is completely empty, you app will have some intelligent defaults:
+
+ Setting.some_setting # returns 'footastic'
+
+Settings may be bound to any existing ActiveRecord object. Define this association like this:
+Notice! has_settings is not do caching in this version.
+
+ class User < ActiveRecord::Base
+ has_settings
+ end
+
+Then you can set/get a setting for a given user instance just by doing this:
+
+ user = User.find(123)
+ user.settings.color = :red
+ user.settings.color # returns :red
+ user.settings.all # { "color" => :red }
+
+I you want to find users having or not having some settings, there are named scopes for this:
+
+ User.with_settings # => returns a scope of users having any setting
+ User.with_settings_for('color') # => returns a scope of users having a 'color' setting
+
+ User.without_settings # returns a scope of users having no setting at all (means user.settings.all == {})
+ User.without_settings('color') # returns a scope of users having no 'color' setting (means user.settings.color == nil)
+
+That's all there is to it! Enjoy!
View
@@ -1,100 +0,0 @@
-= Settings Gem
-
-This is improved from rails-settings, added caching for all settings.
-Settings is a plugin that makes managing a table of global key, value pairs easy.
-Think of it like a global Hash stored in you database, that uses simple ActiveRecord
-like methods for manipulation. Keep track of any global setting that you dont want
-to hard code into your rails app. You can store any kind of object. Strings, numbers,
-arrays, or any object. Ported to Rails 3!
-
-
-== Setup
-
-Edit your Gemfile:
- gem "rails-settings-cached", :require => "rails-settings"
-
-Generate your settings:
- rails g settings <settings_name>
-
-Now just put that migration in the database with:
- rake db:migrate
-
-
-== Usage
-
-You need create a class in app/models/setting.rb :
-
- # app/models/setting.rb
- # extension RailsSettings::CachedSettings
- class Setting < RailsSettings::CachedSettings
- end
-
-The syntax is easy. First, lets create some settings to keep track of:
-
- Setting.admin_password = 'supersecret'
- Setting.date_format = '%m %d, %Y'
- Setting.cocktails = ['Martini', 'Screwdriver', 'White Russian']
- Setting.foo = 123
- Setting.credentials = { :username => 'tom', :password => 'secret' }
-
-Now lets read them back:
-
- Setting.foo # returns 123
-
-Changing an existing setting is the same as creating a new setting:
-
- Setting.foo = 'super duper bar'
-
-For changing an existing setting which is a Hash, you can merge new values with existing ones:
- Setting.merge! :credentials, :password => 'topsecret'
- Setting.credentials # returns { :username => 'tom', :password => 'topsecret' }
-
-Decide you dont want to track a particular setting anymore?
-
- Setting.destroy :foo
- Setting.foo # returns nil
-
-Want a list of all the settings?
-
- Setting.all # returns {'admin_password' => 'super_secret', 'date_format' => '%m %d, %Y'}
-
-You need name spaces and want a list of settings for a give name space? Just choose your prefered named space delimiter and use Setting.all like this:
-
- Setting['preferences.color'] = :blue
- Setting['preferences.size'] = :large
- Setting['license.key'] = 'ABC-DEF'
- Setting.all('preferences.') # returns { 'preferences.color' => :blue, 'preferences.size' => :large }
-
-Set defaults for certain settings of your app. This will cause the defined settings to return with the
-Specified value even if they are not in the database. Make a new file in config/initializers/default_settings.rb
-with the following:
-
- Setting.defaults[:some_setting] = 'footastic'
-
-Now even if the database is completely empty, you app will have some intelligent defaults:
-
- Setting.some_setting # returns 'footastic'
-
-Settings may be bound to any existing ActiveRecord object. Define this association like this:
-Notice! has_settings is not do caching in this version.
-
- class User < ActiveRecord::Base
- has_settings
- end
-
-Then you can set/get a setting for a given user instance just by doing this:
-
- user = User.find(123)
- user.settings.color = :red
- user.settings.color # returns :red
- user.settings.all # { "color" => :red }
-
-I you want to find users having or not having some settings, there are named scopes for this:
-
- User.with_settings # => returns a scope of users having any setting
- User.with_settings_for('color') # => returns a scope of users having a 'color' setting
-
- User.without_settings # returns a scope of users having no setting at all (means user.settings.all == {})
- User.without_settings('color') # returns a scope of users having no 'color' setting (means user.settings.color == nil)
-
-That's all there is to it! Enjoy!
View
@@ -1,20 +0,0 @@
-require 'rubygems'
-require 'rake'
-
-begin
- require 'jeweler'
- Jeweler::Tasks.new() do |gem|
- gem.name = "rails-settings"
- gem.summary = "Settings is a plugin that makes managing a table of global key, value pairs easy. Think of it like a global Hash stored in you database, that uses simple ActiveRecord like methods for manipulation. Keep track of any global setting that you dont want to hard code into your rails app. You can store any kind of object. Strings, numbers, arrays, or any object. Ported to Rails 3!"
- gem.email = "rails-settings@theblackestbox.net"
- gem.homepage = "http://theblackestbox.net"
- gem.authors = ["Squeegy","Georg Ledermann","100hz"]
- gem.add_dependency "rails", ">= 3.0.0"
- end
- Jeweler::GemcutterTasks.new
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
-end
-
-
-task :default => :release
File renamed without changes.
View
No changes.
View
@@ -1 +1 @@
-require 'rails-settings'
+require 'rails-settings-cached'
@@ -0,0 +1,10 @@
+require "spec_helper"
+
+describe RailsSettings do
+ describe "Implementation" do
+ it "can simple use" do
+ Setting.foo = "Foo"
+ Setting.foo.should == "Foo"
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 725ae77

Please sign in to comment.