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 CHANGED
@@ -1 +1 @@
1
- 0.0.7
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{property_sets}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Morten Primdahl"]
@@ -26,74 +26,87 @@ class TestPropertySets < ActiveSupport::TestCase
26
26
  @account = Account.create(:name => "Name")
27
27
  end
28
28
 
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
- # end
45
- #
46
- # should "reject settings with an invalid name" do
47
- # s = AccountSetting.new(:account => @account)
48
- #
49
- # [ 'hello', 'hel_lo', 'hell0' ].each do |valid|
50
- # s.name = valid
51
- # assert s.valid?
52
- # end
53
- #
54
- # [ '_hello', :hello ].each do |invalid|
55
- # s.name = invalid
56
- # assert !s.valid?
57
- # end
58
- # end
59
- #
60
- # should "validate uniqueness of settings" do
61
- # AccountSetting.create!(:account => @account, :name => 'unique')
62
- # assert_raise ActiveRecord::RecordInvalid do
63
- # AccountSetting.create!(:account => @account, :name => 'unique')
64
- # end
65
- # end
66
- #
67
- # should "be creatable using the = operator" do
68
- # assert !@account.settings.foo?
69
- # assert @account.settings.foo = "1"
70
- # assert @account.settings.size == 1
71
- # assert @account.texts.size == 0
72
- # assert @account.settings.foo?
73
- # assert @account.settings.foo = "2"
74
- # assert @account.settings.size == 1
75
- # assert @account.settings.foo?
76
- # end
77
- #
78
- # should "be destroyable through association" do
79
- # assert !@account.settings.foo?
80
- # assert @account.settings.foo = "1"
81
- # assert @account.settings.foo?
82
- # assert @account.settings.foo.destroy
83
- # @account.settings.reload
84
- # assert !@account.settings.foo?
85
- # end
86
- #
87
- # should "support bulk build multiple properties in one go" do
88
- # @account.settings.bulk(:foo => "123", :bar => "456")
89
- # @account.save!
90
- # assert_equal @account.reload.settings.size, 2
91
- # assert_equal @account.settings.foo.value, "123"
92
- # assert_equal @account.settings.foo.name, "foo"
93
- # assert_equal @account.settings.bar.value, "456"
94
- # assert_equal @account.settings.bar.name, "bar"
95
- # end
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: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Morten Primdahl