mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-12 23:46:15 +01:00
Next step in upgrading Tracks to Rails 2.2. Some highlights:
* Ran rake rails:update * Added old actionwebservice framework * Updated RSpec and RSpec-Rails * Removed asset_packager plugin (not compatible, Scott no longer maintaining), and replaced with bundle_fu. See the bundle_fu README for more info. * Hacks to UJS and ARTS plugins, which are no longer supported. Probably should move off both UJS and RJS. * Hack to flashobject_helper plugin (upgrade to Rails 2.2-compatible version if/when it comes out.) * Hack to skinny-spec plugin, for Rails 2.2 compatibility. Should check for official release. * Hacks to resource_feeder plugin, for Rails 2.2 compatibility. Should check for official release (not likely) or move off it. * Addressed some deprecation warnings. More to come. * My mobile mime type hackery is no longer necessary with new Rails features. Yay! * Updated environment.rb.tmpl with changes TODO: * Restore view specs marked pending * Fix failing integration tests. * Try selenium tests. * Investigate OpenID support. * Address deprecation warnings. * Consider moving parts of environment.rb to initializers * Address annoying config.gem warning about highline gem
This commit is contained in:
parent
6d11ebd1b0
commit
35ae5fc431
394 changed files with 15184 additions and 9936 deletions
|
|
@ -1,31 +1,51 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
|
||||
describe "AssignsHashProxy" do
|
||||
before(:each) do
|
||||
@object = Object.new
|
||||
@assigns = Hash.new
|
||||
@object.stub!(:assigns).and_return(@assigns)
|
||||
@proxy = Spec::Rails::Example::AssignsHashProxy.new(@object)
|
||||
def orig_assigns
|
||||
@object.assigns
|
||||
end
|
||||
|
||||
it "has [] accessor" do
|
||||
|
||||
before(:each) do
|
||||
@object = Class.new do
|
||||
attr_accessor :assigns
|
||||
end.new
|
||||
@object.assigns = Hash.new
|
||||
@proxy = Spec::Rails::Example::AssignsHashProxy.new self do
|
||||
@object
|
||||
end
|
||||
end
|
||||
|
||||
it "should set ivars on object using string" do
|
||||
@proxy['foo'] = 'bar'
|
||||
@assigns['foo'].should == 'bar'
|
||||
@object.instance_eval{@foo}.should == 'bar'
|
||||
end
|
||||
|
||||
it "should set ivars on object using symbol" do
|
||||
@proxy[:foo] = 'bar'
|
||||
@object.instance_eval{@foo}.should == 'bar'
|
||||
end
|
||||
|
||||
it "should access object's assigns with a string" do
|
||||
@object.assigns['foo'] = 'bar'
|
||||
@proxy['foo'].should == 'bar'
|
||||
end
|
||||
|
||||
it "works for symbol key" do
|
||||
@assigns[:foo] = 2
|
||||
@proxy[:foo].should == 2
|
||||
|
||||
it "should access object's assigns with a symbol" do
|
||||
@object.assigns['foo'] = 'bar'
|
||||
@proxy[:foo].should == 'bar'
|
||||
end
|
||||
|
||||
it "checks for string key before symbol key" do
|
||||
@assigns['foo'] = false
|
||||
@assigns[:foo] = 2
|
||||
@proxy[:foo].should == false
|
||||
it "should access object's ivars with a string" do
|
||||
@object.instance_variable_set('@foo', 'bar')
|
||||
@proxy['foo'].should == 'bar'
|
||||
end
|
||||
|
||||
it "should access object's ivars with a symbol" do
|
||||
@object.instance_variable_set('@foo', 'bar')
|
||||
@proxy[:foo].should == 'bar'
|
||||
end
|
||||
|
||||
it "each method iterates through each element like a Hash" do
|
||||
it "should iterate through each element like a Hash" do
|
||||
values = {
|
||||
'foo' => 1,
|
||||
'bar' => 2,
|
||||
|
|
@ -34,27 +54,43 @@ describe "AssignsHashProxy" do
|
|||
@proxy['foo'] = values['foo']
|
||||
@proxy['bar'] = values['bar']
|
||||
@proxy['baz'] = values['baz']
|
||||
|
||||
|
||||
@proxy.each do |key, value|
|
||||
key.should == key
|
||||
value.should == values[key]
|
||||
end
|
||||
end
|
||||
|
||||
it "delete method deletes the element of passed in key" do
|
||||
@proxy['foo'] = 'bar'
|
||||
@proxy.delete('foo').should == 'bar'
|
||||
|
||||
it "should delete the ivar of passed in key" do
|
||||
@object.instance_variable_set('@foo', 'bar')
|
||||
@proxy.delete('foo')
|
||||
@proxy['foo'].should be_nil
|
||||
end
|
||||
|
||||
it "has_key? detects the presence of a key" do
|
||||
@proxy['foo'] = 'bar'
|
||||
|
||||
it "should delete the assigned element of passed in key" do
|
||||
@object.assigns['foo'] = 'bar'
|
||||
@proxy.delete('foo')
|
||||
@proxy['foo'].should be_nil
|
||||
end
|
||||
|
||||
it "should detect the presence of a key in assigns" do
|
||||
@object.assigns['foo'] = 'bar'
|
||||
@proxy.has_key?('foo').should == true
|
||||
@proxy.has_key?('bar').should == false
|
||||
end
|
||||
|
||||
it "should sets an instance var" do
|
||||
@proxy['foo'] = 'bar'
|
||||
@object.instance_eval { @foo }.should == 'bar'
|
||||
it "should expose values set in example back to the example" do
|
||||
@proxy[:foo] = 'bar'
|
||||
@proxy[:foo].should == 'bar'
|
||||
end
|
||||
|
||||
it "should allow assignment of false via proxy" do
|
||||
@proxy['foo'] = false
|
||||
@proxy['foo'].should be_false
|
||||
end
|
||||
|
||||
it "should allow assignment of false" do
|
||||
@object.instance_variable_set('@foo',false)
|
||||
@proxy['foo'].should be_false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ require 'controller_spec_controller'
|
|||
describe "A controller example running in #{mode} mode", :type => :controller do
|
||||
controller_name :controller_spec
|
||||
integrate_views if mode == 'integration'
|
||||
|
||||
|
||||
specify "this example should be pending, not an error"
|
||||
|
||||
it "should provide controller.session as session" do
|
||||
get 'action_with_template'
|
||||
session.should equal(controller.session)
|
||||
|
|
@ -38,24 +40,24 @@ require 'controller_spec_controller'
|
|||
response.should render_template("_partial")
|
||||
end
|
||||
|
||||
it "should allow specifying a partial with expect_render" do
|
||||
controller.expect_render(:partial => "controller_spec/partial")
|
||||
it "should allow specifying a partial with should_receive(:render)" do
|
||||
controller.should_receive(:render).with(:partial => "controller_spec/partial")
|
||||
get 'action_with_partial'
|
||||
end
|
||||
|
||||
it "should allow specifying a partial with expect_render with object" do
|
||||
controller.expect_render(:partial => "controller_spec/partial", :object => "something")
|
||||
it "should allow specifying a partial with should_receive(:render) with object" do
|
||||
controller.should_receive(:render).with(:partial => "controller_spec/partial", :object => "something")
|
||||
get 'action_with_partial_with_object', :thing => "something"
|
||||
end
|
||||
|
||||
it "should allow specifying a partial with expect_render with locals" do
|
||||
controller.expect_render(:partial => "controller_spec/partial", :locals => {:thing => "something"})
|
||||
it "should allow specifying a partial with should_receive(:render) with locals" do
|
||||
controller.should_receive(:render).with(:partial => "controller_spec/partial", :locals => {:thing => "something"})
|
||||
get 'action_with_partial_with_locals', :thing => "something"
|
||||
end
|
||||
|
||||
it "should yield to render :update" do
|
||||
template = stub("template")
|
||||
controller.expect_render(:update).and_yield(template)
|
||||
controller.should_receive(:render).with(:update).and_yield(template)
|
||||
template.should_receive(:replace).with(:bottom, "replace_me", :partial => "non_existent_partial")
|
||||
get 'action_with_render_update'
|
||||
end
|
||||
|
|
@ -87,6 +89,71 @@ require 'controller_spec_controller'
|
|||
end.should_not raise_error
|
||||
end
|
||||
|
||||
describe "handling should_receive(:render)" do
|
||||
it "should warn" do
|
||||
controller.should_receive(:render).with(:template => "controller_spec/action_with_template")
|
||||
get :action_with_template
|
||||
end
|
||||
end
|
||||
|
||||
describe "handling should_not_receive(:render)" do
|
||||
it "should warn" do
|
||||
controller.should_not_receive(:render).with(:template => "the/wrong/template")
|
||||
get :action_with_template
|
||||
end
|
||||
end
|
||||
|
||||
describe "handling deprecated expect_render" do
|
||||
it "should warn" do
|
||||
Kernel.should_receive(:warn).with(/expect_render is deprecated/)
|
||||
controller.expect_render(:template => "controller_spec/action_with_template")
|
||||
get :action_with_template
|
||||
end
|
||||
end
|
||||
|
||||
describe "handling deprecated stub_render" do
|
||||
it "should warn" do
|
||||
Kernel.should_receive(:warn).with(/stub_render is deprecated/)
|
||||
controller.stub_render(:template => "controller_spec/action_with_template")
|
||||
get :action_with_template
|
||||
end
|
||||
end
|
||||
|
||||
describe "setting cookies in the request" do
|
||||
|
||||
it "should support a String key" do
|
||||
cookies['cookie_key'] = 'cookie value'
|
||||
get 'action_which_gets_cookie', :expected => "cookie value"
|
||||
end
|
||||
|
||||
it "should support a Symbol key" do
|
||||
cookies[:cookie_key] = 'cookie value'
|
||||
get 'action_which_gets_cookie', :expected => "cookie value"
|
||||
end
|
||||
|
||||
if Rails::VERSION::STRING >= "2.0.0"
|
||||
it "should support a Hash value" do
|
||||
cookies[:cookie_key] = {'value' => 'cookie value', 'path' => '/not/default'}
|
||||
get 'action_which_gets_cookie', :expected => {'value' => 'cookie value', 'path' => '/not/default'}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "reading cookies from the response" do
|
||||
|
||||
it "should support a Symbol key" do
|
||||
get 'action_which_sets_cookie', :value => "cookie value"
|
||||
cookies[:cookie_key].value.should == ["cookie value"]
|
||||
end
|
||||
|
||||
it "should support a String key" do
|
||||
get 'action_which_sets_cookie', :value => "cookie value"
|
||||
cookies['cookie_key'].value.should == ["cookie value"]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it "should support custom routes" do
|
||||
route_for(:controller => "custom_route_spec", :action => "custom_route").should == "/custom_route"
|
||||
end
|
||||
|
|
@ -108,22 +175,9 @@ require 'controller_spec_controller'
|
|||
assigns[:indirect_assigns_key].should == :indirect_assigns_key_value
|
||||
end
|
||||
|
||||
it "should expose the assigns hash directly" do
|
||||
get 'action_setting_the_assigns_hash'
|
||||
assigns[:direct_assigns_key].should == :direct_assigns_key_value
|
||||
end
|
||||
|
||||
it "should complain when calling should_receive(:render) on the controller" do
|
||||
lambda {
|
||||
controller.should_receive(:render)
|
||||
}.should raise_error(RuntimeError, /should_receive\(:render\) has been disabled/)
|
||||
end
|
||||
|
||||
it "should complain when calling stub!(:render) on the controller" do
|
||||
controller.extend Spec::Mocks::Methods
|
||||
lambda {
|
||||
controller.stub!(:render)
|
||||
}.should raise_error(RuntimeError, /stub!\(:render\) has been disabled/)
|
||||
it "should expose instance vars through the assigns hash that are set to false" do
|
||||
get 'action_that_assigns_false_to_a_variable'
|
||||
assigns[:a_variable].should be_false
|
||||
end
|
||||
|
||||
it "should NOT complain when calling should_receive with arguments other than :render" do
|
||||
|
|
@ -132,6 +186,12 @@ require 'controller_spec_controller'
|
|||
controller.rspec_verify
|
||||
}.should raise_error(Exception, /expected :anything_besides_render/)
|
||||
end
|
||||
|
||||
it "should not run a skipped before_filter" do
|
||||
lambda {
|
||||
get 'action_with_skipped_before_filter'
|
||||
}.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "Given a controller spec for RedirectSpecController running in #{mode} mode", :type => :controller do
|
||||
|
|
@ -172,6 +232,19 @@ require 'controller_spec_controller'
|
|||
|
||||
end
|
||||
|
||||
['integration', 'isolation'].each do |mode|
|
||||
describe "A controller example running in #{mode} mode", :type => :controller do
|
||||
controller_name :controller_inheriting_from_application_controller
|
||||
integrate_views if mode == 'integration'
|
||||
|
||||
it "should only have a before filter inherited from ApplicationController run once..." do
|
||||
controller.should_receive(:i_should_only_be_run_once).once
|
||||
get :action_with_inherited_before_filter
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe ControllerSpecController, :type => :controller do
|
||||
it "should not require naming the controller if describe is passed a type" do
|
||||
end
|
||||
|
|
|
|||
74
vendor/plugins/rspec-rails/spec/rails/example/cookies_proxy_spec.rb
vendored
Normal file
74
vendor/plugins/rspec-rails/spec/rails/example/cookies_proxy_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
|
||||
class CookiesProxyExamplesController < ActionController::Base
|
||||
def index
|
||||
cookies[:key] = cookies[:key]
|
||||
end
|
||||
end
|
||||
|
||||
module Spec
|
||||
module Rails
|
||||
module Example
|
||||
describe CookiesProxy, :type => :controller do
|
||||
controller_name :cookies_proxy_examples
|
||||
|
||||
describe "with a String key" do
|
||||
|
||||
it "should accept a String value" do
|
||||
cookies = CookiesProxy.new(self)
|
||||
cookies['key'] = 'value'
|
||||
get :index
|
||||
cookies['key'].should == ['value']
|
||||
end
|
||||
|
||||
if Rails::VERSION::STRING >= "2.0.0"
|
||||
it "should accept a Hash value" do
|
||||
cookies = CookiesProxy.new(self)
|
||||
cookies['key'] = { :value => 'value', :expires => expiration = 1.hour.from_now, :path => path = '/path' }
|
||||
get :index
|
||||
cookies['key'].should == ['value']
|
||||
cookies['key'].value.should == ['value']
|
||||
cookies['key'].expires.should == expiration
|
||||
cookies['key'].path.should == path
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "with a Symbol key" do
|
||||
|
||||
it "should accept a String value" do
|
||||
example_cookies = CookiesProxy.new(self)
|
||||
example_cookies[:key] = 'value'
|
||||
get :index
|
||||
example_cookies[:key].should == ['value']
|
||||
end
|
||||
|
||||
if Rails::VERSION::STRING >= "2.0.0"
|
||||
it "should accept a Hash value" do
|
||||
example_cookies = CookiesProxy.new(self)
|
||||
example_cookies[:key] = { :value => 'value', :expires => expiration = 1.hour.from_now, :path => path = '/path' }
|
||||
get :index
|
||||
example_cookies[:key].should == ['value']
|
||||
example_cookies[:key].value.should == ['value']
|
||||
example_cookies[:key].expires.should == expiration
|
||||
example_cookies[:key].path.should == path
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#delete" do
|
||||
it "should delete from the response cookies" do
|
||||
example_cookies = CookiesProxy.new(self)
|
||||
response_cookies = mock('cookies')
|
||||
response.should_receive(:cookies).and_return(response_cookies)
|
||||
response_cookies.should_receive(:delete).with('key')
|
||||
example_cookies.delete :key
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -82,14 +82,14 @@ describe "A template that includes a partial", :type => :view do
|
|||
response.should have_tag('div', "This is text from a method in the ApplicationHelper")
|
||||
end
|
||||
|
||||
it "should pass expect_render with the right partial" do
|
||||
template.expect_render(:partial => 'partial')
|
||||
it "should pass should_receive(:render) with the right partial" do
|
||||
template.should_receive(:render).with(:partial => 'partial')
|
||||
render!
|
||||
template.verify_rendered
|
||||
end
|
||||
|
||||
it "should fail expect_render with the wrong partial" do
|
||||
template.expect_render(:partial => 'non_existent')
|
||||
it "should fail should_receive(:render) with the wrong partial" do
|
||||
template.should_receive(:render).with(:partial => 'non_existent')
|
||||
render!
|
||||
begin
|
||||
template.verify_rendered
|
||||
|
|
@ -99,14 +99,14 @@ describe "A template that includes a partial", :type => :view do
|
|||
end
|
||||
end
|
||||
|
||||
it "should pass expect_render when a partial is expected twice and happens twice" do
|
||||
template.expect_render(:partial => 'partial_used_twice').twice
|
||||
it "should pass should_receive(:render) when a partial is expected twice and happens twice" do
|
||||
template.should_receive(:render).with(:partial => 'partial_used_twice').twice
|
||||
render!
|
||||
template.verify_rendered
|
||||
end
|
||||
|
||||
it "should pass expect_render when a partial is expected once and happens twice" do
|
||||
template.expect_render(:partial => 'partial_used_twice')
|
||||
it "should pass should_receive(:render) when a partial is expected once and happens twice" do
|
||||
template.should_receive(:render).with(:partial => 'partial_used_twice')
|
||||
render!
|
||||
begin
|
||||
template.verify_rendered
|
||||
|
|
@ -116,17 +116,17 @@ describe "A template that includes a partial", :type => :view do
|
|||
end
|
||||
end
|
||||
|
||||
it "should fail expect_render with the right partial but wrong options" do
|
||||
template.expect_render(:partial => 'partial', :locals => {:thing => Object.new})
|
||||
it "should fail should_receive(:render) with the right partial but wrong options" do
|
||||
template.should_receive(:render).with(:partial => 'partial', :locals => {:thing => Object.new})
|
||||
render!
|
||||
lambda {template.verify_rendered}.should raise_error(Spec::Mocks::MockExpectationError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "A partial that includes a partial", :type => :view do
|
||||
it "should support expect_render with nested partial" do
|
||||
it "should support should_receive(:render) with nested partial" do
|
||||
obj = Object.new
|
||||
template.expect_render(:partial => 'partial', :object => obj)
|
||||
template.should_receive(:render).with(:partial => 'partial', :object => obj)
|
||||
render :partial => "view_spec/partial_with_sub_partial", :locals => { :partial => obj }
|
||||
end
|
||||
end
|
||||
|
|
@ -141,7 +141,7 @@ describe "A view that includes a partial using :collection and :spacer_template"
|
|||
end
|
||||
|
||||
it "should render the partial" do
|
||||
template.expect_render(:partial => 'partial',
|
||||
template.should_receive(:render).with(:partial => 'partial',
|
||||
:collection => ['Alice', 'Bob'],
|
||||
:spacer_template => 'spacer')
|
||||
render "view_spec/template_with_partial_using_collection"
|
||||
|
|
@ -149,37 +149,19 @@ describe "A view that includes a partial using :collection and :spacer_template"
|
|||
|
||||
end
|
||||
|
||||
describe "A view that includes a partial using an array as partial_path", :type => :view do
|
||||
before(:each) do
|
||||
module ActionView::Partials
|
||||
def render_template_with_partial_with_array_support(partial_path, local_assigns = nil, deprecated_local_assigns = nil)
|
||||
if partial_path.is_a?(Array)
|
||||
"Array Partial"
|
||||
else
|
||||
render_partial_without_array_support(partial_path, local_assigns, deprecated_local_assigns)
|
||||
end
|
||||
end
|
||||
|
||||
alias :render_partial_without_array_support :render_partial
|
||||
alias :render_partial :render_template_with_partial_with_array_support
|
||||
if Rails::VERSION::MAJOR >= 2
|
||||
describe "A view that includes a partial using an array as partial_path", :type => :view do
|
||||
before(:each) do
|
||||
renderable_object = Object.new
|
||||
renderable_object.stub!(:name).and_return("Renderable Object")
|
||||
assigns[:array] = [renderable_object]
|
||||
end
|
||||
|
||||
@array = ['Alice', 'Bob']
|
||||
assigns[:array] = @array
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
module ActionView::Partials
|
||||
alias :render_template_with_partial_with_array_support :render_partial
|
||||
alias :render_partial :render_partial_without_array_support
|
||||
undef render_template_with_partial_with_array_support
|
||||
it "should render the array passed through to render_partial without modification" do
|
||||
render "view_spec/template_with_partial_with_array"
|
||||
response.body.should match(/^Renderable Object$/)
|
||||
end
|
||||
end
|
||||
|
||||
it "should render have the array passed through to render_partial without modification" do
|
||||
render "view_spec/template_with_partial_with_array"
|
||||
response.body.should match(/^Array Partial$/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Different types of renders (not :template)", :type => :view do
|
||||
|
|
@ -239,6 +221,20 @@ describe "An instantiated ViewExampleGroupController", :type => :view do
|
|||
end
|
||||
end
|
||||
|
||||
describe "a block helper", :type => :view do
|
||||
it "should not yield when not told to in the example" do
|
||||
template.should_receive(:if_allowed)
|
||||
render "view_spec/block_helper"
|
||||
response.should_not have_tag("div","block helper was rendered")
|
||||
end
|
||||
|
||||
it "should yield when told to in the example" do
|
||||
template.should_receive(:if_allowed).and_yield
|
||||
render "view_spec/block_helper"
|
||||
response.should have_tag("div","block helper was rendered")
|
||||
end
|
||||
end
|
||||
|
||||
describe "render :inline => ...", :type => :view do
|
||||
it "should render ERB right in the spec" do
|
||||
render :inline => %|<%= text_field_tag('field_name', 'Value') %>|
|
||||
|
|
@ -270,3 +266,15 @@ module Spec
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "bug http://rspec.lighthouseapp.com/projects/5645/tickets/510", :type => :view do
|
||||
describe "a view example with should_not_receive" do
|
||||
it "should render the view" do
|
||||
obj = mock('model')
|
||||
obj.should_receive(:render_partial?).and_return false
|
||||
assigns[:obj] = obj
|
||||
template.should_not_receive(:render).with(:partial => 'some_partial')
|
||||
render "view_spec/should_not_receive"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue