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

fixes #9025 - reflect on association for _name(s) methods #2094

Closed
wants to merge 1 commit into from

Conversation

stbenjam
Copy link
Member

The current method doesn't work for associations in another module (like in plugins).

In the Salt plugin, some_host.salt_environment_name resolves to SaltEnvironment instead of ForemanSalt::SaltEnvironment. This PR changes how the class is resolved, by instead relying on active record reflection.

@dLobatog
Copy link
Member

@stbenjam Thanks, works well (I tried with foreman_salt). Can you write a test with a dummy class demonstrating it?

@stbenjam
Copy link
Member Author

@elobato Added a test... Testing that is actually a bit convoluted, and has_many_common.rb already has some tests that validate it's at least working correctly (for Foreman, anyway).

We need another gem called Temping in order to really test the association bits on a plugin model. I have it working, it's maybe a bit too clever?

@dLobatog
Copy link
Member

How about:

  class ::FakePlugin; end 
  class ::FakePlugin::FakeModel 
  end

  test "should return plugin associations" do
    Host::Managed.class_eval do
      belongs_to :fake_model, :class_name => '::FakePlugin::FakeModel'
    end 
    assert_equal FactoryGirl.build(:host).assoc_klass(:fake_model), FakePlugin::FakeModel
  end 

@stbenjam
Copy link
Member Author

@elobato Updated. Thanks, I've used your test and it's 🍏 👍

@dLobatog
Copy link
Member

Merged as 1cf860b, thanks @stbenjam !

@dLobatog dLobatog closed this Jan 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants