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