Permalink
Browse files

Added method #settings? to check for presence of settings

  • Loading branch information...
1 parent 93e209f commit 3bce9e40543eebfeeb60d65335be77c568cbb131 @ledermann committed Mar 4, 2013
Showing with 22 additions and 0 deletions.
  1. +8 −0 lib/rails-settings/base.rb
  2. +14 −0 spec/settings_spec.rb
@@ -22,6 +22,14 @@ 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? }
+ else
+ settings(var).value.present?
+ end
+ end
end
end
end
View
@@ -117,6 +117,11 @@
describe "Object without settings" do
let!(:user) { User.create! :name => 'Mr. White' }
+
+ it "should respond to #settings?" do
+ user.settings?.should == false
+ user.settings?(:dashboard).should == false
+ end
it "should have no setting objects" do
RailsSettings::SettingObject.count.should eq(0)
@@ -145,6 +150,13 @@
end
end
+ it "should respond to #settings?" do
+ user.settings?.should == true
+
+ user.settings?(:dashboard).should == true
+ user.settings?(:calendar).should == true
+ end
+
it "should have two setting objects" do
RailsSettings::SettingObject.count.should eq(2)
end
@@ -171,6 +183,8 @@
user.settings = nil
user.save!
}.to change(RailsSettings::SettingObject, :count).by(-2)
+
+ user.settings?.should == false
end
end

0 comments on commit 3bce9e4

Please sign in to comment.