Skip to content
Browse files

incorporate Engine into chanko

  • Loading branch information...
1 parent 46829f0 commit d6226c149ea863d91edc0fbbff6da93f1d16151a @eudoxa eudoxa committed Apr 24, 2012
View
6 config/routes.rb
@@ -0,0 +1,6 @@
+Chanko::Engine.routes.draw do
+end
+
+Chanko::Application.routes.draw do
+ mount Chanko::Engine => "/ext"
+end
View
6 lib/chanko.rb
@@ -1,3 +1,7 @@
+# singletone issue will be fixed
+# https://github.com/radar/forem/commit/049057a8e94e59610365b6764c733eb7876c8351
+require 'active_support/core_ext/kernel/singleton_class'
+require 'chanko/engine'
+
module Chanko
- require 'chanko/railtie'
end
View
2 lib/chanko/railtie.rb → lib/chanko/engine.rb
@@ -7,7 +7,7 @@ module Chanko
autoload klass.camelize, "chanko/#{klass}"
end
- class Railtie < Rails::Railtie
+ class Engine < ::Rails::Engine
initializer 'chanko.attach' do |app|
::ActionView::Base.send(:include, Chanko::Invoker)
::ActionController::Base.send(:include, Chanko::Invoker)
View
11 lib/chanko/loader.rb
@@ -90,7 +90,6 @@ def aborted_units
self.__aborted.uniq
end
-
def load_expander(unit_name)
%w(models helpers).each do |targets|
Chanko::Loader.directories.each do |directory|
@@ -152,11 +151,21 @@ def deregister(obj)
def load_path_file(file, root)
@directories = Chanko::Directories.load_path_file(file, root)
+ initialize_engines
end
def add_path(path)
@directories ||= Chanko::Directories.new
@directories.add(path)
+ initialize_engines
+ end
+
+ def initialize_engines
+ Chanko::Loader.directories.each do |directory|
+ Pathname.glob("#{directory}/*/lib/*/engine.rb").each do |engine|
+ require engine.sub(/\.rb$/, '')
+ end
+ end
end
def remove_path(path)
View
2 spec/app.rb
@@ -30,6 +30,8 @@ class CreateAllTables < ::ActiveRecord::Migration
def self.up
create_table(:users) {|t| t.string :name }
create_table(:recipes) {|t| t.string :title; t.integer :user_id }
+ create_table(:diaries) {|t| t.string :content; t.integer :user_id }
+ create_table(:comments) {|t| t.string :content; t.integer :user_id }
end
end
View
1 spec/app/route.rb
@@ -1,3 +1,4 @@
Chanko::Application.routes.draw do
+ mount Chanko::Engine => "/"
match '/:controller(/:action(/:id))'
end
View
7 spec/fixtures/test_units/engine_unit/app/controllers/engine_unit/top_controller.rb
@@ -0,0 +1,7 @@
+module EngineUnit
+ class TopController < ActionController::Base
+ def top
+ render :text => 'hoge'
+ end
+ end
+end
View
8 spec/fixtures/test_units/engine_unit/app/models/engine_unit/comment.rb
@@ -0,0 +1,8 @@
+module EngineUnit
+ class Comment < ActiveRecord::Base
+ set_table_name :comments
+ def hello
+ 'hello'
+ end
+ end
+end
View
8 spec/fixtures/test_units/engine_unit/config/routes.rb
@@ -0,0 +1,8 @@
+EngineUnit::Engine.routes.draw do
+ match '/' => 'top#top'
+end
+
+Chanko::Engine.routes.draw do
+ mount EngineUnit::Engine => "/engine_unit"
+end
+
View
5 spec/fixtures/test_units/engine_unit/lib/engine_unit/engine.rb
@@ -0,0 +1,5 @@
+module EngineUnit
+ class Engine < ::Rails::Engine
+ isolate_namespace EngineUnit
+ end
+end
View
13 spec/integration/engine_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe "Chanko", :type => :integration do
+ describe "Engine" do
+ before do
+ end
+
+ it 'access engine action' do
+ visit "/engine_unit"
+ (response || page).body.should == 'hoge'
+ end
+ end
+end
View
27 spec/lib/engine_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe Chanko do
+ shared_examples_for 'engine' do
+ describe 'model' do
+ it 'use engine model method' do
+ EngineUnit::Comment.new.hello.should == 'hello'
+ end
+
+ it'save engine model' do
+ expect {
+ EngineUnit::Comment.create
+ }.to change(EngineUnit::Comment, :count).from(0).to(1)
+ end
+ end
+ end
+
+ context 'with cache_classes' do
+ before { Chanko.config.cache_classes = true }
+ it_should_behave_like 'engine'
+ end
+
+ context 'without cache_classes' do
+ before { Chanko.config.cache_classes = false }
+ it_should_behave_like 'engine'
+ end
+end
View
3 spec/spec_helper.rb
@@ -10,6 +10,7 @@
require 'chanko'
require 'haml'
+require 'fixtures/test_units/engine_unit/lib/engine_unit/engine'
require 'app'
#Rails.root = Fir.dirname(__FILE__)
@@ -45,7 +46,7 @@ def fixtures_path
config.before(:suite) do
$: << fixtures_path.join('lib')
path = fixtures_path.join('test_units')
- Chanko::Loader.directories.unshift(path)
+ Chanko::Loader.add_path(path)
Chanko::ActiveIf.files = [fixtures_path.join('active_if', "main")]
ApplicationController.send(:include, Chanko::Invoker)
ActionView::Base.send(:include, Chanko::Invoker)

0 comments on commit d6226c1

Please sign in to comment.
Something went wrong with that request. Please try again.