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