Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing spec for Engine #173

Open
wafendy opened this issue Sep 27, 2017 · 13 comments
Open

Routing spec for Engine #173

wafendy opened this issue Sep 27, 2017 · 13 comments

Comments

@wafendy
Copy link

wafendy commented Sep 27, 2017

Hi,

I'm using route_translator v5.5.0 gem and running the following issue. I hope someone can clarify why it's behaving this way.

#app/config/routes.rb
App::Engine.routes.draw do

  #This is to hide the extra translation /:locale/engine/:locale/path
  RouteTranslator.config { |config| config.hide_locale = true }

  localized do
    root to: "pages#index"
  end
end

#app/spec/dummy_app/config/routes.rb
Rails.application.routes.draw do
  localized do
    mount App::Engine => "/app"
  end
end

#spec/dummy_app/config/application.rb
module DummyApp
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.1

    I18n.available_locales = [:en, :de]
    I18n.default_locale = :en
  end
end
           Prefix Verb URI Pattern        Controller#Action
app_de                   /de/app              App::Engine {:locale=>"de"}
app_en                   /app                 App::Engine {:locale=>"en"}

Routes for App::Engine:
           root_de GET    /                   app/pages#landing {:locale=>"de"}
           root_en GET    /                   app/pages#landing {:locale=>"en"}
#spec/routing/app_engine_routes_spec.rb
describe 'routes for App engine' do
  routes { App::Engine.routes }
  it 'routes / to the index page' do
    expect(get: '/').to route_to(
      controller: "app/pages",
      action: "index",
      locale: 'en',
    )
  end
end

Since I set my default_locale, I would expect it returns en, but it returns de as locale instead. Any idea how to do proper spec in this scenario?

@wafendy wafendy changed the title Routing Routing spec for Engine Sep 27, 2017
@tagliala
Copy link
Collaborator

which version of Rails?

@wafendy
Copy link
Author

wafendy commented Sep 27, 2017

Rails version Rails 5.1.4

@tagliala
Copy link
Collaborator

Could you please give a try with 5.1.2?

@wafendy
Copy link
Author

wafendy commented Sep 27, 2017

Ok, I just did, i'm still getting the same behavior.
Just in case if you missed, I did set
RouteTranslator.config { |config| config.hide_locale = true } at the engine's route so I won't see the language twice in the URL.

By doing this, I'm getting

Routes for App::Engine:
           root_de GET    /                   app/pages#landing {:locale=>"de"}
           root_en GET    /                   app/pages#landing {:locale=>"en"}

So if I go directly to root path, then it will pick up the first one in the list (I assume).

@tagliala
Copy link
Collaborator

tagliala commented Sep 27, 2017

Sorry, I'm not using this gem with engines, so I don't know what to expect and what the actual behavior is. I thought it could be related to #172, so I've asked your rails version

Also, I don't know how to fix this issue.

Given that we cannot have two paths with two different languages, could you please provide:

  1. what you are trying to do
  2. what you are expecting from route_translator
  3. what is the actual behaviour of route_translator

?

@tagliala
Copy link
Collaborator

tagliala commented Sep 27, 2017

/cc @rvasquez-flip4new (author of the engine support feature)

@wafendy
Copy link
Author

wafendy commented Sep 28, 2017

I want to use route translator on both the main app and my engine. But i'm getting the following path with my route helpers:
/en/engine/en/index

The language is being displayed twice

@tagliala
Copy link
Collaborator

tagliala commented Sep 28, 2017

What does happen if you remove the localized block inside the engine routes?

@wafendy
Copy link
Author

wafendy commented Sep 28, 2017

If you remove localized block inside the engine routes, then all routes from engine don't have any locale information and are not translated.

@tagliala
Copy link
Collaborator

Thanks for the information.

As I mentioned before, I'm not so much into Rails Engines and I don't know how they behave and how route_translator should deal with them.

I would like a summary like this:

Without route translator

routes.rb

# Your routes here

Engine routes

# Your engine routes here

Result of rails routes

              Prefix Verb   URI Pattern                     Controller#Action
                 ... ...    ...

With route translator

routes.rb

# Your routes here

route_translator.rb initialzier

# Your initializer here

Engine routes

# Your engine routes here

Expected result of rails routes

              Prefix Verb   URI Pattern                     Controller#Action
                 ... ...    ...

Actual result of rails routes

              Prefix Verb   URI Pattern                     Controller#Action
                 ... ...    ...

@wafendy
Copy link
Author

wafendy commented Sep 29, 2017

Without route translator

git repo
https://github.com/wafendy/blorgh

routes.yml

en:
  routes:
    articles: articles
    magazines: magazines
id:
  routes:
    articles: artikel
    magazines: majalah

routes.rb

Rails.application.routes.draw do
  localized do
    resources :articles, only: [:index]
    mount Blorgh::Engine => "/blorgh"
  end
end

Engine routes

Blorgh::Engine.routes.draw do
  resources :magazines, only: [:index]
end

Result of rails routes

     Prefix Verb URI Pattern            Controller#Action
articles_id GET  /id/artikel(.:format)  articles#index {:locale=>"id"}
articles_en GET  /en/articles(.:format) articles#index {:locale=>"en"}
  blorgh_id      /id/blorgh             Blorgh::Engine {:locale=>"id"}
  blorgh_en      /en/blorgh             Blorgh::Engine {:locale=>"en"}

Routes for Blorgh::Engine:
magazines GET  /magazines(.:format) blorgh/magazines#index

Would it be possible to automagically include route translator at Engine level when Rails Engine is mounted inside localized block?

Actual Result:

  http://localhost:3000/id/blorgh/magazines

Expected Result:

  http://localhost:3000/id/blorgh/majalah

With route translator

routes.rb

Rails.application.routes.draw do
  localized do
    resources :articles, only: [:index]
    mount Blorgh::Engine => "/blorgh"
  end
end

route_translator.rb initialzier

RouteTranslator.config do |config|
  config.force_locale = true
end

Engine routes

Blorgh::Engine.routes.draw do
  localized do
    resources :magazines, only: [:index]
  end
end

Result of rails routes

     Prefix Verb URI Pattern            Controller#Action
articles_id GET  /id/artikel(.:format)  articles#index {:locale=>"id"}
articles_en GET  /en/articles(.:format) articles#index {:locale=>"en"}
  blorgh_id      /id/blorgh             Blorgh::Engine {:locale=>"id"}
  blorgh_en      /en/blorgh             Blorgh::Engine {:locale=>"en"}

Routes for Blorgh::Engine:
magazines_id GET  /id/majalah(.:format)   blorgh/magazines#index {:locale=>"id"}
magazines_en GET  /en/magazines(.:format) blorgh/magazines#index {:locale=>"en"}

@tagliala
Copy link
Collaborator

So, as far as I understand, if you use route_translator inside your engine and your engine is itself inside a localized block, then:

Actual result

     Prefix Verb URI Pattern            Controller#Action
articles_id GET  /id/artikel(.:format)  articles#index {:locale=>"id"}
articles_en GET  /en/articles(.:format) articles#index {:locale=>"en"}
  blorgh_id      /id/blorgh             Blorgh::Engine {:locale=>"id"}
  blorgh_en      /en/blorgh             Blorgh::Engine {:locale=>"en"}

Routes for Blorgh::Engine:
magazines_id GET  /id/majalah(.:format)   blorgh/magazines#index {:locale=>"id"}
magazines_en GET  /en/magazines(.:format) blorgh/magazines#index {:locale=>"en"}

Expected result

     Prefix Verb URI Pattern            Controller#Action
articles_id GET  /id/artikel(.:format)  articles#index {:locale=>"id"}
articles_en GET  /en/articles(.:format) articles#index {:locale=>"en"}
  blorgh_id      /id/blorgh             Blorgh::Engine {:locale=>"id"}
  blorgh_en      /en/blorgh             Blorgh::Engine {:locale=>"en"}

Routes for Blorgh::Engine:
magazines_id GET  /majalah(.:format)   blorgh/magazines#index {:locale=>"id"}
magazines_en GET  /magazines(.:format) blorgh/magazines#index {:locale=>"en"}

Am I right?

@wafendy
Copy link
Author

wafendy commented Sep 29, 2017

Yup, that's correct.

@tagliala tagliala added this to the 6.0.0 milestone Nov 14, 2017
tagliala added a commit that referenced this issue Dec 3, 2017
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Feb 5, 2018
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Apr 9, 2018
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Apr 10, 2018
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Jun 7, 2018
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Oct 3, 2018
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Jan 19, 2019
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Mar 14, 2019
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue May 16, 2019
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue May 16, 2019
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
@tagliala tagliala removed this from the 7.0.0 milestone Jul 20, 2019
tagliala added a commit that referenced this issue Dec 26, 2019
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Dec 26, 2019
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Dec 26, 2019
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Apr 17, 2020
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
AsgharRaz pushed a commit to AsgharRaz/route_translator that referenced this issue Nov 3, 2020
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes enriclluelles#166, fixes enriclluelles#172, fixes enriclluelles#173 and fixes enriclluelles#178
tagliala added a commit that referenced this issue Jan 13, 2021
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Jan 13, 2021
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Jan 16, 2021
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
tagliala added a commit that referenced this issue Jan 16, 2021
The current engine implementation is buggy and incomplete.

We are going to drop the whole feature, waiting for a new contributor

Fixes #166, fixes #172, fixes #173 and fixes #178
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants