Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

work around lack of application controller by defaulting to ac::base

fixes #922
  • Loading branch information...
commit 87dda86237fe77815170741f8ba1f59096e361da 1 parent c0b2d53
@JonRowe JonRowe authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.