Skip to content
This repository
Browse code

Update checker returns a boolean if callback was executed or not.

  • Loading branch information...
commit 9a51053c1d0fe4db66f82c93454b8fd8e6d7e192 1 parent 2fdc3ab
José Valim josevalim authored
3  activesupport/lib/active_support/file_update_checker.rb
@@ -32,6 +32,9 @@ def execute_if_updated
32 32 if @last_update_at != current_update_at
33 33 @last_update_at = current_update_at
34 34 @block.call
  35 + true
  36 + else
  37 + false
35 38 end
36 39 end
37 40 end
13 activesupport/test/file_update_checker_test.rb
@@ -42,19 +42,18 @@ def test_should_not_invoke_the_block_on_first_call_if_it_calculates_last_updated
42 42
43 43 def test_should_not_invoke_the_block_if_no_file_has_changed
44 44 i = 0
45   - checker = ActiveSupport::FileUpdateChecker.new(args){ i += 1 }
46   - 5.times { checker.execute_if_updated }
47   - assert_equal 1, i
  45 + checker = ActiveSupport::FileUpdateChecker.new(args, true){ i += 1 }
  46 + 5.times { assert !checker.execute_if_updated }
  47 + assert_equal 0, i
48 48 end
49 49
50 50 def test_should_invoke_the_block_if_a_file_has_changed
51 51 i = 0
52   - checker = ActiveSupport::FileUpdateChecker.new(args){ i += 1 }
53   - checker.execute_if_updated
  52 + checker = ActiveSupport::FileUpdateChecker.new(args, true){ i += 1 }
54 53 sleep(1)
55 54 FileUtils.touch(FILES)
56   - checker.execute_if_updated
57   - assert_equal 2, i
  55 + assert checker.execute_if_updated
  56 + assert_equal 1, i
58 57 end
59 58 end
60 59

0 comments on commit 9a51053

Please sign in to comment.
Something went wrong with that request. Please try again.