Sha256: 64b3ac1892d64c47706ee12260da6cc01a47c49a9125c07d5eae6910f91454c5
Contents?: true
Size: 1.84 KB
Versions: 6
Compression:
Stored size: 1.84 KB
Contents
if RUBY_PLATFORM != 'opal' require 'volt/server/rack/http_resource' require 'volt/controllers/http_controller' require 'volt/server/rack/http_request' require 'volt/router/routes' describe Volt::HttpResource do def routes(&block) @routes = Volt::Routes.new @routes.define(&block) end class SimpleController < Volt::HttpController attr_reader :action_called def index @action_called = true render text: 'just some text' end def show render text: "show with id #{params[:stuff_id]} " \ "and #{params[:test]} called" end end let(:app) { ->(env) { [404, env, 'app'] } } before(:each) do routes do get '/stuff', controller: 'simple', action: 'index' get '/stuff/{{ stuff_id }}', controller: 'simple', action: 'show' end end it 'should initialize the correct controller and call the correct action' do http_resource = Volt::HttpResource.new(app, @routes) env = Rack::MockRequest.env_for('http://example.com/stuff') request = Volt::HttpRequest.new(env) controller = SimpleController.new({}, request) expect(SimpleController).to receive(:new).and_return(controller) response = http_resource.call(env) expect(response.status).to eq(200) expect(response.body).to eq(['just some text']) expect(controller.action_called).to eq(true) end it 'should parse the correct params to the controller' do http_resource = Volt::HttpResource.new(app, @routes) env = Rack::MockRequest.env_for('http://example.com/stuff/99?test=another_param') request = Volt::HttpRequest.new(env) response = http_resource.call(env) expect(response.status).to eq(200) expect(response.body).to eq(['show with id 99 and another_param called']) end end end
Version data entries
6 entries across 6 versions & 1 rubygems