hydra_attribute 0.4.2 → 0.5.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.travis.yml +6 -5
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/README.md +3 -3
- data/Rakefile +2 -7
- data/gemfiles/activerecord-3.2.gemfile +5 -0
- data/hydra_attribute.gemspec +6 -7
- data/lib/hydra_attribute.rb +17 -18
- data/lib/hydra_attribute/active_record.rb +34 -13
- data/lib/hydra_attribute/active_record/association_preloader.rb +47 -28
- data/lib/hydra_attribute/active_record/attribute_methods.rb +29 -140
- data/lib/hydra_attribute/active_record/mass_assignment_security.rb +39 -0
- data/lib/hydra_attribute/active_record/migration.rb +4 -4
- data/lib/hydra_attribute/active_record/relation.rb +6 -7
- data/lib/hydra_attribute/active_record/relation/query_methods.rb +28 -18
- data/lib/hydra_attribute/hydra_attribute.rb +12 -49
- data/lib/hydra_attribute/hydra_attribute_set.rb +67 -0
- data/lib/hydra_attribute/hydra_entity.rb +110 -0
- data/lib/hydra_attribute/hydra_entity_attribute_association.rb +155 -0
- data/lib/hydra_attribute/hydra_set.rb +24 -26
- data/lib/hydra_attribute/hydra_value.rb +210 -0
- data/lib/hydra_attribute/identity_map.rb +18 -0
- data/lib/hydra_attribute/middleware/identity_map.rb +15 -0
- data/lib/hydra_attribute/migrator.rb +24 -21
- data/lib/hydra_attribute/model.rb +47 -0
- data/lib/hydra_attribute/model/cacheable.rb +207 -0
- data/lib/hydra_attribute/model/dirty.rb +39 -0
- data/lib/hydra_attribute/model/has_many_through.rb +168 -0
- data/lib/hydra_attribute/model/identity_map.rb +59 -0
- data/lib/hydra_attribute/model/mediator.rb +89 -0
- data/lib/hydra_attribute/model/notifiable.rb +23 -0
- data/lib/hydra_attribute/model/persistence.rb +424 -0
- data/lib/hydra_attribute/model/validations.rb +40 -0
- data/lib/hydra_attribute/version.rb +1 -1
- data/spec/environments/mysql.rb +23 -0
- data/spec/environments/postgresql.rb +23 -0
- data/spec/environments/sqlite.rb +12 -0
- data/spec/fixtures/category.rb +8 -0
- data/spec/fixtures/product.rb +8 -0
- data/spec/fixtures/product_black_list.rb +13 -0
- data/spec/fixtures/product_white_list.rb +13 -0
- data/spec/hydra_attribute/active_record/attribute_methods_spec.rb +23 -28
- data/spec/hydra_attribute/active_record/mass_assignment_security_spec.rb +41 -0
- data/spec/hydra_attribute/active_record_spec.rb +577 -0
- data/spec/hydra_attribute/hydra_attribute_set_spec.rb +651 -0
- data/spec/hydra_attribute/hydra_attribute_spec.rb +208 -10
- data/spec/hydra_attribute/hydra_entity_attribute_association_spec.rb +216 -0
- data/spec/hydra_attribute/hydra_entity_spec.rb +71 -0
- data/spec/hydra_attribute/hydra_set_spec.rb +51 -10
- data/spec/hydra_attribute/hydra_value_spec.rb +286 -0
- data/spec/hydra_attribute/identity_map_spec.rb +47 -0
- data/spec/hydra_attribute/migrator_spec.rb +411 -0
- data/spec/hydra_attribute/model/cacheable_spec.rb +106 -0
- data/spec/hydra_attribute/model/has_many_through_spec.rb +132 -0
- data/spec/hydra_attribute/model/identity_map_spec.rb +39 -0
- data/spec/hydra_attribute/model/mediator_spec.rb +62 -0
- data/spec/hydra_attribute/model/persistence_spec.rb +550 -0
- data/spec/hydra_attribute/model_spec.rb +39 -0
- data/spec/hydra_attribute_spec.rb +36 -0
- data/spec/spec_helper.rb +10 -42
- metadata +76 -100
- data/Appraisals +0 -7
- data/cucumber.yml +0 -1
- data/features/entity/create.feature +0 -145
- data/features/entity/destroy.feature +0 -111
- data/features/entity/new.feature +0 -121
- data/features/entity/update.feature +0 -147
- data/features/hydra_attribute/create.feature +0 -30
- data/features/hydra_attribute/destroy.feature +0 -26
- data/features/hydra_attribute/update.feature +0 -36
- data/features/hydra_set/destroy.feature +0 -31
- data/features/migrations/create_and_drop.feature +0 -165
- data/features/migrations/migrate_and_rollback.feature +0 -211
- data/features/relation/query_methods/group.feature +0 -42
- data/features/relation/query_methods/order.feature +0 -67
- data/features/relation/query_methods/reorder.feature +0 -29
- data/features/relation/query_methods/reverse_order.feature +0 -29
- data/features/relation/query_methods/select.feature +0 -50
- data/features/relation/query_methods/where.feature +0 -115
- data/features/step_definitions/connections.rb +0 -65
- data/features/step_definitions/model_steps.rb +0 -136
- data/features/step_definitions/query_methods.rb +0 -48
- data/features/step_definitions/record_steps.rb +0 -93
- data/features/support/env.rb +0 -38
- data/features/support/world.rb +0 -61
- data/lib/hydra_attribute/active_record/association.rb +0 -113
- data/lib/hydra_attribute/active_record/reflection.rb +0 -16
- data/lib/hydra_attribute/association_builder.rb +0 -69
- data/lib/hydra_attribute/builder.rb +0 -37
- data/lib/hydra_attribute/entity_callbacks.rb +0 -26
- data/lib/hydra_attribute/hydra_attribute_methods.rb +0 -226
- data/lib/hydra_attribute/hydra_methods.rb +0 -528
- data/lib/hydra_attribute/hydra_set_methods.rb +0 -95
- data/lib/hydra_attribute/hydra_value_methods.rb +0 -21
- data/lib/hydra_attribute/memoizable.rb +0 -37
- data/spec/hydra_attribute/active_record/relation/query_methods_spec.rb +0 -31
- data/spec/hydra_attribute/hydra_attribute_methods_spec.rb +0 -458
- data/spec/hydra_attribute/hydra_methods_spec.rb +0 -456
- data/spec/hydra_attribute/hydra_set_methods_spec.rb +0 -203
- data/spec/hydra_attribute/memoizable_spec.rb +0 -95
@@ -1,456 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe HydraAttribute::HydraMethods do
|
4
|
-
describe '.hydra_set_attributes' do
|
5
|
-
let!(:hydra_set) { Product.hydra_sets.create(name: 'Default') }
|
6
|
-
let!(:hydra_attribute1) { hydra_set.hydra_attributes.create(name: 'a', backend_type: 'string') }
|
7
|
-
let!(:hydra_attribute2) { Product.hydra_attributes.create(name: 'b', backend_type: 'string') }
|
8
|
-
|
9
|
-
it 'should return hydra attributes for specific hydra set' do
|
10
|
-
Product.hydra_set_attributes(hydra_set.id).should have(1).hydra_attribute
|
11
|
-
Product.hydra_set_attributes(hydra_set.id).first.should == hydra_attribute1
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should return all hydra attributes if hydra set does not exist' do
|
15
|
-
Product.hydra_set_attributes(0).should have(2).hydra_attributes
|
16
|
-
Product.hydra_set_attributes(0).first.should == hydra_attribute1
|
17
|
-
Product.hydra_set_attributes(0).last.should == hydra_attribute2
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '.hydra_set_attribute_ids' do
|
22
|
-
describe 'create hydra attributes' do
|
23
|
-
let!(:hydra_set) { Product.hydra_sets.create(name: 'Default') }
|
24
|
-
let!(:hydra_attribute1) { hydra_set.hydra_attributes.create(name: 'a', backend_type: 'string') }
|
25
|
-
let!(:hydra_attribute2) { Product.hydra_attributes.create(name: 'b', backend_type: 'string') }
|
26
|
-
|
27
|
-
it 'should return hydra attribute ids for specific hydra set' do
|
28
|
-
Product.hydra_set_attribute_ids(hydra_set.id).should == [hydra_attribute1.id]
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should return all hydra attribute ids if hydra set does not exist' do
|
32
|
-
Product.hydra_set_attribute_ids(0).should =~ [hydra_attribute1.id, hydra_attribute2.id]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should cache result' do
|
37
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_ids).once
|
38
|
-
2.times { Product.hydra_set_attribute_ids(1) }
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should reset method cache after creating hydra attribute' do
|
42
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_ids).twice
|
43
|
-
|
44
|
-
Product.hydra_set_attribute_ids(1)
|
45
|
-
Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
46
|
-
Product.hydra_set_attribute_ids(1)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should reset method cache after updating hydra attribute' do
|
50
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
51
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_ids).twice
|
52
|
-
|
53
|
-
Product.hydra_set_attribute_ids(1)
|
54
|
-
one.update_attributes(name: 'two')
|
55
|
-
Product.hydra_set_attribute_ids(1)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should reset method cache after removing hydra attribute' do
|
59
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
60
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_ids).twice
|
61
|
-
|
62
|
-
Product.hydra_set_attribute_ids(1)
|
63
|
-
one.destroy
|
64
|
-
Product.hydra_set_attribute_ids(1)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '.hydra_set_attribute_names' do
|
69
|
-
describe 'create hydra attributes' do
|
70
|
-
let!(:hydra_set) { Product.hydra_sets.create(name: 'Default') }
|
71
|
-
let!(:hydra_attribute1) { hydra_set.hydra_attributes.create(name: 'a', backend_type: 'string') }
|
72
|
-
let!(:hydra_attribute2) { Product.hydra_attributes.create(name: 'b', backend_type: 'string') }
|
73
|
-
|
74
|
-
it 'should return hydra attribute names for specific hydra set' do
|
75
|
-
Product.hydra_set_attribute_names(hydra_set.id).should == [hydra_attribute1.name]
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should return all hydra attribute names if hydra set does not exist' do
|
79
|
-
Product.hydra_set_attribute_names(0).should =~ [hydra_attribute1.name, hydra_attribute2.name]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should cache result' do
|
84
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_names).once
|
85
|
-
2.times { Product.hydra_set_attribute_names(1) }
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'should reset method cache after creating hydra attribute' do
|
89
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_names).twice
|
90
|
-
|
91
|
-
Product.hydra_set_attribute_names(1)
|
92
|
-
Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
93
|
-
Product.hydra_set_attribute_names(1)
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should reset method cache after updating hydra attribute' do
|
97
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
98
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_names).twice
|
99
|
-
|
100
|
-
Product.hydra_set_attribute_names(1)
|
101
|
-
one.update_attributes(name: 'two')
|
102
|
-
Product.hydra_set_attribute_names(1)
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'should reset method cache after removing hydra attribute' do
|
106
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
107
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_names).twice
|
108
|
-
|
109
|
-
Product.hydra_set_attribute_names(1)
|
110
|
-
one.destroy
|
111
|
-
Product.hydra_set_attribute_names(1)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe '.hydra_set_attribute_backend_types' do
|
116
|
-
describe 'create hydra attributes' do
|
117
|
-
let!(:hydra_set) { Product.hydra_sets.create(name: 'Default') }
|
118
|
-
let!(:hydra_attribute1) { hydra_set.hydra_attributes.create(name: 'a', backend_type: 'string') }
|
119
|
-
let!(:hydra_attribute2) { Product.hydra_attributes.create(name: 'b', backend_type: 'integer') }
|
120
|
-
|
121
|
-
it 'should return hydra attribute backend types for specific hydra set' do
|
122
|
-
Product.hydra_set_attribute_backend_types(hydra_set.id).should == [hydra_attribute1.backend_type]
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'should return all hydra attribute backend types if hydra set does not exist' do
|
126
|
-
Product.hydra_set_attribute_backend_types(0).should =~ [hydra_attribute1.backend_type, hydra_attribute2.backend_type]
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'should return uniq attribute backend type names' do
|
130
|
-
hydra_set.hydra_attributes.create(name: 'c', backend_type: 'string')
|
131
|
-
hydra_set.hydra_attributes.create(name: 'd', backend_type: 'integer')
|
132
|
-
|
133
|
-
backend_types = Product.hydra_set_attribute_backend_types(hydra_set.id)
|
134
|
-
backend_types.should =~ %w(string integer)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'should cache result' do
|
139
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_backend_types).once
|
140
|
-
2.times { Product.hydra_set_attribute_backend_types(1) }
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'should reset method cache after creating hydra attribute' do
|
144
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_backend_types).twice
|
145
|
-
|
146
|
-
Product.hydra_set_attribute_backend_types(1)
|
147
|
-
Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
148
|
-
Product.hydra_set_attribute_backend_types(1)
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'should reset method cache after updating hydra attribute' do
|
152
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
153
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_backend_types).twice
|
154
|
-
|
155
|
-
Product.hydra_set_attribute_backend_types(1)
|
156
|
-
one.update_attributes(name: 'two')
|
157
|
-
Product.hydra_set_attribute_backend_types(1)
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'should reset method cache after removing hydra attribute' do
|
161
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
162
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_backend_types).twice
|
163
|
-
|
164
|
-
Product.hydra_set_attribute_backend_types(1)
|
165
|
-
one.destroy
|
166
|
-
Product.hydra_set_attribute_backend_types(1)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe '.hydra_set_attributes_by_backend_type' do
|
171
|
-
describe 'create attributes' do
|
172
|
-
let!(:hydra_set) { Product.hydra_sets.create(name: 'Default') }
|
173
|
-
let!(:hydra_attr1) { hydra_set.hydra_attributes.create(name: 'a1', backend_type: 'string') }
|
174
|
-
let!(:hydra_attr2) { hydra_set.hydra_attributes.create(name: 'a2', backend_type: 'string') }
|
175
|
-
let!(:hydra_attr3) { hydra_set.hydra_attributes.create(name: 'a3', backend_type: 'integer') }
|
176
|
-
let!(:hydra_attr4) { Product.hydra_attributes.create(name: 'a4', backend_type: 'string') }
|
177
|
-
|
178
|
-
it 'should return hydra attributes for hydra set grouped by backend type' do
|
179
|
-
hydra_attributes = Product.hydra_set_attributes_by_backend_type(hydra_set.id)
|
180
|
-
|
181
|
-
hydra_attributes['string'].should =~ [hydra_attr1, hydra_attr2]
|
182
|
-
hydra_attributes['integer'].should == [hydra_attr3]
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'should return all hydra attributes grouped by backend type if hydra set does not exist' do
|
186
|
-
hydra_attributes = Product.hydra_set_attributes_by_backend_type(0)
|
187
|
-
|
188
|
-
hydra_attributes['string'].should =~ [hydra_attr1, hydra_attr2, hydra_attr4]
|
189
|
-
hydra_attributes['integer'].should == [hydra_attr3]
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'should cache result' do
|
194
|
-
Product.should_receive(:unmemoized_hydra_set_attributes_by_backend_type).once
|
195
|
-
2.times { Product.hydra_set_attributes_by_backend_type(1) }
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'should reset method cache after creating hydra attribute' do
|
199
|
-
Product.should_receive(:unmemoized_hydra_set_attributes_by_backend_type).twice
|
200
|
-
|
201
|
-
Product.hydra_set_attributes_by_backend_type(1)
|
202
|
-
Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
203
|
-
Product.hydra_set_attributes_by_backend_type(1)
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'should reset method cache after updating hydra attribute' do
|
207
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
208
|
-
Product.should_receive(:unmemoized_hydra_set_attributes_by_backend_type).twice
|
209
|
-
|
210
|
-
Product.hydra_set_attributes_by_backend_type(1)
|
211
|
-
one.update_attributes(name: 'two')
|
212
|
-
Product.hydra_set_attributes_by_backend_type(1)
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'should reset method cache after removing hydra attribute' do
|
216
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
217
|
-
Product.should_receive(:unmemoized_hydra_set_attributes_by_backend_type).twice
|
218
|
-
|
219
|
-
Product.hydra_set_attributes_by_backend_type(1)
|
220
|
-
one.destroy
|
221
|
-
Product.hydra_set_attributes_by_backend_type(1)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
describe '.hydra_set_attribute_ids_by_backend_type' do
|
226
|
-
describe 'create attributes' do
|
227
|
-
let!(:hydra_set) { Product.hydra_sets.create(name: 'Default') }
|
228
|
-
let!(:hydra_attr1) { hydra_set.hydra_attributes.create(name: 'a1', backend_type: 'string') }
|
229
|
-
let!(:hydra_attr2) { hydra_set.hydra_attributes.create(name: 'a2', backend_type: 'string') }
|
230
|
-
let!(:hydra_attr3) { hydra_set.hydra_attributes.create(name: 'a3', backend_type: 'integer') }
|
231
|
-
let!(:hydra_attr4) { Product.hydra_attributes.create(name: 'a4', backend_type: 'string') }
|
232
|
-
|
233
|
-
it 'should return hydra attribute ids for hydra set grouped by backend type' do
|
234
|
-
hydra_attributes = Product.hydra_set_attribute_ids_by_backend_type(hydra_set.id)
|
235
|
-
|
236
|
-
hydra_attributes['string'].should =~ [hydra_attr1.id, hydra_attr2.id]
|
237
|
-
hydra_attributes['integer'].should == [hydra_attr3.id]
|
238
|
-
end
|
239
|
-
|
240
|
-
it 'should return all hydra attribute ids grouped by backend type if hydra set does not exist' do
|
241
|
-
hydra_attributes = Product.hydra_set_attribute_ids_by_backend_type(0)
|
242
|
-
|
243
|
-
hydra_attributes['string'].should =~ [hydra_attr1.id, hydra_attr2.id, hydra_attr4.id]
|
244
|
-
hydra_attributes['integer'].should == [hydra_attr3.id]
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
it 'should cache result' do
|
249
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_ids_by_backend_type).once
|
250
|
-
2.times { Product.hydra_set_attribute_ids_by_backend_type(1) }
|
251
|
-
end
|
252
|
-
|
253
|
-
it 'should reset method cache after creating hydra attribute' do
|
254
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_ids_by_backend_type).twice
|
255
|
-
|
256
|
-
Product.hydra_set_attribute_ids_by_backend_type(1)
|
257
|
-
Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
258
|
-
Product.hydra_set_attribute_ids_by_backend_type(1)
|
259
|
-
end
|
260
|
-
|
261
|
-
it 'should reset method cache after updating hydra attribute' do
|
262
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
263
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_ids_by_backend_type).twice
|
264
|
-
|
265
|
-
Product.hydra_set_attribute_ids_by_backend_type(1)
|
266
|
-
one.update_attributes(name: 'two')
|
267
|
-
Product.hydra_set_attribute_ids_by_backend_type(1)
|
268
|
-
end
|
269
|
-
|
270
|
-
it 'should reset method cache after removing hydra attribute' do
|
271
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
272
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_ids_by_backend_type).twice
|
273
|
-
|
274
|
-
Product.hydra_set_attribute_ids_by_backend_type(1)
|
275
|
-
one.destroy
|
276
|
-
Product.hydra_set_attribute_ids_by_backend_type(1)
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
describe '.hydra_set_attribute_names_by_backend_type' do
|
281
|
-
describe 'create attributes' do
|
282
|
-
let!(:hydra_set) { Product.hydra_sets.create(name: 'Default') }
|
283
|
-
let!(:hydra_attr1) { hydra_set.hydra_attributes.create(name: 'a1', backend_type: 'string') }
|
284
|
-
let!(:hydra_attr2) { hydra_set.hydra_attributes.create(name: 'a2', backend_type: 'string') }
|
285
|
-
let!(:hydra_attr3) { hydra_set.hydra_attributes.create(name: 'a3', backend_type: 'integer') }
|
286
|
-
let!(:hydra_attr4) { Product.hydra_attributes.create(name: 'a4', backend_type: 'string') }
|
287
|
-
|
288
|
-
it 'should return hydra attribute names for hydra set grouped by backend type' do
|
289
|
-
hydra_attributes = Product.hydra_set_attribute_names_by_backend_type(hydra_set.id)
|
290
|
-
|
291
|
-
hydra_attributes['string'].should =~ [hydra_attr1.name, hydra_attr2.name]
|
292
|
-
hydra_attributes['integer'].should == [hydra_attr3.name]
|
293
|
-
end
|
294
|
-
|
295
|
-
it 'should return all hydra attribute names grouped by backend type if hydra set does not exist' do
|
296
|
-
hydra_attributes = Product.hydra_set_attribute_names_by_backend_type(0)
|
297
|
-
|
298
|
-
hydra_attributes['string'].should =~ [hydra_attr1.name, hydra_attr2.name, hydra_attr4.name]
|
299
|
-
hydra_attributes['integer'].should == [hydra_attr3.name]
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
it 'should cache result' do
|
304
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_names_by_backend_type).once
|
305
|
-
2.times { Product.hydra_set_attribute_names_by_backend_type(1) }
|
306
|
-
end
|
307
|
-
|
308
|
-
it 'should reset method cache after creating hydra attribute' do
|
309
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_names_by_backend_type).twice
|
310
|
-
|
311
|
-
Product.hydra_set_attribute_names_by_backend_type(1)
|
312
|
-
Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
313
|
-
Product.hydra_set_attribute_names_by_backend_type(1)
|
314
|
-
end
|
315
|
-
|
316
|
-
it 'should reset method cache after updating hydra attribute' do
|
317
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
318
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_names_by_backend_type).twice
|
319
|
-
|
320
|
-
Product.hydra_set_attribute_names_by_backend_type(1)
|
321
|
-
one.update_attributes(name: 'two')
|
322
|
-
Product.hydra_set_attribute_names_by_backend_type(1)
|
323
|
-
end
|
324
|
-
|
325
|
-
it 'should reset method cache after removing hydra attribute' do
|
326
|
-
one = Product.hydra_attributes.create(name: 'one', backend_type: 'string')
|
327
|
-
Product.should_receive(:unmemoized_hydra_set_attribute_names_by_backend_type).twice
|
328
|
-
|
329
|
-
Product.hydra_set_attribute_names_by_backend_type(1)
|
330
|
-
one.destroy
|
331
|
-
Product.hydra_set_attribute_names_by_backend_type(1)
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
describe '.hydra_set_attributes_for_backend_type' do
|
336
|
-
let!(:hydra_set) { Product.hydra_sets.create(name: 'Default') }
|
337
|
-
let!(:hydra_attr1) { hydra_set.hydra_attributes.create(name: 'a1', backend_type: 'string') }
|
338
|
-
let!(:hydra_attr2) { hydra_set.hydra_attributes.create(name: 'a2', backend_type: 'string') }
|
339
|
-
let!(:hydra_attr3) { hydra_set.hydra_attributes.create(name: 'a3', backend_type: 'integer') }
|
340
|
-
let!(:hydra_attr4) { Product.hydra_attributes.create(name: 'a4', backend_type: 'integer') }
|
341
|
-
|
342
|
-
describe 'hydra set exists' do
|
343
|
-
it 'should return hydra attributes for specific hydra set and backend type' do
|
344
|
-
Product.hydra_set_attributes_for_backend_type(hydra_set.id, 'string').should =~ [hydra_attr1, hydra_attr2]
|
345
|
-
Product.hydra_set_attributes_for_backend_type(hydra_set.id, 'integer').should == [hydra_attr3]
|
346
|
-
end
|
347
|
-
|
348
|
-
it 'should return blank array if there are not any hydra attributes' do
|
349
|
-
Product.hydra_set_attributes_for_backend_type(hydra_set.id, 'text').should == []
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
describe 'hydra set does not exist' do
|
354
|
-
it 'should return all hydra attributes for specific backend type' do
|
355
|
-
Product.hydra_set_attributes_for_backend_type(0, 'string').should =~ [hydra_attr1, hydra_attr2]
|
356
|
-
Product.hydra_set_attributes_for_backend_type(0, 'integer').should =~ [hydra_attr3, hydra_attr4]
|
357
|
-
end
|
358
|
-
|
359
|
-
it 'should return blank array if there are not any hydra attributes' do
|
360
|
-
Product.hydra_set_attributes_for_backend_type(0, 'text').should == []
|
361
|
-
end
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
describe '.hydra_set_attribute_ids_for_backend_type' do
|
366
|
-
let!(:hydra_set) { Product.hydra_sets.create(name: 'Default') }
|
367
|
-
let!(:hydra_attr1) { hydra_set.hydra_attributes.create(name: 'a1', backend_type: 'string') }
|
368
|
-
let!(:hydra_attr2) { hydra_set.hydra_attributes.create(name: 'a2', backend_type: 'string') }
|
369
|
-
let!(:hydra_attr3) { hydra_set.hydra_attributes.create(name: 'a3', backend_type: 'integer') }
|
370
|
-
let!(:hydra_attr4) { Product.hydra_attributes.create(name: 'a4', backend_type: 'integer') }
|
371
|
-
|
372
|
-
describe 'hydra set exists' do
|
373
|
-
it 'should return hydra attribute ids for specific hydra set and backend type' do
|
374
|
-
Product.hydra_set_attribute_ids_for_backend_type(hydra_set.id, 'string').should =~ [hydra_attr1.id, hydra_attr2.id]
|
375
|
-
Product.hydra_set_attribute_ids_for_backend_type(hydra_set.id, 'integer').should == [hydra_attr3.id]
|
376
|
-
end
|
377
|
-
|
378
|
-
it 'should return blank array if there are not any hydra attributes' do
|
379
|
-
Product.hydra_set_attribute_ids_for_backend_type(hydra_set.id, 'text').should == []
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
describe 'hydra set does not exist' do
|
384
|
-
it 'should return all hydra attribute ids for specific backend type' do
|
385
|
-
Product.hydra_set_attribute_ids_for_backend_type(0, 'string').should =~ [hydra_attr1.id, hydra_attr2.id]
|
386
|
-
Product.hydra_set_attribute_ids_for_backend_type(0, 'integer').should =~ [hydra_attr3.id, hydra_attr4.id]
|
387
|
-
end
|
388
|
-
|
389
|
-
it 'should return blank array if there are not any hydra attributes' do
|
390
|
-
Product.hydra_set_attributes_for_backend_type(0, 'text').should == []
|
391
|
-
end
|
392
|
-
end
|
393
|
-
end
|
394
|
-
|
395
|
-
describe '.hydra_set_attribute_names_for_backend_type' do
|
396
|
-
let!(:hydra_set) { Product.hydra_sets.create(name: 'Default') }
|
397
|
-
let!(:hydra_attr1) { hydra_set.hydra_attributes.create(name: 'a1', backend_type: 'string') }
|
398
|
-
let!(:hydra_attr2) { hydra_set.hydra_attributes.create(name: 'a2', backend_type: 'string') }
|
399
|
-
let!(:hydra_attr3) { hydra_set.hydra_attributes.create(name: 'a3', backend_type: 'integer') }
|
400
|
-
let!(:hydra_attr4) { Product.hydra_attributes.create(name: 'a4', backend_type: 'integer') }
|
401
|
-
|
402
|
-
describe 'hydra set exists' do
|
403
|
-
it 'should return hydra attribute names for specific hydra set and backend type' do
|
404
|
-
Product.hydra_set_attribute_names_for_backend_type(hydra_set.id, 'string').should =~ [hydra_attr1.name, hydra_attr2.name]
|
405
|
-
Product.hydra_set_attribute_names_for_backend_type(hydra_set.id, 'integer').should == [hydra_attr3.name]
|
406
|
-
end
|
407
|
-
|
408
|
-
it 'should return blank array if there are not any hydra attributes' do
|
409
|
-
Product.hydra_set_attribute_names_for_backend_type(hydra_set.id, 'text').should == []
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
|
-
describe 'hydra set does not exist' do
|
414
|
-
it 'should return all hydra attribute names for specific backend type' do
|
415
|
-
Product.hydra_set_attribute_names_for_backend_type(0, 'string').should =~ [hydra_attr1.name, hydra_attr2.name]
|
416
|
-
Product.hydra_set_attribute_names_for_backend_type(0, 'integer').should =~ [hydra_attr3.name, hydra_attr4.name]
|
417
|
-
end
|
418
|
-
|
419
|
-
it 'should return blank array if there are not any hydra attributes' do
|
420
|
-
Product.hydra_set_attribute_names_for_backend_type(0, 'text').should == []
|
421
|
-
end
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
describe '.clear_hydra_methods!' do
|
426
|
-
it 'should reset cache for all methods' do
|
427
|
-
Product.should_receive(:clear_hydra_attribute_cache!)
|
428
|
-
Product.should_receive(:clear_hydra_set_cache!)
|
429
|
-
Product.should_receive(:clear_hydra_value_cache!)
|
430
|
-
|
431
|
-
[
|
432
|
-
:unmemoized_hydra_set_attribute_ids,
|
433
|
-
:unmemoized_hydra_set_attribute_names,
|
434
|
-
:unmemoized_hydra_set_attribute_backend_types,
|
435
|
-
:unmemoized_hydra_set_attributes_by_backend_type,
|
436
|
-
:unmemoized_hydra_set_attribute_ids_by_backend_type,
|
437
|
-
:unmemoized_hydra_set_attribute_names_by_backend_type
|
438
|
-
].each do |symbol|
|
439
|
-
Product.should_receive(symbol).twice.and_return([])
|
440
|
-
end
|
441
|
-
|
442
|
-
block = lambda do
|
443
|
-
Product.hydra_set_attribute_ids(1)
|
444
|
-
Product.hydra_set_attribute_names(1)
|
445
|
-
Product.hydra_set_attribute_backend_types(1)
|
446
|
-
Product.hydra_set_attributes_by_backend_type(1)
|
447
|
-
Product.hydra_set_attribute_ids_by_backend_type(1)
|
448
|
-
Product.hydra_set_attribute_names_by_backend_type(1)
|
449
|
-
end
|
450
|
-
|
451
|
-
block.call
|
452
|
-
Product.clear_hydra_method_cache!
|
453
|
-
block.call
|
454
|
-
end
|
455
|
-
end
|
456
|
-
end
|