Browse files

properly respond for boolean? methods

  • Loading branch information...
1 parent ddd4fee commit eda271f8ea901090099e96d243fe2bbe7ab7725f @ronakjangir47 ronakjangir47 committed Mar 13, 2013
Showing with 15 additions and 4 deletions.
  1. +2 −1 lib/serial_preference/has_preference_map.rb
  2. +2 −1 spec/fixtures/dummy_class.rb
  3. +11 −2 spec/has_preference_map_spec.rb
View
3 lib/serial_preference/has_preference_map.rb
@@ -44,7 +44,8 @@ def build_preference_definitions
if preference.boolean?
define_method("#{key}?") do
- read_preference_attribute(self.class._preferences_attribute,key).present?
+ value = read_preference_attribute(self.class._preferences_attribute,key)
+ self.class.preference_definition(key).value(value)
end
end
View
3 spec/fixtures/dummy_class.rb
@@ -1,12 +1,13 @@
class DummyClass < ActiveRecord::Base
include SerialPreference::HasSerialPreferences
preferences do
- preference :taxable, data_type: :boolean, required: true
+ preference :taxable, data_type: :boolean, required: true, default: true
preference :required_number, data_type: :integer, required: :true
preference :vat_no, required: false
preference :max_invoice_items, data_type: :integer
preference_group "Preferred Ledgers" do
income_ledger_id data_type: :integer, default: 1
+ creditable data_type: :boolean, default: false
end
end
end
View
13 spec/has_preference_map_spec.rb
@@ -39,8 +39,6 @@ class OverriddenPreferenceAttributeClass < ActiveRecord::Base
d.respond_to?(:vat_no).should be_true
d.respond_to?(:max_invoice_items).should be_true
d.respond_to?(:income_ledger_id).should be_true
- d.respond_to?(:read_preference_attribute).should be_true
- d.respond_to?(:write_preference_attribute).should be_true
end
it "should ensure that the readers returns the correct data" do
@@ -74,6 +72,17 @@ class OverriddenPreferenceAttributeClass < ActiveRecord::Base
it "should have query methods available for booleans" do
DummyClass.new.respond_to?(:taxable?)
end
+
+ it "should respond properly for default true preferences" do
+ DummyClass.new.taxable.should eq(true)
+ DummyClass.new.taxable?.should eq(true)
+ end
+
+ it "should respond properly for default false preferences" do
+ DummyClass.new.creditable.should eq(false)
+ DummyClass.new.creditable?.should eq(false)
+ end
+
end

0 comments on commit eda271f

Please sign in to comment.