shoulda-callback-matchers 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +9 -6
- data/Appraisals +9 -15
- data/README.md +9 -0
- data/gemfiles/rails_3.1.gemfile +15 -0
- data/gemfiles/rails_3.2.gemfile +15 -0
- data/gemfiles/rails_4.0.gemfile +15 -0
- data/gemfiles/rails_4.1.gemfile +15 -0
- data/lib/shoulda/callback/matchers/active_model.rb +39 -11
- data/lib/shoulda/callback/matchers/rails_version_helper.rb +6 -6
- data/lib/shoulda/callback/matchers/version.rb +1 -1
- data/spec/shoulda/active_model/callback_matcher_spec.rb +178 -4
- metadata +25 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89f6042a079fd2d5fef52ef390cf0c52dc28f3e1
|
4
|
+
data.tar.gz: da245bb62f6a4c956ac72708484821b09815a578
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ad1fb3263ea065b34ad6f0fefa000c6f5adddfcd17c2711f98830cd268e6858564515c529aa72d33e5ff9a0c8d6d36f74cebffa73ea51b1b5221f48c81a7efe
|
7
|
+
data.tar.gz: 14d5f259cf09bb0642ef5765a7b16712585e1f64452fc2166000828f3a927247a0aaa1058a65e5274c755dd32333fbc7e2efd1dd37e10fc2eceb9ecb8aace35d
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -2,15 +2,18 @@ rvm:
|
|
2
2
|
- 1.9.3
|
3
3
|
- 2.0.0
|
4
4
|
- 2.1.1
|
5
|
-
- rbx
|
5
|
+
- rbx-20mode
|
6
6
|
- jruby-19mode
|
7
|
-
- jruby-
|
7
|
+
- jruby-head
|
8
8
|
|
9
|
-
script: "bundle
|
9
|
+
script: "bundle exec rspec"
|
10
10
|
|
11
11
|
gemfile:
|
12
|
-
- gemfiles/
|
13
|
-
|
12
|
+
- gemfiles/rails_4.1.gemfile
|
13
|
+
- gemfiles/rails_4.0.gemfile
|
14
|
+
- gemfiles/rails_3.2.gemfile
|
15
|
+
- gemfiles/rails_3.1.gemfile
|
16
|
+
|
14
17
|
matrix:
|
15
18
|
allow_failures:
|
16
|
-
- rvm: rbx
|
19
|
+
- rvm: rbx-20mode
|
data/Appraisals
CHANGED
@@ -1,29 +1,23 @@
|
|
1
|
-
appraise '4.1' do
|
2
|
-
gem 'rails', '~>4.1'
|
1
|
+
appraise 'rails 4.1' do
|
2
|
+
gem 'rails', '~> 4.1.0'
|
3
3
|
gem 'jquery-rails'
|
4
|
-
gem 'sass-rails'
|
5
|
-
end
|
6
|
-
|
7
|
-
appraise '4.0' do
|
8
|
-
gem 'rails', '~>4.0'
|
9
|
-
gem 'jquery-rails'
|
10
|
-
gem 'sass-rails'
|
4
|
+
gem 'sass-rails', '~> 4.0'
|
11
5
|
end
|
12
6
|
|
13
|
-
appraise '
|
14
|
-
gem 'rails', '~>
|
7
|
+
appraise 'rails 4.0' do
|
8
|
+
gem 'rails', '~> 4.0.0'
|
15
9
|
gem 'jquery-rails'
|
16
10
|
gem 'sass-rails'
|
17
11
|
end
|
18
12
|
|
19
|
-
appraise '3.
|
20
|
-
gem 'rails', '~>3.2'
|
13
|
+
appraise 'rails 3.2' do
|
14
|
+
gem 'rails', '~> 3.2.0'
|
21
15
|
gem 'jquery-rails'
|
22
16
|
gem 'sass-rails'
|
23
17
|
end
|
24
18
|
|
25
|
-
appraise '3.
|
26
|
-
gem 'rails', '~>3.
|
19
|
+
appraise 'rails 3.1' do
|
20
|
+
gem 'rails', '~> 3.1.0'
|
27
21
|
gem 'jquery-rails'
|
28
22
|
gem 'sass-rails'
|
29
23
|
end
|
data/README.md
CHANGED
@@ -13,6 +13,11 @@ Method Callbacks:
|
|
13
13
|
it { should callback(:post_to_twitter).after(:create) }
|
14
14
|
it { should callback(:evaluate_if_should_validate).before(:validation) }
|
15
15
|
it { should callback(:add_some_convenience_accessors).after(:find) }
|
16
|
+
|
17
|
+
# with conditions
|
18
|
+
|
19
|
+
it { should callback(:assign_something).before(:create).if(:this_is_true) }
|
20
|
+
it { should callback(:destroy_something_else).before(:destroy).unless(:this_is_true) }
|
16
21
|
end
|
17
22
|
|
18
23
|
describe User do
|
@@ -46,6 +51,10 @@ Object Callbacks:
|
|
46
51
|
it { should callback(CallbackClass).after(:create) }
|
47
52
|
it { should callback(CallbackClass).before(:validation) }
|
48
53
|
it { should callback(CallbackClass).after(:find) }
|
54
|
+
|
55
|
+
# with conditions
|
56
|
+
it { should callback(CallbackClass).before(:create).if(:this_is_true) }
|
57
|
+
it { should callback(CallbackClass).after(:find).unless(:is_this_true?) }
|
49
58
|
end
|
50
59
|
|
51
60
|
describe User do
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "sqlite3", :platform=>:ruby
|
6
|
+
gem "activerecord-jdbc-adapter", :platform=>:jruby
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
|
8
|
+
gem "jdbc-sqlite3", :platform=>:jruby
|
9
|
+
gem "jruby-openssl", :platform=>:jruby
|
10
|
+
gem "therubyrhino", :platform=>:jruby
|
11
|
+
gem "rails", "~> 3.1.0"
|
12
|
+
gem "jquery-rails"
|
13
|
+
gem "sass-rails"
|
14
|
+
|
15
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "sqlite3", :platform=>:ruby
|
6
|
+
gem "activerecord-jdbc-adapter", :platform=>:jruby
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
|
8
|
+
gem "jdbc-sqlite3", :platform=>:jruby
|
9
|
+
gem "jruby-openssl", :platform=>:jruby
|
10
|
+
gem "therubyrhino", :platform=>:jruby
|
11
|
+
gem "rails", "~> 3.2.0"
|
12
|
+
gem "jquery-rails"
|
13
|
+
gem "sass-rails"
|
14
|
+
|
15
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "sqlite3", :platform=>:ruby
|
6
|
+
gem "activerecord-jdbc-adapter", :platform=>:jruby
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
|
8
|
+
gem "jdbc-sqlite3", :platform=>:jruby
|
9
|
+
gem "jruby-openssl", :platform=>:jruby
|
10
|
+
gem "therubyrhino", :platform=>:jruby
|
11
|
+
gem "rails", "~> 4.0.0"
|
12
|
+
gem "jquery-rails"
|
13
|
+
gem "sass-rails"
|
14
|
+
|
15
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "sqlite3", :platform=>:ruby
|
6
|
+
gem "activerecord-jdbc-adapter", :platform=>:jruby
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
|
8
|
+
gem "jdbc-sqlite3", :platform=>:jruby
|
9
|
+
gem "jruby-openssl", :platform=>:jruby
|
10
|
+
gem "therubyrhino", :platform=>:jruby
|
11
|
+
gem "rails", "~> 4.1.0"
|
12
|
+
gem "jquery-rails"
|
13
|
+
gem "sass-rails", "~> 4.0"
|
14
|
+
|
15
|
+
gemspec :path=>"../"
|
@@ -24,8 +24,10 @@ module Shoulda # :nodoc:
|
|
24
24
|
end
|
25
25
|
|
26
26
|
class CallbackMatcher # :nodoc:
|
27
|
+
VALID_OPTIONAL_LIFECYCLES = [:validation, :commit, :rollback].freeze
|
28
|
+
|
27
29
|
include RailsVersionHelper
|
28
|
-
|
30
|
+
|
29
31
|
def initialize method
|
30
32
|
@method = method
|
31
33
|
end
|
@@ -35,7 +37,8 @@ module Shoulda # :nodoc:
|
|
35
37
|
define_method hook do |lifecycle|
|
36
38
|
@hook = hook
|
37
39
|
@lifecycle = lifecycle
|
38
|
-
|
40
|
+
check_for_undefined_callbacks!
|
41
|
+
|
39
42
|
self
|
40
43
|
end
|
41
44
|
end
|
@@ -50,9 +53,7 @@ module Shoulda # :nodoc:
|
|
50
53
|
end
|
51
54
|
|
52
55
|
def on optional_lifecycle
|
53
|
-
|
54
|
-
raise UsageError.new("The .on option is only valid for the validation lifecycle and cannot be used with #{@lifecycle}, use with .before(:validation) or .after(:validation)")
|
55
|
-
end
|
56
|
+
check_for_valid_optional_lifecycles!
|
56
57
|
|
57
58
|
@optional_lifecycle = optional_lifecycle
|
58
59
|
|
@@ -96,8 +97,6 @@ module Shoulda # :nodoc:
|
|
96
97
|
"callback #{@method} #{@hook} #{@lifecycle}#{optional_lifecycle_phrase}#{condition_phrase}"
|
97
98
|
end
|
98
99
|
|
99
|
-
|
100
|
-
|
101
100
|
private
|
102
101
|
|
103
102
|
def check_preconditions!
|
@@ -106,7 +105,19 @@ module Shoulda # :nodoc:
|
|
106
105
|
|
107
106
|
def check_lifecycle_present!
|
108
107
|
unless @lifecycle
|
109
|
-
raise UsageError
|
108
|
+
raise UsageError, "callback #{@method} can not be tested against an undefined lifecycle, use .before, .after or .around", caller
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def check_for_undefined_callbacks!
|
113
|
+
if [:rollback, :commit].include?(@lifecycle) && @hook != :after
|
114
|
+
raise UsageError, "Can not callback before or around #{@lifecycle}, use after.", caller
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def check_for_valid_optional_lifecycles!
|
119
|
+
unless VALID_OPTIONAL_LIFECYCLES.include?(@lifecycle)
|
120
|
+
raise UsageError, "The .on option is only valid for #{VALID_OPTIONAL_LIFECYCLES.to_sentence} and cannot be used with #{@lifecycle}, use with .before(:validation) or .after(:validation)", caller
|
110
121
|
end
|
111
122
|
end
|
112
123
|
|
@@ -164,15 +175,31 @@ module Shoulda # :nodoc:
|
|
164
175
|
|
165
176
|
def lifecycle_context_string
|
166
177
|
if rails_4?
|
167
|
-
|
178
|
+
rails_4_lifecycle_context_string
|
168
179
|
else
|
180
|
+
rails_3_lifecycle_context_string
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def rails_3_lifecycle_context_string
|
185
|
+
if @lifecycle == :validation
|
169
186
|
"self.validation_context == :#{@optional_lifecycle}"
|
187
|
+
else
|
188
|
+
"transaction_include_action?(:#{@optional_lifecycle})"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def rails_4_lifecycle_context_string
|
193
|
+
if @lifecycle == :validation
|
194
|
+
"[:#{@optional_lifecycle}].include? self.validation_context"
|
195
|
+
else
|
196
|
+
"transaction_include_any_action?([:#{@optional_lifecycle}])"
|
170
197
|
end
|
171
198
|
end
|
172
199
|
|
173
200
|
def active_model_proc_matches_optional_lifecycle? if_conditions
|
174
201
|
if_conditions.select{|i| i.is_a? Proc }.any? do |condition|
|
175
|
-
condition.call
|
202
|
+
condition.call ValidationContext.new(@optional_lifecycle)
|
176
203
|
end
|
177
204
|
end
|
178
205
|
|
@@ -185,7 +212,7 @@ module Shoulda # :nodoc:
|
|
185
212
|
end
|
186
213
|
|
187
214
|
def callback_object subject, callback
|
188
|
-
if rails_3? && !callback.filter.is_a?(Symbol)
|
215
|
+
if (rails_3? || rails_4_0?) && !callback.filter.is_a?(Symbol)
|
189
216
|
subject.send("#{callback.filter}_object")
|
190
217
|
else
|
191
218
|
callback.filter
|
@@ -194,6 +221,7 @@ module Shoulda # :nodoc:
|
|
194
221
|
|
195
222
|
end
|
196
223
|
|
224
|
+
ValidationContext = Struct.new :validation_context
|
197
225
|
UsageError = Class.new NameError
|
198
226
|
end
|
199
227
|
end
|
@@ -8,7 +8,7 @@ module Shoulda
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def rails_4_0?
|
11
|
-
rails_4? &&
|
11
|
+
rails_4? && minor_version_equals?(0)
|
12
12
|
end
|
13
13
|
|
14
14
|
def rails_4?
|
@@ -23,17 +23,17 @@ module Shoulda
|
|
23
23
|
|
24
24
|
def major_version_equals? number
|
25
25
|
if active_record?
|
26
|
-
ActiveRecord::VERSION::MAJOR == number
|
26
|
+
::ActiveRecord::VERSION::MAJOR == number
|
27
27
|
else
|
28
|
-
ActiveModel::VERSION::MAJOR == number
|
28
|
+
::ActiveModel::VERSION::MAJOR == number
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def minor_version_equals? number
|
33
33
|
if active_record?
|
34
|
-
ActiveRecord::VERSION::MINOR == number
|
34
|
+
::ActiveRecord::VERSION::MINOR == number
|
35
35
|
else
|
36
|
-
ActiveModel::VERSION::MINOR == number
|
36
|
+
::ActiveModel::VERSION::MINOR == number
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -43,4 +43,4 @@ module Shoulda
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
end
|
46
|
+
end
|
@@ -28,7 +28,7 @@ describe Shoulda::Callback::Matchers::ActiveModel do
|
|
28
28
|
end
|
29
29
|
it "should return a meaningful error when used with an optional lifecycle without the original lifecycle being validation" do
|
30
30
|
lambda { callback(:dance!).after(:create).on(:save) }.should raise_error Shoulda::Callback::Matchers::ActiveModel::UsageError,
|
31
|
-
"The .on option is only valid for
|
31
|
+
"The .on option is only valid for validation, commit, and rollback and cannot be used with create, use with .before(:validation) or .after(:validation)"
|
32
32
|
end
|
33
33
|
it "should return a meaningful error when used without a defined lifecycle" do
|
34
34
|
lambda { callback(@callback_object_class).matches? :foo }.should raise_error Shoulda::Callback::Matchers::ActiveModel::UsageError,
|
@@ -36,14 +36,17 @@ describe Shoulda::Callback::Matchers::ActiveModel do
|
|
36
36
|
end
|
37
37
|
it "should return a meaningful error when used with an optional lifecycle without the original lifecycle being validation" do
|
38
38
|
lambda { callback(@callback_object_class).after(:create).on(:save) }.should raise_error Shoulda::Callback::Matchers::ActiveModel::UsageError,
|
39
|
-
"The .on option is only valid for
|
39
|
+
"The .on option is only valid for validation, commit, and rollback and cannot be used with create, use with .before(:validation) or .after(:validation)"
|
40
|
+
end
|
41
|
+
it "should return a meaningful error when used with rollback or commit and before" do
|
42
|
+
lambda { callback(@callback_object_class).before(:commit).on(:destroy) }.should raise_error Shoulda::Callback::Matchers::ActiveModel::UsageError,
|
43
|
+
"Can not callback before or around commit, use after."
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
47
|
[:save, :create, :update, :destroy].each do |lifecycle|
|
44
48
|
context "on #{lifecycle}" do
|
45
49
|
before do
|
46
|
-
|
47
50
|
@callback_object_class = define_model(:callback) do
|
48
51
|
define_method("before_#{lifecycle}"){}
|
49
52
|
define_method("after_#{lifecycle}"){}
|
@@ -354,8 +357,179 @@ describe Shoulda::Callback::Matchers::ActiveModel do
|
|
354
357
|
end
|
355
358
|
end
|
356
359
|
|
357
|
-
|
360
|
+
|
361
|
+
[:rollback, :commit].each do |lifecycle|
|
362
|
+
context "on #{lifecycle}" do
|
363
|
+
before do
|
364
|
+
@callback_object_class = define_model(:callback) do
|
365
|
+
define_method("after_#{lifecycle}"){}
|
366
|
+
end
|
367
|
+
|
368
|
+
@callback_object_class2 = define_model(:callback2) do
|
369
|
+
define_method("after_#{lifecycle}"){}
|
370
|
+
end
|
371
|
+
|
372
|
+
callback_object = @callback_object_class.new
|
373
|
+
callback_object2 = @callback_object_class2.new
|
374
|
+
|
375
|
+
@callback_object_not_found_class = define_model(:callback_not_found) do
|
376
|
+
define_method("after_#{lifecycle}"){}
|
377
|
+
end
|
378
|
+
@model = define_model(:example, :attr => :string,
|
379
|
+
:other => :integer) do
|
380
|
+
send :"after_#{lifecycle}", :dance!, :if => :evaluates_to_false!
|
381
|
+
send :"after_#{lifecycle}", :shake!, :unless => :evaluates_to_true!
|
382
|
+
send :"after_#{lifecycle}", :dress!, :on => :create
|
383
|
+
send :"after_#{lifecycle}", :shriek!, :on => :update, :unless => :evaluates_to_true!
|
384
|
+
send :"after_#{lifecycle}", :pucker!, :on => :destroy, :if => :evaluates_to_false!
|
385
|
+
send :"after_#{lifecycle}", callback_object, :if => :evaluates_to_false!
|
386
|
+
send :"after_#{lifecycle}", callback_object, :unless => :evaluates_to_true!
|
387
|
+
send :"after_#{lifecycle}", callback_object, :on => :create
|
388
|
+
send :"after_#{lifecycle}", callback_object, :on => :update, :unless => :evaluates_to_true!
|
389
|
+
send :"after_#{lifecycle}", callback_object2, :on => :destroy, :if => :evaluates_to_false!
|
390
|
+
define_method(:dance!){}
|
391
|
+
define_method(:shake!){}
|
392
|
+
define_method(:dress!){}
|
393
|
+
define_method(:shriek!){}
|
394
|
+
define_method(:pucker!){}
|
395
|
+
end.new
|
396
|
+
end
|
358
397
|
|
398
|
+
context "as a simple callback test" do
|
399
|
+
it "should find the callback after the fact" do
|
400
|
+
@model.should callback(:shake!).after(lifecycle)
|
401
|
+
end
|
402
|
+
it "should not find callbacks that are not there" do
|
403
|
+
@model.should_not callback(:scream!).after(lifecycle)
|
404
|
+
end
|
405
|
+
it "should have a meaningful description" do
|
406
|
+
matcher = callback(:dance!).after(lifecycle)
|
407
|
+
matcher.description.should == "callback dance! after #{lifecycle}"
|
408
|
+
end
|
409
|
+
|
410
|
+
it "should find the callback after the fact" do
|
411
|
+
@model.should callback(@callback_object_class).after(lifecycle)
|
412
|
+
end
|
413
|
+
it "should not find callbacks that are not there" do
|
414
|
+
@model.should_not callback(@callback_object_not_found_class).after(lifecycle)
|
415
|
+
end
|
416
|
+
it "should have a meaningful description" do
|
417
|
+
matcher = callback(@callback_object_class).after(lifecycle)
|
418
|
+
matcher.description.should == "callback Callback after #{lifecycle}"
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
context "with additinal lifecycles defined" do
|
423
|
+
it "should find the callback after the fact on create" do
|
424
|
+
@model.should callback(:dress!).after(lifecycle).on(:create)
|
425
|
+
end
|
426
|
+
it "should find the callback after the fact on update" do
|
427
|
+
@model.should callback(:shriek!).after(lifecycle).on(:update)
|
428
|
+
end
|
429
|
+
it "should find the callback after the fact on save" do
|
430
|
+
@model.should callback(:pucker!).after(lifecycle).on(:destroy)
|
431
|
+
end
|
432
|
+
it "should not find a callback for pucker! after the fact on update" do
|
433
|
+
@model.should_not callback(:pucker!).after(lifecycle).on(:update)
|
434
|
+
end
|
435
|
+
it "should have a meaningful description" do
|
436
|
+
matcher = callback(:dance!).after(lifecycle).on(:update)
|
437
|
+
matcher.description.should == "callback dance! after #{lifecycle} on update"
|
438
|
+
end
|
439
|
+
|
440
|
+
it "should find the callback before the fact on create" do
|
441
|
+
@model.should callback(@callback_object_class).after(lifecycle).on(:create)
|
442
|
+
end
|
443
|
+
it "should find the callback after the fact on update" do
|
444
|
+
@model.should callback(@callback_object_class).after(lifecycle).on(:update)
|
445
|
+
end
|
446
|
+
it "should find the callback after the fact on save" do
|
447
|
+
@model.should callback(@callback_object_class2).after(lifecycle).on(:destroy)
|
448
|
+
end
|
449
|
+
it "should not find a callback for Callback after the fact on update" do
|
450
|
+
@model.should_not callback(@callback_object_class2).after(lifecycle).on(:update)
|
451
|
+
end
|
452
|
+
it "should have a meaningful description" do
|
453
|
+
matcher = callback(@callback_object_class).after(lifecycle).on(:update)
|
454
|
+
matcher.description.should == "callback Callback after #{lifecycle} on update"
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
context "with conditions" do
|
459
|
+
it "should match the if condition" do
|
460
|
+
@model.should callback(:dance!).after(lifecycle).if(:evaluates_to_false!)
|
461
|
+
end
|
462
|
+
it "should match the unless condition" do
|
463
|
+
@model.should callback(:shake!).after(lifecycle).unless(:evaluates_to_true!)
|
464
|
+
end
|
465
|
+
it "should not find callbacks not matching the conditions" do
|
466
|
+
@model.should_not callback(:giggle!).after(lifecycle).unless(:evaluates_to_false!)
|
467
|
+
end
|
468
|
+
it "should not find callbacks that are not there entirely" do
|
469
|
+
@model.should_not callback(:scream!).after(lifecycle).unless(:evaluates_to_false!)
|
470
|
+
end
|
471
|
+
it "should have a meaningful description" do
|
472
|
+
matcher = callback(:dance!).after(lifecycle).unless(:evaluates_to_false!)
|
473
|
+
matcher.description.should == "callback dance! after #{lifecycle} unless evaluates_to_false! evaluates to false"
|
474
|
+
end
|
475
|
+
|
476
|
+
it "should match the if condition" do
|
477
|
+
@model.should callback(@callback_object_class).after(lifecycle).if(:evaluates_to_false!)
|
478
|
+
end
|
479
|
+
it "should match the unless condition" do
|
480
|
+
@model.should callback(@callback_object_class).after(lifecycle).unless(:evaluates_to_true!)
|
481
|
+
end
|
482
|
+
it "should not find callbacks not matching the conditions" do
|
483
|
+
@model.should_not callback(@callback_object_class).after(lifecycle).unless(:evaluates_to_false!)
|
484
|
+
end
|
485
|
+
it "should not find callbacks that are not there entirely" do
|
486
|
+
@model.should_not callback(@callback_object_not_found_class).after(lifecycle).unless(:evaluates_to_false!)
|
487
|
+
end
|
488
|
+
it "should have a meaningful description" do
|
489
|
+
matcher = callback(@callback_object_class).after(lifecycle).unless(:evaluates_to_false!)
|
490
|
+
matcher.description.should == "callback Callback after #{lifecycle} unless evaluates_to_false! evaluates to false"
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
context "with conditions and additional lifecycles" do
|
495
|
+
it "should find the callback before the fact on create" do
|
496
|
+
@model.should callback(:dress!).after(lifecycle).on(:create)
|
497
|
+
end
|
498
|
+
it "should find the callback after the fact on update with the unless condition" do
|
499
|
+
@model.should callback(:shriek!).after(lifecycle).on(:update).unless(:evaluates_to_true!)
|
500
|
+
end
|
501
|
+
it "should find the callback after the fact on save with the if condition" do
|
502
|
+
@model.should callback(:pucker!).after(lifecycle).on(:destroy).if(:evaluates_to_false!)
|
503
|
+
end
|
504
|
+
it "should not find a callback for pucker! after the fact on save with the wrong condition" do
|
505
|
+
@model.should_not callback(:pucker!).after(lifecycle).on(:destroy).unless(:evaluates_to_false!)
|
506
|
+
end
|
507
|
+
it "should have a meaningful description" do
|
508
|
+
matcher = callback(:dance!).after(lifecycle).on(:save).unless(:evaluates_to_false!)
|
509
|
+
matcher.description.should == "callback dance! after #{lifecycle} on save unless evaluates_to_false! evaluates to false"
|
510
|
+
end
|
511
|
+
|
512
|
+
it "should find the callback before the fact on create" do
|
513
|
+
@model.should callback(@callback_object_class).after(lifecycle).on(:create)
|
514
|
+
end
|
515
|
+
it "should find the callback after the fact on update with the unless condition" do
|
516
|
+
@model.should callback(@callback_object_class).after(lifecycle).on(:update).unless(:evaluates_to_true!)
|
517
|
+
end
|
518
|
+
it "should find the callback after the fact on save with the if condition" do
|
519
|
+
@model.should callback(@callback_object_class2).after(lifecycle).on(:destroy).if(:evaluates_to_false!)
|
520
|
+
end
|
521
|
+
it "should not find a callback for Callback after the fact on save with the wrong condition" do
|
522
|
+
@model.should_not callback(@callback_object_class).after(lifecycle).on(:destroy).unless(:evaluates_to_false!)
|
523
|
+
end
|
524
|
+
it "should have a meaningful description" do
|
525
|
+
matcher = callback(@callback_object_class).after(lifecycle).on(:destroy).unless(:evaluates_to_false!)
|
526
|
+
matcher.description.should == "callback Callback after #{lifecycle} on destroy unless evaluates_to_false! evaluates to false"
|
527
|
+
end
|
528
|
+
end
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
[:initialize, :find, :touch].each do |lifecycle|
|
359
533
|
context "on #{lifecycle}" do
|
360
534
|
before do
|
361
535
|
|
metadata
CHANGED
@@ -1,111 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda-callback-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Beat Richartz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: appraisal
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.5'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: aruba
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '1.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '10'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '10'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec-rails
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - ~>
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '2'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - ~>
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '2'
|
111
111
|
description: Making callback tests easy on the fingers and eyes
|
@@ -115,8 +115,8 @@ extensions:
|
|
115
115
|
- ext/mkrf_conf.rb
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- .gitignore
|
119
|
-
- .travis.yml
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
120
|
- Appraisals
|
121
121
|
- CONTRIBUTING.md
|
122
122
|
- Gemfile
|
@@ -125,6 +125,10 @@ files:
|
|
125
125
|
- README.md
|
126
126
|
- Rakefile
|
127
127
|
- ext/mkrf_conf.rb
|
128
|
+
- gemfiles/rails_3.1.gemfile
|
129
|
+
- gemfiles/rails_3.2.gemfile
|
130
|
+
- gemfiles/rails_4.0.gemfile
|
131
|
+
- gemfiles/rails_4.1.gemfile
|
128
132
|
- lib/shoulda-callback-matchers.rb
|
129
133
|
- lib/shoulda/callback/matchers.rb
|
130
134
|
- lib/shoulda/callback/matchers/active_model.rb
|
@@ -147,12 +151,12 @@ require_paths:
|
|
147
151
|
- lib
|
148
152
|
required_ruby_version: !ruby/object:Gem::Requirement
|
149
153
|
requirements:
|
150
|
-
- -
|
154
|
+
- - ">="
|
151
155
|
- !ruby/object:Gem::Version
|
152
156
|
version: '0'
|
153
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
158
|
requirements:
|
155
|
-
- -
|
159
|
+
- - ">="
|
156
160
|
- !ruby/object:Gem::Version
|
157
161
|
version: '0'
|
158
162
|
requirements: []
|
@@ -166,3 +170,4 @@ test_files:
|
|
166
170
|
- spec/spec_helper.rb
|
167
171
|
- spec/support/class_builder.rb
|
168
172
|
- spec/support/model_builder.rb
|
173
|
+
has_rdoc:
|