Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #1 from ronakjangir47/master

properly respond for boolean? methods for default
  • Loading branch information...
commit b922b746af259e6a4f4df3b0a7ab3a5ccc130988 2 parents ddd4fee + eda271f
Aditya Sanghi authored March 13, 2013
3  lib/serial_preference/has_preference_map.rb
@@ -44,7 +44,8 @@ def build_preference_definitions
44 44
 
45 45
           if preference.boolean?
46 46
             define_method("#{key}?") do
47  
-              read_preference_attribute(self.class._preferences_attribute,key).present?
  47
+              value = read_preference_attribute(self.class._preferences_attribute,key)
  48
+              self.class.preference_definition(key).value(value)
48 49
             end
49 50
           end
50 51
 
3  spec/fixtures/dummy_class.rb
... ...
@@ -1,12 +1,13 @@
1 1
 class DummyClass < ActiveRecord::Base
2 2
   include SerialPreference::HasSerialPreferences
3 3
   preferences do
4  
-    preference :taxable, data_type: :boolean, required: true
  4
+    preference :taxable, data_type: :boolean, required: true, default: true
5 5
     preference :required_number, data_type: :integer, required: :true
6 6
     preference :vat_no, required: false
7 7
     preference :max_invoice_items, data_type: :integer
8 8
     preference_group "Preferred Ledgers" do
9 9
       income_ledger_id data_type: :integer, default: 1
  10
+      creditable data_type: :boolean, default: false
10 11
     end
11 12
   end
12 13
 end
13  spec/has_preference_map_spec.rb
@@ -39,8 +39,6 @@ class OverriddenPreferenceAttributeClass < ActiveRecord::Base
39 39
       d.respond_to?(:vat_no).should be_true
40 40
       d.respond_to?(:max_invoice_items).should be_true
41 41
       d.respond_to?(:income_ledger_id).should be_true
42  
-      d.respond_to?(:read_preference_attribute).should be_true
43  
-      d.respond_to?(:write_preference_attribute).should be_true
44 42
     end
45 43
 
46 44
     it "should ensure that the readers returns the correct data" do
@@ -74,6 +72,17 @@ class OverriddenPreferenceAttributeClass < ActiveRecord::Base
74 72
     it "should have query methods available for booleans" do
75 73
       DummyClass.new.respond_to?(:taxable?)
76 74
     end
  75
+
  76
+    it "should respond properly for default true preferences" do
  77
+      DummyClass.new.taxable.should eq(true)
  78
+      DummyClass.new.taxable?.should eq(true)
  79
+    end
  80
+
  81
+    it "should respond properly for default false preferences" do
  82
+      DummyClass.new.creditable.should eq(false)
  83
+      DummyClass.new.creditable?.should eq(false)
  84
+    end
  85
+
77 86
   end
78 87
 
79 88
 

0 notes on commit b922b74

Please sign in to comment.
Something went wrong with that request. Please try again.