Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Whitespace cleanup

  • Loading branch information...
commit b428d01e26a986fae15f4da81911c7ba00113cbe 1 parent 2527c83
@ledermann authored
View
2  Changelog.md
@@ -35,4 +35,4 @@ Version 1.0.0 (2011-11-05)
- Conversion from Plugin to Gem
- Destroying false values (thanks to @Pavling)
-- Testing with Travis
+- Testing with Travis
View
2  MIT-LICENSE
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
6 README.md
@@ -98,7 +98,7 @@ User.without_settings_for(:calendar)
## Requirements
-Rails 3.1.x or 3.2.x
+Rails 3.1.x or 3.2.x
Ruby 1.8.7, 1.9.3 or 2.0.0
@@ -127,7 +127,7 @@ If you don't want to upgrade, you find the old version in the [1.x](https://gith
## License
-MIT License
+MIT License
Copyright (c) 2013 Georg Ledermann
-This gem is a complete rewrite of [rails-settings](https://github.com/Squeegy/rails-settings) by [Alex Wayne](https://github.com/Squeegy)
+This gem is a complete rewrite of [rails-settings](https://github.com/Squeegy/rails-settings) by [Alex Wayne](https://github.com/Squeegy)
View
2  Rakefile
@@ -2,4 +2,4 @@ require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
-task :default => :spec
+task :default => :spec
View
2  ci/Gemfile.rails-3.1.x
@@ -3,4 +3,4 @@ source :rubygems
gem 'activerecord', '~> 3.1.0'
gem 'sqlite3', '~> 1.3'
gem 'rake', '~> 10.0'
-gem 'rspec', '~> 2.13'
+gem 'rspec', '~> 2.13'
View
2  ci/Gemfile.rails-3.2.x
@@ -3,4 +3,4 @@ source :rubygems
gem 'activerecord', '~> 3.2.0'
gem 'sqlite3', '~> 1.3'
gem 'rake', '~> 10.0'
-gem 'rspec', '~> 2.13'
+gem 'rspec', '~> 2.13'
View
2  lib/app/models/setting_object.rb
@@ -28,7 +28,7 @@ def method_missing(method_name, *args, &block)
# Setter
if self.value[$1] != args.first
self.value_will_change!
-
+
if args.first.nil?
self.value.delete($1)
else
View
2  lib/generators/rails_settings/migration/migration_generator.rb
@@ -20,4 +20,4 @@ def self.next_migration_number(dirname)
end
end
end
-end
+end
View
2  lib/generators/rails_settings/migration/templates/migration.rb
@@ -12,4 +12,4 @@ def self.up
def self.down
drop_table :settings
end
-end
+end
View
8 lib/rails-settings/base.rb
@@ -7,14 +7,14 @@ def self.included(base)
:autosave => true,
:dependent => :delete_all,
:class_name => self.setting_object_class_name
-
+
def settings(var)
raise ArgumentError unless var.is_a?(Symbol)
raise ArgumentError.new("Unknown key: #{var}") unless self.class.default_settings[var]
-
+
setting_objects.detect { |s| s.var == var.to_s } || setting_objects.build(:var => var.to_s)
end
-
+
def settings=(value)
if value.nil?
setting_objects.each(&:mark_for_destruction)
@@ -22,7 +22,7 @@ def settings=(value)
raise ArgumentError
end
end
-
+
def settings?(var=nil)
if var.nil?
setting_objects.any? { |setting_object| !setting_object.marked_for_destruction? && setting_object.value.present? }
View
6 lib/rails-settings/scopes.rb
@@ -9,7 +9,7 @@ def self.included(base)
scope :with_settings_for, lambda { |var|
raise ArgumentError unless var.is_a?(Symbol)
-
+
joins("JOIN settings ON (settings.target_id = #{self.table_name}.#{self.primary_key} AND
settings.target_type = '#{self.base_class.name}') AND
settings.var = '#{var}'")
@@ -24,7 +24,7 @@ def self.included(base)
scope :without_settings_for, lambda { |var|
raise ArgumentError unless var.is_a?(Symbol)
-
+
joins("LEFT JOIN settings ON (settings.target_id = #{self.table_name}.#{self.primary_key} AND
settings.target_type = '#{self.base_class.name}') AND
settings.var = '#{var}'").
@@ -33,4 +33,4 @@ def self.included(base)
end
end
end
-end
+end
View
2  rails-settings.gemspec
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ['lib']
-
+
gem.add_dependency 'activerecord', '~> 3.1'
gem.add_development_dependency 'rake', '~> 10.0'
View
4 spec/configuration_spec.rb
@@ -62,7 +62,7 @@ class Dummy
Dummy.setting_object_class_name.should == 'MyClass'
end
end
-
+
describe Configuration, 'failure' do
it "should fail without args" do
expect {
@@ -105,4 +105,4 @@ class Dummy
}.to raise_error(ArgumentError)
end
end
-end
+end
View
24 spec/queries_spec.rb
@@ -9,7 +9,7 @@
user.save!
}.to perform_queries(1)
end
-
+
it 'should be saved with settings for one key by two SQL queries' do
expect {
user.settings(:dashboard).foo = 42
@@ -17,7 +17,7 @@
user.save!
}.to perform_queries(2)
end
-
+
it 'should be saved with settings for two keys by three SQL queries' do
expect {
user.settings(:dashboard).foo = 42
@@ -27,7 +27,7 @@
}.to perform_queries(3)
end
end
-
+
context 'Existing record without settings' do
let!(:user) { User.create! :name => 'Mr. Pink' }
@@ -36,7 +36,7 @@
user.save!
}.to perform_queries(0)
end
-
+
it 'should be saved with settings for one key by two SQL queries' do
expect {
user.settings(:dashboard).foo = 42
@@ -44,7 +44,7 @@
user.save!
}.to perform_queries(2)
end
-
+
it 'should be saved with settings for two keys by three SQL queries' do
expect {
user.settings(:dashboard).foo = 42
@@ -54,7 +54,7 @@
}.to perform_queries(3)
end
end
-
+
context 'Existing record with settings' do
let!(:user) do
User.create! :name => 'Mr. Pink' do |user|
@@ -68,7 +68,7 @@
user.save!
}.to perform_queries(0)
end
-
+
it 'should be saved with settings for one key by one SQL queries' do
expect {
user.settings(:dashboard).foo = 42
@@ -76,7 +76,7 @@
user.save!
}.to perform_queries(1)
end
-
+
it 'should be saved with settings for two keys by two SQL queries' do
expect {
user.settings(:dashboard).foo = 42
@@ -85,19 +85,19 @@
user.save!
}.to perform_queries(2)
end
-
+
it 'should be destroyed by two SQL queries' do
expect {
user.destroy
}.to perform_queries(2)
end
-
+
it "should update settings by one SQL query" do
expect {
user.settings(:dashboard).update_attributes! :foo => 'bar'
}.to perform_queries(1)
end
-
+
it "should not touch database if there are no changes made" do
expect {
user.settings(:dashboard).update_attributes :theme => 'pink'
@@ -105,4 +105,4 @@
}.to perform_queries(0)
end
end
-end
+end
View
4 spec/scopes_spec.rb
@@ -3,7 +3,7 @@
describe 'scopes' do
let!(:user1) { User.create! :name => 'Mr. White' do |user| user.settings(:dashboard).theme = 'white' end }
let!(:user2) { User.create! :name => 'Mr. Blue' }
-
+
it "should find objects with existing settings" do
User.with_settings.should eq([user1])
end
@@ -21,7 +21,7 @@
User.without_settings_for(:foo).should eq([user1, user2])
User.without_settings_for(:dashboard).should eq([user2])
end
-
+
it "should require symbol as key" do
[ nil, "string", 42 ].each do |invalid_key|
expect { User.without_settings_for(invalid_key) }.to raise_error(ArgumentError)
View
10 spec/setting_object_spec.rb
@@ -16,14 +16,14 @@
expect { new_setting_object.foo! }.to raise_error(NoMethodError)
expect { new_setting_object.foo? }.to raise_error(NoMethodError)
end
-
+
it "should not respond if a block is given" do
- expect {
+ expect {
new_setting_object.foo do
end
}.to raise_error(NoMethodError)
end
-
+
it "should not respond if params are given" do
expect { new_setting_object.foo(42) }.to raise_error(NoMethodError)
expect { new_setting_object.foo(42,43) }.to raise_error(NoMethodError)
@@ -70,7 +70,7 @@
saved_setting_object.should_not be_value_changed
saved_setting_object.should_not be_changed
end
-
+
it "should delete key on assigning nil" do
saved_setting_object.theme = nil
saved_setting_object.value.should == { 'filter' => true }
@@ -88,7 +88,7 @@
new_setting_object.should_not be_new_record
new_setting_object.id.should_not be_zero
end
-
+
it 'should not save blank hash' do
new_setting_object.update_attributes({}).should be_false
end
View
34 spec/settings_spec.rb
@@ -6,10 +6,10 @@
end
it "should be stored for parent class" do
- User.default_settings.should eq(:dashboard => { 'theme' => 'blue', 'view' => 'monthly', 'filter' => false },
+ User.default_settings.should eq(:dashboard => { 'theme' => 'blue', 'view' => 'monthly', 'filter' => false },
:calendar => { 'scope' => 'company'})
end
-
+
it "should be stored for child class" do
GuestUser.default_settings.should eq(:dashboard => { 'theme' => 'red', 'view' => 'monthly', 'filter' => false })
end
@@ -25,7 +25,7 @@
account.settings(:portal).enabled.should eq(true)
account.settings(:portal).template.should eq('black')
end
-
+
it "should return nil for not existing key" do
account.settings(:portal).foo.should eq(nil)
end
@@ -52,14 +52,14 @@
account.reload
account.settings(:portal).premium.should eq(true)
account.settings(:portal).fee.should eq(42.5)
-
+
RailsSettings::SettingObject.count.should eq(1)
RailsSettings::SettingObject.first.value.should == { 'premium' => true, 'fee' => 42.5 }
end
-
+
it "should save settings separated" do
account.save!
-
+
settings = account.settings(:portal)
settings.enabled = true
settings.template = 'black'
@@ -80,10 +80,10 @@
user.settings(:dashboard).filter.should eq(false)
user.settings(:calendar).scope.should eq('company')
end
-
+
it 'should have default settings after changing one' do
user.settings(:dashboard).theme = 'gray'
-
+
user.settings(:dashboard).theme.should eq('gray')
user.settings(:dashboard).view.should eq('monthly')
user.settings(:dashboard).filter.should eq(false)
@@ -122,7 +122,7 @@
user.settings?.should eq(false)
user.settings?(:dashboard).should eq(false)
end
-
+
it "should have no setting objects" do
RailsSettings::SettingObject.count.should eq(0)
end
@@ -149,7 +149,7 @@
user.settings(:calendar).scope = 'all'
end
end
-
+
it "should respond to #settings?" do
user.settings?.should eq(true)
@@ -173,34 +173,34 @@
it "should update settings by saving object" do
user.settings(:dashboard).smart = true
user.save!
-
+
user.reload
user.settings(:dashboard).smart.should eq(true)
end
-
+
it "should destroy settings with nil" do
expect {
user.settings = nil
user.save!
}.to change(RailsSettings::SettingObject, :count).by(-2)
-
+
user.settings?.should == false
end
end
describe "Customized SettingObject" do
let(:project) { Project.create! :name => 'Heist' }
-
+
it "should not accept invalid attributes" do
project.settings(:info).owner_name = 42
project.settings(:info).should_not be_valid
-
+
project.settings(:info).owner_name = ''
project.settings(:info).should_not be_valid
end
-
+
it "should accept valid attributes" do
project.settings(:info).owner_name = 'Mr. Brown'
project.settings(:info).should be_valid
end
-end
+end
View
6 spec/spec_helper.rb
@@ -14,7 +14,7 @@
# the seed, which is printed after each run.
# --seed 1234
# config.order = 'random'
-
+
config.before(:each) do
clear_db
end
@@ -73,7 +73,7 @@ def setup_db
create_table :accounts do |t|
t.string :subdomain
end
-
+
create_table :projects do |t|
t.string :name
end
@@ -87,4 +87,4 @@ def clear_db
end
puts "Testing with ActiveRecord #{ActiveRecord::VERSION::STRING}"
-setup_db
+setup_db
View
4 spec/support/matchers/perform_queries.rb
@@ -12,7 +12,7 @@ def query_count(&block)
ActiveSupport::Notifications.subscribe('sql.active_record', @counter.to_proc)
yield
ActiveSupport::Notifications.unsubscribe(@counter.to_proc)
-
+
@counter.query_count
end
-end
+end
View
2  spec/support/query_counter.rb
@@ -14,4 +14,4 @@ def callback(name, start, finish, message_id, values)
@query_count += 1 unless %w(CACHE SCHEMA).include?(values[:name]) || values[:sql] == 'begin transaction' || values[:sql] == 'commit transaction'
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.