2012-12-21 16:29:15 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'generator_spec/test_case'
|
|
|
|
require 'fileutils'
|
|
|
|
|
2012-12-22 03:51:44 +08:00
|
|
|
TEMP = "#{File.dirname(__FILE__)}/tmp/"
|
|
|
|
|
2012-12-21 16:29:15 +08:00
|
|
|
feature Paloma::SetupGenerator do
|
|
|
|
include GeneratorSpec::TestCase
|
2012-12-22 03:51:44 +08:00
|
|
|
destination TEMP
|
2012-12-21 16:29:15 +08:00
|
|
|
|
|
|
|
before do
|
|
|
|
prepare_destination
|
|
|
|
run_generator
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
destination_root.should have_structure {
|
2012-12-22 03:51:44 +08:00
|
|
|
directory Paloma.destination do
|
|
|
|
file 'paloma.js'
|
|
|
|
file 'index.js'
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
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('// test')}
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feature Paloma::AddGenerator, 'creating controller folder only' do
|
|
|
|
include GeneratorSpec::TestCase
|
|
|
|
destination TEMP
|
|
|
|
arguments ['sexy_controller']
|
|
|
|
|
|
|
|
before do
|
|
|
|
prepare_destination
|
|
|
|
mimic_setup
|
|
|
|
run_generator
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
destination_root.should have_structure {
|
|
|
|
directory Paloma.destination do
|
|
|
|
directory 'sexy_controller'
|
|
|
|
|
|
|
|
file 'index.js' do
|
|
|
|
contains '//= require ./sexy_controller/_callbacks'
|
2012-12-21 16:29:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-12-22 03:51:44 +08:00
|
|
|
|
|
|
|
feature Paloma::AddGenerator, 'creating action with existing controller folder' do
|
2012-12-21 16:29:15 +08:00
|
|
|
include GeneratorSpec::TestCase
|
2012-12-22 03:51:44 +08:00
|
|
|
destination TEMP
|
2013-01-03 15:14:40 +08:00
|
|
|
arguments ['existing_controller_folder new_action']
|
2012-12-21 16:29:15 +08:00
|
|
|
|
|
|
|
before do
|
2012-12-22 03:51:44 +08:00
|
|
|
prepare_destination
|
|
|
|
mimic_setup
|
|
|
|
Dir.mkdir "#{Paloma.destination}/existing_controller_folder"
|
|
|
|
|
2012-12-21 16:29:15 +08:00
|
|
|
run_generator
|
|
|
|
end
|
2012-12-22 03:51:44 +08:00
|
|
|
|
|
|
|
specify do
|
|
|
|
destination_root.should have_structure {
|
|
|
|
directory Paloma.destination do
|
|
|
|
directory 'existing_controller_folder' do
|
|
|
|
file 'new_action.js' do
|
|
|
|
contains "Paloma.callbacks['existing_controller_folder/new_action']"
|
|
|
|
end
|
2013-01-02 22:46:13 +08:00
|
|
|
|
|
|
|
file '_callbacks.js' do
|
2013-01-02 23:02:50 +08:00
|
|
|
contains "//= require ./_local.js"
|
2013-01-02 22:46:13 +08:00
|
|
|
contains "//= require_tree ."
|
|
|
|
end
|
2012-12-22 03:51:44 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2012-12-21 16:29:15 +08:00
|
|
|
|
2012-12-22 03:51:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
feature Paloma::AddGenerator, 'creating both controller folder and action file' do
|
|
|
|
include GeneratorSpec::TestCase
|
|
|
|
destination TEMP
|
2013-01-03 15:14:40 +08:00
|
|
|
arguments ['new_controller_folder new_action']
|
2012-12-22 03:51:44 +08:00
|
|
|
|
|
|
|
before do
|
|
|
|
prepare_destination
|
|
|
|
mimic_setup
|
|
|
|
run_generator
|
|
|
|
end
|
|
|
|
|
2012-12-21 16:29:15 +08:00
|
|
|
specify do
|
|
|
|
destination_root.should have_structure {
|
2012-12-22 03:51:44 +08:00
|
|
|
directory Paloma.destination do
|
|
|
|
directory 'new_controller_folder' do
|
|
|
|
file 'new_action.js' do
|
|
|
|
contains "Paloma.callbacks['new_controller_folder/new_action']"
|
2012-12-21 16:29:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
2012-12-22 03:51:44 +08:00
|
|
|
end
|
2012-12-21 16:29:15 +08:00
|
|
|
end
|
2013-01-03 16:39:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feature Paloma::AddGenerator, 'creating namespaced controller folder and action file' do
|
|
|
|
include GeneratorSpec::TestCase
|
|
|
|
destination TEMP
|
|
|
|
arguments ['namespace/new_controller_folder new_action']
|
|
|
|
|
|
|
|
before do
|
|
|
|
prepare_destination
|
|
|
|
mimic_setup
|
|
|
|
run_generator
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
destination_root.should have_structure {
|
|
|
|
directory Paloma.destination do
|
|
|
|
directory 'namespace' do
|
|
|
|
directory 'new_controller_folder' do
|
|
|
|
file 'new_action.js' do
|
|
|
|
contains "Paloma.callbacks['new_controller_folder/new_action']"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2013-01-03 19:04:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feature Paloma::AddGenerator, 'creating controller folder and action file under an existing namespace' do
|
|
|
|
include GeneratorSpec::TestCase
|
|
|
|
destination TEMP
|
|
|
|
arguments ['namespace/new_controller_folder new_action']
|
|
|
|
|
|
|
|
before do
|
|
|
|
prepare_destination
|
|
|
|
mimic_setup
|
|
|
|
Dir.mkdir "#{Paloma.destination}/namespace"
|
|
|
|
|
|
|
|
run_generator
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
destination_root.should have_structure {
|
|
|
|
directory Paloma.destination do
|
|
|
|
directory 'namespace' do
|
|
|
|
directory 'new_controller_folder' do
|
|
|
|
file 'new_action.js' do
|
|
|
|
contains "Paloma.callbacks['new_controller_folder/new_action']"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
file 'index.js' do
|
|
|
|
contains '//= require ./namespace/new_controller_folder/_callbacks'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|