Commit ca261caf authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix-build' into 'master'

Fix autoloading issue in test environment

Always prefer to use the full class namespace when specifying a superclass inside a module, because autoloading can occur in a different order between execution environments.

```ruby
module Foo
  class Base
    def initialize
      raise "This is the wrong super class!"
    end
  end
end

module Foo
  module Bar
    class Sample < Base
      # Inherits from ::Foo::Base because Foo::Bar::Base isn't defined yet
    end
  end
end

module Foo
  module Bar
    class Base
      def initialize
        puts "Success!"
      end
    end
  end
end

> Foo::Bar::Sample.new
=> RuntimeError: This is the wrong super class!
```

The trouble occurs when Rails has already autoloaded `Gitlab::SearchResults` and not `Gitlab::Elastic::SearchResults`. In this case, Rails will never need to autoload `Gitlab::Elastic::SearchResults` because `Gitlab::SearchResults` already matches the superclass. This is why this [build](https://gitlab.com/gitlab-org/gitlab-ee/builds/2464466) only fails when the spec run after `spec/lib/gitlab/search_results_spec.rb`.

/cc @DouweM @rspeicher @vsizov 



See merge request !571
parents 8f67feae 448e7721
module Gitlab module Gitlab
module Elastic module Elastic
class ProjectSearchResults < SearchResults # Always prefer to use the full class namespace when specifying a
# superclass inside a module, because autoloading can occur in a
# different order between execution environments.
class ProjectSearchResults < Gitlab::Elastic::SearchResults
attr_reader :project, :repository_ref attr_reader :project, :repository_ref
def initialize(current_user, project_id, query, repository_ref = nil) def initialize(current_user, project_id, query, repository_ref = nil)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment