Permalink
Browse files

Removing application controller. Updating to 0.0.10.pre.3

  • Loading branch information...
gus committed May 8, 2010
1 parent 70c8860 commit 78605ec6e9c7d2d1c32db06625e93949ac94cdcb
View
@@ -1,3 +1,5 @@
+*0.0.10.pre.3*
+
*0.0.9.pre*
* To accommodate the last change, added concept of context helpers. It's so simple you can define your own. [jaknowlden]
View
@@ -1 +1 @@
-0.0.10.pre.2
+0.0.10.pre.3
@@ -1,8 +0,0 @@
-require 'action_controller/test_case'
-require 'action_view/test_case'
-
-require 'riot/rails'
-require 'riot/action_controller/context_macros'
-require 'riot/action_controller/assertion_macros'
-require 'riot/action_controller/situation_macros'
-require 'riot/action_controller/context_helper'
@@ -1,123 +0,0 @@
-module RiotRails
- module ActionController
- # Asserts that calling body on whatever is passed in matches the expected value. Expected value can be a
- # literal string or a regular expression. It makes most sense to provide this macro with the response.
- #
- # rails_context UsersController do
- # hookup { get :index }
- # asserts(:response).renders("a bunch of html")
- # asserts(:response).renders(/bunch of/)
- # end
- class RendersMacro < Riot::AssertionMacro
- register :renders
-
- def evaluate(actual, expected)
- actual_body = actual.body
- if (expected.kind_of?(Regexp) ? (actual_body =~ expected) : (expected == actual_body))
- pass
- else
- verb = expected.kind_of?(Regexp) ? "match" : "equal"
- fail expected_message.response_body(actual_body).to.push("#{verb} #{expected.inspect}")
- end
- end
- end
-
- # Asserts that the name you provide is the basename of the rendered template. For instance, if you
- # expect the rendered template is named "foo_bar.html.haml" and you pass "foo_bar" into
- # renders_template, the assertion would pass. If instead you pass "foo" into renders_template, the
- # assertion will fail. Using Rails' assert_template both assertions would pass.
- #
- # It's important to note that the actual value provided must respond to +#rendered+. It's best to run
- # this assertion on the response
- #
- # rails_context ThingsController do
- # hookup { get :index }
- # asserts(:response).renders_template(:index)
- # asserts(:response).renders_template("index")
- # asserts(:response).renders_template("index.erb") # fails even if that's the name of the template
- # end
- class RendersTemplateMacro < Riot::AssertionMacro
- register :renders_template
-
- def evaluate(actual, expected_name)
- name = expected_name.to_s
- actual_template_path = Array(actual.template.rendered[:template]).map(&:inspect).first.to_s # yuck
- actual_template_name = File.basename(actual_template_path)
- if actual_template_name.to_s.match(%r[^#{name}(\.\w+)*$])
- pass new_message.renders_template(name)
- else
- fail expected_message.template(name).not(actual_template_path)
- end
- end
- end
-
- # Asserts that the HTTP response code equals your expectation. You can use the symbolized form of the
- # status code or the integer code itself. Not currently supporting status ranges; such as: +:success+,
- # +:redirect+, etc.
- #
- # It's important to note that the actual value provided must respond to +#response_code+. It's best to
- # run this assertion on the response
- #
- # asserts(:response).code(:ok)
- # asserts(:response).code(200)
- #
- # asserts(:response).code(:not_found)
- # asserts(:response).code(404)
- #
- # # A redirect
- # asserts(:response).code(:found)
- # asserts(:response).code(302)
- #
- # See +ActionController::StatusCodes+ for the list of available codes.
- class ResponseCodeMacro < Riot::AssertionMacro
- register :code
-
- def evaluate(actual, expected_code)
- if expected_code.kind_of?(Symbol)
- expected_code = ::Rack::Utils::SYMBOL_TO_STATUS_CODE[expected_code]
- end
- actual_code = actual.response_code
- if expected_code == actual_code
- pass("returns response code #{expected_code}")
- else
- fail("expected response code #{expected_code}, not #{actual_code}")
- end
- end
- end
-
- # Asserts that the response from an action is a redirect and that the path or URL matches your
- # expectations. If the response code is not in the 300s, the assertion will fail. If the ressponse code
- # is fine, but the redirect-to path or URL do not exactly match your expectation, the assertion will
- # fail.
- #
- # In order to use named routes which are handy, provide the path in a block. +redirected_to+ expects the
- # actual value to quack like a response object, which means it must respond to +response_code+ and
- # +redirected_to+.
- #
- # rails_context PeopleController do
- # hookup do
- # post :create, :person { ... }
- # end
- #
- # asserts(:response).redirected_to { person_path(...) }
- # end
- #
- # PS: There is a difference between saying +named_route_path+ and +named_route_url+ and Riot Rails will
- # be very strict (read: annoying) about it :)
- class RedirectedToMacro < Riot::AssertionMacro
- register :redirected_to
-
- def evaluate(actual, expected_redirect)
- actual_response_code = actual.response_code
- if (300...400).member?(actual_response_code)
- actual_redirect = actual.redirect_url
- msg = "expected to redirect to <#{expected_redirect}>, not <#{actual_redirect}>"
- expected_redirect == actual_redirect ? pass("redirected to #{expected_redirect}") : fail(msg)
- else
- fail("expected response to be a redirect, but was #{actual_response_code}")
- end
- end
- end
-
- end # ActionController
-end # RiotRails
@@ -1,12 +0,0 @@
-module RiotRails
- register_context_helper do
- def prepare_context(context)
- context.controlling(context.description) if action_controller_context?(context)
- end
- private
- def action_controller_context?(context)
- description = context.description
- description.kind_of?(Class) && description.ancestors.include?(::ActionController::Base)
- end
- end
-end # RiotRails
@@ -1,93 +0,0 @@
-module RiotRails #:nodoc:
- module ActionController #:nodoc:
-
- module ContextMacros
- # Sets up a context (and possibly child contexts) for testing a controller. Right now, it just takes a
- # symbol. Should change to allow you to pass in the class directly.
- #
- # rails_context "the FooBarsController" do
- # controlling :foo_bars
- # hookup { get :index }
- # end
- def controlling(controller_name)
- controller_class = constantize_controller_name(controller_name)
- premium_setup do
- controller_class.instance_eval { include ::ActionController::TestCase::RaiseActionExceptions }
- @request = ::ActionController::TestRequest.new
- @response = ::ActionController::TestResponse.new
- @controller = controller_class.new
- @controller.params = {}
- @controller.request = @request
- @controller
- end
- end
-
- # Creates a shortcut assertion that is to be used with the assertion macros for ActionController.
- #
- # rails_context "the FoosController" do
- # controlling :foos
- # hookup { get :index }
- #
- # asserts_controller.response_status(:found)
- # asserts_controller.redirected_to { new_foo_path }
- # end
- #
- # Works the same as if you wrote the following assertions:
- #
- # asserts("controller") { controller }.response_status(:found)
- # asserts("controller") { controller }.redirected_to { new_foo_path }
- def asserts_controller
- asserts("controller") { controller }
- end
-
- # Creates a shortcut assertion in order to test the response directly. If you provide an argument
- # it is assumed you want to call the relevant method on the response in order test it's returned value.
- #
- # rails_context "the FoosController" do
- # controlling :foos
- # hookup { get :index }
- #
- # asserts_response.kind_of(ActionController::TestResponse)
- # asserts_response(:body).kind_of(String)
- # end
- def asserts_response(shortcut_method=nil)
- asserts("the response") { shortcut_method ? response.send(shortcut_method) : response }
- end
-
- # Creates a shortcut assertion in order to test the request directly. If you provide an argument
- # it is assumed you want to call the relevant method on the request in order test it's returned value.
- #
- # rails_context "the FoosController" do
- # controlling :foos
- # hookup { get :index }
- #
- # asserts_request.kind_of(ActionController::TestRequest)
- # asserts_request(:cookies).kind_of(Hash)
- # end
- def asserts_request(shortcut_method=nil)
- asserts("the request") { shortcut_method ? request.send(shortcut_method) : request }
- end
-
- # Creates a shortcut assertion that returns the value of an assigned variable from the controller
- #
- # rails_context UsersController do
- # hookup { get :show, :id => 1 }
- #
- # asserts_assigned(:user).kind_of(User)
- # end
- def asserts_assigned(variable)
- asserts("value assigned to @#{variable}") do
- @controller.instance_variable_get("@#{variable}".to_sym)
- end
- end
- private
- def constantize_controller_name(name)
- name.kind_of?(Class) ? name : "#{name.to_s.camelize}Controller".constantize
- end
- end # ContextMacros
-
- # We do this everywhere because you never know when someone might define a rails_context that doesn't
- # automatically translate to an ActionController context
- RailsContext.instance_eval { include ContextMacros }
- end # ActionController
-end # RiotRails
@@ -1,78 +0,0 @@
-module RiotRails #:nodoc:
- module ActionController #:nodoc:
-
- # Nabbed form actionpack-3.0.0.beta
- module HttpSupport
- attr_reader :controller, :request, :response
-
- # Simulates a GET HTTP request and handles response
- def get(*args) submit_request("GET", *args); end
-
- # Simulates a POST HTTP request and handles response
- def post(*args) submit_request("POST", *args); end
-
- # Simulates a PUT HTTP request and handles response
- def put(*args) submit_request("PUT", *args); end
-
- # Simulates a DELETE HTTP request and handles response
- def delete(*args) submit_request("DELETE", *args); end
-
- # Simulates a HEAD HTTP request and handles response
- def head(*args) submit_request("HEAD", *args); end
-
- # Simulates an XML HTTP Request (which allows for AJAX ya'll) for whatever HTTP method you want
- def xml_http_request(request_method, *args)
- # @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
- # @request.env['HTTP_ACCEPT'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
- # returning submit_request(request_method.to_s.upcase, *args) do
- # @request.env.delete 'HTTP_X_REQUESTED_WITH'
- # @request.env.delete 'HTTP_ACCEPT'
- # end
- end
- alias :xhr :xml_http_request
- private
- def submit_request(http_method, action, parameters = nil, session = nil, flash = nil)
- @request.recycle!
- @response.recycle!
- @controller.response_body = nil
- @controller.formats = nil
- @controller.params = nil
-
- @html_document = nil
- @request.env['REQUEST_METHOD'] = http_method
-
- parameters ||= {}
- @request.assign_parameters(@controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters)
-
- @request.session = ActionController::TestSession.new(session) unless session.nil?
- @request.session["flash"] = @request.flash.update(flash || {})
- @request.session["flash"].sweep
-
- @controller.request = @request
- @controller.params.merge!(parameters)
- build_request_uri(action, parameters)
- ::ActionController::Base.class_eval { include ::ActionController::Testing }
- @controller.process_with_new_base_test(@request, @response)
- @request.session.delete('flash') if @request.session['flash'].blank?
- @response
- end
-
- def build_request_uri(action, parameters)
- unless @request.env['REQUEST_URI']
- options = @controller.__send__(:rewrite_options, parameters)
- options.update(:only_path => true, :action => action)
-
- url = ::ActionController::UrlRewriter.new(@request, parameters)
- @request.request_uri = url.rewrite(options)
- end
- end
- end # HttpSupport
-
- end # ActionController
-end # RiotRails
-
-Riot::Situation.instance_eval do
- include RiotRails::ActionController::HttpSupport
- include ::ActionController::UrlFor
- default_url_options[:host] = "test.host"
-end
@@ -1,54 +0,0 @@
-require 'teststrap'
-
-class FoosController < ActionController::Base
- def index
- @thing = "hoo ray"
- render :text => ''
- end
-end
-
-rails_context "A controller test" do
- controlling :foos
-
- asserts_controller.kind_of(FoosController)
- asserts_topic.kind_of(FoosController)
-
- asserts("request is accessible") { request }.kind_of(::ActionDispatch::TestRequest)
- asserts("response is accessible") { response }.kind_of(::ActionDispatch::TestResponse)
- asserts("params is accessible") { controller.params }.equals({})
-
- asserts("http method shortcut for get") { self }.responds_to(:get)
- asserts("http method shortcut for post") { self }.responds_to(:post)
- asserts("http method shortcut for put") { self }.responds_to(:put)
- asserts("http method shortcut for delete") { self }.responds_to(:delete)
- asserts("http method shortcut for xml_http_request") { self }.responds_to(:xml_http_request)
- asserts("http method shortcut for xhr") { self }.responds_to(:xhr)
-
- asserts("an unknown action call") do
- get :burberry
- end.raises(::ActionController::UnknownAction, "The action 'burberry' could not be found")
-end # A controller test
-
-rails_context "A controller test using class as argument" do
- controlling FoosController
-
- asserts_controller.kind_of(FoosController)
-end # A controller test using class as argument
-
-rails_context FoosController do
- hookup do
- @actual_class_name = topic.class.name
- get :index
- end
-
- asserts("actual class name") { @actual_class_name }.equals("FoosController")
-
- asserts_assigned(:thing).equals("hoo ray")
- asserts_assigned(:that).nil
-
- asserts_response.kind_of(::ActionDispatch::TestResponse)
- asserts_response(:response_code).equals(200)
-
- asserts_request.kind_of(::ActionDispatch::TestRequest)
- asserts_request(:cookies).kind_of(Hash)
-end # A controller test with a hookup using the controller
Oops, something went wrong.

0 comments on commit 78605ec

Please sign in to comment.