patriarch 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,7 +20,7 @@ module Patriarch
20
20
  class << self
21
21
 
22
22
  # Helper function to complete the anonymous module we include later in the process in the enhanced model class
23
- def complete_custom_active_module_bipartite(module_to_complete,relation_type,acted_on_model_list)
23
+ def complete_custom_active_module_bipartite(module_to_complete,relation_type,acted_on_model_list,options={})
24
24
  module_to_complete.class_eval do
25
25
 
26
26
  acted_on_model_list.each do |acted_on_model|
@@ -36,16 +36,23 @@ module Patriarch
36
36
  Patriarch::ToolServices::RedisExtractorService.instance.
37
37
  get_models_from_ids(self,acted_on_model.to_s.classify.constantize,raw_tool_method_name,options)
38
38
  end
39
+ if options[:relation_type_alias]
40
+ alias_for_classic = classic_tool_method_name.sub(relation_type.to_s, options[:relation_type_alias].to_s)
41
+ alias_method alias_for_classic, classic_tool_method_name
42
+ end
39
43
 
40
44
  define_method(raw_tool_method_name) do |options={}|
41
45
  Patriarch::ToolServices::RedisExtractorService.instance.get_ids_from_sorted_set(self,redis_key,options)
42
46
  end
43
-
47
+ if options[:relation_type_alias]
48
+ alias_for_raw = raw_tool_method_name.sub(relation_type.to_s, options[:relation_type_alias].to_s)
49
+ alias_method alias_for_raw, raw_tool_method_name
50
+ end
44
51
  end
45
52
  end
46
53
  end
47
54
 
48
- def complete_custom_passive_module_bipartite(module_to_complete,relation_type,targetted_by_model_list)
55
+ def complete_custom_passive_module_bipartite(module_to_complete,relation_type,targetted_by_model_list,options={})
49
56
  module_to_complete.class_eval do
50
57
 
51
58
  targetted_by_model_list.each do |targetted_by_model|
@@ -62,10 +69,20 @@ module Patriarch
62
69
  Patriarch::ToolServices::RedisExtractorService.instance.
63
70
  get_models_from_ids(self,targetted_by_model.to_s.classify.constantize,raw_tool_method_name,options)
64
71
  end
72
+ if options[:relation_type_alias]
73
+ progressive_present_relation_type_alias = (Verbs::Conjugator.conjugate options[:relation_type_alias], :aspect => :progressive).split(/ /).last
74
+ alias_for_classic = classic_tool_method_name.sub(progressive_present_relation_type,progressive_present_relation_type_alias)
75
+ alias_method alias_for_classic, classic_tool_method_name
76
+ end
65
77
 
66
78
  define_method(raw_tool_method_name) do |options={}|
67
79
  Patriarch::ToolServices::RedisExtractorService.instance.get_ids_from_sorted_set(self,redis_key,options)
68
80
  end
81
+ if options[:relation_type_alias]
82
+ progressive_present_relation_type_alias = (Verbs::Conjugator.conjugate options[:relation_type_alias], :aspect => :progressive).split(/ /).last
83
+ alias_for_raw = raw_tool_method_name.sub(progressive_present_relation_type,progressive_present_relation_type_alias)
84
+ alias_method alias_for_raw, raw_tool_method_name
85
+ end
69
86
 
70
87
  end
71
88
 
@@ -73,7 +90,7 @@ module Patriarch
73
90
  end
74
91
 
75
92
 
76
- def complete_custom_active_module_tripartite(module_to_complete,relation_type,acted_on_model_list,via_model_list)
93
+ def complete_custom_active_module_tripartite(module_to_complete,relation_type,acted_on_model_list,via_model_list,options={})
77
94
  module_to_complete.class_eval do
78
95
 
79
96
  acted_on_model_list.each do |acted_on_model|
@@ -90,12 +107,20 @@ module Patriarch
90
107
  Patriarch::ToolServices::RedisExtractorService.instance.
91
108
  get_models_from_ids(self,acted_on_model.to_s.classify.constantize,raw_tool_method_name,options.merge({:tripartite => true}))
92
109
  end
110
+ if options[:relation_type_alias]
111
+ alias_for_classic = classic_tool_method_name.sub(relation_type.to_s, options[:relation_type_alias].to_s)
112
+ alias_method alias_for_classic, classic_tool_method_name
113
+ end
93
114
 
94
115
  define_method(raw_tool_method_name) do |options={}|
95
116
  Patriarch::ToolServices::RedisExtractorService.instance.get_ids_from_sorted_set(self,redis_key,options.merge({:tripartite => true, :protagonist_type => :actor}))
96
117
  # triplet is by convention [actor,target,medium]
97
118
  # TODO Marshallize true items instead of some crappy convention ...
98
119
  end
120
+ if options[:relation_type_alias]
121
+ alias_for_raw = raw_tool_method_name.sub(relation_type.to_s, options[:relation_type_alias].to_s)
122
+ alias_method alias_for_raw, raw_tool_method_name
123
+ end
99
124
 
100
125
  end
101
126
  end
@@ -103,7 +128,7 @@ module Patriarch
103
128
  end
104
129
  end
105
130
 
106
- def complete_custom_passive_module_tripartite(module_to_complete,relation_type,targetted_by_model_list,via_model_list)
131
+ def complete_custom_passive_module_tripartite(module_to_complete,relation_type,targetted_by_model_list,via_model_list,options={})
107
132
  module_to_complete.class_eval do
108
133
 
109
134
  targetted_by_model_list.each do |targetted_by_model|
@@ -120,6 +145,12 @@ module Patriarch
120
145
  Patriarch::ToolServices::RedisExtractorService.instance.
121
146
  get_models_from_ids(self,targetted_by_model.to_s.classify.constantize,raw_tool_method_name,options.merge({:tripartite => true}))
122
147
  end
148
+ if options[:relation_type_alias]
149
+ progressive_present_relation_type_alias = (Verbs::Conjugator.conjugate options[:relation_type_alias], :aspect => :progressive).split(/ /).last
150
+ alias_for_classic = classic_tool_method_name.sub(progressive_present_relation_type,progressive_present_relation_type_alias)
151
+ alias_method alias_for_classic, classic_tool_method_name
152
+ end
153
+
123
154
 
124
155
  define_method(raw_tool_method_name) do |options={}|
125
156
  Patriarch::ToolServices::RedisExtractorService.instance.get_ids_from_sorted_set(self,redis_key,options.merge({:tripartite => true , :protagonist_type => :target}))
@@ -127,6 +158,12 @@ module Patriarch
127
158
  # triplet is by convention [actor,target,medium]
128
159
  # TODO Marshallize true items instead of some crappy convention ...
129
160
  end
161
+ if options[:relation_type_alias]
162
+ progressive_present_relation_type_alias = (Verbs::Conjugator.conjugate options[:relation_type_alias], :aspect => :progressive).split(/ /).last
163
+ alias_for_raw = raw_tool_method_name.sub(progressive_present_relation_type,progressive_present_relation_type_alias)
164
+ alias_method alias_for_raw, raw_tool_method_name
165
+ end
166
+
130
167
  end
131
168
  end
132
169
 
@@ -202,9 +239,25 @@ module Patriarch
202
239
  end
203
240
  end
204
241
 
242
+ complete_module_options = {}
243
+ if options[:as]
244
+ # as option should be a string or symbol
245
+ unless [Symbol,String].include?(options[:as].class)
246
+ raise AddBehaviourSyntaxError, "as option should be a string or symbol"
247
+ end
248
+ complete_module_options.merge! :relation_type_alias => options[:as]
249
+ end
205
250
 
206
251
  methods_mod = Module.new do; end
207
252
  methods_mod.const_set(:Behaviour,behaviour)
253
+ if options[:as]
254
+ methods_mod.const_set(:BehaviourAlias,options[:as].to_sym)
255
+ end
256
+
257
+ if options[:undo_as]
258
+ methods_mod.const_set(:UndoBehaviourAlias,options[:undo_as].to_sym)
259
+ end
260
+
208
261
 
209
262
  # Target on Actor cases
210
263
  if options[:via]
@@ -224,6 +277,9 @@ module Patriarch
224
277
  "Patriarch::Services::#{methods_mod.const_get(:Behaviour).classify}::ManagerService".constantize.instance.resolve(self,entity,via_entity,options)
