This project is archived and is in readonly mode.

#2992 ✓resolved
Nobuhiro IMAI

[PATCH] visibility of fixture accssor methods

Reported by Nobuhiro IMAI | August 4th, 2009 @ 07:16 AM | in 3.0.2

Hello,

this is similar to #1708, but including another problem,
so I attached the same patch again. If there are the ways to
tell of updating the ticket that was marked as "incomplete" or
"invalid", please let met know.

Well, the teardown method is invoked even when the test method
comes from outside of the test script.

$ cat test/unit/test_result_test.rb 
require 'test_helper'

class TestResultTest < ActiveSupport::TestCase
  def teardown
    p @method_name
  end
end
$ ruby -Itest test/unit/test_result_test.rb -v
Loaded suite test/unit/test_result_test
Started
test_results(ActionController::IntegrationTest): .
test_results(ActionController::TestCase): .
test_results(ActionMailer::TestCase): .
test_results(ActionView::TestCase): .
test_results(ActiveRecord::TestCase): .
test_results(ActiveSupport::TestCase): .
test_results(TestResultTest): "test_results"
.

Finished in 0.233754 seconds.

7 tests, 0 assertions, 0 failures, 0 errors

Actually, I'm very annoyed the following case:

require 'test_helper'

class TestResultTest < ActiveSupport::TestCase
  def setup
    File.unlink(logfile)
  rescue Errno::ENOENT
  end

  def teardown
    assert_equal 1, File.unlink(logfile)
  end

  def logfile
    @logfile ||= Rails.root + "tmp/logfile"
  end

  test "create log 1" do
    File.open(logfile, "w"){|f| f.puts("log 1")}
  end

  test "create log 2" do
    File.open(logfile, "w"){|f| f.puts("log 2")}
  end
end

the result of above test is:

$ ruby -Itest test/unit/test_result_test.rb -v
Loaded suite test/unit/test_result_test
Started
test_results(ActionController::IntegrationTest): .
test_results(ActionController::TestCase): .
test_results(ActionMailer::TestCase): .
test_results(ActionView::TestCase): .
test_results(ActiveRecord::TestCase): .
test_results(ActiveSupport::TestCase): .
test_create_log_1(TestResultTest): .
test_create_log_2(TestResultTest): .
test_results(TestResultTest): E

Finished in 0.220522 seconds.

  1) Error:
test_results(TestResultTest):
Errno::ENOENT: No such file or directory - /tmp/233/tmp/logfile
    test/unit/test_result_test.rb:10:in `unlink'
    test/unit/test_result_test.rb:10:in `teardown'

9 tests, 2 assertions, 0 failures, 1 errors

Hmm, I don't know about the test_results method,
at least in my test/unit/test_result_test.rb.

After patching,

$ ruby -Itest test/unit/test_result_test.rb -v
Loaded suite test/unit/test_result_test
Started
test_create_log_1(TestResultTest): .
test_create_log_2(TestResultTest): .

Finished in 0.202083 seconds.

2 tests, 2 assertions, 0 failures, 0 errors

the result is quite simple and this is what I want :-).

Thanks,

Comments and changes to this ticket

  • Nobuhiro IMAI

    Nobuhiro IMAI September 12th, 2009 @ 12:20 AM

    • Title changed from “visibility of fixture accssor methods” to “[PATCH] visibility of fixture accssor methods”
    • Assigned user set to “Pratik”

    How about to include this patch into the next release? 2.3.5?

    Thanks,

  • CancelProfileIsBroken

    CancelProfileIsBroken September 25th, 2009 @ 12:59 PM

    • Tag changed from 2.3.3, 2.3.4, activerecord, fixtures, patch to 2.3.3, 2.3.4, activerecord, bugmash, fixtures, patch
    • Assigned user cleared.
  • Elad Meidar

    Elad Meidar September 26th, 2009 @ 03:01 AM

    +1 on the patch, applies cleanly on 2-3-stable and Master. @Nobuhiro: although it's all seems like the correct way to go, are you sure this won't backfire on something ?

  • Elad Meidar

    Elad Meidar September 26th, 2009 @ 03:03 AM

    • Tag changed from 2.3.3, 2.3.4, activerecord, bugmash, fixtures, patch to 2.3.3, 2.3.4, activerecord, bugmash, bugmash-review, fixtures, patch
  • Nobuhiro IMAI

    Nobuhiro IMAI September 26th, 2009 @ 03:32 AM

    @Elad: Fixture accessor methods are only used in test scripts, so that it's ok even if the visibility is private, I guess. Thanks.

  • sr.iniv.t

    sr.iniv.t September 27th, 2009 @ 05:34 AM

    +1 verified. Patch applies cleanly.

  • CancelProfileIsBroken

    CancelProfileIsBroken September 27th, 2009 @ 11:47 AM

    • Tag changed from 2.3.3, 2.3.4, activerecord, bugmash, bugmash-review, fixtures, patch to 2.3.3, 2.3.4, activerecord, bugmash-review, fixtures, patch
  • CancelProfileIsBroken

    CancelProfileIsBroken September 27th, 2009 @ 12:33 PM

    • Tag changed from 2.3.3, 2.3.4, activerecord, bugmash-review, fixtures, patch to 2.3.3, 2.3.4, activerecord, bugmash-review, fixtures, patch
  • Nobuhiro IMAI

    Nobuhiro IMAI December 23rd, 2009 @ 07:46 AM

    • Tag changed from 2.3.3, 2.3.4, activerecord, bugmash-review, fixtures, patch to 2.3.6, activerecord, bugmash-review, fixtures, patch

    With Rails 2.3.5, the situation seems to have deteriorated.

    $ ruby -Itest test/unit/test_result_test.rb -v
    Loaded suite test/unit/test_result_test
    Started
    test_results(ActionController::IntegrationTest): .
    test_results(ActionController::TestCase): .
    test_results(ActionMailer::TestCase): .
    test_results(ActionView::TestCase): E
    test_results(ActiveRecord::TestCase): .
    test_results(ActiveSupport::TestCase): .
    test_results(TestResultTest): .
    test_the_truth(TestResultTest): .
    
    Finished in 0.356134 seconds.
    
      1) Error:
    test_results(ActionView::TestCase):
    TypeError: wrong argument type Class (expected Module)
        
    
    8 tests, 1 assertions, 0 failures, 1 errors
    

    This is because the hook, setup_with_controller(), is added to ActionView::TestCase.

    .../actionpack-2.3.5/lib/action_view/test_case.rb:81:in `helper_class'
    .../actionpack-2.3.5/lib/action_view/test_case.rb:106:in `include_helper_modules!'
    .../actionpack-2.3.5/lib/action_view/test_case.rb:59:in `send'
    .../actionpack-2.3.5/lib/action_view/test_case.rb:59:in `setup_with_controller'
    (snip)
    

    and in determine_default_helper_class(), trying to include ActionView::TestCase itself as a helper module, then raises TypeError.
    At this point, determine_default_helper_class should be as follow:

           def determine_default_helper_class(name)
    -        name.sub(/Test$/, '').constantize
    +        name.sub!(/Test\z/, '').try(:constantize)
           rescue NameError
             nil
           end
    

    Anyway, it's no problem if the fixtures accessor methods are private.
    Attached patch is cleanly applied even now, at least using git-apply. Thanks.

  • Rizwan Reza

    Rizwan Reza May 15th, 2010 @ 06:45 PM

    • Tag changed from 2.3.6, activerecord, bugmash-review, fixtures, patch to 2.3.6, activerecord, bugmash, fixtures, patch
  • Casey Dreier

    Casey Dreier May 15th, 2010 @ 09:04 PM

    +1 Verified that patch applies cleanly for 2.3-stable branch.

  • Rizwan Reza

    Rizwan Reza May 15th, 2010 @ 09:13 PM

    • Milestone set to 2.3.6
    • State changed from “new” to “open”

    Casey, also update us if the tests pass.

  • Rizwan Reza

    Rizwan Reza May 15th, 2010 @ 09:15 PM

    • Tag changed from 2.3.6, activerecord, bugmash, fixtures, patch to 2.3.6, activerecord, bugmash-review, fixtures, patch
  • Casey Dreier

    Casey Dreier May 16th, 2010 @ 12:38 AM

    Yes, all tests on master pass with this patch applied.

  • Rizwan Reza

    Rizwan Reza May 16th, 2010 @ 02:41 AM

    • Tag changed from 2.3.6, activerecord, bugmash-review, fixtures, patch to 2.3.6, activerecord, bugmash, bugmash-review, fixtures, patch
  • Rizwan Reza

    Rizwan Reza May 16th, 2010 @ 02:58 AM

    • Milestone cleared.
    • Tag changed from 2.3.6, activerecord, bugmash, bugmash-review, fixtures, patch to 2.3.6, 3.0, activerecord, bugmash, bugmash-review, fixtures, patch
    • State changed from “open” to “verified”

    The patch above is for both: master and 2-3-stable.

  • Rizwan Reza

    Rizwan Reza May 16th, 2010 @ 02:58 AM

    • Tag changed from 2.3.6, 3.0, activerecord, bugmash, bugmash-review, fixtures, patch to 2.3.6, 3.0, activerecord, bugmash, fixtures, patch
  • Rizwan Reza

    Rizwan Reza May 16th, 2010 @ 02:58 AM

    • Tag changed from 2.3.6, 3.0, activerecord, bugmash, fixtures, patch to 2.3.6, 3.0, activerecord, bugmash-review, fixtures, patch
  • Rizwan Reza

    Rizwan Reza May 16th, 2010 @ 02:58 AM

    • no changes were found...
  • José Valim

    José Valim May 16th, 2010 @ 09:51 AM

    • Milestone cleared.
    • Tag changed from 2.3.6, 3.0, activerecord, bugmash-review, fixtures, patch to 2.3.6, 3.0, activerecord, bugmash, fixtures, patch
    • State changed from “verified” to “open”
    • Assigned user set to “José Valim”

    The patch does not apply on master anymore. Can anyone rebase please?

  • Wijnand Wiersma
  • Casey Dreier

    Casey Dreier May 16th, 2010 @ 06:25 PM

    +1 Verified that new patches apply cleanly to both master and 2.3-stable branch.
    Does not cause any failing tests on either branch.

  • Repository

    Repository May 16th, 2010 @ 07:16 PM

    • State changed from “open” to “resolved”

    (from [5d0afe75ebd7d88f982a57af84dba1ef62b14c0c]) prevent to run fixture accessor (e.g. test_foos for TestFoo model) as a test case [#2992 state:resolved]

    Signed-off-by: Wijnand Wiersma wijnand@videre.net
    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/5d0afe75ebd7d88f982a57af84dba1...

  • José Valim

    José Valim May 16th, 2010 @ 07:23 PM

    • Tag changed from 2.3.6, 3.0, activerecord, bugmash, fixtures, patch to 2.3.6, 3.0, activerecord, fixtures, patch
  • Jeremy Kemper

    Jeremy Kemper October 15th, 2010 @ 11:01 PM

    • Milestone set to 3.0.2
    • Importance changed from “” to “High”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages