packed_fields 0.0.2 → 0.0.3
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.
- data/VERSION +1 -1
- data/lib/active_record/packed_fields.rb +5 -0
- data/packed_fields.gemspec +1 -1
- data/spec/active_record/packed_fields_spec.rb +19 -4
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -5,8 +5,10 @@ module ActiveRecord
|
|
5
5
|
def packed(options)
|
6
6
|
column = options[:column] || :packed
|
7
7
|
fields = options[:fields]
|
8
|
+
validation = options[:validation]
|
8
9
|
|
9
10
|
serialize column, Hash
|
11
|
+
|
10
12
|
|
11
13
|
fields.each do |field|
|
12
14
|
define_method(field) {
|
@@ -23,8 +25,11 @@ module ActiveRecord
|
|
23
25
|
write_attribute(column, { field => value })
|
24
26
|
end
|
25
27
|
}
|
28
|
+
|
29
|
+
validates field, validation.dup if validation
|
26
30
|
end
|
27
31
|
end
|
32
|
+
|
28
33
|
end
|
29
34
|
|
30
35
|
def self.included(base)
|
data/packed_fields.gemspec
CHANGED
@@ -4,7 +4,7 @@ require 'packed_fields'
|
|
4
4
|
class ModelWithPacked < ActiveRecord::Base
|
5
5
|
set_table_name 'mixins'
|
6
6
|
|
7
|
-
packed :fields => [:foo, :bar]
|
7
|
+
packed :fields => [:foo, :bar], :validation => { :length => { :within => 0..5, :allow_nil => true } }
|
8
8
|
end
|
9
9
|
|
10
10
|
class CanSetColumnName < ActiveRecord::Base
|
@@ -20,15 +20,21 @@ describe ModelWithPacked do
|
|
20
20
|
|
21
21
|
let(:model) { ModelWithPacked.new }
|
22
22
|
|
23
|
-
describe "
|
23
|
+
describe "blank model" do
|
24
|
+
|
25
|
+
its(:foo) { should be_nil }
|
26
|
+
its(:bar) { should be_nil }
|
27
|
+
it { should be_valid }
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "setting foo 'blah'" do
|
24
32
|
subject {
|
25
33
|
model.foo = "blah"
|
26
|
-
model.bar = 1
|
27
34
|
model.save
|
28
35
|
model.reload
|
29
36
|
}
|
30
37
|
its(:foo) { should eq 'blah' }
|
31
|
-
its(:bar) { should eq 1 }
|
32
38
|
|
33
39
|
it "packed[:foo] should == 'blah'" do
|
34
40
|
subject.packed[:foo].should eq 'blah'
|
@@ -39,6 +45,15 @@ describe ModelWithPacked do
|
|
39
45
|
expect { model.foo = "blah" ; model.save }.to change { model.packed }
|
40
46
|
end
|
41
47
|
|
48
|
+
describe "validation" do
|
49
|
+
describe "for example, validates length and bar is too long string" do
|
50
|
+
subject { model.bar = 'toolongstring'; model.valid?; model }
|
51
|
+
it { should be_invalid }
|
52
|
+
it "errors[:bar] exists" do
|
53
|
+
subject.errors[:bar].should be
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
42
57
|
|
43
58
|
end
|
44
59
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: packed_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- holysugar
|
@@ -92,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
92
|
requirements:
|
93
93
|
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
hash:
|
95
|
+
hash: 3194017773500699839
|
96
96
|
segments:
|
97
97
|
- 0
|
98
98
|
version: "0"
|