merb-slices 0.9.7 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +4 -4
- data/Rakefile +27 -13
- data/TODO +1 -2
- data/bin/slice +77 -0
- data/lib/generators/templates/common/Rakefile +16 -12
- data/lib/generators/templates/full/README +4 -4
- data/lib/generators/templates/full/Rakefile +32 -13
- data/lib/generators/templates/full/config/init.rb +43 -0
- data/lib/generators/templates/full/lib/%base_name%.rb +3 -1
- data/lib/generators/templates/full/spec/%base_name%_spec.rb +10 -121
- data/lib/generators/templates/full/spec/controllers/main_spec.rb +18 -8
- data/lib/generators/templates/thin/README +4 -4
- data/lib/generators/templates/very_thin/README +4 -4
- data/lib/merb-slices.rb +3 -3
- data/lib/merb-slices/controller_mixin.rb +34 -7
- data/lib/merb-slices/merbtasks.rb +5 -34
- data/lib/merb-slices/module.rb +9 -3
- data/lib/merb-slices/module_mixin.rb +19 -31
- data/lib/merb-slices/router_ext.rb +10 -7
- data/spec/full_slice_generator_spec.rb +31 -2
- data/spec/full_slice_spec.rb +162 -0
- data/spec/merb-slice_spec.rb +97 -3
- data/spec/slice_generator_spec.rb +15 -3
- data/spec/slices/full-test-slice/LICENSE +20 -0
- data/spec/slices/full-test-slice/README +170 -0
- data/spec/slices/full-test-slice/Rakefile +67 -0
- data/spec/slices/full-test-slice/TODO +15 -0
- data/spec/slices/full-test-slice/app/controllers/application.rb +5 -0
- data/spec/slices/full-test-slice/app/controllers/main.rb +7 -0
- data/spec/slices/full-test-slice/app/helpers/application_helper.rb +64 -0
- data/spec/slices/full-test-slice/app/views/layout/full_test_slice.html.erb +16 -0
- data/spec/slices/full-test-slice/app/views/main/index.html.erb +1 -0
- data/spec/slices/full-test-slice/config/init.rb +43 -0
- data/spec/slices/full-test-slice/lib/full-test-slice.rb +80 -0
- data/spec/slices/full-test-slice/lib/full-test-slice/merbtasks.rb +103 -0
- data/spec/slices/full-test-slice/lib/full-test-slice/slicetasks.rb +18 -0
- data/spec/slices/full-test-slice/lib/full-test-slice/spectasks.rb +65 -0
- data/spec/slices/full-test-slice/public/javascripts/master.js +0 -0
- data/spec/slices/full-test-slice/public/stylesheets/master.css +2 -0
- data/spec/slices/full-test-slice/stubs/app/controllers/application.rb +2 -0
- data/spec/slices/full-test-slice/stubs/app/controllers/main.rb +2 -0
- data/spec/slices/thin-test-slice/LICENSE +20 -0
- data/spec/slices/thin-test-slice/README +130 -0
- data/spec/slices/thin-test-slice/Rakefile +43 -0
- data/spec/slices/thin-test-slice/TODO +7 -0
- data/spec/slices/thin-test-slice/application.rb +36 -0
- data/spec/slices/thin-test-slice/lib/thin-test-slice.rb +93 -0
- data/spec/slices/thin-test-slice/lib/thin-test-slice/merbtasks.rb +103 -0
- data/spec/slices/thin-test-slice/lib/thin-test-slice/slicetasks.rb +18 -0
- data/spec/slices/thin-test-slice/public/javascripts/master.js +0 -0
- data/spec/slices/thin-test-slice/public/stylesheets/master.css +2 -0
- data/spec/slices/thin-test-slice/stubs/application.rb +9 -0
- data/spec/slices/thin-test-slice/views/layout/thin_test_slice.html.erb +16 -0
- data/spec/slices/thin-test-slice/views/main/index.html.erb +1 -0
- data/spec/slices/very-thin-test-slice/LICENSE +20 -0
- data/spec/slices/very-thin-test-slice/README +110 -0
- data/spec/slices/very-thin-test-slice/Rakefile +43 -0
- data/spec/slices/very-thin-test-slice/TODO +7 -0
- data/spec/slices/very-thin-test-slice/application.rb +36 -0
- data/spec/slices/very-thin-test-slice/lib/very-thin-test-slice.rb +89 -0
- data/spec/slices/very-thin-test-slice/lib/very-thin-test-slice/merbtasks.rb +103 -0
- data/spec/slices/very-thin-test-slice/lib/very-thin-test-slice/slicetasks.rb +18 -0
- data/spec/spec_helper.rb +27 -2
- data/spec/thin_slice_generator_spec.rb +24 -2
- data/spec/thin_slice_spec.rb +139 -0
- data/spec/very_thin_slice_generator_spec.rb +22 -2
- data/spec/very_thin_slice_spec.rb +119 -0
- metadata +79 -5
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
|
4
|
+
require 'merb-core'
|
5
|
+
require 'merb-core/tasks/merb'
|
6
|
+
|
7
|
+
GEM_NAME = "very-thin-test-slice"
|
8
|
+
AUTHOR = "Your Name"
|
9
|
+
EMAIL = "Your Email"
|
10
|
+
HOMEPAGE = "http://merbivore.com/"
|
11
|
+
SUMMARY = "Merb Slice that provides ..."
|
12
|
+
GEM_VERSION = "0.9.8"
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.rubyforge_project = 'merb'
|
16
|
+
s.name = GEM_NAME
|
17
|
+
s.version = GEM_VERSION
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
21
|
+
s.summary = SUMMARY
|
22
|
+
s.description = s.summary
|
23
|
+
s.author = AUTHOR
|
24
|
+
s.email = EMAIL
|
25
|
+
s.homepage = HOMEPAGE
|
26
|
+
s.add_dependency('merb-slices', '>= 0.9.8')
|
27
|
+
s.require_path = 'lib'
|
28
|
+
s.files = %w(LICENSE README Rakefile TODO application.rb) + Dir.glob("{lib,spec,app,public,stubs,views}/**/*")
|
29
|
+
end
|
30
|
+
|
31
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
32
|
+
pkg.gem_spec = spec
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Install the gem"
|
36
|
+
task :install do
|
37
|
+
Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Uninstall the gem"
|
41
|
+
task :uninstall do
|
42
|
+
Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
|
43
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
TODO:
|
2
|
+
|
3
|
+
- Fix VeryThinTestSlice.description and VeryThinTestSlice.version
|
4
|
+
- Fix LICENSE with your name
|
5
|
+
- Fix Rakefile with your name and contact info
|
6
|
+
- Add your code to lib/very-thin-test-slice.rb
|
7
|
+
- Add your Merb rake tasks to lib/very-thin-test-slice/merbtasks.rb
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module VeryThinTestSlice
|
2
|
+
|
3
|
+
# All Slice code is expected to be namespaced inside this module.
|
4
|
+
|
5
|
+
class Application < Merb::Controller
|
6
|
+
|
7
|
+
controller_for_slice
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
# Construct a path relative to the public directory
|
12
|
+
def public_path_for(type, *segments)
|
13
|
+
::VeryThinTestSlice.public_path_for(type, *segments)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Construct an app-level path.
|
17
|
+
def app_path_for(type, *segments)
|
18
|
+
::VeryThinTestSlice.app_path_for(type, *segments)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Construct a slice-level path
|
22
|
+
def slice_path_for(type, *segments)
|
23
|
+
::VeryThinTestSlice.slice_path_for(type, *segments)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
class Main < Application
|
29
|
+
|
30
|
+
def index
|
31
|
+
render "#{slice.description} (v. #{slice.version})"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
if defined?(Merb::Plugins)
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__)
|
4
|
+
|
5
|
+
load_dependency 'merb-slices'
|
6
|
+
Merb::Plugins.add_rakefiles "very-thin-test-slice/merbtasks", "very-thin-test-slice/slicetasks"
|
7
|
+
|
8
|
+
# Register the Slice for the current host application
|
9
|
+
Merb::Slices::register(__FILE__)
|
10
|
+
|
11
|
+
# Slice configuration - set this in a before_app_loads callback.
|
12
|
+
Merb::Slices::config[:very_thin_test_slice][:foo] ||= :bar
|
13
|
+
|
14
|
+
# All Slice code is expected to be namespaced inside a module
|
15
|
+
module VeryThinTestSlice
|
16
|
+
|
17
|
+
# Slice metadata
|
18
|
+
self.description = "VeryThinTestSlice is a very thin Merb slice!"
|
19
|
+
self.version = "0.0.1"
|
20
|
+
self.author = "YOUR NAME"
|
21
|
+
|
22
|
+
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
23
|
+
# right after a slice's classes have been loaded internally.
|
24
|
+
def self.loaded
|
25
|
+
end
|
26
|
+
|
27
|
+
# Initialization hook - runs before AfterAppLoads BootLoader
|
28
|
+
def self.init
|
29
|
+
end
|
30
|
+
|
31
|
+
# Activation hook - runs after AfterAppLoads BootLoader
|
32
|
+
def self.activate
|
33
|
+
end
|
34
|
+
|
35
|
+
# Deactivation hook - triggered by Merb::Slices.deactivate(VeryThinTestSlice)
|
36
|
+
def self.deactivate
|
37
|
+
end
|
38
|
+
|
39
|
+
# Setup routes inside the host application
|
40
|
+
#
|
41
|
+
# @param scope<Merb::Router::Behaviour>
|
42
|
+
# Routes will be added within this scope (namespace). In fact, any
|
43
|
+
# router behaviour is a valid namespace, so you can attach
|
44
|
+
# routes at any level of your router setup.
|
45
|
+
#
|
46
|
+
# @note prefix your named routes with :very_thin_test_slice_
|
47
|
+
# to avoid potential conflicts with global named routes.
|
48
|
+
def self.setup_router(scope)
|
49
|
+
end
|
50
|
+
|
51
|
+
# This sets up a very thin slice's structure.
|
52
|
+
def self.setup_default_structure!
|
53
|
+
self.push_app_path(:root, Merb.root / 'slices' / self.identifier, nil)
|
54
|
+
|
55
|
+
self.push_path(:stub, root_path('stubs'), nil)
|
56
|
+
self.push_app_path(:stub, app_dir_for(:root), nil)
|
57
|
+
|
58
|
+
self.push_path(:application, root, 'application.rb')
|
59
|
+
self.push_app_path(:application, app_dir_for(:root), 'application.rb')
|
60
|
+
|
61
|
+
self.push_path(:public, root_path('public'), nil)
|
62
|
+
self.push_app_path(:public, Merb.root / 'public' / 'slices' / self.identifier, nil)
|
63
|
+
|
64
|
+
public_components.each do |component|
|
65
|
+
self.push_path(component, dir_for(:public) / "#{component}s", nil)
|
66
|
+
self.push_app_path(component, app_dir_for(:public) / "#{component}s", nil)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
# Setup the slice layout for VeryThinTestSlice
|
73
|
+
#
|
74
|
+
# Use VeryThinTestSlice.push_path and VeryThinTestSlice.push_app_path
|
75
|
+
# to set paths to very-thin-test-slice-level and app-level paths. Example:
|
76
|
+
#
|
77
|
+
# VeryThinTestSlice.push_path(:application, VeryThinTestSlice.root)
|
78
|
+
# VeryThinTestSlice.push_app_path(:application, Merb.root / 'slices' / 'very-thin-test-slice')
|
79
|
+
# ...
|
80
|
+
#
|
81
|
+
# Any component path that hasn't been set will default to VeryThinTestSlice.root
|
82
|
+
#
|
83
|
+
# For a very thin slice we just add application.rb and :public locations.
|
84
|
+
VeryThinTestSlice.setup_default_structure!
|
85
|
+
|
86
|
+
# Add dependencies for other VeryThinTestSlice classes below. Example:
|
87
|
+
# dependency "very-thin-test-slice/other"
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
namespace :slices do
|
2
|
+
namespace :very_thin_test_slice do
|
3
|
+
|
4
|
+
desc "Install VeryThinTestSlice"
|
5
|
+
task :install => [:preflight, :setup_directories, :copy_assets, :migrate]
|
6
|
+
|
7
|
+
desc "Test for any dependencies"
|
8
|
+
task :preflight do # see slicetasks.rb
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Setup directories"
|
12
|
+
task :setup_directories do
|
13
|
+
puts "Creating directories for host application"
|
14
|
+
VeryThinTestSlice.mirrored_components.each do |type|
|
15
|
+
if File.directory?(VeryThinTestSlice.dir_for(type))
|
16
|
+
if !File.directory?(dst_path = VeryThinTestSlice.app_dir_for(type))
|
17
|
+
relative_path = dst_path.relative_path_from(Merb.root)
|
18
|
+
puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}"
|
19
|
+
mkdir_p(dst_path)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Copy stub files to host application"
|
26
|
+
task :stubs do
|
27
|
+
puts "Copying stubs for VeryThinTestSlice - resolves any collisions"
|
28
|
+
copied, preserved = VeryThinTestSlice.mirror_stubs!
|
29
|
+
puts "- no files to copy" if copied.empty? && preserved.empty?
|
30
|
+
copied.each { |f| puts "- copied #{f}" }
|
31
|
+
preserved.each { |f| puts "! preserved override as #{f}" }
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Copy stub files and views to host application"
|
35
|
+
task :patch => [ "stubs", "freeze:views" ]
|
36
|
+
|
37
|
+
desc "Copy public assets to host application"
|
38
|
+
task :copy_assets do
|
39
|
+
puts "Copying assets for VeryThinTestSlice - resolves any collisions"
|
40
|
+
copied, preserved = VeryThinTestSlice.mirror_public!
|
41
|
+
puts "- no files to copy" if copied.empty? && preserved.empty?
|
42
|
+
copied.each { |f| puts "- copied #{f}" }
|
43
|
+
preserved.each { |f| puts "! preserved override as #{f}" }
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Migrate the database"
|
47
|
+
task :migrate do # see slicetasks.rb
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "Freeze VeryThinTestSlice into your app (only very-thin-test-slice/app)"
|
51
|
+
task :freeze => [ "freeze:app" ]
|
52
|
+
|
53
|
+
namespace :freeze do
|
54
|
+
|
55
|
+
desc "Freezes VeryThinTestSlice by installing the gem into application/gems"
|
56
|
+
task :gem do
|
57
|
+
ENV["GEM"] ||= "very-thin-test-slice"
|
58
|
+
Rake::Task['slices:install_as_gem'].invoke
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "Freezes VeryThinTestSlice by copying all files from very-thin-test-slice/app to your application"
|
62
|
+
task :app do
|
63
|
+
puts "Copying all very-thin-test-slice/app files to your application - resolves any collisions"
|
64
|
+
copied, preserved = VeryThinTestSlice.mirror_app!
|
65
|
+
puts "- no files to copy" if copied.empty? && preserved.empty?
|
66
|
+
copied.each { |f| puts "- copied #{f}" }
|
67
|
+
preserved.each { |f| puts "! preserved override as #{f}" }
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "Freeze all views into your application for easy modification"
|
71
|
+
task :views do
|
72
|
+
puts "Copying all view templates to your application - resolves any collisions"
|
73
|
+
copied, preserved = VeryThinTestSlice.mirror_files_for :view
|
74
|
+
puts "- no files to copy" if copied.empty? && preserved.empty?
|
75
|
+
copied.each { |f| puts "- copied #{f}" }
|
76
|
+
preserved.each { |f| puts "! preserved override as #{f}" }
|
77
|
+
end
|
78
|
+
|
79
|
+
desc "Freeze all models into your application for easy modification"
|
80
|
+
task :models do
|
81
|
+
puts "Copying all models to your application - resolves any collisions"
|
82
|
+
copied, preserved = VeryThinTestSlice.mirror_files_for :model
|
83
|
+
puts "- no files to copy" if copied.empty? && preserved.empty?
|
84
|
+
copied.each { |f| puts "- copied #{f}" }
|
85
|
+
preserved.each { |f| puts "! preserved override as #{f}" }
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Freezes VeryThinTestSlice as a gem and copies over very-thin-test-slice/app"
|
89
|
+
task :app_with_gem => [:gem, :app]
|
90
|
+
|
91
|
+
desc "Freezes VeryThinTestSlice by unpacking all files into your application"
|
92
|
+
task :unpack do
|
93
|
+
puts "Unpacking VeryThinTestSlice files to your application - resolves any collisions"
|
94
|
+
copied, preserved = VeryThinTestSlice.unpack_slice!
|
95
|
+
puts "- no files to copy" if copied.empty? && preserved.empty?
|
96
|
+
copied.each { |f| puts "- copied #{f}" }
|
97
|
+
preserved.each { |f| puts "! preserved override as #{f}" }
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace :slices do
|
2
|
+
namespace :very_thin_test_slice do
|
3
|
+
|
4
|
+
# add your own very-thin-test-slice tasks here
|
5
|
+
|
6
|
+
# implement this to test for structural/code dependencies
|
7
|
+
# like certain directories or availability of other files
|
8
|
+
desc "Test for any dependencies"
|
9
|
+
task :preflight do
|
10
|
+
end
|
11
|
+
|
12
|
+
# implement this to perform any database related setup steps
|
13
|
+
desc "Migrate the database"
|
14
|
+
task :migrate do
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,34 @@
|
|
1
|
-
$TESTING=true
|
2
1
|
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
3
2
|
|
4
3
|
require 'rubygems'
|
5
4
|
require 'merb-gen'
|
5
|
+
require 'merb-slices'
|
6
|
+
|
6
7
|
require 'generators/base'
|
7
8
|
require 'generators/full'
|
8
9
|
require 'generators/thin'
|
9
|
-
require 'generators/very_thin'
|
10
|
+
require 'generators/very_thin'
|
11
|
+
|
12
|
+
module Merb
|
13
|
+
module Test
|
14
|
+
module SliceHelper
|
15
|
+
|
16
|
+
def current_slice_root=(path)
|
17
|
+
@current_slice_root = File.expand_path(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
# The absolute path to the current slice
|
21
|
+
def current_slice_root
|
22
|
+
@current_slice_root || File.expand_path(File.dirname(__FILE__))
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Runner.configure do |config|
|
30
|
+
config.include(Merb::Test::ViewHelper)
|
31
|
+
config.include(Merb::Test::RouteHelper)
|
32
|
+
config.include(Merb::Test::ControllerHelper)
|
33
|
+
config.include(Merb::Test::SliceHelper)
|
34
|
+
end
|
@@ -1,14 +1,36 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
+
slices_path = File.dirname(__FILE__) / 'slices'
|
4
|
+
|
3
5
|
describe Merb::Generators::ThinSliceGenerator do
|
4
6
|
|
5
7
|
describe "templates" do
|
6
8
|
|
9
|
+
before(:all) { FileUtils.rm_rf(slices_path / 'testing-thin') rescue nil }
|
10
|
+
after(:all) { FileUtils.rm_rf(slices_path / 'testing-thin') rescue nil }
|
11
|
+
|
7
12
|
before do
|
8
|
-
@generator = Merb::Generators::ThinSliceGenerator.new(
|
13
|
+
@generator = Merb::Generators::ThinSliceGenerator.new(slices_path, {}, 'testing-thin')
|
9
14
|
end
|
10
15
|
|
11
|
-
it "should create a number of templates"
|
16
|
+
it "should create a number of templates" do
|
17
|
+
@generator.invoke!
|
18
|
+
files = Dir[slices_path / 'testing-thin' / '**' / '*'].map do |path|
|
19
|
+
path.relative_path_from(slices_path)
|
20
|
+
end
|
21
|
+
expected = [
|
22
|
+
"testing-thin/application.rb", "testing-thin/lib", "testing-thin/lib/testing-thin",
|
23
|
+
"testing-thin/lib/testing-thin/merbtasks.rb", "testing-thin/lib/testing-thin/slicetasks.rb",
|
24
|
+
"testing-thin/lib/testing-thin.rb", "testing-thin/LICENSE", "testing-thin/public",
|
25
|
+
"testing-thin/public/javascripts", "testing-thin/public/javascripts/master.js",
|
26
|
+
"testing-thin/public/stylesheets", "testing-thin/public/stylesheets/master.css",
|
27
|
+
"testing-thin/Rakefile", "testing-thin/README", "testing-thin/stubs",
|
28
|
+
"testing-thin/stubs/application.rb", "testing-thin/TODO", "testing-thin/views",
|
29
|
+
"testing-thin/views/layout", "testing-thin/views/layout/testing_thin.html.erb",
|
30
|
+
"testing-thin/views/main", "testing-thin/views/main/index.html.erb"
|
31
|
+
]
|
32
|
+
files.should == expected
|
33
|
+
end
|
12
34
|
|
13
35
|
it "should render templates successfully" do
|
14
36
|
lambda { @generator.render! }.should_not raise_error
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
slices_path = File.dirname(__FILE__) / 'slices'
|
4
|
+
|
5
|
+
describe "A thin slice" do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
self.current_slice_root = slices_path / 'thin-test-slice'
|
9
|
+
|
10
|
+
# Uncomment this re-generate the slice
|
11
|
+
|
12
|
+
# FileUtils.rm_rf(slices_path / 'thin-test-slice') rescue nil
|
13
|
+
# generator = Merb::Generators::ThinSliceGenerator.new(slices_path, {}, 'thin-test-slice')
|
14
|
+
# generator.invoke!
|
15
|
+
|
16
|
+
# Add the slice to the search path
|
17
|
+
Merb::Plugins.config[:merb_slices][:auto_register] = true
|
18
|
+
Merb::Plugins.config[:merb_slices][:search_path] = slices_path
|
19
|
+
|
20
|
+
Merb.start(
|
21
|
+
:testing => true,
|
22
|
+
:adapter => 'runner',
|
23
|
+
:environment => ENV['MERB_ENV'] || 'test',
|
24
|
+
:merb_root => Merb.root
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Uncomment this re-generate the slice
|
29
|
+
|
30
|
+
# after(:all) do
|
31
|
+
# FileUtils.rm_rf(slices_path / 'thin-test-slice') rescue nil
|
32
|
+
# end
|
33
|
+
|
34
|
+
before :all do
|
35
|
+
Merb::Router.prepare { add_slice(:thin_test_slice) }
|
36
|
+
end
|
37
|
+
|
38
|
+
after :all do
|
39
|
+
Merb::Router.reset!
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should be registered in Merb::Slices.slices" do
|
43
|
+
Merb::Slices.slices.should include(ThinTestSlice)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be registered in Merb::Slices.paths" do
|
47
|
+
Merb::Slices.paths[ThinTestSlice.name].should == current_slice_root
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should have an :identifier property" do
|
51
|
+
ThinTestSlice.identifier.should == "thin-test-slice"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should have an :identifier_sym property" do
|
55
|
+
ThinTestSlice.identifier_sym.should == :thin_test_slice
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should have a :root property" do
|
59
|
+
ThinTestSlice.root.should == Merb::Slices.paths[ThinTestSlice.name]
|
60
|
+
ThinTestSlice.root_path('app').should == current_slice_root / 'app'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should have a :file property" do
|
64
|
+
ThinTestSlice.file.should == current_slice_root / 'lib' / 'thin-test-slice.rb'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have metadata properties" do
|
68
|
+
ThinTestSlice.description.should == "ThinTestSlice is a thin Merb slice!"
|
69
|
+
ThinTestSlice.version.should == "0.0.1"
|
70
|
+
ThinTestSlice.author.should == "YOUR NAME"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should have a :named_routes property" do
|
74
|
+
ThinTestSlice.named_routes[:default].should be_kind_of(Merb::Router::Route)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should have a :layout config option set" do
|
78
|
+
ThinTestSlice.config[:layout].should == :thin_test_slice
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have a dir_for method" do
|
82
|
+
app_path = ThinTestSlice.dir_for(:application)
|
83
|
+
app_path.should == current_slice_root
|
84
|
+
[:view].each do |type|
|
85
|
+
ThinTestSlice.dir_for(type).should == app_path / "#{type}s"
|
86
|
+
end
|
87
|
+
public_path = ThinTestSlice.dir_for(:public)
|
88
|
+
public_path.should == current_slice_root / 'public'
|
89
|
+
[:stylesheet, :javascript, :image].each do |type|
|
90
|
+
ThinTestSlice.dir_for(type).should == public_path / "#{type}s"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should have a app_dir_for method" do
|
95
|
+
root_path = ThinTestSlice.app_dir_for(:root)
|
96
|
+
root_path.should == Merb.root / 'slices' / 'thin-test-slice'
|
97
|
+
app_path = ThinTestSlice.app_dir_for(:application)
|
98
|
+
app_path.should == root_path
|
99
|
+
[:view].each do |type|
|
100
|
+
ThinTestSlice.app_dir_for(type).should == app_path / "#{type}s"
|
101
|
+
end
|
102
|
+
public_path = ThinTestSlice.app_dir_for(:public)
|
103
|
+
public_path.should == Merb.dir_for(:public) / 'slices' / 'thin-test-slice'
|
104
|
+
[:stylesheet, :javascript, :image].each do |type|
|
105
|
+
ThinTestSlice.app_dir_for(type).should == public_path / "#{type}s"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should have a public_dir_for method" do
|
110
|
+
public_path = ThinTestSlice.public_dir_for(:public)
|
111
|
+
public_path.should == '/slices' / 'thin-test-slice'
|
112
|
+
[:stylesheet, :javascript, :image].each do |type|
|
113
|
+
ThinTestSlice.public_dir_for(type).should == public_path / "#{type}s"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should have a public_path_for method" do
|
118
|
+
public_path = ThinTestSlice.public_dir_for(:public)
|
119
|
+
ThinTestSlice.public_path_for("path", "to", "file").should == public_path / "path" / "to" / "file"
|
120
|
+
[:stylesheet, :javascript, :image].each do |type|
|
121
|
+
ThinTestSlice.public_path_for(type, "path", "to", "file").should == public_path / "#{type}s" / "path" / "to" / "file"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should have a app_path_for method" do
|
126
|
+
ThinTestSlice.app_path_for("path", "to", "file").should == ThinTestSlice.app_dir_for(:root) / "path" / "to" / "file"
|
127
|
+
ThinTestSlice.app_path_for(:controller, "path", "to", "file").should == ThinTestSlice.app_dir_for(:controller) / "path" / "to" / "file"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should have a slice_path_for method" do
|
131
|
+
ThinTestSlice.slice_path_for("path", "to", "file").should == ThinTestSlice.dir_for(:root) / "path" / "to" / "file"
|
132
|
+
ThinTestSlice.slice_path_for(:controller, "path", "to", "file").should == ThinTestSlice.dir_for(:controller) / "path" / "to" / "file"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should keep a list of path component types to use when copying files" do
|
136
|
+
(ThinTestSlice.mirrored_components & ThinTestSlice.slice_paths.keys).length.should == ThinTestSlice.mirrored_components.length
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|