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

Support namespace #1117

Merged
merged 3 commits into from Mar 27, 2018
Merged

Support namespace #1117

merged 3 commits into from Mar 27, 2018

Conversation

kaevee
Copy link
Contributor

@kaevee kaevee commented Mar 22, 2018

The current generator did not support namespace models. The patch fixes following issues

  1. The migration file not named correctly if namespace is used in models.

rails g devise_token_auth:install Sprint::V1::Auth::User auth
create config/initializers/devise_token_auth.rb
**create db/migrate/devise_token_auth_create_sprint/v1/auth/20180322050951_users.rb**
create app/models/sprint/v1/auth/user.rb
insert app/controllers/application_controller.rb
gsub config/routes.rb

  1. Class name and table name in migration file is incorrect
class DeviseTokenAuthCreateSprint::V1::Auth::Users < ActiveRecord::Migration[5.1]
  def change
    create_table(:sprint/v1/auth/users) do |t|
      ## Required
      t.string :provider, :null => false, :default => "email"
      t.string :uid, :null => false, :default => ""

snipped

    add_index :sprint/v1/auth/users, :email,                unique: true
    add_index :sprint/v1/auth/users, [:uid, :provider],     unique: true
    add_index :sprint/v1/auth/users, :reset_password_token, unique: true
    add_index :sprint/v1/auth/users, :confirmation_token,   unique: true
    # add_index :sprint/v1/auth/users, :unlock_token,       unique: true
  1. The model file generated needs a fix
    class Sprint::v1::auth::user < ActiveRecord::Base
      # Include default devise modules. Others available are:
      # :confirmable, :lockable, :timeoutable and :omniauthable
      devise :database_authenticatable, :registerable,
             :recoverable, :rememberable, :trackable, :validatable
      include DeviseTokenAuth::Concerns::User
    end

Generator and template were refactored to support namespaced
models.
@zachfeldman
Copy link
Contributor

@kaevee ok, but can you add a test for this? Thanks!

@kaevee
Copy link
Contributor Author

kaevee commented Mar 23, 2018

Sure. I will. Thanks!

@kaevee
Copy link
Contributor Author

kaevee commented Mar 23, 2018

To keep things simple, I have created a separate test for user models with namespace.

@zachfeldman
Copy link
Contributor

Very awesome @kaevee ! Going to just re-run the tests to be sure

@zachfeldman zachfeldman reopened this Mar 23, 2018
@zachfeldman zachfeldman self-assigned this Mar 23, 2018
@zachfeldman zachfeldman self-requested a review March 23, 2018 15:55
Copy link
Collaborator

@MaicolBen MaicolBen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More tests than I expected!

@MaicolBen MaicolBen merged commit 5857e39 into lynndylanhurley:master Mar 27, 2018
@kaevee
Copy link
Contributor Author

kaevee commented Mar 28, 2018

Thanks. Lack of namespace support has been bugging me since late 2016. I wonder why I did not take this up all these days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants