Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (36 sloc) 1.95 KB

PoB: parent_id gets included with :finder_sql association

This sample Rails web-application tends to reproduce a part of Foreman's architecture in order to highlight a potential bug of Rails.

How to fire the bug

Using functional testing

run `rake test`, or the following command:

$ rake test TEST=test/functional/hosts_controller_test.rb

You will get:

DEPRECATION WARNING: The :finder_sql association option is deprecated. Please find an alternative (such as using scopes). (called from /data/theforeman/test-shortcut/app/models/host.rb:5)
Loaded suite /data/theforeman/test-shortcut/vendor/ruby/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
........E
Finished in 0.328863 seconds.

  1) Error:
test_should_update_lookup_value(HostsControllerTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: lookup_values.host_id: SELECT "lookup_values".* FROM "lookup_values"  WHERE "lookup_values"."host_id" = 980190962 AND "lookup_values"."id" IN (980190962)
    app/controllers/hosts_controller.rb:62:in `update'
    app/controllers/hosts_controller.rb:61:in `update'
    test/functional/hosts_controller_test.rb:56:in `test_should_update_lookup_value'

9 tests, 11 assertions, 0 failures, 1 errors
rake aborted!
Command failed with status (1): [/usr/bin/ruby1.8 -I"lib:test" -I"/data/the...]

Tasks: TOP => test:single
(See full trace by running task with --trace)

Manually through the web UI

  1. Create a puppetclass

  2. Create a lookup key

  3. Create a lookup value, with matcher “hostname=foo”

  4. Create a host of name “foo”

  5. Associate the host to the created puppetclass

  6. Edit the host

    Eventually modify the lookup value's value

    Save

You will get:

ActiveRecord::StatementInvalid in HostsController#update

SQLite3::SQLException: no such column: lookup_values.host_id: SELECT "lookup_values".* FROM "lookup_values"  WHERE "lookup_values"."host_id" = 1 AND "lookup_values"."id" IN (1)
Something went wrong with that request. Please try again.