This project is archived and is in readonly mode.

#897 ✓wontfix

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

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

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

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

  test "something is memoized" do
     assert_equal 1, my_model.something(7)
     assert_equal 1, my_model.something(7)
     assert_equal 2, my_model.something(100)

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 set to “josh”

    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}"

    Changing the implementation just to suit tests seems broken.

  • josh

    josh 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.


    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

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=""></a>

People watching this ticket