Namespace
Methods
S
T
Instance Public methods
setup()
# File activesupport/test/memoizable_test.rb, line 121
def setup
  @person = Person.new
  @calculator = Calculator.new
end
test_double_memoization()
# File activesupport/test/memoizable_test.rb, line 257
def test_double_memoization
  assert_raise(RuntimeError) { Person.memoize :name }
  person = Person.new
  ActiveSupport::Deprecation.silence do
    person.extend ActiveSupport::Memoizable
  end
  assert_raise(RuntimeError) { person.memoize :name }

  company = Company.new
  ActiveSupport::Deprecation.silence do
    company.extend ActiveSupport::Memoizable
  end
  company.memoize :name
  assert_raise(RuntimeError) { company.memoize :name }
end
test_flush_cache()
# File activesupport/test/memoizable_test.rb, line 166
def test_flush_cache
  assert_equal 1, @calculator.counter

  assert @calculator.instance_variable_get(:@_memoized_counter).any?
  @calculator.flush_cache(:counter)
  assert @calculator.instance_variable_get(:@_memoized_counter).empty?

  assert_equal 2, @calculator.counter
end
test_memoization()
# File activesupport/test/memoizable_test.rb, line 126
def test_memoization
  assert_equal "Josh", @person.name
  assert_equal 1, @person.name_calls

  3.times { assert_equal "Josh", @person.name }
  assert_equal 1, @person.name_calls
end
test_memoization_cache_is_different_for_each_instance()
# File activesupport/test/memoizable_test.rb, line 191
def test_memoization_cache_is_different_for_each_instance
  assert_equal 1, @calculator.counter
  assert_equal 2, @calculator.counter(:reload)
  assert_equal 1, Calculator.new.counter
end
test_memoization_flush_with_punctuation()
# File activesupport/test/memoizable_test.rb, line 143
def test_memoization_flush_with_punctuation
  assert_equal true, @person.name?
  @person.flush_cache(:name?)
  3.times { assert_equal true, @person.name? }
  assert_equal 2, @person.name_query_calls
end
test_memoization_with_args()
# File activesupport/test/memoizable_test.rb, line 203
def test_memoization_with_args
  assert_equal 55, @calculator.fib(10)
  assert_equal 11, @calculator.fib_calls
end
test_memoization_with_boolean_arg()
# File activesupport/test/memoizable_test.rb, line 217
def test_memoization_with_boolean_arg
  assert_equal 4, @calculator.add_or_subtract(2, 2, true)
  assert_equal 2, @calculator.add_or_subtract(4, 2, false)
end
test_memoization_with_nil_value()
# File activesupport/test/memoizable_test.rb, line 150
def test_memoization_with_nil_value
  assert_equal nil, @person.age
  assert_equal 1, @person.age_calls

  3.times { assert_equal nil, @person.age }
  assert_equal 1, @person.age_calls
end
test_memoization_with_punctuation()
# File activesupport/test/memoizable_test.rb, line 134
def test_memoization_with_punctuation
  assert_equal true, @person.name?

  assert_nothing_raised(NameError) do
    @person.memoize_all
    @person.unmemoize_all
  end
end
test_memoize_all()
# File activesupport/test/memoizable_test.rb, line 186
def test_memoize_all
  @calculator.memoize_all
  assert @calculator.instance_variable_defined?(:@_memoized_counter)
end
test_memoized_is_not_affected_by_freeze()
# File activesupport/test/memoizable_test.rb, line 197
def test_memoized_is_not_affected_by_freeze
  @person.freeze
  assert_equal "Josh", @person.name
  assert_equal "Joshua", @person.update("Joshua")
end
test_memoized_module_methods()
# File activesupport/test/memoizable_test.rb, line 236
def test_memoized_module_methods
  assert_equal 1.025, @calculator.sales_tax(10)
  assert_equal 1, @calculator.sales_tax_calls
  assert_equal 1.025, @calculator.sales_tax(10)
  assert_equal 1, @calculator.sales_tax_calls
  assert_equal 2.5625, @calculator.sales_tax(25)
  assert_equal 2, @calculator.sales_tax_calls
end
test_object_memoization()
# File activesupport/test/memoizable_test.rb, line 222
def test_object_memoization
  [Company.new, Company.new, Company.new].each do |company|
    ActiveSupport::Deprecation.silence do
      company.extend ActiveSupport::Memoizable
    end
    company.memoize :name

    assert_equal "37signals", company.name
    assert_equal 1, company.name_calls
    assert_equal "37signals", company.name
    assert_equal 1, company.name_calls
  end
end
test_object_memoized_module_methods()
# File activesupport/test/memoizable_test.rb, line 245
def test_object_memoized_module_methods
  company = Company.new
  company.extend(Rates)

  assert_equal 1.025, company.sales_tax(10)
  assert_equal 1, company.sales_tax_calls
  assert_equal 1.025, company.sales_tax(10)
  assert_equal 1, company.sales_tax_calls
  assert_equal 2.5625, company.sales_tax(25)
  assert_equal 2, company.sales_tax_calls
end
test_private_method_memoization()
# File activesupport/test/memoizable_test.rb, line 280
def test_private_method_memoization
  person = Person.new

  assert_raise(NoMethodError) { person.is_developer? }
  assert_equal "Yes", person.send(:is_developer?)
  assert_equal 1, person.is_developer_calls
  assert_equal "Yes", person.send(:is_developer?)
  assert_equal 1, person.is_developer_calls
end
test_protected_method_memoization()
# File activesupport/test/memoizable_test.rb, line 273
def test_protected_method_memoization
  person = Person.new

  assert_raise(NoMethodError) { person.memoize_protected_test }
  assert_equal "protected", person.send(:memoize_protected_test)
end
test_reloadable()
# File activesupport/test/memoizable_test.rb, line 158
def test_reloadable
  assert_equal 1, @calculator.counter
  assert_equal 2, @calculator.counter(:reload)
  assert_equal 2, @calculator.counter
  assert_equal 3, @calculator.counter(true)
  assert_equal 3, @calculator.counter
end
test_reloadable_with_args()
# File activesupport/test/memoizable_test.rb, line 208
def test_reloadable_with_args
  assert_equal 55, @calculator.fib(10)
  assert_equal 11, @calculator.fib_calls
  assert_equal 55, @calculator.fib(10, :reload)
  assert_equal 12, @calculator.fib_calls
  assert_equal 55, @calculator.fib(10, true)
  assert_equal 13, @calculator.fib_calls
end
test_unmemoize_all()
# File activesupport/test/memoizable_test.rb, line 176
def test_unmemoize_all
  assert_equal 1, @calculator.counter

  assert @calculator.instance_variable_get(:@_memoized_counter).any?
  @calculator.unmemoize_all
  assert @calculator.instance_variable_get(:@_memoized_counter).empty?

  assert_equal 2, @calculator.counter
end