has_dynamic_columns 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e80b2327256e42bf94544f2002936cf1170de952
|
4
|
+
data.tar.gz: 8da148b09230ca67502a734597cb595390fa32a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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"
|
data/lib/has_dynamic_columns.rb
CHANGED
@@ -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
|
+
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-
|
11
|
+
date: 2015-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|