Module: Spree::TestingSupport::ControllerRequests

Extended by:
ActiveSupport::Concern
Defined in:
lib/spree/testing_support/controller_requests.rb

Overview

A module providing convenience methods to test Solidus controllers in Rails controller/functional tests. Possibly from inside an application with a mounted Solidus engine.

*There is generaly no need* to use this module. Instead, in a functional/controller test against a Spree controller, just use standard Rails functionality by including:

routes { Spree::Core::Engine.routes }

And then use standard Rails test `get`, `post` etc methods.

But some legacy code uses this ControllerRequests helper. It must be included only in tests against Spree controllers, it will interfere with tests against local app or other engine controllers, resulting in ActionController::UrlGenerationError.

To use this module, inside your spec_helper.rb, include this module inside the RSpec.configure block by:

require 'spree/testing_support/controller_requests'
RSpec.configure do |c|
  c.include Spree::TestingSupport::ControllerRequests, spree_controller: true
end

Then, in your controller tests against spree controllers, you can access tag to use this module, and access spree routes like this:

require 'spec_helper'

describe Spree::ProductsController, :spree_controller do
  it "can see all the products" do
    spree_get :index
  end
end

Use spree_get, spree_post, spree_put or spree_delete to make requests to the Spree engine, and use regular get, post, put or delete to make requests to your application.

Instance Method Summary collapse

Instance Method Details

#spree_delete(action, parameters = nil, session = nil, flash = nil) ⇒ Object

Executes a request simulating DELETE HTTP method and set/volley the response



69
70
71
# File 'lib/spree/testing_support/controller_requests.rb', line 69

def spree_delete(action, parameters = nil, session = nil, flash = nil)
  process_spree_action(action, parameters, session, flash, "DELETE")
end

#spree_get(action, parameters = nil, session = nil, flash = nil) ⇒ Object



51
52
53
# File 'lib/spree/testing_support/controller_requests.rb', line 51

def spree_get(action, parameters = nil, session = nil, flash = nil)
  process_spree_action(action, parameters, session, flash, "GET")
end

#spree_post(action, parameters = nil, session = nil, flash = nil) ⇒ Object

Executes a request simulating POST HTTP method and set/volley the response



57
58
59
# File 'lib/spree/testing_support/controller_requests.rb', line 57

def spree_post(action, parameters = nil, session = nil, flash = nil)
  process_spree_action(action, parameters, session, flash, "POST")
end

#spree_put(action, parameters = nil, session = nil, flash = nil) ⇒ Object

Executes a request simulating PUT HTTP method and set/volley the response



63
64
65
# File 'lib/spree/testing_support/controller_requests.rb', line 63

def spree_put(action, parameters = nil, session = nil, flash = nil)
  process_spree_action(action, parameters, session, flash, "PUT")
end

#spree_xhr_delete(action, parameters = nil, session = nil, flash = nil) ⇒ Object



89
90
91
# File 'lib/spree/testing_support/controller_requests.rb', line 89

def spree_xhr_delete(action, parameters = nil, session = nil, flash = nil)
  process_spree_xhr_action(action, parameters, session, flash, :delete)
end

#spree_xhr_get(action, parameters = nil, session = nil, flash = nil) ⇒ Object



74
75
76
# File 'lib/spree/testing_support/controller_requests.rb', line 74

def spree_xhr_get(action, parameters = nil, session = nil, flash = nil)
  process_spree_xhr_action(action, parameters, session, flash, :get)
end

#spree_xhr_post(action, parameters = nil, session = nil, flash = nil) ⇒ Object



79
80
81
# File 'lib/spree/testing_support/controller_requests.rb', line 79

def spree_xhr_post(action, parameters = nil, session = nil, flash = nil)
  process_spree_xhr_action(action, parameters, session, flash, :post)
end

#spree_xhr_put(action, parameters = nil, session = nil, flash = nil) ⇒ Object



84
85
86
# File 'lib/spree/testing_support/controller_requests.rb', line 84

def spree_xhr_put(action, parameters = nil, session = nil, flash = nil)
  process_spree_xhr_action(action, parameters, session, flash, :put)
end