1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

Hook for paloma:add when using 'rails generate controller actions*'

This commit is contained in:
kbparagua 2013-02-12 23:17:46 +08:00
parent 6fb346d86b
commit 668d4d4388
6 changed files with 101 additions and 13 deletions

View file

@ -19,6 +19,7 @@ module Paloma
def self.templates
@templates ||= "#{Paloma.root}/app/templates"
end
end
require 'action_controller/railtie'
@ -30,3 +31,4 @@ require 'paloma/generators/add_generator'
require 'paloma/generators/setup_generator'
require 'paloma/action_controller_filters'
require 'paloma/action_controller_extension'
require 'paloma/rails/controller_generator'

View file

@ -0,0 +1,11 @@
module ::Rails::Generators
class ControllerGenerator < NamedBase
class_option :paloma, :type => :boolean, :default => true
def paloma
invoke 'paloma:add', ([file_name] + actions) if options[:paloma]
end
end
end

15
spec/generator_helper.rb Normal file
View file

@ -0,0 +1,15 @@
require 'rails/generators/named_base'
require 'rails/generators/rails/controller/controller_generator'
require 'fileutils'
require 'generator_spec/test_case'
TEMP = "#{File.dirname(__FILE__)}/tmp/"
def mimic_setup
# Mimic SetupGenerator results before running the AddGenerator
FileUtils.cd TEMP
FileUtils.mkpath Paloma.destination
File.open("#{Paloma.destination}/index.js", 'w') { |f| f.write('//= require ./paloma.js')}
end

View file

@ -1,8 +1,6 @@
require 'spec_helper'
require 'generator_spec/test_case'
require 'fileutils'
require 'generator_helper'
TEMP = "#{File.dirname(__FILE__)}/tmp/"
# rails g paloma:setup
feature Paloma::SetupGenerator do
@ -25,15 +23,6 @@ feature Paloma::SetupGenerator do
end
def mimic_setup
# Mimic SetupGenerator results before running the AddGenerator
FileUtils.cd TEMP
FileUtils.mkpath Paloma.destination
File.open("#{Paloma.destination}/index.js", 'w') { |f| f.write('//= require ./paloma.js')}
end
# rails g paloma:add sexy_controller
feature Paloma::AddGenerator, 'creating controller folder only' do
include GeneratorSpec::TestCase

View file

@ -0,0 +1,71 @@
require 'spec_helper'
require 'generator_helper'
feature ::Rails::Generators::ControllerGenerator, 'generating a rails controller without action' do
include GeneratorSpec::TestCase
destination TEMP
arguments ['my_controller']
before do
prepare_destination
mimic_setup
run_generator
end
specify do
destination_root.should have_structure {
directory Paloma.destination do
directory 'my_controller' do
file '_local.js' do
contains 'Paloma.my_controller = {'
end
file '_callbacks.js' do
contains '//= require ./_local.js'
contains '//= require_tree .'
end
end
end
}
end
end
feature ::Rails::Generators::ControllerGenerator, 'generating a rails controller with actions' do
include GeneratorSpec::TestCase
destination TEMP
arguments ['my_controller', 'new', 'edit']
before do
prepare_destination
# Create config/routes.rb
FileUtils.cd TEMP
FileUtils.mkpath 'config'
File.open("config/routes.rb", 'w') { |f| f.write('')}
mimic_setup
run_generator
end
specify do
destination_root.should have_structure {
directory Paloma.destination do
directory 'my_controller' do
file '_local.js' do
contains 'Paloma.my_controller = {'
end
file '_callbacks.js' do
contains '//= require ./_local.js'
contains '//= require_tree .'
end
file 'new.js'
file 'edit.js'
end
end
}
end
end

View file

@ -5,10 +5,10 @@ Bundler.require
require 'sample_app/init'
require 'rspec/rails'
require 'capybara/rspec'
require 'database_cleaner'
RSpec.configure do |config|
config.before :each do
DatabaseCleaner.strategy = :truncation