Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
[dm-is-remixable] Don't use should_receive to see if a hook is executed
Browse files Browse the repository at this point in the history
* Methods involved in hooks may not always be testable using this method,
  and it is better to test for the side effect of the method rather than
  if a specific method was called.
  • Loading branch information
dkubb committed Mar 31, 2010
1 parent 9867150 commit dd22e1a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dm-is-remixable/lib/dm-is-remixable/is/remixable.rb
Expand Up @@ -405,7 +405,7 @@ def belongs_to_name(class_name)

def clone_hooks(remixable, model)
# event name is by default :create, :destroy etc
remixable.instance_hooks.map do |event_name, hooks|
remixable.instance_hooks.each do |event_name, hooks|
[:after, :before].each do |callback|
hooks[callback].each do |hook|
model.send(callback, event_name, hook[:name])
Expand Down
9 changes: 7 additions & 2 deletions dm-is-remixable/spec/data/image.rb
Expand Up @@ -7,9 +7,14 @@ module Image
property :description, String
property :path, String

after :save, :run_hook_method
after :save, :hook_method

def run_hook_method
def hook_method
@hook_method = true
end

def hook_method_called?
defined?(@hook_method) ? true : false
end

# These methods will be available to the class remixing this module
Expand Down
5 changes: 3 additions & 2 deletions dm-is-remixable/spec/integration/remixable_spec.rb
Expand Up @@ -135,8 +135,9 @@ def self.test_enhance_2
article = Article.new
article.pics = (@pic = ArticleImage.new)

@pic.should_receive(:run_hook_method).once
article.save
expect {
article.save
}.to change(@pic, :hook_method_called?).from(false).to(true)
end

it "should copy validation contexts from the Remixable Module to the Remixed Model" do
Expand Down

0 comments on commit dd22e1a

Please sign in to comment.