Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Don't assume presence of ApplicationController for anonymous controllers. #924

Merged
merged 2 commits into from

4 participants

@JonRowe
Owner

Apparently some of our developers don't have a root ApplicationController so
let's check for it's presence and use ActionController::Base when it's not
around. Should fix #922.

@JonRowe
Owner
@alindeman
Collaborator

Sweet! Thanks for doing this. When Travis goes green, I'll merge.

@alindeman
Collaborator

Darn it! Fooled by def

@alindeman alindeman added this to the 3.0.0.beta2 milestone
@alindeman alindeman merged commit 2a44340 into master
@alindeman alindeman deleted the dont_assume_root_controller_is_application_controller branch
@billychan

That's nice!

@mhenrixon

So nice of you to fix that! Thanks a bunch :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 6, 2014
  1. @JonRowe
Commits on Feb 10, 2014
  1. @alindeman

    Changelog [ci skip]

    alindeman authored
This page is out of date. Refresh to see the latest.
View
2  Changelog.md
@@ -8,6 +8,8 @@ Bug fixes
* Routes are drawn correctly for anonymous controllers with abstract
parents. (Billy Chan)
* Loads ActiveSupport properly to support changes in Rails 4.1. (Andy Lindeman)
+* Anonymous controllers inherit from `ActionController::Base` if `ApplicationController`
+ is not present. (Jon Rowe)
Enhancements
View
5 lib/rspec/rails/example/controller_example_group.rb
@@ -58,11 +58,12 @@ def controller(base_class = nil, &body)
if RSpec.configuration.infer_base_class_for_anonymous_controllers?
base_class ||= controller_class
end
- base_class ||= ApplicationController
+ base_class ||= defined?(ApplicationController) ? ApplicationController : ActionController::Base
metadata[:example_group][:described_class] = Class.new(base_class) do
def self.name
- if superclass == ApplicationController || superclass.abstract?
+ root_controller = defined?(ApplicationController) ? ApplicationController : ActionController::Base
+ if superclass == root_controller || superclass.abstract?
"AnonymousController"
else
superclass.to_s
View
46 spec/rspec/rails/example/controller_example_group_spec.rb
@@ -85,20 +85,46 @@ module RSpec::Rails
expect(RSpec.configuration.infer_base_class_for_anonymous_controllers).to be_truthy
end
- it "infers the anonymous controller class when infer_base_class_for_anonymous_controllers is true" do
- allow(RSpec.configuration).to receive(:infer_base_class_for_anonymous_controllers?).and_return(true)
- group.controller { }
+ context "when infer_base_class_for_anonymous_controllers is true" do
+ before do
+ allow(RSpec.configuration).to receive(:infer_base_class_for_anonymous_controllers?).and_return(true)
+ end
- controller_class = group.metadata[:example_group][:described_class]
- expect(controller_class.superclass).to eq(group.controller_class)
+ it "infers the anonymous controller class" do
+ group.controller { }
+
+ controller_class = group.metadata[:example_group][:described_class]
+ expect(controller_class.superclass).to eq(group.controller_class)
+ end
+
+ it "infers the anonymous controller class when no ApplicationController is present" do
+ hide_const '::ApplicationController'
+ group.controller { }
+
+ controller_class = group.metadata[:example_group][:described_class]
+ expect(controller_class.superclass).to eq(group.controller_class)
+ end
end
- it "sets the anonymous controller class to ApplicationController when infer_base_class_for_anonymous_controllers is false" do
- allow(RSpec.configuration).to receive(:infer_base_class_for_anonymous_controllers?).and_return(false)
- group.controller { }
+ context "when infer_base_class_for_anonymous_controllers is false" do
+ before do
+ allow(RSpec.configuration).to receive(:infer_base_class_for_anonymous_controllers?).and_return(false)
+ end
- controller_class = group.metadata[:example_group][:described_class]
- expect(controller_class.superclass).to eq(ApplicationController)
+ it "sets the anonymous controller class to ApplicationController" do
+ group.controller { }
+
+ controller_class = group.metadata[:example_group][:described_class]
+ expect(controller_class.superclass).to eq(ApplicationController)
+ end
+
+ it "sets the anonymous controller class to ActiveController::Base when no ApplicationController is present" do
+ hide_const '::ApplicationController'
+ group.controller { }
+
+ controller_class = group.metadata[:example_group][:described_class]
+ expect(controller_class.superclass).to eq(ActionController::Base)
+ end
end
end
Something went wrong with that request. Please try again.