property_sets 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/property_sets/property_set_model.rb +9 -0
- data/property_sets.gemspec +1 -1
- data/test/test_property_sets.rb +81 -68
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
@@ -1,6 +1,15 @@
|
|
1
1
|
module PropertySets
|
2
2
|
module PropertySetModel
|
3
3
|
module InstanceMethods
|
4
|
+
|
5
|
+
def create
|
6
|
+
self.value = self.class.default(name.to_sym) if self.value.nil?
|
7
|
+
if new_record?
|
8
|
+
super
|
9
|
+
end
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
4
13
|
def protected?
|
5
14
|
self.class.protected?(self.name.to_sym)
|
6
15
|
end
|
data/property_sets.gemspec
CHANGED
data/test/test_property_sets.rb
CHANGED
@@ -26,74 +26,87 @@ class TestPropertySets < ActiveSupport::TestCase
|
|
26
26
|
@account = Account.create(:name => "Name")
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
29
|
+
should "construct the container class" do
|
30
|
+
assert defined?(AccountSetting)
|
31
|
+
assert defined?(AccountText)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "be empty on a new account" do
|
35
|
+
assert @account.settings.empty?
|
36
|
+
assert @account.texts.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
should "respond to defaults" do
|
40
|
+
assert_equal false, @account.settings.bar?
|
41
|
+
assert_equal nil, @account.settings.bar.value
|
42
|
+
assert_equal true, @account.settings.hep?
|
43
|
+
assert_equal 'skep', @account.settings.hep.value
|
44
|
+
assert @account.settings.hep.id.nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
should "reject settings with an invalid name" do
|
48
|
+
s = AccountSetting.new(:account => @account)
|
49
|
+
|
50
|
+
[ 'hello', 'hel_lo', 'hell0' ].each do |valid|
|
51
|
+
s.name = valid
|
52
|
+
assert s.valid?
|
53
|
+
end
|
54
|
+
|
55
|
+
[ '_hello', :hello ].each do |invalid|
|
56
|
+
s.name = invalid
|
57
|
+
assert !s.valid?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
should "validate uniqueness of settings" do
|
62
|
+
AccountSetting.create!(:account => @account, :name => 'unique')
|
63
|
+
assert_raise ActiveRecord::RecordInvalid do
|
64
|
+
AccountSetting.create!(:account => @account, :name => 'unique')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
should "be creatable using the = operator" do
|
69
|
+
assert !@account.settings.foo?
|
70
|
+
assert @account.settings.foo = "1"
|
71
|
+
assert @account.settings.size == 1
|
72
|
+
assert @account.texts.size == 0
|
73
|
+
assert @account.settings.foo?
|
74
|
+
assert @account.settings.foo = "2"
|
75
|
+
assert @account.settings.size == 1
|
76
|
+
assert @account.settings.foo?
|
77
|
+
end
|
78
|
+
|
79
|
+
should "be creatable through association" do
|
80
|
+
assert @account.settings.foo.create.id
|
81
|
+
@account.settings.foo.destroy
|
82
|
+
@account.reload
|
83
|
+
assert @account.settings.foo.new_record?
|
84
|
+
assert @account.settings.foo.update_attributes(:value => 8)
|
85
|
+
assert @account.settings.foo.id
|
86
|
+
assert @account.settings.foo.value == "8"
|
87
|
+
assert @account.settings.hep.create
|
88
|
+
assert_equal @account.settings.hep.value, "skep"
|
89
|
+
end
|
90
|
+
|
91
|
+
should "be destroyable through association" do
|
92
|
+
assert !@account.settings.foo?
|
93
|
+
assert @account.settings.foo = "1"
|
94
|
+
assert @account.settings.foo?
|
95
|
+
assert @account.settings.foo.destroy
|
96
|
+
@account.settings.reload
|
97
|
+
assert !@account.settings.foo?
|
98
|
+
end
|
99
|
+
|
100
|
+
should "support bulk build multiple properties in one go" do
|
101
|
+
@account.settings.bulk(:foo => "123", :bar => "456")
|
102
|
+
@account.save!
|
103
|
+
assert_equal @account.reload.settings.size, 2
|
104
|
+
assert_equal @account.settings.foo.value, "123"
|
105
|
+
assert_equal @account.settings.foo.name, "foo"
|
106
|
+
assert_equal @account.settings.bar.value, "456"
|
107
|
+
assert_equal @account.settings.bar.name, "bar"
|
108
|
+
end
|
109
|
+
|
97
110
|
should "be updatable as nested attributes" do
|
98
111
|
assert !@account.texts.foo?
|
99
112
|
assert !@account.texts.bar?
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: property_sets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Morten Primdahl
|