ohm-contrib 0.0.21 → 0.0.22

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.21
1
+ 0.0.22
data/lib/ohm/contrib.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ohm
2
2
  module Contrib
3
- VERSION = '0.0.21'
3
+ VERSION = '0.0.22'
4
4
  end
5
5
 
6
6
  autoload :Boundaries, "ohm/contrib/boundaries"
@@ -39,6 +39,7 @@ module Ohm
39
39
  module Callbacks
40
40
  def self.included(base)
41
41
  base.extend Macros
42
+ base.extend Overrides
42
43
  end
43
44
 
44
45
  module Macros
@@ -109,6 +110,18 @@ module Ohm
109
110
  @callbacks ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] }}
110
111
  end
111
112
  end
113
+
114
+ # This module is for class method overrides. As of now
115
+ # it only overrides Ohm::Model::create to force calling save
116
+ # instead of calling create so that Model.create will call
117
+ # not only before/after :create but also before/after :save
118
+ module Overrides
119
+ def create(*args)
120
+ model = new(*args)
121
+ model.save
122
+ model
123
+ end
124
+ end
112
125
 
113
126
  # Overrides the validate method of Ohm::Model. This is a bit tricky,
114
127
  # since typically you override this. Make sure you do something like:
@@ -170,4 +183,4 @@ module Ohm
170
183
  end
171
184
  end
172
185
  end
173
- end
186
+ end
data/ohm-contrib.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ohm-contrib}
8
- s.version = "0.0.21"
8
+ s.version = "0.0.22"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cyril David"]
@@ -94,6 +94,29 @@ class OhmContribCallbacksTest < Test::Unit::TestCase
94
94
  end
95
95
  end
96
96
 
97
+ context "on create when valid state" do
98
+ setup do
99
+ @post = Post.create(:body => "The Body")
100
+ end
101
+
102
+ should "call all callbacks" do
103
+ assert @post.did?(:do_before_validate)
104
+ assert @post.did?(:do_after_validate)
105
+ assert @post.did?(:do_before_create)
106
+ assert @post.did?(:do_after_create)
107
+ assert @post.did?(:do_before_save)
108
+ assert @post.did?(:do_after_save)
109
+ end
110
+
111
+ should "call create / save callbacks only once" do
112
+ assert_equal 1, @post.count(:do_before_create)
113
+ assert_equal 1, @post.count(:do_after_create)
114
+ assert_equal 1, @post.count(:do_before_save)
115
+ assert_equal 1, @post.count(:do_after_create)
116
+ end
117
+ end
118
+
119
+
97
120
  context "on save of an existing object" do
98
121
  setup do
99
122
  @post = Post.create(:body => "The Body")
@@ -167,4 +190,4 @@ class OhmContribCallbacksTest < Test::Unit::TestCase
167
190
  assert ! @post.did?(:do_after_save)
168
191
  end
169
192
  end
170
- end
193
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 21
9
- version: 0.0.21
8
+ - 22
9
+ version: 0.0.22
10
10
  platform: ruby
11
11
  authors:
12
12
  - Cyril David