hydra_attribute 0.3.0.beta1 → 0.3.0
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/features/destroy.feature +102 -0
- data/features/step_definitions/model_steps.rb +6 -0
- data/features/step_definitions/record_steps.rb +6 -2
- data/gemfiles/3.1.gemfile.lock +1 -1
- data/gemfiles/3.2.gemfile.lock +1 -1
- data/lib/hydra_attribute/active_record/attribute_methods.rb +38 -11
- data/lib/hydra_attribute/association_builder.rb +6 -0
- data/lib/hydra_attribute/version.rb +1 -1
- metadata +21 -19
@@ -0,0 +1,102 @@
|
|
1
|
+
Feature: destroy model
|
2
|
+
When destroy model
|
3
|
+
Then all associated values should be deleted too
|
4
|
+
|
5
|
+
Background: create hydra attributes
|
6
|
+
Given create "HydraAttribute::HydraAttribute" models with attributes as "hashes":
|
7
|
+
| entity_type | name | backend_type | default_value |
|
8
|
+
| Product | code | string | [nil:] |
|
9
|
+
| Product | price | float | [string:0] |
|
10
|
+
| Product | active | boolean | [string:0] |
|
11
|
+
| Product | info | text | [string:] |
|
12
|
+
| Product | started | datetime | [string:2012-01-01] |
|
13
|
+
|
14
|
+
Scenario: destroy model
|
15
|
+
Given create "Product" model with attributes as "hashes":
|
16
|
+
| code | price | active | info | started |
|
17
|
+
| [string:1] | [float:1] | [boolean:true] | [string:a] | [string:2012-01-01] |
|
18
|
+
| [string:2] | [float:2] | [boolean:true] | [string:b] | [string:2012-01-02] |
|
19
|
+
| [string:3] | [float:3] | [boolean:true] | [string:c] | [string:2012-01-03] |
|
20
|
+
| [string:4] | [float:4] | [boolean:true] | [string:d] | [string:2012-01-04] |
|
21
|
+
| [string:5] | [float:5] | [boolean:true] | [string:e] | [string:2012-01-05] |
|
22
|
+
|
23
|
+
When select first "HydraAttribute::HydraStringProduct" record
|
24
|
+
Then record read attribute "value" and value should be "[string:1]"
|
25
|
+
When select first "HydraAttribute::HydraFloatProduct" record
|
26
|
+
Then record read attribute "value" and value should be "[float:1]"
|
27
|
+
When select first "HydraAttribute::HydraBooleanProduct" record
|
28
|
+
Then record read attribute "value" and value should be "[boolean:true]"
|
29
|
+
When select first "HydraAttribute::HydraTextProduct" record
|
30
|
+
Then record read attribute "value" and value should be "[string:a]"
|
31
|
+
When select first "HydraAttribute::HydraDatetimeProduct" record
|
32
|
+
Then record read attribute "value" and value should be "[string:2012-01-01]"
|
33
|
+
|
34
|
+
Given select first "Product" record
|
35
|
+
And destroy record
|
36
|
+
|
37
|
+
When select first "HydraAttribute::HydraStringProduct" record
|
38
|
+
Then record read attribute "value" and value should be "[string:2]"
|
39
|
+
When select first "HydraAttribute::HydraFloatProduct" record
|
40
|
+
Then record read attribute "value" and value should be "[float:2]"
|
41
|
+
When select first "HydraAttribute::HydraBooleanProduct" record
|
42
|
+
Then record read attribute "value" and value should be "[boolean:true]"
|
43
|
+
When select first "HydraAttribute::HydraTextProduct" record
|
44
|
+
Then record read attribute "value" and value should be "[string:b]"
|
45
|
+
When select first "HydraAttribute::HydraDatetimeProduct" record
|
46
|
+
Then record read attribute "value" and value should be "[string:2012-01-02]"
|
47
|
+
|
48
|
+
Given select first "Product" record
|
49
|
+
And destroy record
|
50
|
+
|
51
|
+
When select first "HydraAttribute::HydraStringProduct" record
|
52
|
+
Then record read attribute "value" and value should be "[string:3]"
|
53
|
+
When select first "HydraAttribute::HydraFloatProduct" record
|
54
|
+
Then record read attribute "value" and value should be "[float:3]"
|
55
|
+
When select first "HydraAttribute::HydraBooleanProduct" record
|
56
|
+
Then record read attribute "value" and value should be "[boolean:true]"
|
57
|
+
When select first "HydraAttribute::HydraTextProduct" record
|
58
|
+
Then record read attribute "value" and value should be "[string:c]"
|
59
|
+
When select first "HydraAttribute::HydraDatetimeProduct" record
|
60
|
+
Then record read attribute "value" and value should be "[string:2012-01-03]"
|
61
|
+
|
62
|
+
Given select first "Product" record
|
63
|
+
And destroy record
|
64
|
+
|
65
|
+
When select first "HydraAttribute::HydraStringProduct" record
|
66
|
+
Then record read attribute "value" and value should be "[string:4]"
|
67
|
+
When select first "HydraAttribute::HydraFloatProduct" record
|
68
|
+
Then record read attribute "value" and value should be "[float:4]"
|
69
|
+
When select first "HydraAttribute::HydraBooleanProduct" record
|
70
|
+
Then record read attribute "value" and value should be "[boolean:true]"
|
71
|
+
When select first "HydraAttribute::HydraTextProduct" record
|
72
|
+
Then record read attribute "value" and value should be "[string:d]"
|
73
|
+
When select first "HydraAttribute::HydraDatetimeProduct" record
|
74
|
+
Then record read attribute "value" and value should be "[string:2012-01-04]"
|
75
|
+
|
76
|
+
Given select first "Product" record
|
77
|
+
And destroy record
|
78
|
+
|
79
|
+
When select first "HydraAttribute::HydraStringProduct" record
|
80
|
+
Then record read attribute "value" and value should be "[string:5]"
|
81
|
+
When select first "HydraAttribute::HydraFloatProduct" record
|
82
|
+
Then record read attribute "value" and value should be "[float:5]"
|
83
|
+
When select first "HydraAttribute::HydraBooleanProduct" record
|
84
|
+
Then record read attribute "value" and value should be "[boolean:true]"
|
85
|
+
When select first "HydraAttribute::HydraTextProduct" record
|
86
|
+
Then record read attribute "value" and value should be "[string:e]"
|
87
|
+
When select first "HydraAttribute::HydraDatetimeProduct" record
|
88
|
+
Then record read attribute "value" and value should be "[string:2012-01-05]"
|
89
|
+
|
90
|
+
Given select first "Product" record
|
91
|
+
And destroy record
|
92
|
+
|
93
|
+
When select first "HydraAttribute::HydraStringProduct" record
|
94
|
+
Then record should be nil
|
95
|
+
When select first "HydraAttribute::HydraFloatProduct" record
|
96
|
+
Then record should be nil
|
97
|
+
When select first "HydraAttribute::HydraBooleanProduct" record
|
98
|
+
Then record should be nil
|
99
|
+
When select first "HydraAttribute::HydraTextProduct" record
|
100
|
+
Then record should be nil
|
101
|
+
When select first "HydraAttribute::HydraDatetimeProduct" record
|
102
|
+
Then record should be nil
|
@@ -2,6 +2,12 @@ Given /^create "([^"]+)" model$/ do |klass|
|
|
2
2
|
klass.constantize.create!
|
3
3
|
end
|
4
4
|
|
5
|
+
Given /^create "([^"]+)" model with attributes as "([^"]+):"$/ do |klass, format, table|
|
6
|
+
Array.wrap(table.send(format)).each do |hash|
|
7
|
+
klass.constantize.create!(type_cast_hash(hash))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
Given /^(load and )?(save|create|update(?: all| attributes)?|destroy(?: all)?|delete(?: all)?)(?: for)? "([^"]+)" models? with attributes as "([^"]+)":$/ do |load, action, klass, format, table|
|
6
12
|
action = action.gsub(' ', '_')
|
7
13
|
klass = klass.constantize
|
@@ -1,9 +1,9 @@
|
|
1
1
|
When /^load all "([^"]+)" records$/ do |klass|
|
2
|
-
@records =
|
2
|
+
@records = klass.constantize.all
|
3
3
|
end
|
4
4
|
|
5
5
|
When /^select (first|last) "([^"]+)" record$/ do |method, klass|
|
6
|
-
@record =
|
6
|
+
@record = klass.constantize.send(method)
|
7
7
|
end
|
8
8
|
|
9
9
|
When /^assign attributes as "([^"]+)":$/ do |format, table|
|
@@ -21,6 +21,10 @@ When /^keep "([^"]+)" attribute$/ do |attribute|
|
|
21
21
|
@keep[attribute] = @record.send(attribute)
|
22
22
|
end
|
23
23
|
|
24
|
+
Then /^record should be nil$/ do
|
25
|
+
@record.should be_nil
|
26
|
+
end
|
27
|
+
|
24
28
|
Then /^attribute "([^"]+)" (should(?:\snot)?) be the same$/ do |attribute, behavior|
|
25
29
|
method = behavior.sub(/\s/, '_')
|
26
30
|
@keep[attribute].send(method) == @record.send(attribute)
|
data/gemfiles/3.1.gemfile.lock
CHANGED
data/gemfiles/3.2.gemfile.lock
CHANGED
@@ -111,6 +111,12 @@ module HydraAttribute
|
|
111
111
|
reset_hydra_attribute_methods
|
112
112
|
super
|
113
113
|
end
|
114
|
+
|
115
|
+
def inspect
|
116
|
+
attr_list = columns.map { |c| "#{c.name}: #{c.type}" }
|
117
|
+
attr_list += hydra_attributes.map { |a| "#{a.name}: #{a.backend_type}" }
|
118
|
+
"#{name}(#{attr_list.join(', ')})"
|
119
|
+
end
|
114
120
|
end
|
115
121
|
|
116
122
|
def respond_to?(name, include_private = false)
|
@@ -118,17 +124,16 @@ module HydraAttribute
|
|
118
124
|
super
|
119
125
|
end
|
120
126
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
EOS
|
127
|
+
def attributes
|
128
|
+
hydra_value_models.each_with_object(super) do |model, attributes|
|
129
|
+
attributes[model.attribute_name] = model.read_attribute('value')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def attributes_before_type_cast
|
134
|
+
hydra_value_models.each_with_object(super) do |model, attributes|
|
135
|
+
attributes[model.attribute_name] = model.read_attribute_before_type_cast('value')
|
136
|
+
end
|
132
137
|
end
|
133
138
|
|
134
139
|
%w(read_attribute read_attribute_before_type_cast).each do |method|
|
@@ -148,6 +153,22 @@ module HydraAttribute
|
|
148
153
|
EOS
|
149
154
|
end
|
150
155
|
|
156
|
+
def hydra_attribute_names
|
157
|
+
@hydra_attribute_names ||= hydra_value_models.map(&:attribute_name)
|
158
|
+
end
|
159
|
+
|
160
|
+
def hydra_attribute_backend_types
|
161
|
+
@hydra_attribute_backend_types ||= self.class.hydra_attribute_backend_types.select do |backend_type|
|
162
|
+
hydra_value_association(backend_type).all_models.any?
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def inspect
|
167
|
+
attrs = self.class.column_names.map { |name| "#{name}: #{attribute_for_inspect(name)}" }
|
168
|
+
attrs += hydra_value_models.map { |model| "#{model.attribute_name}: #{model.attribute_for_inspect('value')}" }
|
169
|
+
"#<#{self.class} #{attrs.join(', ')}>"
|
170
|
+
end
|
171
|
+
|
151
172
|
private
|
152
173
|
|
153
174
|
def hydra_value_model(identifier)
|
@@ -159,6 +180,12 @@ module HydraAttribute
|
|
159
180
|
end
|
160
181
|
end
|
161
182
|
|
183
|
+
def hydra_value_models
|
184
|
+
@hydra_value_models ||= self.class.hydra_attribute_backend_types.inject([]) do |models, backend_type|
|
185
|
+
models + hydra_value_association(backend_type).all_models
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
162
189
|
def hydra_value_association(backend_type)
|
163
190
|
association(::HydraAttribute::AssociationBuilder.association_name(backend_type))
|
164
191
|
end
|
@@ -39,6 +39,12 @@ module HydraAttribute
|
|
39
39
|
value_model.belongs_to :entity, class_name: klass.model_name, autosave: false
|
40
40
|
value_model.belongs_to :hydra_attribute, class_name: 'HydraAttribute::HydraAttribute'
|
41
41
|
value_model.attr_accessible :hydra_attribute_id, :value
|
42
|
+
|
43
|
+
value_model.class_eval <<-EOS, __FILE__, __LINE__ + 1
|
44
|
+
def attribute_name
|
45
|
+
#{klass.model_name}.hydra_attribute(hydra_attribute_id).name
|
46
|
+
end
|
47
|
+
EOS
|
42
48
|
end
|
43
49
|
|
44
50
|
def add_association
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra_attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kostyantyn Stepanyuk
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-26 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152204220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152204220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152203520 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152203520
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: cucumber
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152202360 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152202360
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
|
-
requirement: &
|
49
|
+
requirement: &2152201580 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152201580
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: database_cleaner
|
60
|
-
requirement: &
|
60
|
+
requirement: &2152200720 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2152200720
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: appraisal
|
71
|
-
requirement: &
|
71
|
+
requirement: &2152199780 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2152199780
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rake
|
82
|
-
requirement: &
|
82
|
+
requirement: &2152198420 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2152198420
|
91
91
|
description: hydra_attribute is an implementation of EAV pattern for ActiveRecord
|
92
92
|
models.
|
93
93
|
email: kostya.stepanyuk@gmail.com
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- features/attributes/update.feature
|
111
111
|
- features/create.feature
|
112
112
|
- features/define.feature
|
113
|
+
- features/destroy.feature
|
113
114
|
- features/query_methods/group.feature
|
114
115
|
- features/query_methods/order.feature
|
115
116
|
- features/query_methods/select.feature
|
@@ -163,9 +164,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
163
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
165
|
none: false
|
165
166
|
requirements:
|
166
|
-
- - ! '
|
167
|
+
- - ! '>='
|
167
168
|
- !ruby/object:Gem::Version
|
168
|
-
version:
|
169
|
+
version: '0'
|
169
170
|
requirements: []
|
170
171
|
rubyforge_project:
|
171
172
|
rubygems_version: 1.8.10
|
@@ -179,6 +180,7 @@ test_files:
|
|
179
180
|
- features/attributes/update.feature
|
180
181
|
- features/create.feature
|
181
182
|
- features/define.feature
|
183
|
+
- features/destroy.feature
|
182
184
|
- features/query_methods/group.feature
|
183
185
|
- features/query_methods/order.feature
|
184
186
|
- features/query_methods/select.feature
|