Skip to content

Commit

Permalink
Merge pull request #273 from AlfonsoUceda/fix-container-routes-bug
Browse files Browse the repository at this point in the history
Fix container router bugs
  • Loading branch information
AlfonsoUceda committed Jun 30, 2015
2 parents 36db29e + 37643c6 commit 9df89c6
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 31 deletions.
79 changes: 57 additions & 22 deletions test/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,6 @@ def verify_csrf_token?
end
end

module Admin
class Application < Lotus::Application
configure do
routes do
get '/home', to: 'home#index', as: :home
end
end
end
end

module CallCenter
class Application < Lotus::Application
configure do
routes do
get '/home', to: 'home#index', as: :home
end
end
end
end

module ForceSslApp
class Application < Lotus::Application
configure do
Expand Down Expand Up @@ -208,7 +188,7 @@ module ContainerForceSsl
class Application < Lotus::Application
configure do
routes do
get '/', to: 'home#show'
get '/', to: 'home#show'
end

force_ssl true
Expand Down Expand Up @@ -236,7 +216,7 @@ module ContainerNoForceSsl
class Application < Lotus::Application
configure do
routes do
get '/', to: 'home#show'
get '/', to: 'home#show'
end
end

Expand All @@ -255,3 +235,58 @@ def call(params)
end
end
end

module Back
class Application < Lotus::Application
configure do
routes do
get '/home', to: 'home#show', as: :home
get '/users', to: 'users#index'
end
end
end

module Controllers
module Home
class Show
include Lotus::Action

def call(params)
self.body = 'hello Back'
end
end
end
module Users
class Index
include Lotus::Action

def call(params)
self.body = 'hello from Back users endpoint'
end
end
end
end
end

module Front
class Application < Lotus::Application
configure do
routes do
get '/home', to: 'home#show', as: :home
end
end
end

module Controllers
module Home
class Show
include Lotus::Action

def call(params)
self.body = 'hello Front'
end
end
end
end
end

56 changes: 47 additions & 9 deletions test/integration/container_test.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,55 @@
require 'test_helper'
require 'rack/test'

describe Lotus::Container do
describe 'apps mounted with container' do
it 'should generate correct paths with route helper' do
Lotus::Container.configure do
mount Admin::Application, at: '/admin'
mount CallCenter::Application, at: '/callcenter'
end
include Rack::Test::Methods

Lotus::Container.new
before do
Lotus::Container.configure do
mount Front::Application, at: '/front'
mount Back::Application, at: '/back'
end

@container = Lotus::Container.new
Front::Application.load!
Back::Application.load!
end

def app
@container
end

def response
last_response
end

CallCenter::Routes.path(:home).must_equal '/callcenter/home'
Admin::Routes.path(:home).must_equal '/admin/home'
it 'reach to endpoints' do
get '/back/home'
response.status.must_equal 200
response.body.must_equal 'hello Back'

get '/front/home'
response.status.must_equal 200
response.body.must_equal 'hello Front'

get '/back/users'
response.status.must_equal 200
response.body.must_equal 'hello from Back users endpoint'
end

it 'print correct routes' do
matches = [
'GET, HEAD /front/home Front::Controllers::Home::Show',
'GET, HEAD /back/home Back::Controllers::Home::Show',
'GET, HEAD /back/users Back::Controllers::Users::Index'
]
matches.each do |match|
@container.routes.inspector.to_s.must_match match
end
end

it 'generate correct urls with route helpers' do
Front::Routes.path(:home).must_equal '/front/home'
Back::Routes.path(:home).must_equal '/back/home'
end
end

0 comments on commit 9df89c6

Please sign in to comment.