#897 √ wontfix
MatthewRudy

[PATCH] :memoized methods are stored in Klass.memoized_methods

Reported by MatthewRudy | August 25th, 2008 @ 10:41 AM | in 2.x

http://groups.google.com/group/r...


class MyKlass
  def something(n)
     return randomly(n)
  end
  memoize :something
end

class MyKlassTest
  test "something is declared as memoized" do
    assert MyKlass.memoized_methods.include?(:something)
  end

  test "something is memoized" do
     my_model.stubs(:randomly).returns(1,2,3)
     assert_equal 1, my_model.something(7)
     assert_equal 1, my_model.something(7)
     assert_equal 2, my_model.something(100)
  end
end

I've currently put the :memoized_methods method on the Klass, perhaps it should be on the record, or called :memoized_instance_methods.

But it feels that, as it's declared in the class scope, it should set :memoized_methods in the same scope.

Comments and changes to this ticket

  • Michael Koziarski

    Michael Koziarski August 25th, 2008 @ 03:03 PM

    • → Assigned user changed from “” to “Joshua Peek”

    I still feel that this is better handled by you writing your own assertion

    
    def assert_memoized(object, method)
      assert object.respond_to? "_unmemoized_#{method}"
    end
    

    Changing the implementation just to suit tests seems broken.

  • Joshua Peek

    Joshua Peek August 25th, 2008 @ 04:18 PM

    • → State changed from “new” to “wontfix”

    You might want to add some test coverage for mixins, inheritance, and extending objects. You might find an instance variable just won't work how you except it. Seriously, I tried this approach when I first wrote this helper.

  • MatthewRudy

    MatthewRudy August 26th, 2008 @ 01:01 AM

    hmm, yeah. maybe Mr Koz.

    I still don't understand why this doesn't use alias_method_chain, though.

    I may just abandon using :memoize anyway, as it doesn't seem like the best idea in the world.

    I still see a use in asserting that a rails method has been used.

    eg.

    Model.should have_many(:sausages).with(:conditions => {:tasty => true})

    is useful.

    Although, I guess my particular brand of testing logic is distinct from yours.

    Take it easy. Will nudge you at RailsConf in a week-ish

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

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

Source available from github

The Git repository resides at http://github.com/rails

Check out the current development trunk (Edge Rails) with:

git clone git://github.com/rails/rails.git

Creating or reviewing a patch

See the contributor guide.

Creating a feature request

Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.

Creating a bug report

When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.

Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.

Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too".

Shared Ticket Bins

People watching this ticket

Attachments