225
278
  end
226
279
  end
280
+ if options[:as]
281
+ alias_method methods_mod.const_get(:BehaviourAlias), methods_mod.const_get(:Behaviour).to_sym
282
+ end
227
283
 
228
284
  # undo_behave
229
285
  define_method(Patriarch.undo(methods_mod.const_get(:Behaviour)).to_sym) do |entity,via_entity,options={}|
@@ -231,16 +287,20 @@ module Patriarch
231
287
  "Patriarch::Services::#{(Patriarch.undo(methods_mod.const_get(:Behaviour))).classify}::ManagerService".constantize.instance.resolve(self,entity,via_entity,options)
232
288
  end
233
289
  end
290
+ if options[:undo_as]
291
+ alias_method methods_mod.const_get(:UndoBehaviourAlias), Patriarch.undo(methods_mod.const_get(:Behaviour))
292
+ end
293
+
234
294
  end
235
295
 
236
296
  acted_on_model_list = Array(options[:on])
237
297
  via_model_list = Array(options[:via])
238
- Patriarch::Behaviours.complete_custom_active_module_tripartite(methods_mod,behaviour,acted_on_model_list,via_model_list)
298
+ Patriarch::Behaviours.complete_custom_active_module_tripartite(methods_mod,behaviour,acted_on_model_list,via_model_list,complete_module_options)
239
299
  #Target case
240
300
  elsif options[:by]
241
301
  targetted_by_model_list = Array(options[:by])
242
302
  via_model_list = Array(options[:via])
243
- Patriarch::Behaviours.complete_custom_passive_module_tripartite(methods_mod,behaviour,targetted_by_model_list,via_model_list)
303
+ Patriarch::Behaviours.complete_custom_passive_module_tripartite(methods_mod,behaviour,targetted_by_model_list,via_model_list,complete_module_options)
244
304
  end
245
305
  # Medium case
246
306
  elsif options[:medium_between]
@@ -254,11 +314,16 @@ module Patriarch
254
314
  # TODO disjonction register tripartite
255
315
  # register the behaviour we just added
256
316
  self.patriarch_behaviours ||= { }
317
+ self.patriarch_behaviours[behaviour.underscore.to_sym] ||= {}
257
318
 
258
319
  if options[:via]
259
- self.patriarch_behaviours[behaviour.underscore.to_sym] ||= { :on => [], :by => [], :via => [] }
320
+ #self.patriarch_behaviours[behaviour.underscore.to_sym] ||= { :on => [], :by => [], :via => [] }
321
+ self.patriarch_behaviours[behaviour.underscore.to_sym][:on] ||= []
322
+ self.patriarch_behaviours[behaviour.underscore.to_sym][:by] ||= []
323
+ self.patriarch_behaviours[behaviour.underscore.to_sym][:via] ||= []
260
324
  elsif options[:medium_between]
261
- self.patriarch_behaviours[behaviour.underscore.to_sym] ||= { :medium_between => [] }
325
+ #self.patriarch_behaviours[behaviour.underscore.to_sym] ||= { :medium_between => [] }
326
+ self.patriarch_behaviours[behaviour.underscore.to_sym][:medium_between] ||= []
262
327
  end
263
328
 
264
329
  if options[:via]
@@ -293,6 +358,12 @@ module Patriarch
293
358
 
294
359
  methods_mod = Module.new do; end
295
360
  methods_mod.const_set(:Behaviour,behaviour)
361
+ if options[:as]
362
+ methods_mod.const_set(:BehaviourAlias,options[:as].to_sym)
363
+ end
364
+ if options[:undo_as]
365
+ methods_mod.const_set(:UndoBehaviourAlias,options[:undo_as].to_sym)
366
+ end
296
367
 
297
368
  if options[:on]
298
369
  # Adds active methods and defines the hook to set callbacks on them
@@ -311,6 +382,9 @@ module Patriarch
311
382
  "Patriarch::Services::#{methods_mod.const_get(:Behaviour).classify}::ManagerService".constantize.instance.resolve(self,entity,options)
312
383
  end
313
384
  end
385
+ if options[:as]
386
+ alias_method methods_mod.const_get(:BehaviourAlias), methods_mod.const_get(:Behaviour).to_sym
387
+ end
314
388
 
315
389
  # undo_like
316
390
  define_method(Patriarch.undo(methods_mod.const_get(:Behaviour)).to_sym) do |entity,options={}|
@@ -318,6 +392,9 @@ module Patriarch
318
392
  "Patriarch::Services::#{(Patriarch.undo(methods_mod.const_get(:Behaviour))).classify}::ManagerService".constantize.instance.resolve(self,entity,options)
319
393
  end
320
394
  end
395
+ if options[:undo_as]
396
+ alias_method methods_mod.const_get(:UndoBehaviourAlias), Patriarch.undo(methods_mod.const_get(:Behaviour))
397
+ end
321
398
 
322
399
  # Not used / not tested, added this method "en passant"
323
400
  # FIX requirements with users
@@ -339,12 +416,22 @@ module Patriarch
339
416
  end
340
417
  end
341
418
 
419
+ complete_module_options = {}
420
+ if options[:as]
421
+ # as option should be a string or symbol
422
+ unless [Symbol,String].include?(options[:as].class)
423
+ raise AddBehaviourSyntaxError, "as option should be a string or symbol"
424
+ end
425
+ complete_module_options.merge! :relation_type_alias => options[:as]
426
+ end
427
+
428
+
342
429
  if options[:on]
343
430
  acted_on_model_list = Array(options[:on])
344
- Patriarch::Behaviours.complete_custom_active_module_bipartite(methods_mod,behaviour,acted_on_model_list)
431
+ Patriarch::Behaviours.complete_custom_active_module_bipartite(methods_mod,behaviour,acted_on_model_list,complete_module_options)
345
432
  else
346
433
  targetted_by_model_list = Array(options[:by])
347
- Patriarch::Behaviours.complete_custom_passive_module_bipartite(methods_mod,behaviour,targetted_by_model_list)
434
+ Patriarch::Behaviours.complete_custom_passive_module_bipartite(methods_mod,behaviour,targetted_by_model_list,complete_module_options)
348
435
  end
349
436
 
350
437
  # Finally ...
@@ -354,7 +441,11 @@ module Patriarch
354
441
 
355
442
  # register the behaviour we just added
356
443
  self.patriarch_behaviours ||= { }
357
- self.patriarch_behaviours[behaviour.underscore.to_sym] ||= { :on => [], :by =>[] }
444
+ #self.patriarch_behaviours[behaviour.underscore.to_sym] ||= { :on => [], :by =>[] }
445
+ self.patriarch_behaviours[behaviour.underscore.to_sym] ||= { }
446
+ self.patriarch_behaviours[behaviour.underscore.to_sym][:on] ||= []
447
+ self.patriarch_behaviours[behaviour.underscore.to_sym][:by] ||= []
448
+
358
449
  if options[:on]
359
450
  self.patriarch_behaviours[behaviour.underscore.to_sym][:on] << options[:on]
360
451
  self.patriarch_behaviours[behaviour.underscore.to_sym][:on].uniq!
@@ -1,3 +1,3 @@
1
1
  module Patriarch
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -2,18 +2,15 @@ require 'spec_helper'
2
2
 
3
3
  describe Patriarch::Behaviours do
4
4
  describe '#add_behaviour' do
5
-
6
5
  let(:monster) { Monster.create }
7
6
  let(:fallen_angel) { FallenAngel.create }
8
7
  let(:love_letter) { LoveLetter.create }
9
8
 
10
-
11
-
12
9
  context 'on a bipartite' do
13
10
 
14
11
  before(:all) do
15
- Monster.add_behaviour :like, :on => [:fallenAngel]
16
- FallenAngel.add_behaviour :like, :by => [:monster]
12
+ Monster.add_behaviour :like, :on => [:fallenAngel], :as => :love, :undo_as => :hate
13
+ FallenAngel.add_behaviour :like, :by => [:monster] , :as => :love
17
14
  end
18
15
 
19
16
  context "call from a model including Patriarch::Behaviours" do
