has_dynamic_columns 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39e5eb44c24247b1b6b2bd23eef9950f73d06954
4
- data.tar.gz: b67d157f05f56617c7c9fe4cb8d74a64fb781c53
3
+ metadata.gz: e80b2327256e42bf94544f2002936cf1170de952
4
+ data.tar.gz: 8da148b09230ca67502a734597cb595390fa32a4
5
5
  SHA512:
6
- metadata.gz: 9f5ffd8504ae8bc64e775119ec8b7c967e8186faf60c44414dc51ff072e3e0f790cd06f9b9c2642227b2ae562a24c4cd870b6e792ca8ff205a006da0c6c4b74b
7
- data.tar.gz: c90bc7f0c510690e168ad8caff93ae2416ee466be0c981b288ef4ad76b182de8e078e06eb59fe09ad0d74b344471a13927f88f92361f355da6b98bbef4bde200
6
+ metadata.gz: 24a2777ffcd2b9feb28512fedb92ad9b224893a399bbdf50ec43160b4dd301e27e14b466736a68979347105d26db496f5e0359ddbcdd3f1b45f325ac53810195
7
+ data.tar.gz: e23a81b217be7906f6b8f65d8e7d65baf74f19dc1b7ca1a739a3de5205b1becda01a483e6c229e5cd0cbdbbbef30680b1e3d5351ec9432e833d4ec9a4f269812
@@ -15,7 +15,12 @@ module HasDynamicColumns
15
15
  when "datetime"
16
16
  self[:value]
17
17
  when "boolean"
18
- (self[:value] == 1)
18
+
19
+ if self[:value].is_a?(TrueClass) || self[:value].is_a?(FalseClass)
20
+ self[:value]
21
+ else
22
+ self[:value].to_i === 1
23
+ end
19
24
  when "integer"
20
25
  self[:value]
21
26
  when "date"
@@ -44,7 +49,7 @@ module HasDynamicColumns
44
49
  when "datetime"
45
50
  self[:value] = v
46
51
  when "boolean"
47
- self[:value] = v
52
+ self[:value] = (v)? 1 : 0
48
53
  when "integer"
49
54
  self[:value] = v
50
55
  when "date"
@@ -1,3 +1,3 @@
1
1
  module HasDynamicColumns
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -29,7 +29,8 @@ module HasDynamicColumns
29
29
  as: :field_scope
30
30
  has_many :activerecord_#{configuration[:as]}_data,
31
31
  class_name: "HasDynamicColumns::DynamicColumnDatum",
32
- as: :owner
32
+ as: :owner,
33
+ autosave: true
33
34
 
34
35
  # only add to attr_accessible
35
36
  # if the class has some mass_assignment_protection
@@ -8,6 +8,7 @@ describe HasDynamicColumns do
8
8
  account.activerecord_dynamic_columns.build(:dynamic_type => "Customer", :key => "first_name", :data_type => "string")
9
9
  account.activerecord_dynamic_columns.build(:dynamic_type => "Customer", :key => "last_name", :data_type => "string")
10
10
  account.activerecord_dynamic_columns.build(:dynamic_type => "Customer", :key => "email", :data_type => "string")
11
+ account.activerecord_dynamic_columns.build(:dynamic_type => "Customer", :key => "trusted", :data_type => "boolean")
11
12
 
12
13
  # Setup dynamic fields for CustomerAddress under this account
13
14
  account.activerecord_dynamic_columns.build(:dynamic_type => "CustomerAddress", :key => "address_1", :data_type => "string")
@@ -41,6 +42,7 @@ describe HasDynamicColumns do
41
42
  "first_name" => "Butch",
42
43
  "last_name" => "Marshall",
43
44
  "email" => "butch.a.marshall@gmail.com",
45
+ "trusted" => true,
44
46
  }
45
47
  end
46
48
 
@@ -83,8 +85,29 @@ describe HasDynamicColumns do
83
85
  "first_name" => "Butch",
84
86
  "last_name" => "Marshall",
85
87
  "email" => "butch.a.marshall@gmail.com",
88
+ "trusted" => true,
86
89
  })
87
90
  end
91
+
92
+ it 'should get and set boolean values properly' do
93
+ c = customer
94
+
95
+ c.fields = { "trusted" => true }
96
+ expect(c.as_json["fields"]).to eq({"first_name"=>"Butch", "last_name"=>"Marshall", "email"=>"butch.a.marshall@gmail.com", "trusted"=>true})
97
+ c.save
98
+ expect(c.as_json["fields"]).to eq({"first_name"=>"Butch", "last_name"=>"Marshall", "email"=>"butch.a.marshall@gmail.com", "trusted"=>true})
99
+
100
+ c = Customer.find(c.id)
101
+ expect(c.as_json["fields"]).to eq({"first_name"=>"Butch", "last_name"=>"Marshall", "email"=>"butch.a.marshall@gmail.com", "trusted"=>true})
102
+
103
+ c.fields = { "trusted" => false }
104
+ expect(c.as_json["fields"]).to eq({"first_name"=>"Butch", "last_name"=>"Marshall", "email"=>"butch.a.marshall@gmail.com", "trusted"=>false})
105
+ c.save
106
+ expect(c.as_json["fields"]).to eq({"first_name"=>"Butch", "last_name"=>"Marshall", "email"=>"butch.a.marshall@gmail.com", "trusted"=>false})
107
+
108
+ c = Customer.find(c.id)
109
+ expect(c.as_json["fields"]).to eq({"first_name"=>"Butch", "last_name"=>"Marshall", "email"=>"butch.a.marshall@gmail.com", "trusted"=>false})
110
+ end
88
111
  end
89
112
 
90
113
  describe CustomerAddress do
@@ -132,6 +155,7 @@ describe HasDynamicColumns do
132
155
  "first_name" => "Butch",
133
156
  "last_name" => "Marshall",
134
157
  "email" => "butch.a.marshall@gmail.com",
158
+ "trusted" => true,
135
159
  })
136
160
  end
137
161
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_dynamic_columns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Butch Marshall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-25 00:00:00.000000000 Z
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord