Permalink
Browse files

Support controller specs with both Rails 3.0 and 3.1

- also removed a couple of cukes that are obsolete in 3.1
  • Loading branch information...
1 parent 92bad32 commit 4597ecdc528696f29c6e7c219a7c4e0ebbf1990a @dchelimsky dchelimsky committed May 5, 2011
@@ -26,45 +26,3 @@ Feature: be_a_new matcher
"""
When I run `rspec spec/models/widget_spec.rb`
Then the examples should all pass
-
- Scenario: example spec using be_a_new.with
- Given a file named "spec/models/widget_spec.rb" with:
- """
- require "spec_helper"
-
- class Widget < ActiveRecord::Base
- establish_connection :adapter => 'sqlite3',
- :database => ':memory:'
-
- connection.execute <<-eosql
- CREATE TABLE widgets (
- foo_id integer,
- number integer
- )
- eosql
- end
-
- describe Widget do
- context "when initialized with attributes" do
- subject { Widget.new(:foo_id => 1, :number => 1) }
-
- it "has all of the attributes" do
- should be_a_new(Widget).with(:foo_id => 1, :number => 1)
- end
-
- it "has one of the attributes" do
- should be_a_new(Widget).with(:foo_id => 1)
- end
-
- it "has none of the attributes" do
- should_not be_a_new(Widget).with(:blah => 'blah')
- end
-
- it "has one of the attribute values not the same" do
- should_not be_a_new(Widget).with(:foo_id => 2)
- end
- end
- end
- """
- When I run `rspec spec/models/widget_spec.rb`
- Then the examples should all pass
@@ -134,25 +134,6 @@ Feature: view spec
When I run `rspec spec/views`
Then the examples should all pass
- Scenario: passing spec with rendering of Prototype helper update
- Given a file named "spec/views/widgets/prototype_update.html.erb_spec.rb" with:
- """
- require "spec_helper"
-
- describe "render a Prototype helper update" do
- it "hides the status indicator" do
-
- render :update do |page|
- page.hide 'status-indicator'
- end
-
- rendered.should =~ /Element.hide\(\"status-indicator\"\);/
- end
- end
- """
- When I run `rspec spec/views`
- Then the examples should all pass
-
Scenario: spec with view that accesses helper_method helpers
Given a file named "app/views/secrets/index.html.erb" with:
"""
@@ -0,0 +1,5 @@
+require File.expand_path("../base.rb", __FILE__)
+
+extend GemfileBase
+
+gem "rails", "3.1.0.beta1"
@@ -127,15 +127,15 @@ def valid_attributes
<%= file_name %> = <%= class_name %>.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
<%= class_name %>.any_instance.stub(:save).and_return(false)
- put :update, :id => <%= file_name %>.id.to_s
+ put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
end
it "re-renders the 'edit' template" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
<%= class_name %>.any_instance.stub(:save).and_return(false)
- put :update, :id => <%= file_name %>.id.to_s
+ put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
response.should render_template("edit")
end
end
@@ -142,7 +142,13 @@ def _include_controller_helpers
before do
_include_controller_helpers
- controller.controller_path = _controller_path
+ if view.lookup_context.respond_to?(:prefixes)
+ # rails 3.1
+ view.lookup_context.prefixes << _controller_path
@dolzenko

dolzenko Sep 28, 2011

Contributor

Why don't we set controller.controller_path under 3.1 like we do for 3.0? This makes it empty in view specs for me

+ else
+ # rails 3.0
+ controller.controller_path = _controller_path
+ end
controller.request.path_parameters["controller"] = _controller_path
controller.request.path_parameters["action"] = _inferred_action unless _inferred_action =~ /^_/
end

0 comments on commit 4597ecd

Please sign in to comment.