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,203 +0,0 @@
|
|
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
|
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe HydraAttribute::Memoizable do
|
4
|
-
def anonymous(arity = 0)
|
5
|
-
params = (1..arity).map{ |i| "a#{i}" }.join(', ')
|
6
|
-
|
7
|
-
anonymous = Class.new do
|
8
|
-
extend HydraAttribute::Memoizable
|
9
|
-
|
10
|
-
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
11
|
-
def my_method(#{params})
|
12
|
-
result(#{params})
|
13
|
-
end
|
14
|
-
hydra_memoize :my_method
|
15
|
-
EOS
|
16
|
-
end
|
17
|
-
anonymous.new
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#memoize' do
|
21
|
-
it 'method without parameters' do
|
22
|
-
instance = anonymous
|
23
|
-
instance.should_receive(:result).once.and_return([1,2,3])
|
24
|
-
2.times { instance.my_method.should == [1,2,3] }
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'method without parameters which returns nil' do
|
28
|
-
instance = anonymous
|
29
|
-
instance.should_receive(:result).once.and_return(nil)
|
30
|
-
2.times { instance.my_method.should == nil }
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'method with one parameter' do
|
34
|
-
instance = anonymous(1)
|
35
|
-
instance.should_receive(:result).with(1).once.and_return([1,1,1])
|
36
|
-
instance.should_receive(:result).with(2).once.and_return([2,2,2])
|
37
|
-
|
38
|
-
2.times { instance.my_method(1).should == [1,1,1] }
|
39
|
-
2.times { instance.my_method(2).should == [2,2,2] }
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'method with one parameter which returns nil' do
|
43
|
-
instance = anonymous(1)
|
44
|
-
instance.should_receive(:result).with(1).once.and_return(nil)
|
45
|
-
instance.should_receive(:result).with(2).once.and_return(nil)
|
46
|
-
|
47
|
-
2.times { instance.my_method(1).should == nil }
|
48
|
-
2.times { instance.my_method(2).should == nil }
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'method with two parameters' do
|
52
|
-
instance = anonymous(2)
|
53
|
-
instance.should_receive(:result).with(1, 1).once.and_return([1,1,1])
|
54
|
-
instance.should_receive(:result).with(1, 2).once.and_return([1,1,2])
|
55
|
-
instance.should_receive(:result).with(2, 1).once.and_return([2,2,1])
|
56
|
-
|
57
|
-
2.times { instance.my_method(1, 1).should == [1,1,1] }
|
58
|
-
2.times { instance.my_method(1, 2).should == [1,1,2] }
|
59
|
-
2.times { instance.my_method(2, 1).should == [2,2,1] }
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'method with two parameters' do
|
63
|
-
instance = anonymous(2)
|
64
|
-
instance.should_receive(:result).with(1, 1).once.and_return(nil)
|
65
|
-
instance.should_receive(:result).with(1, 2).once.and_return(nil)
|
66
|
-
instance.should_receive(:result).with(2, 1).once.and_return(nil)
|
67
|
-
|
68
|
-
2.times { instance.my_method(1, 1).should == nil }
|
69
|
-
2.times { instance.my_method(1, 2).should == nil }
|
70
|
-
2.times { instance.my_method(2, 1).should == nil }
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'method with three parameters' do
|
74
|
-
instance = anonymous(3)
|
75
|
-
instance.should_receive(:result).with(1, 1, 2).once.and_return([1,1,2])
|
76
|
-
instance.should_receive(:result).with(1, 2, 2).once.and_return([1,2,2])
|
77
|
-
instance.should_receive(:result).with(2, 2, 1).once.and_return([2,2,1])
|
78
|
-
|
79
|
-
2.times { instance.my_method(1, 1, 2).should == [1,1,2] }
|
80
|
-
2.times { instance.my_method(1, 2, 2).should == [1,2,2] }
|
81
|
-
2.times { instance.my_method(2, 2, 1).should == [2,2,1] }
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'method with three parameters' do
|
85
|
-
instance = anonymous(3)
|
86
|
-
instance.should_receive(:result).with(1, 1, 2).once.and_return(nil)
|
87
|
-
instance.should_receive(:result).with(1, 2, 2).once.and_return(nil)
|
88
|
-
instance.should_receive(:result).with(2, 2, 1).once.and_return(nil)
|
89
|
-
|
90
|
-
2.times { instance.my_method(1, 1, 2).should == nil }
|
91
|
-
2.times { instance.my_method(1, 2, 2).should == nil }
|
92
|
-
2.times { instance.my_method(2, 2, 1).should == nil }
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|