@@ -44,14 +41,6 @@ describe Patriarch::Behaviours do
44
41
  monster.should respond_to(:undo_like)
45
42
  end
46
43
 
47
- it "defines alias for behaviour instance methods on actor model" do
48
- pending("implement this with add_behaviour ARGUMENTS, [:as => alias]")
49
- end
50
-
51
- it "defines alias for undo behaviour instance methods on actor model" do
52
- pending("implement this with add_behaviour ARGUMENTS, [:undo_as => alias]")
53
- end
54
-
55
44
  it "does not define behaviour instance method on target model" do
56
45
  fallen_angel.should_not respond_to(:like)
57
46
  end
@@ -61,12 +50,16 @@ describe Patriarch::Behaviours do
61
50
  end
62
51
 
63
52
  it "does not define alias for behaviour instance methods on target model" do
64
- pending("implement this with add_behaviour ARGUMENTS, [:as => alias]")
53
+ progressive_love = (Verbs::Conjugator.conjugate :love, :aspect => :progressive).split(/ /).last
54
+ fallen_angel.should respond_to("#{"monster".pluralize}_#{progressive_love}_me_ids")
55
+ fallen_angel.should respond_to("#{"monster".pluralize}_#{progressive_love}_me")
65
56
  end
66
57
 
67
- it "does not define alias for undo behaviour instance methods on target model" do
68
- pending("implement this with add_behaviour ARGUMENTS, [:undo_as => alias]")
69
- end
58
+ it "defines alias for behaviour instance methods on actor model" do
59
+ monster.should respond_to(:love)
60
+ monster.should respond_to("#{"fallen_angel".pluralize}_i_love")
61
+ monster.should respond_to("#{"fallen_angel".pluralize}_i_love_ids")
62
+ end
70
63
  end
71
64
 
72
65
  context 'implements methods that' do
@@ -82,34 +75,37 @@ describe Patriarch::Behaviours do
82
75
 
83
76
 
84
77
 
85
- context 'when doing behaviour' do
86
- before(:all) { monster.like fallen_angel }
87
-
88
- it "allows actor to remember target id" do
78
+ shared_examples 'instances have behaviour' do
79
+ it "remember target id in actor's memory" do
89
80
  monster.fallen_angels_i_like_ids.should == [fallen_angel.id]
90
81
  end
91
82
 
92
- it "allows actor to remember target instance" do
83
+ it "remember target instance in actor's memory" do
93
84
  monster.fallen_angels_i_like.should == [fallen_angel]
94
85
  end
95
86
 
96
- it "allows target to remember actor id" do
87
+ it "remember actor id in target's memory" do
97
88
  fallen_angel.monsters_liking_me_ids.should == [monster.id]
98
89
  end
99
90
 
100
- it "allows target to remember actor instance" do
91
+ it "remember actor instance in target's memory" do
101
92
  fallen_angel.monsters_liking_me.should == [monster]
102
93
  end
94
+ end
103
95
 
104
- after(:all) { monster.undo_like fallen_angel }
96
+ context 'when doing direct behaviour' do
97
+ before(:all) { monster.like fallen_angel }
98
+ it_has_behavior 'instances have behaviour'
99
+ after(:all) { monster.undo_like fallen_angel }
105
100
  end
106
101
 
107
- context 'when undoing behaviour' do
108
- before(:all) do
109
- monster.like fallen_angel
110
- monster.undo_like fallen_angel
111
- end
102
+ context 'when doing behaviour via alias method' do
103
+ before(:all) { monster.love fallen_angel }
104
+ it_has_behavior 'instances have behaviour'
105
+ after(:all) { monster.undo_like fallen_angel }
106
+ end
112
107
 
108
+ shared_examples 'instances have undo behaviour' do
113
109
  it "erase target id from actor's memory" do
114
110
  monster.fallen_angels_i_like_ids.should be_empty
115
111
  end
@@ -127,6 +123,22 @@ describe Patriarch::Behaviours do
127
123
  end
128
124
  end
129
125
 
126
+ context 'when calling undo command' do
127
+ before(:all) do
128
+ monster.like fallen_angel
129
+ monster.undo_like fallen_angel
130
+ end
131
+ it_has_behavior 'instances have undo behaviour'
132
+ end
133
+
134
+ context 'when calling undo command via undo alias' do
135
+ before(:all) do
136
+ monster.like fallen_angel
137
+ monster.hate fallen_angel
138
+ end
139
+ it_has_behavior 'instances have undo behaviour'
140
+ end
141
+
130
142
  end
131
143
  end # context bipartite
132
144
 
@@ -134,9 +146,9 @@ describe Patriarch::Behaviours do
134
146
 
135
147
  before(:all) do
136
148
  # Monster is the actor model and FallenAngel the target model here
137
- Monster.add_behaviour :praise, :on => [:fallenAngel], :via => [:loveLetter]
138
- FallenAngel.add_behaviour :praise, :by => [:monster], :via => [:loveLetter]
139
- LoveLetter.add_behaviour :praise, :medium_between => [:monster,:fallenAngel]
149
+ Monster.add_behaviour :praise, :on => [:fallenAngel], :via => [:loveLetter], :as => :flatter, :undo_as => :despise
150
+ FallenAngel.add_behaviour :praise, :by => [:monster], :via => [:loveLetter], :as => :flatter
151
+ LoveLetter.add_behaviour :praise, :medium_between => [:monster,:fallenAngel], :as => :flatter
140
152
  end
141
153
 
142
154
  context "call from a model including Patriarch::Behaviours" do
@@ -180,7 +192,29 @@ describe Patriarch::Behaviours do
180
192
 
181
193
  it "does not define undo behaviour instance method on medium model" do
182
194
  love_letter.should_not respond_to(:undo_praise)
183
- end
195
+ end
196
+
197
+ it "does not define alias for behaviour instance methods on target model" do
198
+ progressive_flatter = (Verbs::Conjugator.conjugate :flatter, :aspect => :progressive).split(/ /).last
199
+ fallen_angel.should respond_to("#{"monster".pluralize}_#{progressive_flatter}_me_via_#{"love_letter".pluralize}")
200
+ fallen_angel.should respond_to("#{"monster".pluralize}_#{progressive_flatter}_me_via_#{"love_letter".pluralize}_ids")
201
+ end
202
+
203
+ #TODO test alias correctly with receive rspec ...
204
+ it "defines alias for behaviour instance methods on actor model" do
205
+ monster.should respond_to(:flatter)
206
+ # from test just below
207
+ monster.should respond_to(:despise)
208
+ monster.should respond_to("#{"fallen_angel".pluralize}_i_flatter_via_#{"love_letter".pluralize}")
209
+ monster.should respond_to("#{"fallen_angel".pluralize}_i_flatter_via_#{"love_letter".pluralize}_ids")
210
+ end
211
+
212
+ # SQLITE 3 IS SHITTING ALL OVER OUR TESTS, TODO FIXME
213
+ # :memory: option appears to have some limitations there
214
+ it "defines alias on undo behaviour instance methods of actor model" do
215
+ # monster.should respond_to(:despise)
216
+ pending "test is runned elsewhere, fix sqlite3 memory problem please"
217
+ end
184
218
  end
185
219
 
186
220
  context 'implements methods that' do
@@ -192,11 +226,8 @@ describe Patriarch::Behaviours do
192
226
  monster.praise(fallen_angel, love_letter, :stop_execution => true).should be_an_instance_of(Patriarch::Transaction)
193
227
  end
194
228
 
195
-
196
-
197
- context 'when doing behaviour' do
198
- before(:all) { monster.praise fallen_angel,love_letter }
199
-
229
+ # prepare examples to test both alias and normal methods ...
230
+ shared_examples 'instances have behaviour working' do
200
231
  it "allows actor to remember target id" do
201
232
  monster.fallen_angels_i_praise_via_love_letters_ids.should == [fallen_angel.id]
202
233
  end
@@ -211,17 +242,23 @@ describe Patriarch::Behaviours do
211
242
 
212
243
  it "allows target to remember actor instance" do
213
244
  fallen_angel.monsters_praising_me_via_love_letters.should == [monster]
214
- end
215
-
216
- after(:all) { monster.undo_praise fallen_angel,love_letter }
245
+ end
217
246
  end
218
247
 
