richzhou-rspec-rails 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. data/.document +7 -0
  2. data/.gitignore +8 -0
  3. data/Contribute.rdoc +4 -0
  4. data/Gemfile +4 -0
  5. data/History.rdoc +321 -0
  6. data/License.txt +33 -0
  7. data/Manifest.txt +165 -0
  8. data/README.rdoc +48 -0
  9. data/Rakefile +12 -0
  10. data/TODO.txt +17 -0
  11. data/Upgrade.rdoc +148 -0
  12. data/generators/integration_spec/integration_spec_generator.rb +10 -0
  13. data/generators/integration_spec/templates/integration_spec.rb +4 -0
  14. data/generators/rspec/CHANGES +1 -0
  15. data/generators/rspec/rspec_generator.rb +72 -0
  16. data/generators/rspec/templates/previous_failures.txt +0 -0
  17. data/generators/rspec/templates/rcov.opts +2 -0
  18. data/generators/rspec/templates/rspec.rake +146 -0
  19. data/generators/rspec/templates/script/autospec +6 -0
  20. data/generators/rspec/templates/script/spec +10 -0
  21. data/generators/rspec/templates/spec.opts +4 -0
  22. data/generators/rspec/templates/spec_helper.rb +54 -0
  23. data/generators/rspec_controller/USAGE +33 -0
  24. data/generators/rspec_controller/rspec_controller_generator.rb +47 -0
  25. data/generators/rspec_controller/templates/controller_spec.rb +25 -0
  26. data/generators/rspec_controller/templates/helper_spec.rb +11 -0
  27. data/generators/rspec_controller/templates/view_spec.rb +12 -0
  28. data/generators/rspec_default_values.rb +28 -0
  29. data/generators/rspec_model/USAGE +18 -0
  30. data/generators/rspec_model/rspec_model_generator.rb +35 -0
  31. data/generators/rspec_model/templates/model_spec.rb +13 -0
  32. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +154 -0
  33. data/generators/rspec_scaffold/templates/controller_spec.rb +131 -0
  34. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +25 -0
  35. data/generators/rspec_scaffold/templates/helper_spec.rb +11 -0
  36. data/generators/rspec_scaffold/templates/index_erb_spec.rb +27 -0
  37. data/generators/rspec_scaffold/templates/new_erb_spec.rb +25 -0
  38. data/generators/rspec_scaffold/templates/routing_spec.rb +33 -0
  39. data/generators/rspec_scaffold/templates/show_erb_spec.rb +22 -0
  40. data/init.rb +9 -0
  41. data/lib/autotest/discover.rb +5 -0
  42. data/lib/autotest/rails_rspec.rb +76 -0
  43. data/lib/spec/rails.rb +26 -0
  44. data/lib/spec/rails/example.rb +48 -0
  45. data/lib/spec/rails/example/assigns_hash_proxy.rb +39 -0
  46. data/lib/spec/rails/example/controller_example_group.rb +285 -0
  47. data/lib/spec/rails/example/cookies_proxy.rb +29 -0
  48. data/lib/spec/rails/example/functional_example_group.rb +106 -0
  49. data/lib/spec/rails/example/helper_example_group.rb +153 -0
  50. data/lib/spec/rails/example/integration_example_group.rb +16 -0
  51. data/lib/spec/rails/example/model_example_group.rb +15 -0
  52. data/lib/spec/rails/example/render_observer.rb +82 -0
  53. data/lib/spec/rails/example/routing_example_group.rb +16 -0
  54. data/lib/spec/rails/example/routing_helpers.rb +66 -0
  55. data/lib/spec/rails/example/view_example_group.rb +203 -0
  56. data/lib/spec/rails/extensions.rb +11 -0
  57. data/lib/spec/rails/extensions/action_controller/rescue.rb +42 -0
  58. data/lib/spec/rails/extensions/action_controller/test_case.rb +16 -0
  59. data/lib/spec/rails/extensions/action_controller/test_response.rb +21 -0
  60. data/lib/spec/rails/extensions/action_view/base.rb +35 -0
  61. data/lib/spec/rails/extensions/active_record/base.rb +45 -0
  62. data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
  63. data/lib/spec/rails/extensions/spec/matchers/have.rb +23 -0
  64. data/lib/spec/rails/extensions/spec/runner/configuration.rb +45 -0
  65. data/lib/spec/rails/interop/testcase.rb +14 -0
  66. data/lib/spec/rails/matchers.rb +32 -0
  67. data/lib/spec/rails/matchers/ar_be_valid.rb +27 -0
  68. data/lib/spec/rails/matchers/assert_select.rb +180 -0
  69. data/lib/spec/rails/matchers/change.rb +13 -0
  70. data/lib/spec/rails/matchers/have_text.rb +57 -0
  71. data/lib/spec/rails/matchers/include_text.rb +54 -0
  72. data/lib/spec/rails/matchers/redirect_to.rb +126 -0
  73. data/lib/spec/rails/matchers/render_template.rb +129 -0
  74. data/lib/spec/rails/matchers/route_to.rb +149 -0
  75. data/lib/spec/rails/mocks.rb +140 -0
  76. data/lib/spec/rails/version.rb +16 -0
  77. data/rspec-rails.gemspec +25 -0
  78. data/spec/autotest/mappings_spec.rb +86 -0
  79. data/spec/rails_suite.rb +7 -0
  80. data/spec/resources/controllers/action_view_base_spec_controller.rb +2 -0
  81. data/spec/resources/controllers/application.rb +9 -0
  82. data/spec/resources/controllers/controller_spec_controller.rb +127 -0
  83. data/spec/resources/controllers/example.txt +1 -0
  84. data/spec/resources/controllers/redirect_spec_controller.rb +70 -0
  85. data/spec/resources/controllers/render_spec_controller.rb +34 -0
  86. data/spec/resources/controllers/rjs_spec_controller.rb +58 -0
  87. data/spec/resources/helpers/addition_helper.rb +5 -0
  88. data/spec/resources/helpers/explicit_helper.rb +46 -0
  89. data/spec/resources/helpers/more_explicit_helper.rb +5 -0
  90. data/spec/resources/helpers/plugin_application_helper.rb +6 -0
  91. data/spec/resources/helpers/view_spec_helper.rb +13 -0
  92. data/spec/resources/models/animal.rb +4 -0
  93. data/spec/resources/models/person.rb +18 -0
  94. data/spec/resources/models/thing.rb +3 -0
  95. data/spec/resources/views/controller_spec/_partial.html.erb +0 -0
  96. data/spec/resources/views/controller_spec/action_setting_flash_after_session_reset.html.erb +1 -0
  97. data/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.html.erb +1 -0
  98. data/spec/resources/views/controller_spec/action_setting_the_assigns_hash.html.erb +0 -0
  99. data/spec/resources/views/controller_spec/action_with_errors_in_template.html.erb +1 -0
  100. data/spec/resources/views/controller_spec/action_with_template.html.erb +1 -0
  101. data/spec/resources/views/controller_spec/non_existent_action_with_existent_template.html.erb +1 -0
  102. data/spec/resources/views/layouts/application.html.erb +0 -0
  103. data/spec/resources/views/layouts/simple.html.erb +0 -0
  104. data/spec/resources/views/objects/_object.html.erb +1 -0
  105. data/spec/resources/views/render_spec/_a_partial.html.erb +0 -0
  106. data/spec/resources/views/render_spec/action_with_alternate_layout.html.erb +0 -0
  107. data/spec/resources/views/render_spec/some_action.html.erb +0 -0
  108. data/spec/resources/views/render_spec/some_action.js.rjs +1 -0
  109. data/spec/resources/views/rjs_spec/_replacement_partial.html.erb +1 -0
  110. data/spec/resources/views/rjs_spec/hide_div.js.rjs +1 -0
  111. data/spec/resources/views/rjs_spec/hide_page_element.js.rjs +1 -0
  112. data/spec/resources/views/rjs_spec/insert_html.js.rjs +1 -0
  113. data/spec/resources/views/rjs_spec/replace.js.rjs +1 -0
  114. data/spec/resources/views/rjs_spec/replace_html.js.rjs +1 -0
  115. data/spec/resources/views/rjs_spec/replace_html_with_partial.js.rjs +1 -0
  116. data/spec/resources/views/rjs_spec/visual_effect.js.rjs +1 -0
  117. data/spec/resources/views/rjs_spec/visual_toggle_effect.js.rjs +1 -0
  118. data/spec/resources/views/tag_spec/no_tags.html.erb +1 -0
  119. data/spec/resources/views/tag_spec/single_div_with_no_attributes.html.erb +1 -0
  120. data/spec/resources/views/tag_spec/single_div_with_one_attribute.html.erb +1 -0
  121. data/spec/resources/views/view_spec/_partial.html.erb +2 -0
  122. data/spec/resources/views/view_spec/_partial_used_twice.html.erb +0 -0
  123. data/spec/resources/views/view_spec/_partial_with_local_variable.html.erb +1 -0
  124. data/spec/resources/views/view_spec/_partial_with_sub_partial.html.erb +1 -0
  125. data/spec/resources/views/view_spec/_spacer.html.erb +1 -0
  126. data/spec/resources/views/view_spec/accessor.html.erb +6 -0
  127. data/spec/resources/views/view_spec/block_helper.html.erb +3 -0
  128. data/spec/resources/views/view_spec/entry_form.html.erb +2 -0
  129. data/spec/resources/views/view_spec/explicit_helper.html.erb +2 -0
  130. data/spec/resources/views/view_spec/foo/show.html.erb +1 -0
  131. data/spec/resources/views/view_spec/implicit_helper.html.erb +2 -0
  132. data/spec/resources/views/view_spec/multiple_helpers.html.erb +3 -0
  133. data/spec/resources/views/view_spec/path_params.html.erb +1 -0
  134. data/spec/resources/views/view_spec/should_not_receive.html.erb +3 -0
  135. data/spec/resources/views/view_spec/template_with_partial.html.erb +5 -0
  136. data/spec/resources/views/view_spec/template_with_partial_using_collection.html.erb +3 -0
  137. data/spec/resources/views/view_spec/template_with_partial_with_array.html.erb +1 -0
  138. data/spec/resources/views/view_spec/view_helpers.html.erb +1 -0
  139. data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +109 -0
  140. data/spec/spec/rails/example/configuration_spec.rb +67 -0
  141. data/spec/spec/rails/example/controller_example_group_spec.rb +307 -0
  142. data/spec/spec/rails/example/controller_isolation_spec.rb +75 -0
  143. data/spec/spec/rails/example/cookies_proxy_spec.rb +87 -0
  144. data/spec/spec/rails/example/error_handling_spec.rb +90 -0
  145. data/spec/spec/rails/example/example_group_factory_spec.rb +112 -0
  146. data/spec/spec/rails/example/helper_example_group_spec.rb +247 -0
  147. data/spec/spec/rails/example/model_example_group_spec.rb +32 -0
  148. data/spec/spec/rails/example/routing_example_group_spec.rb +9 -0
  149. data/spec/spec/rails/example/shared_routing_example_group_examples.rb +241 -0
  150. data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +33 -0
  151. data/spec/spec/rails/example/view_example_group_spec.rb +346 -0
  152. data/spec/spec/rails/extensions/action_view_base_spec.rb +79 -0
  153. data/spec/spec/rails/extensions/active_record_spec.rb +14 -0
  154. data/spec/spec/rails/interop/testcase_spec.rb +70 -0
  155. data/spec/spec/rails/matchers/ar_be_valid_spec.rb +19 -0
  156. data/spec/spec/rails/matchers/assert_select_spec.rb +835 -0
  157. data/spec/spec/rails/matchers/errors_on_spec.rb +37 -0
  158. data/spec/spec/rails/matchers/have_text_spec.rb +69 -0
  159. data/spec/spec/rails/matchers/include_text_spec.rb +62 -0
  160. data/spec/spec/rails/matchers/redirect_to_spec.rb +253 -0
  161. data/spec/spec/rails/matchers/render_template_spec.rb +208 -0
  162. data/spec/spec/rails/matchers/should_change_spec.rb +15 -0
  163. data/spec/spec/rails/mocks/ar_classes.rb +10 -0
  164. data/spec/spec/rails/mocks/mock_model_spec.rb +112 -0
  165. data/spec/spec/rails/mocks/stub_model_spec.rb +80 -0
  166. data/spec/spec/rails/sample_modified_fixture.rb +8 -0
  167. data/spec/spec/rails/sample_spec.rb +8 -0
  168. data/spec/spec/rails/spec_spec.rb +11 -0
  169. data/spec/spec_helper.rb +78 -0
  170. metadata +363 -0
@@ -0,0 +1,140 @@
1
+ module Spec
2
+ module Rails
3
+
4
+ class IllegalDataAccessException < StandardError; end
5
+
6
+ module Mocks
7
+
8
+ # Creates a mock object instance for a +model_class+ with common
9
+ # methods stubbed out. Additional methods may be easily stubbed (via
10
+ # add_stubs) if +stubs+ is passed.
11
+ def mock_model(model_class, options_and_stubs = {})
12
+ id = options_and_stubs[:id] || next_id
13
+ options_and_stubs = options_and_stubs.reverse_merge({
14
+ :id => id,
15
+ :to_param => id.to_s,
16
+ :new_record? => false,
17
+ :destroyed? => false,
18
+ :marked_for_destruction? => false,
19
+ :errors => stub("errors", :count => 0)
20
+ })
21
+ m = mock("#{model_class.name}_#{id}", options_and_stubs)
22
+ m.__send__(:__mock_proxy).instance_eval <<-CODE
23
+ def @target.as_new_record
24
+ self.stub(:id).and_return nil
25
+ self.stub(:to_param).and_return nil
26
+ self.stub(:new_record?).and_return true
27
+ self
28
+ end
29
+ def @target.to_str
30
+ self.to_s
31
+ end
32
+ def @target.is_a?(other)
33
+ #{model_class}.ancestors.include?(other)
34
+ end
35
+ def @target.kind_of?(other)
36
+ #{model_class}.ancestors.include?(other)
37
+ end
38
+ def @target.instance_of?(other)
39
+ other == #{model_class}
40
+ end
41
+ def @target.class
42
+ #{model_class}
43
+ end
44
+ CODE
45
+ yield m if block_given?
46
+ m
47
+ end
48
+
49
+ module ModelStubber
50
+ def connection
51
+ raise Spec::Rails::IllegalDataAccessException.new("stubbed models are not allowed to access the database")
52
+ end
53
+ def new_record?
54
+ id.nil?
55
+ end
56
+ def as_new_record
57
+ self.id = nil
58
+ self
59
+ end
60
+ end
61
+
62
+ # :call-seq:
63
+ # stub_model(Model)
64
+ # stub_model(Model).as_new_record
65
+ # stub_model(Model, hash_of_stubs)
66
+ # stub_model(Model, instance_variable_name, hash_of_stubs)
67
+ #
68
+ # Creates an instance of +Model+ that is prohibited from accessing the
69
+ # database*. For each key in +hash_of_stubs+, if the model has a
70
+ # matching attribute (determined by asking it) are simply assigned the
71
+ # submitted values. If the model does not have a matching attribute, the
72
+ # key/value pair is assigned as a stub return value using RSpec's
73
+ # mocking/stubbing framework.
74
+ #
75
+ # <tt>new_record?</tt> is overridden to return the result of id.nil?
76
+ # This means that by default new_record? will return false. If you want
77
+ # the object to behave as a new record, sending it +as_new_record+ will
78
+ # set the id to nil. You can also explicitly set :id => nil, in which
79
+ # case new_record? will return true, but using +as_new_record+ makes the
80
+ # example a bit more descriptive.
81
+ #
82
+ # While you can use stub_model in any example (model, view, controller,
83
+ # helper), it is especially useful in view examples, which are
84
+ # inherently more state-based than interaction-based.
85
+ #
86
+ # == Database Independence
87
+ #
88
+ # +stub_model+ does not make your examples entirely
89
+ # database-independent. It does not stop the model class itself from
90
+ # loading up its columns from the database. It just prevents data access
91
+ # from the object itself. To completely decouple from the database, take
92
+ # a look at libraries like unit_record or NullDB.
93
+ #
94
+ # == Examples
95
+ #
96
+ # stub_model(Person)
97
+ # stub_model(Person).as_new_record
98
+ # stub_model(Person, :id => 37)
99
+ # stub_model(Person) do |person|
100
+ # person.first_name = "David"
101
+ # end
102
+ def stub_model(model_class, stubs={})
103
+ stubs = {:id => next_id}.merge(stubs)
104
+ model_class.new.tap do |model|
105
+ model.id = stubs.delete(:id)
106
+ model.extend ModelStubber
107
+ stubs.each do |k,v|
108
+ if model.has_attribute?(k)
109
+ model[k] = stubs.delete(k)
110
+ end
111
+ end
112
+ model.stub!(stubs)
113
+ yield model if block_given?
114
+ end
115
+ end
116
+
117
+ # DEPRECATED - use object.stub!(:method => value, :method2 => value)
118
+ #
119
+ # Stubs methods on +object+ (if +object+ is a symbol or string a new mock
120
+ # with that name will be created). +stubs+ is a Hash of +method=>value+
121
+ def add_stubs(object, stubs = {}) #:nodoc:
122
+ Kernel.warn <<-WARNING
123
+ DEPRECATION NOTICE: add_stubs is deprecated and will be removed
124
+ from a future version of rspec-rails. Use this instead:
125
+
126
+ object.stub!(:method => value, :method2 => value)
127
+
128
+ WARNING
129
+ object.stub!(stubs)
130
+ end
131
+
132
+ private
133
+ @@model_id = 1000
134
+ def next_id
135
+ @@model_id += 1
136
+ end
137
+
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,16 @@
1
+ module Spec # :nodoc:
2
+ module Rails # :nodoc:
3
+ module VERSION # :nodoc:
4
+ unless defined? MAJOR
5
+ MAJOR = 1
6
+ MINOR = 3
7
+ TINY = 4
8
+ PRE = nil
9
+
10
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
11
+
12
+ SUMMARY = "rspec-rails #{STRING}"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "spec/rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "richzhou-rspec-rails"
7
+ s.version = Spec::Rails::VERSION::STRING
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["RSpec Development Team"]
10
+ s.email = ["rspec-devel@rubyforge.org"]
11
+ s.homepage = "http://github.com/dchelimsky/rspec-rails"
12
+ s.summary = Spec::Rails::VERSION::SUMMARY
13
+ s.description = "Behaviour Driven Development for Ruby on Rails."
14
+
15
+ s.rubyforge_project = "rspec"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "rspec", "~> 1.3.1"
23
+ s.add_dependency "rack", ">= 1.0.0"
24
+ s.add_development_dependency "cucumber",">= 0.3.99"
25
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+ require File.dirname(__FILE__) + '/../../lib/autotest/rails_rspec'
3
+ require File.dirname(__FILE__) + '/../../../rspec/spec/autotest/autotest_matchers'
4
+
5
+ describe Autotest::RailsRspec, "file mapping" do
6
+ before(:each) do
7
+ @autotest = Autotest::RailsRspec.new
8
+ @autotest.hook :initialize
9
+ end
10
+
11
+ it "should map model example to model" do
12
+ @autotest.should map_specs(['spec/models/thing_spec.rb']).
13
+ to('app/models/thing.rb')
14
+ end
15
+
16
+ it "should map controller example to controller" do
17
+ @autotest.should map_specs(['spec/controllers/things_controller_spec.rb']).
18
+ to('app/controllers/things_controller.rb')
19
+ end
20
+
21
+ it "should map view.rhtml" do
22
+ @autotest.should map_specs(['spec/views/things/index.rhtml_spec.rb']).
23
+ to('app/views/things/index.rhtml')
24
+ end
25
+
26
+ it "should map view.rhtml with underscores in example filename" do
27
+ @autotest.should map_specs(['spec/views/things/index_rhtml_spec.rb']).
28
+ to('app/views/things/index.rhtml')
29
+ end
30
+
31
+ it "should map view.html.erb" do
32
+ @autotest.should map_specs(['spec/views/things/index.html.erb_spec.rb']).
33
+ to('app/views/things/index.html.erb')
34
+ end
35
+
36
+ describe "between routes.rb and things which depend on routes" do
37
+ it "should map routes.rb to controllers" do
38
+ @autotest.should map_specs(['spec/controllers/things_controller_spec.rb']).
39
+ to('config/routes.rb')
40
+ end
41
+
42
+ it "should map routes.rb to views" do
43
+ @autotest.should map_specs(['spec/views/things/action.html.erb_spec.rb']).
44
+ to('config/routes.rb')
45
+ end
46
+
47
+ it "should map routes.rb to helpers" do
48
+ @autotest.should map_specs(['spec/helpers/things_helper_spec.rb']).
49
+ to('config/routes.rb')
50
+ end
51
+
52
+ it "should map routing example to routes" do
53
+ @autotest.should map_specs(['spec/routing/thing_spec.rb']).
54
+ to('config/routes.rb')
55
+ end
56
+ end
57
+
58
+ describe "between the config and specs" do
59
+ ['spec/controllers/things_controller_spec.rb',
60
+ 'spec/views/things/action.html.erb_spec.rb',
61
+ 'spec/helpers/things_helper_spec.rb',
62
+ 'spec/routing/thing_spec.rb',
63
+ 'spec/models/thing_spec.rb'].each do |file_path|
64
+
65
+ it "should map environment.rb to #{file_path}" do
66
+ @autotest.should map_specs([file_path]).
67
+ to('config/environment.rb')
68
+ end
69
+
70
+ it "should map environments/test.rb to #{file_path}" do
71
+ @autotest.should map_specs([file_path]).
72
+ to('config/environments/test.rb')
73
+ end
74
+
75
+ it "should map boot.rb to #{file_path}" do
76
+ @autotest.should map_specs([file_path]).
77
+ to('config/boot.rb')
78
+ end
79
+
80
+ it "should map spec_helper.rb to #{file_path}" do
81
+ @autotest.should map_specs([file_path]).
82
+ to('spec/spec_helper.rb')
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,7 @@
1
+ dir = File.dirname(__FILE__)
2
+ Dir["#{dir}/**/*_example.rb"].each do |file|
3
+ require file
4
+ end
5
+ Dir["#{dir}/**/*_spec.rb"].each do |file|
6
+ require file
7
+ end
@@ -0,0 +1,2 @@
1
+ class ActionViewBaseSpecController < ActionController::Base
2
+ end
@@ -0,0 +1,9 @@
1
+ class ApplicationController < ActionController::Base
2
+ before_filter :i_should_only_be_run_once,
3
+ :only => 'action_with_inherited_before_filter'
4
+
5
+ def i_should_only_be_run_once
6
+ true
7
+ end
8
+ private :i_should_only_be_run_once
9
+ end
@@ -0,0 +1,127 @@
1
+ class ControllerSpecController < ActionController::Base
2
+ before_filter :raise_error, :only => :action_with_skipped_before_filter
3
+
4
+ def raise_error
5
+ raise "from a before filter"
6
+ end
7
+
8
+ skip_before_filter :raise_error
9
+
10
+ prepend_view_path File.join(File.dirname(__FILE__), "..", "views")
11
+
12
+ def some_action
13
+ render :template => "template/that/does/not/actually/exist"
14
+ end
15
+
16
+ def some_action_with_implied_template
17
+ end
18
+
19
+ def action_with_template
20
+ render :template => "controller_spec/action_with_template"
21
+ end
22
+
23
+ def action_which_sets_flash
24
+ flash[:flash_key] = "flash value"
25
+ render :text => ""
26
+ end
27
+
28
+ def action_which_gets_session
29
+ raise "expected #{params[:session_key].inspect}\ngot #{session[:session_key].inspect}" unless (session[:session_key] == params[:expected])
30
+ render :text => ""
31
+ end
32
+
33
+ def action_which_sets_session
34
+ session[:session_key] = "session value"
35
+ end
36
+
37
+ def action_which_gets_cookie
38
+ raise "expected #{params[:expected].inspect}, got #{cookies[:cookie_key].inspect}" unless (cookies[:cookie_key] == params[:expected])
39
+ render :text => ""
40
+ end
41
+
42
+ def action_which_sets_cookie
43
+ cookies['cookie_key'] = params[:value]
44
+ render :text => ""
45
+ end
46
+
47
+ def action_with_partial
48
+ render :partial => "controller_spec/partial"
49
+ end
50
+
51
+ def action_with_partial_with_object
52
+ render :partial => "controller_spec/partial", :object => params[:thing]
53
+ end
54
+
55
+ def action_with_partial_with_locals
56
+ render :partial => "controller_spec/partial", :locals => {:thing => params[:thing]}
57
+ end
58
+
59
+ def action_with_errors_in_template
60
+ render :template => "controller_spec/action_with_errors_in_template"
61
+ end
62
+
63
+ def action_setting_the_assigns_hash
64
+ @indirect_assigns_key = :indirect_assigns_key_value
65
+ end
66
+
67
+ def action_setting_flash_after_session_reset
68
+ reset_session
69
+ flash[:after_reset] = "available"
70
+ end
71
+
72
+ def action_setting_flash_before_session_reset
73
+ flash[:before_reset] = 'available'
74
+ reset_session
75
+ end
76
+
77
+ def action_with_render_update
78
+ render :update do |page|
79
+ page.replace :bottom, 'replace_me',
80
+ :partial => 'non_existent_partial'
81
+ end
82
+ end
83
+
84
+ def action_with_skipped_before_filter
85
+ render :text => ""
86
+ end
87
+
88
+ def action_that_renders_inline
89
+ render :inline => "<%= 'inline code' %>"
90
+ end
91
+
92
+ def action_that_assigns_false_to_a_variable
93
+ @a_variable = false
94
+ render :text => ""
95
+ end
96
+
97
+ def action_with_two_arg_render
98
+ render :update, :status => 404 do |page|
99
+ page.visual_effect :highlight, 'user_list'
100
+ end
101
+ end
102
+
103
+ class RescuedError < Exception; end
104
+ class UnRescuedError < Exception; end
105
+
106
+ rescue_from RescuedError do |e|
107
+ render :text => 'Rescued!'
108
+ end
109
+
110
+ def rescued_error_action
111
+ raise ControllerSpecController::RescuedError
112
+ end
113
+
114
+ def un_rescued_error_action
115
+ raise ControllerSpecController::UnRescuedError
116
+ end
117
+
118
+ def action_that_returns_headers
119
+ render :text => request.headers[params[:header]]
120
+ end
121
+ end
122
+
123
+ class ControllerInheritingFromApplicationControllerController < ApplicationController
124
+ def action_with_inherited_before_filter
125
+ render :text => ""
126
+ end
127
+ end
@@ -0,0 +1 @@
1
+ This is an example file to download.
@@ -0,0 +1,70 @@
1
+ class RedirectSpecController < ApplicationController
2
+
3
+ def action_with_no_redirect
4
+ render :text => "this is just here to keep this from causing a MissingTemplate error"
5
+ end
6
+
7
+ def action_with_redirect_to_somewhere
8
+ redirect_to :action => 'somewhere'
9
+ end
10
+
11
+ def action_with_redirect_to_other_somewhere
12
+ redirect_to :controller => 'render_spec', :action => 'text_action'
13
+ end
14
+
15
+ def action_with_redirect_to_somewhere_and_return
16
+ redirect_to :action => 'somewhere' and return
17
+ render :text => "this is after the return"
18
+ end
19
+
20
+ def somewhere
21
+ render :text => "this is just here to keep this from causing a MissingTemplate error"
22
+ end
23
+
24
+ def action_with_redirect_to_rspec_site
25
+ redirect_to "http://rspec.rubyforge.org"
26
+ end
27
+
28
+ def action_with_redirect_back
29
+ redirect_to :back
30
+ end
31
+
32
+ def action_with_redirect_in_respond_to
33
+ respond_to do |wants|
34
+ wants.html { redirect_to :action => 'somewhere' }
35
+ end
36
+ end
37
+
38
+ def action_with_redirect_which_creates_query_string
39
+ redirect_to :action => "somewhere", :id => 1111, :param1 => "value1", :param2 => "value2"
40
+ end
41
+
42
+ # note: sometimes this is the URL which rails will generate from the hash in
43
+ # action_with_redirect_which_creates_query_string
44
+ def action_with_redirect_with_query_string_order1
45
+ redirect_to "http://test.host/redirect_spec/somewhere/1111?param1=value1&param2=value2"
46
+ end
47
+
48
+ # note: sometimes this is the URL which rails will generate from the hash in
49
+ # action_with_redirect_which_creates_query_string
50
+ def action_with_redirect_with_query_string_order2
51
+ redirect_to "http://test.host/redirect_spec/somewhere/1111?param2=value2&param1=value1"
52
+ end
53
+
54
+ def action_with_redirect_to_unroutable_url_inside_app
55
+ redirect_to :controller => "nonexistant", :action => "none"
56
+ end
57
+
58
+ def action_with_method_restriction
59
+ render :text => ''
60
+ end
61
+
62
+ def action_to_redirect_to_action_with_method_restriction
63
+ redirect_to :action => 'action_with_method_restriction'
64
+ end
65
+
66
+ def action_with_redirect_to_somewhere_with_status
67
+ redirect_to :action => 'somewhere', :status => 301
68
+ end
69
+ end
70
+