riot_rails 0.0.8 → 0.0.9.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +122 -0
- data/MIT-LICENSE +1 -1
- data/README.markdown +22 -7
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/lib/riot/action_controller/assertion_macros.rb +48 -34
- data/lib/riot/action_controller/context_helper.rb +12 -0
- data/lib/riot/action_controller/context_macros.rb +58 -12
- data/lib/riot/action_controller/situation_macros.rb +73 -6
- data/lib/riot/action_controller.rb +2 -0
- data/lib/riot/active_record/assertion_macros.rb +3 -158
- data/lib/riot/active_record/context_helper.rb +19 -0
- data/lib/riot/active_record/database_macros.rb +58 -0
- data/lib/riot/active_record/reflection_macros.rb +106 -0
- data/lib/riot/active_record/validation_macros.rb +187 -0
- data/lib/riot/active_record.rb +2 -0
- data/lib/riot/rails.rb +1 -2
- data/lib/riot/rails_context.rb +84 -0
- data/riot_rails.gemspec +35 -9
- data/test/action_controller/controller_context_test.rb +39 -9
- data/test/action_controller/redirected_to_test.rb +6 -11
- data/test/action_controller/renders_template_test.rb +7 -7
- data/test/action_controller/renders_test.rb +6 -6
- data/test/action_controller/response_status_test.rb +11 -11
- data/test/active_record/allowing_values_test.rb +9 -9
- data/test/active_record/attribute_is_invalid_test.rb +20 -0
- data/test/active_record/belongs_to_test.rb +22 -0
- data/test/active_record/has_and_belongs_to_many_test.rb +22 -0
- data/test/active_record/has_database_index_on_test.rb +73 -0
- data/test/active_record/has_many_test.rb +7 -3
- data/test/active_record/has_one_test.rb +22 -0
- data/test/active_record/validates_length_of_test.rb +31 -0
- data/test/active_record/validates_presence_of_test.rb +1 -1
- data/test/active_record/validates_uniqueness_of_test.rb +3 -3
- data/test/rails_context_test.rb +103 -0
- data/test/rails_root/config/environment.rb +46 -0
- data/test/rails_root/config/routes.rb +3 -4
- data/test/rails_root/db/schema.rb +1 -2
- data/test/teststrap.rb +44 -69
- metadata +39 -6
data/CHANGELOG
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
*0.0.9.pre*
|
2
|
+
|
3
|
+
* To accommodate the last change, added concept of context helpers. It's so simple you can define your own. [jaknowlden]
|
4
|
+
|
5
|
+
module RiotRails
|
6
|
+
register_context_helper do
|
7
|
+
def prepare_context(original_description, context)
|
8
|
+
# ...
|
9
|
+
context.<do-something-before-the-context-runs-if-you-want-to>
|
10
|
+
# ...
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
* Well. Aren't we special? We don't have include ActiveRecord or ActionController code if we don't want to. But if you do: [jaknowlden]
|
16
|
+
|
17
|
+
# teststrap.rb
|
18
|
+
require 'riot/activerecord' # implicit riot/rails require
|
19
|
+
require 'riot/actioncontroller' # also an implicit riot/rails require
|
20
|
+
|
21
|
+
* Added asserts_request and asserts_response context macros. They also take a possible method to call.
|
22
|
+
[jaknowlden]
|
23
|
+
|
24
|
+
rails_context UsersController do
|
25
|
+
hookup { get :show, :id => 1 }
|
26
|
+
|
27
|
+
asserts_response.kind_of(ActionController::TestResponse)
|
28
|
+
asserts_response(:body).kind_of(String)
|
29
|
+
|
30
|
+
asserts_request.kind_of(ActionController::TestRequest)
|
31
|
+
asserts_request(:cookies).kind_of(Hash)
|
32
|
+
end
|
33
|
+
|
34
|
+
* Controller assertions now no longer assume the actual value is a controller instance. Instead, the actual
|
35
|
+
value is something that should quack like a response. [jaknowlden]
|
36
|
+
|
37
|
+
* Added asserts_assigned context macro [jaknowlden]
|
38
|
+
|
39
|
+
rails_context UsersController do
|
40
|
+
hookup { get :show, :id => 1 }
|
41
|
+
|
42
|
+
asserts_assigned(:user).kind_of(User)
|
43
|
+
end
|
44
|
+
|
45
|
+
* rails_context now recognizes controllers [jaknowlden]
|
46
|
+
|
47
|
+
rails_context RoomsController do
|
48
|
+
hookup { get :index }
|
49
|
+
asserts_controller.reponse_status :ok
|
50
|
+
end
|
51
|
+
|
52
|
+
Plus, you can only use controlling within a rails_context now
|
53
|
+
|
54
|
+
rails_context "rooms" do
|
55
|
+
controlling :rooms
|
56
|
+
hookup { get :index }
|
57
|
+
asserts_controller.reponse_status :ok
|
58
|
+
end
|
59
|
+
|
60
|
+
* controlling now lets you pass a controller class reference in [jaknowlden]
|
61
|
+
|
62
|
+
rails_context "rooms" do
|
63
|
+
controlling RoomsController
|
64
|
+
end
|
65
|
+
|
66
|
+
* Reflection macros now test the options [emschwar]
|
67
|
+
|
68
|
+
rails_context Room do
|
69
|
+
asserts_topic.has_one :floor, :class_name => "Surface"
|
70
|
+
asserts_topic.has_many :walls, :join_table => "foos"
|
71
|
+
end
|
72
|
+
|
73
|
+
* Added the has_one reflection macro [emschwar]
|
74
|
+
|
75
|
+
rails_context Room do
|
76
|
+
asserts_topic.has_one :floor
|
77
|
+
end
|
78
|
+
|
79
|
+
* Added the attribute_is_invalid validation macro [jaknowlden]
|
80
|
+
|
81
|
+
rails_context Room do
|
82
|
+
hookup { topic.location = nil }
|
83
|
+
asserts_topic.attribute_is_invalid(:location, "can't be blank")
|
84
|
+
end
|
85
|
+
|
86
|
+
* Added validates_length_of assertion macro (minimalistic) [jaknowlden]
|
87
|
+
|
88
|
+
rails_context Room do
|
89
|
+
asserts_topic.validates_length_of :name, (2..36)
|
90
|
+
end
|
91
|
+
|
92
|
+
* Added transactional support to RailsContext. Disabled by default [jaknowlden]
|
93
|
+
|
94
|
+
rails_context Room do
|
95
|
+
set :transactional, true
|
96
|
+
end
|
97
|
+
|
98
|
+
* Added option enabling to RailsContext [jaknowlden]
|
99
|
+
|
100
|
+
rails_context Room do
|
101
|
+
set :this, "that"
|
102
|
+
end
|
103
|
+
|
104
|
+
* Added initial #rails_context. Assumes ActiveRecord class for now [jaknowlden]
|
105
|
+
|
106
|
+
class Room < ActiveRecord::Base
|
107
|
+
# ...
|
108
|
+
end
|
109
|
+
|
110
|
+
# TEST
|
111
|
+
|
112
|
+
rails_context Room do
|
113
|
+
asserts_topic.belongs_to(:house)
|
114
|
+
asserts_topic.validates_presence_of(:house_id)
|
115
|
+
end
|
116
|
+
|
117
|
+
* Added the #belongs_to ActiveRecord assertion macro [jaknowlden]
|
118
|
+
|
119
|
+
context "a Room" do
|
120
|
+
setup { Room.new }
|
121
|
+
asserts_topic.belongs_to(:house)
|
122
|
+
end
|
data/MIT-LICENSE
CHANGED
data/README.markdown
CHANGED
@@ -1,16 +1,31 @@
|
|
1
|
-
#
|
1
|
+
# Riot Rails
|
2
2
|
|
3
3
|
[Riot](http://github.com/thumblemonks/riot) macros for Rails application testing.
|
4
4
|
|
5
5
|
LOTS more to come ...
|
6
6
|
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
We're a gem! Install per the normal course of installing gems.
|
10
|
+
|
11
|
+
gem install riot_rails
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Tons of documentation to come. Try looking at the [RDoc](http://rdoc.info/projects/thumblemonks/riot_rails) for now. As a note, you will likely put this in your `teststrap.rb` or `test_helper.rb`:
|
16
|
+
|
17
|
+
require 'riot/rails'
|
18
|
+
|
7
19
|
### ActiveRecord
|
8
20
|
|
9
|
-
|
21
|
+
Awesome stuff in the works. Doc coming soon.
|
22
|
+
|
23
|
+
### ActionController
|
24
|
+
|
25
|
+
Awesome stuff in the works. Doc coming soon.
|
26
|
+
|
27
|
+
### ActionMailer
|
10
28
|
|
11
|
-
|
12
|
-
* #allows\_values\_for
|
13
|
-
* #does\_not\_allow\_values\_for
|
14
|
-
* #validates\_uniquness\_of
|
29
|
+
Awesome stuff coming soon. See [Shoulda Action Mailer](http://github.com/thumblemonks/shoulda_action_mailer) - which is also by us - in the meantime.
|
15
30
|
|
16
|
-
|
31
|
+
I told you we liked Shoulda.
|
data/Rakefile
CHANGED
@@ -32,8 +32,9 @@ begin
|
|
32
32
|
gem.email = "gus@gusg.us"
|
33
33
|
gem.homepage = "http://github.com/thumblemonks/riot_rails"
|
34
34
|
gem.authors = ["Justin 'Gus' Knowlden"]
|
35
|
-
gem.add_dependency("riot", ">= 0.10.
|
36
|
-
gem.add_development_dependency("activerecord", ">=
|
35
|
+
gem.add_dependency("riot", ">= 0.10.13.pre")
|
36
|
+
gem.add_development_dependency("activerecord", ">= 3.0.0.pre")
|
37
|
+
gem.add_development_dependency("actionpack", ">= 3.0.0.pre")
|
37
38
|
end
|
38
39
|
Jeweler::GemcutterTasks.new
|
39
40
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.9.pre
|
@@ -1,20 +1,23 @@
|
|
1
1
|
module RiotRails
|
2
2
|
module ActionController
|
3
|
-
# Asserts that
|
4
|
-
#
|
3
|
+
# Asserts that calling body on whatever is passed in matches the expected value. Expected value can be a
|
4
|
+
# literal string or a regular expression. It makes most sense to provide this macro with the response.
|
5
5
|
#
|
6
|
-
#
|
7
|
-
#
|
6
|
+
# rails_context UsersController do
|
7
|
+
# hookup { get :index }
|
8
|
+
# asserts(:response).renders("a bunch of html")
|
9
|
+
# asserts(:response).renders(/bunch of/)
|
10
|
+
# end
|
8
11
|
class RendersMacro < Riot::AssertionMacro
|
9
12
|
register :renders
|
10
13
|
|
11
14
|
def evaluate(actual, expected)
|
12
|
-
actual_body = actual.
|
15
|
+
actual_body = actual.body
|
13
16
|
if (expected.kind_of?(Regexp) ? (actual_body =~ expected) : (expected == actual_body))
|
14
17
|
pass
|
15
18
|
else
|
16
19
|
verb = expected.kind_of?(Regexp) ? "match" : "equal"
|
17
|
-
fail(
|
20
|
+
fail expected_message.response_body(actual_body).to.push("#{verb} #{expected.inspect}")
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
@@ -22,23 +25,28 @@ module RiotRails
|
|
22
25
|
# Asserts that the name you provide is the basename of the rendered template. For instance, if you
|
23
26
|
# expect the rendered template is named "foo_bar.html.haml" and you pass "foo_bar" into
|
24
27
|
# renders_template, the assertion would pass. If instead you pass "foo" into renders_template, the
|
25
|
-
# assertion will fail. Using Rails' assert_template both assertions would pass
|
28
|
+
# assertion will fail. Using Rails' assert_template both assertions would pass.
|
29
|
+
#
|
30
|
+
# It's important to note that the actual value provided must respond to +#rendered+. It's best to run
|
31
|
+
# this assertion on the response
|
26
32
|
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
33
|
+
# rails_context ThingsController do
|
34
|
+
# hookup { get :index }
|
35
|
+
# asserts(:response).renders_template(:index)
|
36
|
+
# asserts(:response).renders_template("index")
|
37
|
+
# asserts(:response).renders_template("index.erb") # fails even if that's the name of the template
|
38
|
+
# end
|
31
39
|
class RendersTemplateMacro < Riot::AssertionMacro
|
32
40
|
register :renders_template
|
33
41
|
|
34
42
|
def evaluate(actual, expected_name)
|
35
43
|
name = expected_name.to_s
|
36
|
-
actual_template_path = actual.
|
44
|
+
actual_template_path = Array(actual.template.rendered[:template]).map(&:inspect).first.to_s # yuck
|
37
45
|
actual_template_name = File.basename(actual_template_path)
|
38
|
-
if actual_template_name.to_s.match(
|
39
|
-
pass(
|
46
|
+
if actual_template_name.to_s.match(%r[^#{name}(\.\w+)*$])
|
47
|
+
pass new_message.renders_template(name)
|
40
48
|
else
|
41
|
-
fail
|
49
|
+
fail expected_message.template(name).not(actual_template_path)
|
42
50
|
end
|
43
51
|
end
|
44
52
|
end
|
@@ -47,25 +55,28 @@ module RiotRails
|
|
47
55
|
# status code or the integer code itself. Not currently supporting status ranges; such as: +:success+,
|
48
56
|
# +:redirect+, etc.
|
49
57
|
#
|
50
|
-
#
|
51
|
-
#
|
58
|
+
# It's important to note that the actual value provided must respond to +#response_code+. It's best to
|
59
|
+
# run this assertion on the response
|
60
|
+
#
|
61
|
+
# asserts(:response).code(:ok)
|
62
|
+
# asserts(:response).code(200)
|
52
63
|
#
|
53
|
-
#
|
54
|
-
#
|
64
|
+
# asserts(:response).code(:not_found)
|
65
|
+
# asserts(:response).code(404)
|
55
66
|
#
|
56
67
|
# # A redirect
|
57
|
-
#
|
58
|
-
#
|
68
|
+
# asserts(:response).code(:found)
|
69
|
+
# asserts(:response).code(302)
|
59
70
|
#
|
60
71
|
# See +ActionController::StatusCodes+ for the list of available codes.
|
61
72
|
class ResponseCodeMacro < Riot::AssertionMacro
|
62
|
-
register :
|
73
|
+
register :code
|
63
74
|
|
64
75
|
def evaluate(actual, expected_code)
|
65
76
|
if expected_code.kind_of?(Symbol)
|
66
|
-
expected_code = ::
|
77
|
+
expected_code = ::Rack::Utils::SYMBOL_TO_STATUS_CODE[expected_code]
|
67
78
|
end
|
68
|
-
actual_code = actual.
|
79
|
+
actual_code = actual.response_code
|
69
80
|
if expected_code == actual_code
|
70
81
|
pass("returns response code #{expected_code}")
|
71
82
|
else
|
@@ -75,28 +86,31 @@ module RiotRails
|
|
75
86
|
end
|
76
87
|
|
77
88
|
# Asserts that the response from an action is a redirect and that the path or URL matches your
|
78
|
-
# expectations. If the response code is not in the 300s, the assertion will fail. If the
|
89
|
+
# expectations. If the response code is not in the 300s, the assertion will fail. If the ressponse code
|
79
90
|
# is fine, but the redirect-to path or URL do not exactly match your expectation, the assertion will
|
80
91
|
# fail.
|
81
92
|
#
|
82
|
-
#
|
83
|
-
#
|
93
|
+
# In order to use named routes which are handy, provide the path in a block. +redirected_to+ expects the
|
94
|
+
# actual value to quack like a response object, which means it must respond to +response_code+ and
|
95
|
+
# +redirected_to+.
|
84
96
|
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
97
|
+
# rails_context PeopleController do
|
98
|
+
# hookup do
|
99
|
+
# post :create, :person { ... }
|
100
|
+
# end
|
89
101
|
#
|
90
|
-
#
|
102
|
+
# asserts(:response).redirected_to { person_path(...) }
|
103
|
+
# end
|
91
104
|
#
|
92
105
|
# PS: There is a difference between saying +named_route_path+ and +named_route_url+ and Riot Rails will
|
93
106
|
# be very strict (read: annoying) about it :)
|
94
107
|
class RedirectedToMacro < Riot::AssertionMacro
|
95
108
|
register :redirected_to
|
109
|
+
|
96
110
|
def evaluate(actual, expected_redirect)
|
97
|
-
actual_response_code = actual.
|
111
|
+
actual_response_code = actual.response_code
|
98
112
|
if (300...400).member?(actual_response_code)
|
99
|
-
actual_redirect = actual.
|
113
|
+
actual_redirect = actual.redirect_url
|
100
114
|
msg = "expected to redirect to <#{expected_redirect}>, not <#{actual_redirect}>"
|
101
115
|
expected_redirect == actual_redirect ? pass("redirected to #{expected_redirect}") : fail(msg)
|
102
116
|
else
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module RiotRails
|
2
|
+
register_context_helper do
|
3
|
+
def prepare_context(context)
|
4
|
+
context.controlling(context.description) if action_controller_context?(context)
|
5
|
+
end
|
6
|
+
private
|
7
|
+
def action_controller_context?(context)
|
8
|
+
description = context.description
|
9
|
+
description.kind_of?(Class) && description.ancestors.include?(::ActionController::Base)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end # RiotRails
|
@@ -1,32 +1,32 @@
|
|
1
|
-
module
|
1
|
+
module RiotRails #:nodoc:
|
2
2
|
module ActionController #:nodoc:
|
3
3
|
|
4
4
|
module ContextMacros
|
5
5
|
# Sets up a context (and possibly child contexts) for testing a controller. Right now, it just takes a
|
6
|
-
# symbol. Should change to allow you to pass in the class directly.
|
7
|
-
# top of your context definition.
|
6
|
+
# symbol. Should change to allow you to pass in the class directly.
|
8
7
|
#
|
9
|
-
#
|
8
|
+
# rails_context "the FooBarsController" do
|
10
9
|
# controlling :foo_bars
|
11
|
-
#
|
10
|
+
# hookup { get :index }
|
12
11
|
# end
|
13
12
|
def controlling(controller_name)
|
14
|
-
controller_class =
|
15
|
-
|
13
|
+
controller_class = constantize_controller_name(controller_name)
|
14
|
+
premium_setup do
|
16
15
|
controller_class.instance_eval { include ::ActionController::TestCase::RaiseActionExceptions }
|
17
16
|
@request = ::ActionController::TestRequest.new
|
18
17
|
@response = ::ActionController::TestResponse.new
|
19
18
|
@controller = controller_class.new
|
20
19
|
@controller.params = {}
|
21
20
|
@controller.request = @request
|
21
|
+
@controller
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
# Creates a shortcut assertion that is to be used with the assertion macros for ActionController.
|
26
26
|
#
|
27
|
-
#
|
27
|
+
# rails_context "the FoosController" do
|
28
28
|
# controlling :foos
|
29
|
-
#
|
29
|
+
# hookup { get :index }
|
30
30
|
#
|
31
31
|
# asserts_controller.response_status(:found)
|
32
32
|
# asserts_controller.redirected_to { new_foo_path }
|
@@ -39,9 +39,55 @@ module Riot #:nodoc:
|
|
39
39
|
def asserts_controller
|
40
40
|
asserts("controller") { controller }
|
41
41
|
end
|
42
|
+
|
43
|
+
# Creates a shortcut assertion in order to test the response directly. If you provide an argument
|
44
|
+
# it is assumed you want to call the relevant method on the response in order test it's returned value.
|
45
|
+
#
|
46
|
+
# rails_context "the FoosController" do
|
47
|
+
# controlling :foos
|
48
|
+
# hookup { get :index }
|
49
|
+
#
|
50
|
+
# asserts_response.kind_of(ActionController::TestResponse)
|
51
|
+
# asserts_response(:body).kind_of(String)
|
52
|
+
# end
|
53
|
+
def asserts_response(shortcut_method=nil)
|
54
|
+
asserts("the response") { shortcut_method ? response.send(shortcut_method) : response }
|
55
|
+
end
|
56
|
+
|
57
|
+
# Creates a shortcut assertion in order to test the request directly. If you provide an argument
|
58
|
+
# it is assumed you want to call the relevant method on the request in order test it's returned value.
|
59
|
+
#
|
60
|
+
# rails_context "the FoosController" do
|
61
|
+
# controlling :foos
|
62
|
+
# hookup { get :index }
|
63
|
+
#
|
64
|
+
# asserts_request.kind_of(ActionController::TestRequest)
|
65
|
+
# asserts_request(:cookies).kind_of(Hash)
|
66
|
+
# end
|
67
|
+
def asserts_request(shortcut_method=nil)
|
68
|
+
asserts("the request") { shortcut_method ? request.send(shortcut_method) : request }
|
69
|
+
end
|
70
|
+
|
71
|
+
# Creates a shortcut assertion that returns the value of an assigned variable from the controller
|
72
|
+
#
|
73
|
+
# rails_context UsersController do
|
74
|
+
# hookup { get :show, :id => 1 }
|
75
|
+
#
|
76
|
+
# asserts_assigned(:user).kind_of(User)
|
77
|
+
# end
|
78
|
+
def asserts_assigned(variable)
|
79
|
+
asserts("value assigned to @#{variable}") do
|
80
|
+
@controller.instance_variable_get("@#{variable}".to_sym)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
private
|
84
|
+
def constantize_controller_name(name)
|
85
|
+
name.kind_of?(Class) ? name : "#{name.to_s.camelize}Controller".constantize
|
86
|
+
end
|
42
87
|
end # ContextMacros
|
43
88
|
|
89
|
+
# We do this everywhere because you never know when someone might define a rails_context that doesn't
|
90
|
+
# automatically translate to an ActionController context
|
91
|
+
RailsContext.instance_eval { include ContextMacros }
|
44
92
|
end # ActionController
|
45
|
-
end #
|
46
|
-
|
47
|
-
Riot::Context.instance_eval { include Riot::ActionController::ContextMacros }
|
93
|
+
end # RiotRails
|
@@ -1,14 +1,81 @@
|
|
1
|
-
module
|
1
|
+
module RiotRails #:nodoc:
|
2
2
|
module ActionController #:nodoc:
|
3
3
|
|
4
|
-
|
4
|
+
# Nabbed form actionpack-3.0.0.beta
|
5
|
+
module HttpSupport
|
5
6
|
attr_reader :controller, :request, :response
|
6
|
-
|
7
|
+
|
8
|
+
# Simulates a GET HTTP request and handles response
|
9
|
+
def get(*args) submit_request("GET", *args); end
|
10
|
+
|
11
|
+
# Simulates a POST HTTP request and handles response
|
12
|
+
def post(*args) submit_request("POST", *args); end
|
13
|
+
|
14
|
+
# Simulates a PUT HTTP request and handles response
|
15
|
+
def put(*args) submit_request("PUT", *args); end
|
16
|
+
|
17
|
+
# Simulates a DELETE HTTP request and handles response
|
18
|
+
def delete(*args) submit_request("DELETE", *args); end
|
19
|
+
|
20
|
+
# Simulates a HEAD HTTP request and handles response
|
21
|
+
def head(*args) submit_request("HEAD", *args); end
|
22
|
+
|
23
|
+
# Simulates an XML HTTP Request (which allows for AJAX ya'll) for whatever HTTP method you want
|
24
|
+
def xml_http_request(request_method, *args)
|
25
|
+
# @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
26
|
+
# @request.env['HTTP_ACCEPT'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
|
27
|
+
# returning submit_request(request_method.to_s.upcase, *args) do
|
28
|
+
# @request.env.delete 'HTTP_X_REQUESTED_WITH'
|
29
|
+
# @request.env.delete 'HTTP_ACCEPT'
|
30
|
+
# end
|
31
|
+
end
|
32
|
+
alias :xhr :xml_http_request
|
33
|
+
private
|
34
|
+
def submit_request(http_method, action, parameters = nil, session = nil, flash = nil)
|
35
|
+
@request.recycle!
|
36
|
+
@response.recycle!
|
37
|
+
@controller.response_body = nil
|
38
|
+
@controller.formats = nil
|
39
|
+
@controller.params = nil
|
40
|
+
|
41
|
+
@html_document = nil
|
42
|
+
@request.env['REQUEST_METHOD'] = http_method
|
43
|
+
|
44
|
+
parameters ||= {}
|
45
|
+
@request.assign_parameters(@controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters)
|
46
|
+
|
47
|
+
# @request.session = ActionController::TestSession.new(session) unless session.nil?
|
48
|
+
# @request.session["flash"] = @request.flash.update(flash || {})
|
49
|
+
# @request.session["flash"].sweep
|
50
|
+
|
51
|
+
@controller.request = @request
|
52
|
+
@controller.params.merge!(parameters)
|
53
|
+
build_request_uri(action, parameters)
|
54
|
+
::ActionController::Base.class_eval { include ::ActionController::Testing }
|
55
|
+
@controller.process_with_new_base_test(@request, @response)
|
56
|
+
# @request.session.delete('flash') if @request.session['flash'].blank?
|
57
|
+
@response
|
58
|
+
end
|
59
|
+
|
60
|
+
def build_request_uri(action, parameters)
|
61
|
+
unless @request.env['REQUEST_URI']
|
62
|
+
options = @controller.__send__(:rewrite_options, parameters)
|
63
|
+
options.update(:only_path => true, :action => action)
|
64
|
+
|
65
|
+
url = ::ActionController::UrlRewriter.new(@request, parameters)
|
66
|
+
@request.request_uri = url.rewrite(options)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end # HttpSupport
|
7
70
|
|
8
71
|
end # ActionController
|
9
|
-
end #
|
72
|
+
end # RiotRails
|
10
73
|
|
11
74
|
Riot::Situation.instance_eval do
|
12
|
-
include ActionController::
|
13
|
-
|
75
|
+
include RiotRails::ActionController::HttpSupport
|
76
|
+
|
77
|
+
# Making routes work in the situation
|
78
|
+
Rails::Application.routes.named_routes.install(self)
|
79
|
+
include ActionController::UrlFor
|
80
|
+
default_url_options[:host] = "test.host"
|
14
81
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'action_controller/test_case'
|
2
2
|
require 'action_view/test_case'
|
3
3
|
|
4
|
+
require 'riot/rails'
|
4
5
|
require 'riot/action_controller/context_macros'
|
5
6
|
require 'riot/action_controller/assertion_macros'
|
6
7
|
require 'riot/action_controller/situation_macros'
|
8
|
+
require 'riot/action_controller/context_helper'
|