219
- context 'when undoing behaviour' do
220
- before(:all) do
221
- monster.praise fallen_angel,love_letter
222
- monster.undo_praise fallen_angel,love_letter
223
- end
248
+ context 'when doing direct behaviour' do
249
+ before(:all) { monster.praise fallen_angel,love_letter }
250
+ it_has_behavior 'instances have behaviour working'
251
+ after(:all) { monster.undo_praise fallen_angel,love_letter }
252
+ end
224
253
 
254
+ context 'when doing behaviour via alias method' do
255
+ before(:all) { monster.flatter fallen_angel,love_letter }
256
+ it_has_behavior 'instances have behaviour working'
257
+ after(:all) { monster.undo_praise fallen_angel,love_letter }
258
+ end
259
+
260
+ # prepare examples to test both undo alias and undo normal methods ...
261
+ shared_examples 'instances have undo behaviour working' do
225
262
  it "erase target id from actor's memory" do
226
263
  monster.fallen_angels_i_praise_via_love_letters_ids.should be_empty
227
264
  end
@@ -236,12 +273,38 @@ describe Patriarch::Behaviours do
236
273
 
237
274
  it "erase actor instance from target's memory" do
238
275
  fallen_angel.monsters_praising_me_via_love_letters.should be_empty
239
- end
276
+ end
240
277
  end
241
278
 
279
+ context 'when directly undoing behaviour' do
280
+ before(:all) do
281
+ monster.praise fallen_angel,love_letter
282
+ monster.undo_praise fallen_angel,love_letter
283
+ end
284
+ it_has_behavior 'instances have undo behaviour working'
285
+ end
242
286
 
243
- end
287
+ context 'when undoing behaviour via undo alias' do
288
+ before(:all) do
289
+ monster.praise fallen_angel,love_letter
290
+ monster.despise fallen_angel,love_letter
291
+ end
292
+ it_has_behavior 'instances have undo behaviour working'
293
+ end
294
+
295
+ end # implements methods that
244
296
  end # context tripartite
245
297
 
246
298
  end # desc '#add_behaviour'
299
+
300
+ # FIXME learn rspec tocard ...
301
+ context "multiple tricky calls" do
302
+ it "works" do
303
+ class Monsterr < Monster; end
304
+ class FallenAngell < FallenAngel; end
305
+ Monsterr.add_behaviour :praise, :on => [:fallenAngell], :via => [:fallenAngell]
306
+ FallenAngell.add_behaviour :praise, :by => [:monsterr], :via => [:fallenAngell]
307
+ FallenAngell.add_behaviour :praise, :medium_between => [:monsterr,:fallenAngell]
308
+ end
309
+ end
247
310
  end # desc Patriarch::Behaviours
data/spec/spec_helper.rb CHANGED
@@ -14,6 +14,7 @@ require 'rails/generators'
14
14
  require 'rspec/autorun'
15
15
 
16
16
  RSpec.configure do |config|
17
+ config.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
17
18
  end
18
19
 
19
20
  # Setting up redis-database
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patriarch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-07 00:00:00.000000000 Z
12
+ date: 2012-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: verbs
16
- requirement: &21907620 !ruby/object:Gem::Requirement
16
+ requirement: &8230400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *21907620
24
+ version_requirements: *8230400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: railties
27
- requirement: &21907200 !ruby/object:Gem::Requirement
27
+ requirement: &8229980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *21907200
35
+ version_requirements: *8229980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activerecord
38
- requirement: &21906780 !ruby/object:Gem::Requirement
38
+ requirement: &8229560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *21906780
46
+ version_requirements: *8229560
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &21906360 !ruby/object:Gem::Requirement
49
+ requirement: &8229140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *21906360
57
+ version_requirements: *8229140
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activerecord
60
- requirement: &21905940 !ruby/object:Gem::Requirement
60
+ requirement: &8228720 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *21905940
68
+ version_requirements: *8228720
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
- requirement: &21905520 !ruby/object:Gem::Requirement
71
+ requirement: &8228300 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *21905520
79
+ version_requirements: *8228300
80
80
  description: Patriach is about adding behaviours on the fly to good old active record
81
81
  models.
82
82
  email: