Permalink
Browse files

Whitespace cleanup

  • Loading branch information...
1 parent 2527c83 commit b428d01e26a986fae15f4da81911c7ba00113cbe @ledermann committed Mar 7, 2013
View
@@ -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
@@ -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
@@ -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,4 +2,4 @@ require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
-task :default => :spec
+task :default => :spec
View
@@ -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
@@ -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'
@@ -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
@@ -20,4 +20,4 @@ def self.next_migration_number(dirname)
end
end
end
-end
+end
@@ -12,4 +12,4 @@ def self.up
def self.down
drop_table :settings
end
-end
+end
@@ -7,22 +7,22 @@ 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)
else
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? }
@@ -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
@@ -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'
@@ -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
@@ -9,15 +9,15 @@
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
user.settings(:dashboard).bar = 'string'
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,15 +36,15 @@
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
user.settings(:dashboard).bar = 'string'
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,15 +68,15 @@
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
user.settings(:dashboard).bar = 'string'
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,24 +85,24 @@
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'
user.settings(:calendar).update_attributes :scope => 'all'
}.to perform_queries(0)
end
end
-end
+end
View
@@ -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)
@@ -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
Oops, something went wrong.

0 comments on commit b428d01

Please sign in to comment.