custom-attributes 0.1.1 → 0.1.2
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/custom_attributes.rb +5 -4
- data/spec/custom_attributes/has_custom_attributes_spec.rb +8 -2
- data/spec/models.rb +4 -0
- data/spec/schema.rb +1 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -15,15 +15,16 @@ module ActiveRecord
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def has_custom_attributes(extra_field_types = {}, &block)
|
18
|
-
|
18
|
+
field_types = extra_field_types
|
19
|
+
field_types = self.defined_custom_field_types.merge(extra_field_types) if has_custom_attributes?
|
19
20
|
|
20
|
-
field_definitions = CustomAttributeDefinitionHelper.new
|
21
|
-
yield field_definitions
|
21
|
+
field_definitions = CustomAttributeDefinitionHelper.new field_types
|
22
|
+
yield field_definitions if block_given?
|
22
23
|
defined_custom_attributes = field_definitions.defined_attributes
|
23
24
|
|
24
25
|
if has_custom_attributes?
|
25
26
|
write_inheritable_attribute(:defined_custom_attributes, self.defined_custom_attributes.deep_merge(defined_custom_attributes))
|
26
|
-
write_inheritable_attribute(:defined_custom_field_types,
|
27
|
+
write_inheritable_attribute(:defined_custom_field_types, field_types)
|
27
28
|
else
|
28
29
|
write_inheritable_attribute(:defined_custom_attributes, defined_custom_attributes)
|
29
30
|
class_inheritable_reader(:defined_custom_attributes)
|
@@ -40,7 +40,7 @@ describe "Custom attributes of a person" do
|
|
40
40
|
fields[0].value.should == "06 28 61 06 28"
|
41
41
|
end
|
42
42
|
|
43
|
-
it "should cache
|
43
|
+
it "should cache the 'born on' date locally" do
|
44
44
|
@person.custom_attributes.add_date "Born on", Date.civil(1981, 5, 31)
|
45
45
|
@person.save
|
46
46
|
@person.born_on.should == Date.civil(1981,5, 31)
|
@@ -103,13 +103,19 @@ describe "Custom attributes of a product" do
|
|
103
103
|
fields[0].value.should == 5.60
|
104
104
|
end
|
105
105
|
|
106
|
-
it "should cache
|
106
|
+
it "should not cache width locally" do
|
107
107
|
@product.custom_attributes.add_size "Width", 5.60
|
108
108
|
@product.save
|
109
109
|
@product.width.should == nil
|
110
110
|
@product.custom_attributes.size_value_of(:width).should == 5.60
|
111
111
|
end
|
112
112
|
|
113
|
+
it "should cache the details url locally" do
|
114
|
+
@product.custom_attributes.add_url "Details", "http://example.com/"
|
115
|
+
@product.save
|
116
|
+
@product.details_url.should == "http://example.com/"
|
117
|
+
end
|
118
|
+
|
113
119
|
it "should rename labels" do
|
114
120
|
@product.custom_attributes.add_size "Width", 5.60
|
115
121
|
|
data/spec/models.rb
CHANGED
@@ -10,10 +10,14 @@ end
|
|
10
10
|
|
11
11
|
class Product < ActiveRecord::Base
|
12
12
|
|
13
|
+
has_custom_attributes :url => :string
|
14
|
+
|
13
15
|
has_custom_attributes :size => :float do |fields|
|
14
16
|
fields.size :width, :height, :depth
|
17
|
+
fields.url :details, :on_model => { :details => :details_url }
|
15
18
|
end
|
16
19
|
|
20
|
+
|
17
21
|
end
|
18
22
|
|
19
23
|
class Location < ActiveRecord::Base
|
data/spec/schema.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: custom-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthijs Groen
|