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



67
68
69
# File 'lib/spree/testing_support/controller_requests.rb', line 67

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



49
50
51
# File 'lib/spree/testing_support/controller_requests.rb', line 49

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



55
56
57
# File 'lib/spree/testing_support/controller_requests.rb', line 55

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



61
62
63
# File 'lib/spree/testing_support/controller_requests.rb', line 61

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



87
88
89
# File 'lib/spree/testing_support/controller_requests.rb', line 87

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



72
73
74
# File 'lib/spree/testing_support/controller_requests.rb', line 72

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



77
78
79
# File 'lib/spree/testing_support/controller_requests.rb', line 77

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



82
83
84
# File 'lib/spree/testing_support/controller_requests.rb', line 82

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