rails-engines

Running spec for a rails engine from its parent app

耗尽温柔 提交于 2019-12-05 23:17:05
问题 I have rspec suite for parent app, and also some spec for engines attached. What I want is to run them with one command. Is there a way to include my gems paths into rspec load path? Or should I write rake task for this? 回答1: I think this is an interesting question, but my opinion is that Rails Engines should be treated as an independent code base and therefore not tested in your parent app. The effect is that you'd treat a Rails Engine in your parent app much like you treat other gems (EG,

How to develop a Rails3 engine against a real app, using RSpec?

让人想犯罪 __ 提交于 2019-12-05 13:09:24
A lot has been written about engine development, and using a dummy app for testing. In our case we're developing an engine that is not a stand-alone entity, but has dependencies on a real Rails 3 application. We still want this code to live in an engine, and not become part of the app, because the engine's job is to import data from a legacy system that has its own tables and model mappings, and we want to eventually remove it again. The data mappings between the old legacy tables and the new schema are complex, and we want to TDD (using rspec) the engine. I've followed Jose Valim's book

Reopening Rails 3 engine classes from parent app

喜欢而已 提交于 2019-12-05 04:51:57
As it stands now, you can't reopen Engine classes contained within the engine's /app directory by simply adding the same class in the parent app's /app dir. For example: /my_engine/app/controllers/users_controller.rb /my_app/app/controllers/users_controller.rb The file from my_engine will not even load if there is a file with the same name in the parent app. More details here: http://www.cowboycoded.com/2011/02/28/why-you-cant-reopen-rails-3-engine-classes-from-the-parent-app/ I am looking for a workaround that will allow me to drop the same filename/class in the same path as the parent app,

Rails Engines: Helpers only are reloaded when restarting the server

时光总嘲笑我的痴心妄想 提交于 2019-12-05 00:13:16
I'm currently experimenting with moving functionality into engines. It works nicely so far, but I'm a bit confused why certain parts of the engine are always automatically reloaded when something changed, and some are not. Specifically, when adding a helper method, I have to restart the Rails server, otherwise it is not seen by Rails. Is this normal behavior? Here's the relevant part of my engine: components/iq_list.rb # encoding: utf-8 require 'iq_list/engine' # Load IqList Modules module IqList extend ActiveSupport::Autoload autoload :Helpers autoload :Models autoload :Controllers end

No Route Matches … Rails Engine

巧了我就是萌 提交于 2019-12-04 23:52:58
So I keep getting the error: No route matches {:action=>"create", :controller=>"xaaron/api_keys"} Which is thrown in the test: it "should not create an api key for those not logged in" do post :create expect(response).to redirect_to xaaron.login_path end when I go to spec/dummy and run the rake routes command I see: api_keys GET /api_keys(.:format) xaaron/api_keys#index POST /api_keys(.:format) xaaron/api_keys#create new_api_key GET /api_keys/new(.:format) xaaron/api_keys#new edit_api_key GET /api_keys/:id/edit(.:format) xaaron/api_keys#edit api_key GET /api_keys/:id(.:format) xaaron/api_keys

Creating a belongs_to relationship with a model from the main app from an engine model

纵然是瞬间 提交于 2019-12-04 21:13:08
I've built myself a Rails Engine that requires that the main app have a Users table. I need to be able to create a relationship between one of the models in my engine and the Users table in the main app. Is this more complicated than just saying belongs_to :user ? I'm getting an error that says the User object is nil, but when I use the console it returns the right user. My assumption is that Rails assumed my belongs_to :user call meant a User's class in the same namespace as the engine, i.e. MyEngine::User. Is there a way for me to explicitly specify that the User class is in the main app's

Rails engine and devise

旧巷老猫 提交于 2019-12-04 12:53:51
I have a Rails Engine, where I want to use Devise. I installed devise like normal following this guide . I added this in my engine devise.rb: Devise.setup do |config| config.router_name = :cms_user end I added this in my routes file: Cms::User::Engine.routes.draw do devise_for :users, { class_name: 'Cms::User', module: :devise } end I added this in my routes: devise_for :users, { class_name: 'Cms::User', module: :devise } However I keep getting this error: undefined method 'cms_user' What am I doing wrong ? Here's the how to: Rails plugin new cms --mountable -d postgresql 2: Install devise

rails prepend_view_path of mountable engine

你离开我真会死。 提交于 2019-12-04 11:33:50
In one hand, I have a mountable engine let's say Front Front contain my assets and couple of pages It's isolated from MainApp. I don't want it to touch the main app. In the other hand I want my MainApp using layout and partial of the Front. So I setup the layout this way : class ApplicationController < ActionController::Base layout 'front/application' end But the front/application refer to engine partial directly, because of isolation, like this render 'header' # front/ prefix is not required So the MainApp views try to load app/views/application/header instead of app/views/front/application

Rails Engine + Mongoid: No configuration could be found for a session named 'default'

坚强是说给别人听的谎言 提交于 2019-12-04 09:36:11
问题 I've created a Rails Mountable App and added 'mongoid' and 'rspec' gem's. If I try to run my specs now I get the following error: Mongoid::Errors::NoSessionConfig: Problem: No configuration could be found for a session named 'default'. Summary: When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect. Resolution: Double check your mongoid.yml to make sure

How to override Rails app routes from an engine?

孤街醉人 提交于 2019-12-04 08:30:01
I have a Rails app that I am trying to integrate a Rails engine in to. The host app has some catch all routes: # magic urls match '/' => 'admin/rendering#show' match '*path/edit' => 'admin/rendering#show', :defaults => { :editing => true } match '*path' => 'admin/rendering#show' It looks like the engine routes are loaded after the application catches all routes. /sitemap.xml(.:format) {:format=>"xml", :controller=>"admin/sitemaps", :action=>"show"} /(.:format) {:controller=>"admin/rendering", :action=>"show"} /*path/edit(.:format) {:controller=>"admin/rendering", :action=>"show"} /*path {