dynamic_attributes 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/dynamic_attributes.rb +4 -0
- data/test/test_dynamic_attributes.rb +15 -3
- metadata +4 -13
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
data/lib/dynamic_attributes.rb
CHANGED
@@ -33,6 +33,10 @@ module DynamicAttributes
|
|
33
33
|
super(attributes.except(*dynamic_attributes.keys))
|
34
34
|
set_dynamic_attributes(dynamic_attributes)
|
35
35
|
end
|
36
|
+
|
37
|
+
def has_dynamic_attribute?(dynamic_attribute)
|
38
|
+
return persisting_dynamic_attributes.include?(dynamic_attribute.to_s)
|
39
|
+
end
|
36
40
|
|
37
41
|
# On saving an AR record, the attributes to be persisted are re-evaluated and written to the serialization field.
|
38
42
|
def evaluate_dynamic_attributes
|
@@ -20,6 +20,7 @@ class TestDynamicAttributes < Test::Unit::TestCase
|
|
20
20
|
assert_equal 'hello', @dynamic_model.field_test
|
21
21
|
assert @dynamic_model.persisting_dynamic_attributes.include?('field_test')
|
22
22
|
assert @dynamic_model.dynamic_attributes.keys.include?('field_test')
|
23
|
+
assert @dynamic_model.has_dynamic_attribute?(:field_test)
|
23
24
|
end
|
24
25
|
|
25
26
|
def test_should_create_dynamic_attributes_for_hash
|
@@ -27,7 +28,9 @@ class TestDynamicAttributes < Test::Unit::TestCase
|
|
27
28
|
assert dynamic_model.persisting_dynamic_attributes.include?('field_test1')
|
28
29
|
assert dynamic_model.persisting_dynamic_attributes.include?('field_test2')
|
29
30
|
assert_equal 'Hello', dynamic_model.field_test1
|
30
|
-
assert_equal 'World', dynamic_model.field_test2
|
31
|
+
assert_equal 'World', dynamic_model.field_test2
|
32
|
+
assert dynamic_model.has_dynamic_attribute?(:field_test1)
|
33
|
+
assert dynamic_model.has_dynamic_attribute?(:field_test2)
|
31
34
|
end
|
32
35
|
|
33
36
|
def test_should_update_attributes
|
@@ -39,13 +42,18 @@ class TestDynamicAttributes < Test::Unit::TestCase
|
|
39
42
|
|
40
43
|
@dynamic_model.reload
|
41
44
|
assert_equal 'Hello', @dynamic_model.field_test1
|
42
|
-
assert_equal 'World', @dynamic_model.field_test2
|
45
|
+
assert_equal 'World', @dynamic_model.field_test2
|
46
|
+
|
47
|
+
assert @dynamic_model.has_dynamic_attribute?(:field_test1)
|
48
|
+
assert @dynamic_model.has_dynamic_attribute?(:field_test2)
|
43
49
|
end
|
44
50
|
|
45
51
|
def test_should_load_dynamic_attributes_after_find
|
46
52
|
DynamicModel.update_all("dynamic_attributes = '---\nfield_test: Hi!\n'", :id => @dynamic_model.id)
|
47
53
|
dynamic_model = DynamicModel.find(@dynamic_model.id)
|
48
54
|
assert_equal 'Hi!', dynamic_model.field_test
|
55
|
+
|
56
|
+
assert dynamic_model.has_dynamic_attribute?(:field_test)
|
49
57
|
end
|
50
58
|
|
51
59
|
def test_should_set_dynamic_attribute_to_nil_if_configured
|
@@ -53,12 +61,14 @@ class TestDynamicAttributes < Test::Unit::TestCase
|
|
53
61
|
assert_nil @dynamic_model.field_test
|
54
62
|
assert @dynamic_model.persisting_dynamic_attributes.include?('field_test')
|
55
63
|
assert @dynamic_model.dynamic_attributes.include?('field_test')
|
64
|
+
assert @dynamic_model.has_dynamic_attribute?(:field_test)
|
56
65
|
|
57
66
|
DynamicModel.destroy_dynamic_attribute_for_nil = true
|
58
67
|
assert @dynamic_model.update_attribute(:field_test,nil)
|
59
68
|
assert !@dynamic_model.persisting_dynamic_attributes.include?('field_test')
|
60
69
|
assert !@dynamic_model.dynamic_attributes.include?('field_test')
|
61
70
|
assert !@dynamic_model.respond_to?('field_test=')
|
71
|
+
assert !@dynamic_model.has_dynamic_attribute?(:field_test)
|
62
72
|
end
|
63
73
|
|
64
74
|
def test_should_allow_different_prefix
|
@@ -68,7 +78,9 @@ class TestDynamicAttributes < Test::Unit::TestCase
|
|
68
78
|
assert_equal 'hello', @dynamic_model.what_test
|
69
79
|
assert @dynamic_model.persisting_dynamic_attributes.include?('what_test')
|
70
80
|
assert @dynamic_model.dynamic_attributes.keys.include?('what_test')
|
71
|
-
|
81
|
+
assert @dynamic_model.has_dynamic_attribute?(:what_test)
|
82
|
+
assert !@dynamic_model.has_dynamic_attribute?(:field_test)
|
83
|
+
|
72
84
|
assert_raises NoMethodError do
|
73
85
|
@dynamic_model.field_test = 'Fail'
|
74
86
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 17
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 1
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
8
|
+
- 2
|
9
|
+
version: 1.1.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Reinier de Lange
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-16 00:00:00 +02:00
|
19
18
|
default_executable:
|
20
19
|
dependencies: []
|
21
20
|
|
@@ -39,10 +38,6 @@ files:
|
|
39
38
|
- VERSION
|
40
39
|
- init.rb
|
41
40
|
- lib/dynamic_attributes.rb
|
42
|
-
- test/helper.rb
|
43
|
-
- test/test_dynamic_attributes.rb
|
44
|
-
- test/database.yml
|
45
|
-
- test/schema.rb
|
46
41
|
has_rdoc: true
|
47
42
|
homepage: http://github.com/moiristo/dynamic_attributes
|
48
43
|
licenses: []
|
@@ -53,27 +48,23 @@ rdoc_options:
|
|
53
48
|
require_paths:
|
54
49
|
- lib
|
55
50
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
51
|
requirements:
|
58
52
|
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 3
|
61
54
|
segments:
|
62
55
|
- 0
|
63
56
|
version: "0"
|
64
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
hash: 3
|
70
61
|
segments:
|
71
62
|
- 0
|
72
63
|
version: "0"
|
73
64
|
requirements: []
|
74
65
|
|
75
66
|
rubyforge_project:
|
76
|
-
rubygems_version: 1.3.
|
67
|
+
rubygems_version: 1.3.6
|
77
68
|
signing_key:
|
78
69
|
specification_version: 3
|
79
70
|
summary: dynamic_attributes is a gem that lets you dynamically specify attributes on ActiveRecord models, which will be serialized and deserialized to a given text column.
|