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

Teach jsonapi:resource generator to respect namespaced models and controllers #141

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

alsemyonov
Copy link

@alsemyonov alsemyonov commented Oct 25, 2018

Fixes the issue with namespaced models.

rails generate jsonapi:resource Blog::Post

Before

  1. generates app/serializables/blog/serializable_post.rb file with SerializableBlog::Post class inside (💣 breaks autoloading).
  2. generated controller is app/controllers/blog/posts_controller.rb,
    but config/routes.rb includes:
    resources :blog/posts
    (💣 and breaks everything with Syntax Error)
  3. Factory generated by rails generate factory_bot:model Blog::Post is called :blog_post,
    but API request specs try to create(:post) (💣 Factory not registered! )
  4. API request specs files put into spec/api/v1/posts/blog/{create,destroy,index,show,update}_spec.rb (← posts/blog? what is that?)
  5. API request specs try to send jsonapi_{get,delete,post,put} '/api/v1/posts' (💣 which nothing can handle)

After:

  1. generates app/serializables/blog/serializable_post.rb file with Blog::SerializablePost class inside.
  2. generated controller is app/controllers/blog/posts_controller.rb,
    and config/routes.rb includes
    namespace :blog do
      resources :posts
    end
  3. Factory generated by rails generate factory_bot:model Blog::Post is called :blog_post,
    and API requests specs try to create(:blog_post)
  4. API request specs files put into spec/api/v1/blog/posts/{create,destroy,index,show,update}_spec.rb (← blog/posts, according to generated controller)
  5. API request specs try to send jsonapi_{get,delete,post,put} '/api/v1/blog/posts' (which is handled by generated Blog::PostsController

@alsemyonov alsemyonov changed the title Teach jsonapi:resource generator respect namespaces models and controllers Teach jsonapi:resource generator to respect namespaced models and controllers Oct 25, 2018
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.

1 participant