opium 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/opium/model/callbacks.rb +3 -2
- data/lib/opium/version.rb +1 -1
- data/spec/opium/model/callbacks_spec.rb +8 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcecdde21391716e2fa90f3d7e69ed2ab99cec6e
|
4
|
+
data.tar.gz: b424a700e0cd350b3840ddaae829ef3b964776ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f8768756d6016fad4a9c92065b955dee1b3382d9626a7079782cbb71ad2287653bb1e016fc1cac2ea43c221a0ed9e6126d04d88e30a70dfcb93d367cb1dccb9
|
7
|
+
data.tar.gz: e7def16e2b043a3ce5121fd65d8a08aa7f4ed94a6d45617217e5260b090fcae1f50c9bd87d9c12341bd43db2506e29a35b69b5eaf2e0c5eb08965c37c1fe8886
|
data/CHANGELOG.md
CHANGED
@@ -15,16 +15,17 @@ module Opium
|
|
15
15
|
define_model_callbacks :save, :create, :update, :destroy
|
16
16
|
|
17
17
|
wrap_callbacks_around :save, :destroy, :touch, :find
|
18
|
-
wrap_callbacks_around :initialize, :
|
18
|
+
wrap_callbacks_around :initialize, :_create, :_update, private: true
|
19
19
|
end
|
20
20
|
|
21
21
|
module ClassMethods
|
22
22
|
def wrap_callbacks_around( *methods )
|
23
23
|
options = methods.last.is_a?(::Hash) ? methods.pop : {}
|
24
24
|
methods.each do |method|
|
25
|
+
callback_name = method.to_s.gsub(/\A_/, '').to_sym
|
25
26
|
class_eval do
|
26
27
|
define_method method do |*args|
|
27
|
-
run_callbacks(
|
28
|
+
run_callbacks( callback_name ) do
|
28
29
|
super( *args )
|
29
30
|
end
|
30
31
|
end
|
data/lib/opium/version.rb
CHANGED
@@ -7,11 +7,12 @@ describe Opium::Model::Callbacks do
|
|
7
7
|
def save( o = {} ) end
|
8
8
|
def destroy; end
|
9
9
|
def touch; end
|
10
|
-
def
|
10
|
+
def _create; end
|
11
|
+
def _update; end
|
11
12
|
def update; end
|
12
13
|
def find( id ) end
|
13
14
|
|
14
|
-
private :
|
15
|
+
private :_create, :_update
|
15
16
|
|
16
17
|
include Opium::Model::Callbacks
|
17
18
|
end
|
@@ -35,7 +36,7 @@ describe Opium::Model::Callbacks do
|
|
35
36
|
subject { model.new }
|
36
37
|
|
37
38
|
it 'should run callbacks' do
|
38
|
-
subject.should receive(:run_callbacks).with(method)
|
39
|
+
subject.should receive(:run_callbacks).with(options[:callback_name] || method)
|
39
40
|
subject.send(method, *options[:args])
|
40
41
|
end
|
41
42
|
|
@@ -51,9 +52,11 @@ describe Opium::Model::Callbacks do
|
|
51
52
|
|
52
53
|
it_should_behave_like 'its callbacks should be invoked for', :initialize, private: true
|
53
54
|
it_should_behave_like 'its callbacks should be invoked for', :save
|
54
|
-
it_should_behave_like 'its callbacks should be invoked for', :
|
55
|
-
it_should_behave_like 'its callbacks should be invoked for', :
|
55
|
+
it_should_behave_like 'its callbacks should be invoked for', :_create, private: true, callback_name: :create
|
56
|
+
it_should_behave_like 'its callbacks should be invoked for', :_update, private: true, callback_name: :update
|
56
57
|
it_should_behave_like 'its callbacks should be invoked for', :destroy
|
57
58
|
it_should_behave_like 'its callbacks should be invoked for', :touch
|
58
59
|
it_should_behave_like 'its callbacks should be invoked for', :find, args: ['abcd1234']
|
60
|
+
|
61
|
+
it { expect( model.new ).to respond_to(:update) }
|
59
62
|
end
|