Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

observed_classes get redefined properly - fixes #3505 #6068

Closed
wants to merge 1 commit into from
Closed

observed_classes get redefined properly - fixes #3505 #6068

wants to merge 1 commit into from

Conversation

frodsan
Copy link
Contributor

@frodsan frodsan commented Apr 29, 2012

I'm trying to fix #3505 issue:

I need help with this:

rails/activemodel/lib/active_model/observing.rb:199: warning: previous definition of observed_classes was here
rails/activemodel/lib/active_model/observing.rb:199: warning: method redefined; discarding old observed_classes

I'm getting those warnings in this test:

test "passes observers to subclasses" do
    FooObserver.instance
    bar = Class.new(Foo)
    assert_equal Foo.observers_count, bar.observers_count
end

I don't know how to check if the method is already defined in the subclass?

  def observe(*models)
    models.flatten!
    models.collect! { |model| model.respond_to?(:to_sym) ? model.to_s.camelize.constantize : model }

    unless self.singleton_class.respond_to?(:observed_classes)
      define_singleton_method(:observed_classes) { models }
    end
  end

@jeremyf
Copy link
Contributor

jeremyf commented Apr 30, 2012

@frodsan There are failing tests:

./activerecord/test/cases/lifecycle_test.rb "test_auto_observer"

@marcandre
Copy link
Contributor

Your patch won't work in cases where observe changes again; see the patch I created (I was working in Observing today)

@frodsan
Copy link
Contributor Author

frodsan commented Apr 30, 2012

@marcandre nice :)

@frodsan frodsan closed this Apr 30, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActiveRecord::Observer.observed_classes doesn't get redefined properly
3 participants