darkhelmet-sinatra_more 0.3.33
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +23 -0
- data/IDEAS.md +54 -0
- data/LICENSE +20 -0
- data/README.rdoc +756 -0
- data/ROADMAP +88 -0
- data/Rakefile +63 -0
- data/TODO +60 -0
- data/VERSION +1 -0
- data/bin/sinatra_gen +6 -0
- data/generators/base_app/.gitignore +7 -0
- data/generators/base_app/Gemfile +13 -0
- data/generators/base_app/app/.empty_directory +0 -0
- data/generators/base_app/app/helpers/.empty_directory +0 -0
- data/generators/base_app/app/helpers/view_helpers.rb +3 -0
- data/generators/base_app/app/mailers/.empty_directory +0 -0
- data/generators/base_app/app/models/.empty_directory +0 -0
- data/generators/base_app/app/routes/.empty_directory +0 -0
- data/generators/base_app/app/views/.empty_directory +0 -0
- data/generators/base_app/config.ru.tt +10 -0
- data/generators/base_app/config/boot.rb.tt +42 -0
- data/generators/base_app/config/dependencies.rb.tt +41 -0
- data/generators/base_app/lib/.empty_directory +0 -0
- data/generators/base_app/public/images/.empty_directory +0 -0
- data/generators/base_app/public/images/.gitignore +0 -0
- data/generators/base_app/public/javascripts/.empty_directory +0 -0
- data/generators/base_app/public/stylesheets/.empty_directory +0 -0
- data/generators/base_app/test/models/.empty_directory +0 -0
- data/generators/base_app/test/routes/.empty_directory +0 -0
- data/generators/base_app/test/test_config.rb.tt +5 -0
- data/generators/base_app/vendor/gems/.empty_directory +0 -0
- data/generators/components/component_actions.rb +48 -0
- data/generators/components/mocks/mocha_mock_gen.rb +8 -0
- data/generators/components/mocks/rr_mock_gen.rb +8 -0
- data/generators/components/orms/activerecord_orm_gen.rb +99 -0
- data/generators/components/orms/couchrest_orm_gen.rb +64 -0
- data/generators/components/orms/datamapper_orm_gen.rb +52 -0
- data/generators/components/orms/mongomapper_orm_gen.rb +101 -0
- data/generators/components/orms/sequel_orm_gen.rb +61 -0
- data/generators/components/renderers/erb_renderer_gen.rb +7 -0
- data/generators/components/renderers/haml_renderer_gen.rb +22 -0
- data/generators/components/scripts/jquery_script_gen.rb +9 -0
- data/generators/components/scripts/prototype_script_gen.rb +10 -0
- data/generators/components/scripts/rightjs_script_gen.rb +10 -0
- data/generators/components/tests/bacon_test_gen.rb +21 -0
- data/generators/components/tests/riot_test_gen.rb +19 -0
- data/generators/components/tests/rspec_test_gen.rb +19 -0
- data/generators/components/tests/shoulda_test_gen.rb +19 -0
- data/generators/components/tests/testspec_test_gen.rb +19 -0
- data/generators/generator_actions.rb +79 -0
- data/generators/skeleton_generator.rb +53 -0
- data/lib/sinatra/mailer_plugin.rb +14 -0
- data/lib/sinatra/mailer_plugin/mail_object.rb +39 -0
- data/lib/sinatra/mailer_plugin/mailer_base.rb +75 -0
- data/lib/sinatra/markup_plugin.rb +19 -0
- data/lib/sinatra/markup_plugin/asset_tag_helpers.rb +109 -0
- data/lib/sinatra/markup_plugin/form_builder/abstract_form_builder.rb +133 -0
- data/lib/sinatra/markup_plugin/form_builder/standard_form_builder.rb +31 -0
- data/lib/sinatra/markup_plugin/form_helpers.rb +194 -0
- data/lib/sinatra/markup_plugin/format_helpers.rb +74 -0
- data/lib/sinatra/markup_plugin/output_helpers.rb +98 -0
- data/lib/sinatra/markup_plugin/tag_helpers.rb +42 -0
- data/lib/sinatra/render_plugin.rb +12 -0
- data/lib/sinatra/render_plugin/render_helpers.rb +63 -0
- data/lib/sinatra/routing_plugin.rb +50 -0
- data/lib/sinatra/routing_plugin/named_route.rb +27 -0
- data/lib/sinatra/routing_plugin/routing_helpers.rb +22 -0
- data/lib/sinatra/support_lite.rb +19 -0
- data/lib/sinatra/warden_plugin.rb +51 -0
- data/lib/sinatra/warden_plugin/warden_helpers.rb +60 -0
- data/lib/sinatra_more.rb +7 -0
- data/sinatra_more.gemspec +215 -0
- data/test/active_support_helpers.rb +7 -0
- data/test/fixtures/mailer_app/app.rb +51 -0
- data/test/fixtures/mailer_app/views/demo_mailer/sample_mail.erb +1 -0
- data/test/fixtures/mailer_app/views/sample_mailer/anniversary_message.erb +2 -0
- data/test/fixtures/mailer_app/views/sample_mailer/birthday_message.erb +2 -0
- data/test/fixtures/markup_app/app.rb +66 -0
- data/test/fixtures/markup_app/views/capture_concat.erb +14 -0
- data/test/fixtures/markup_app/views/capture_concat.haml +13 -0
- data/test/fixtures/markup_app/views/content_for.erb +11 -0
- data/test/fixtures/markup_app/views/content_for.haml +9 -0
- data/test/fixtures/markup_app/views/content_tag.erb +11 -0
- data/test/fixtures/markup_app/views/content_tag.haml +9 -0
- data/test/fixtures/markup_app/views/fields_for.erb +8 -0
- data/test/fixtures/markup_app/views/fields_for.haml +6 -0
- data/test/fixtures/markup_app/views/form_for.erb +56 -0
- data/test/fixtures/markup_app/views/form_for.haml +47 -0
- data/test/fixtures/markup_app/views/form_tag.erb +57 -0
- data/test/fixtures/markup_app/views/form_tag.haml +45 -0
- data/test/fixtures/markup_app/views/link_to.erb +5 -0
- data/test/fixtures/markup_app/views/link_to.haml +4 -0
- data/test/fixtures/markup_app/views/mail_to.erb +3 -0
- data/test/fixtures/markup_app/views/mail_to.haml +3 -0
- data/test/fixtures/markup_app/views/meta_tag.erb +3 -0
- data/test/fixtures/markup_app/views/meta_tag.haml +3 -0
- data/test/fixtures/render_app/app.rb +54 -0
- data/test/fixtures/render_app/views/erb/test.erb +1 -0
- data/test/fixtures/render_app/views/haml/test.haml +1 -0
- data/test/fixtures/render_app/views/template/_user.haml +7 -0
- data/test/fixtures/render_app/views/template/haml_template.haml +1 -0
- data/test/fixtures/render_app/views/template/some_template.haml +2 -0
- data/test/fixtures/routing_app/app.rb +48 -0
- data/test/fixtures/routing_app/views/index.haml +7 -0
- data/test/fixtures/warden_app/app.rb +75 -0
- data/test/fixtures/warden_app/views/dashboard.haml +6 -0
- data/test/generators/test_skeleton_generator.rb +190 -0
- data/test/helper.rb +73 -0
- data/test/mailer_plugin/test_mail_object.rb +24 -0
- data/test/mailer_plugin/test_mailer_base.rb +81 -0
- data/test/markup_plugin/test_asset_tag_helpers.rb +171 -0
- data/test/markup_plugin/test_form_builder.rb +627 -0
- data/test/markup_plugin/test_form_helpers.rb +417 -0
- data/test/markup_plugin/test_format_helpers.rb +96 -0
- data/test/markup_plugin/test_output_helpers.rb +63 -0
- data/test/markup_plugin/test_tag_helpers.rb +73 -0
- data/test/test_mailer_plugin.rb +33 -0
- data/test/test_render_plugin.rb +78 -0
- data/test/test_routing_plugin.rb +94 -0
- data/test/test_warden_plugin.rb +105 -0
- metadata +307 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sinatra_more'
|
3
|
+
require 'haml'
|
4
|
+
|
5
|
+
class RenderUser
|
6
|
+
attr_accessor :name
|
7
|
+
def initialize(name); @name = name; end
|
8
|
+
end
|
9
|
+
|
10
|
+
class RenderDemo < Sinatra::Base
|
11
|
+
register Sinatra::RenderPlugin
|
12
|
+
|
13
|
+
configure do
|
14
|
+
set :root, File.dirname(__FILE__)
|
15
|
+
end
|
16
|
+
|
17
|
+
# haml_template
|
18
|
+
get '/render_haml' do
|
19
|
+
@template = 'haml'
|
20
|
+
haml_template 'haml/test'
|
21
|
+
end
|
22
|
+
|
23
|
+
# erb_template
|
24
|
+
get '/render_erb' do
|
25
|
+
@template = 'erb'
|
26
|
+
erb_template 'erb/test'
|
27
|
+
end
|
28
|
+
|
29
|
+
# render_template with explicit engine
|
30
|
+
get '/render_template/:engine' do
|
31
|
+
@template = params[:engine]
|
32
|
+
render_template "template/#{@template}_template", :template_engine => @template
|
33
|
+
end
|
34
|
+
|
35
|
+
# render_template without explicit engine
|
36
|
+
get '/render_template' do
|
37
|
+
render_template "template/some_template"
|
38
|
+
end
|
39
|
+
|
40
|
+
# partial with object
|
41
|
+
get '/partial/object' do
|
42
|
+
partial 'template/user', :object => RenderUser.new('John'), :locals => { :extra => "bar" }
|
43
|
+
end
|
44
|
+
|
45
|
+
# partial with collection
|
46
|
+
get '/partial/collection' do
|
47
|
+
partial 'template/user', :collection => [RenderUser.new('John'), RenderUser.new('Billy')], :locals => { :extra => "bar" }
|
48
|
+
end
|
49
|
+
|
50
|
+
# partial with locals
|
51
|
+
get '/partial/locals' do
|
52
|
+
partial 'template/user', :locals => { :user => RenderUser.new('John'), :extra => "bar" }
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>This is a <%= @template %> template!</h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
%h1 This is a #{@template} template!
|
@@ -0,0 +1 @@
|
|
1
|
+
%h1 This is a #{@template} template sent from render_template!
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sinatra_more'
|
3
|
+
require 'haml'
|
4
|
+
|
5
|
+
class RoutingDemo < Sinatra::Base
|
6
|
+
register Sinatra::RoutingPlugin
|
7
|
+
|
8
|
+
configure do
|
9
|
+
set :root, File.dirname(__FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
map(:admin, :show).to("/admin/:id/show")
|
13
|
+
map :admin do |namespace|
|
14
|
+
namespace.map(:update).to("/admin/:id/update/:name")
|
15
|
+
namespace.map(:destroy).to("/admin/:id/destroy")
|
16
|
+
end
|
17
|
+
map(:account).to("/the/accounts/:name/path/:id/end")
|
18
|
+
map(:accounts).to("/the/accounts/index/?")
|
19
|
+
|
20
|
+
namespace :admin do
|
21
|
+
get :show do
|
22
|
+
"<p>admin show for id #{params[:id]}</p>"
|
23
|
+
end
|
24
|
+
|
25
|
+
get :update do
|
26
|
+
"<p>updated admin with id #{params[:id]} and name #{params[:name]}</p>"
|
27
|
+
end
|
28
|
+
|
29
|
+
get :destroy do
|
30
|
+
"<p>destroy admin with id #{params[:id]}</p>"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
get :account do
|
34
|
+
"<h1>the account url for #{params[:name]} and id #{params[:id]}</h1>"
|
35
|
+
end
|
36
|
+
|
37
|
+
get :accounts do
|
38
|
+
"<h1>the accounts index</h1>"
|
39
|
+
end
|
40
|
+
|
41
|
+
get '/links' do
|
42
|
+
haml :index
|
43
|
+
end
|
44
|
+
|
45
|
+
get '/failed_route' do
|
46
|
+
url_for(:some, :not_real, :id => 5)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
%p.admin_url= url_for(:admin, :show, :id => 25)
|
2
|
+
%p.app_admin_url= url_for(:routing_demo, :admin, :show, :id => 25)
|
3
|
+
%p.admin_url2= url_for(:admin, :update, :id => 10, :name => "test")
|
4
|
+
%p.admin_url3= url_for(:admin, :destroy, :id => 12)
|
5
|
+
%p.account_url= url_for(:account, :name => 'foobar', :id => 10)
|
6
|
+
%p.accounts_index=url_for(:accounts)
|
7
|
+
%p.app_accounts_index=url_for(:routing_demo, :accounts)
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sinatra_more'
|
3
|
+
require 'warden'
|
4
|
+
|
5
|
+
class WardenUser
|
6
|
+
attr_accessor :id, :name, :username, :password
|
7
|
+
|
8
|
+
def initialize(id, name, username, password)
|
9
|
+
self.id, self.name, self.username, self.password = id, name, username, password
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find(id)
|
13
|
+
return self.john_user if id == self.john_user.id
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.authenticate(username, password)
|
17
|
+
return self.john_user if username == self.john_user.username && password == self.john_user.password
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.john_user
|
21
|
+
@john ||= WardenUser.new(21, "John", 'john21', 'secret')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class WardenDemo < Sinatra::Base
|
26
|
+
use Rack::Session::Cookie
|
27
|
+
register Sinatra::WardenPlugin
|
28
|
+
Sinatra::WardenPlugin::PasswordStrategy.user_class = WardenUser
|
29
|
+
|
30
|
+
configure do
|
31
|
+
set :root, File.dirname(__FILE__)
|
32
|
+
end
|
33
|
+
|
34
|
+
get '/login' do
|
35
|
+
"<h1>Please login!</h1>"
|
36
|
+
end
|
37
|
+
|
38
|
+
post '/login' do
|
39
|
+
authenticate_user!
|
40
|
+
end
|
41
|
+
|
42
|
+
get '/logout' do
|
43
|
+
logout_user!
|
44
|
+
end
|
45
|
+
|
46
|
+
get '/logged_in' do
|
47
|
+
"<h1>logged_in? #{logged_in?}</h1>"
|
48
|
+
end
|
49
|
+
|
50
|
+
get '/authenticated' do
|
51
|
+
haml :dashboard
|
52
|
+
end
|
53
|
+
|
54
|
+
get '/unregistered' do
|
55
|
+
haml :dashboard
|
56
|
+
end
|
57
|
+
|
58
|
+
get '/must_be_authorized' do
|
59
|
+
must_be_authorized!('/login')
|
60
|
+
"<h1>Valid Authorized Page</h1>"
|
61
|
+
end
|
62
|
+
|
63
|
+
post '/unauthenticated/?' do
|
64
|
+
status 401
|
65
|
+
'<h2>Unauthenticated</h2>'
|
66
|
+
end
|
67
|
+
|
68
|
+
get '/current_user' do
|
69
|
+
if current_user
|
70
|
+
"<h1>#{current_user.name}</h1>"
|
71
|
+
else
|
72
|
+
"<h2>Not logged in</h2>"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'thor'
|
3
|
+
require File.dirname(__FILE__) + "/../../generators/skeleton_generator"
|
4
|
+
|
5
|
+
class TestSkeletonGenerator < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
`rm -rf /tmp/sample_app`
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'the skeleton generator' do
|
11
|
+
should "allow simple generator to run and create base_app with no options" do
|
12
|
+
assert_nothing_raised { silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--script=none']) } }
|
13
|
+
assert File.exist?('/tmp/sample_app')
|
14
|
+
assert File.exist?('/tmp/sample_app/config/dependencies.rb')
|
15
|
+
assert File.exist?('/tmp/sample_app/test/test_config.rb')
|
16
|
+
end
|
17
|
+
should "create components file containing options chosen with defaults" do
|
18
|
+
silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp']) }
|
19
|
+
components_chosen = YAML.load_file('/tmp/sample_app/.components')
|
20
|
+
assert_equal 'datamapper', components_chosen[:orm]
|
21
|
+
assert_equal 'bacon', components_chosen[:test]
|
22
|
+
assert_equal 'mocha', components_chosen[:mock]
|
23
|
+
assert_equal 'jquery', components_chosen[:script]
|
24
|
+
assert_equal 'erb', components_chosen[:renderer]
|
25
|
+
end
|
26
|
+
should "create components file containing options chosen" do
|
27
|
+
component_options = ['--orm=datamapper', '--test=riot', '--mock=mocha', '--script=prototype', '--renderer=erb']
|
28
|
+
silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', *component_options]) }
|
29
|
+
components_chosen = YAML.load_file('/tmp/sample_app/.components')
|
30
|
+
assert_equal 'datamapper', components_chosen[:orm]
|
31
|
+
assert_equal 'riot', components_chosen[:test]
|
32
|
+
assert_equal 'mocha', components_chosen[:mock]
|
33
|
+
assert_equal 'prototype', components_chosen[:script]
|
34
|
+
assert_equal 'erb', components_chosen[:renderer]
|
35
|
+
end
|
36
|
+
should "output to log components being applied" do
|
37
|
+
component_options = ['--orm=datamapper', '--test=riot', '--mock=mocha', '--script=prototype', '--renderer=erb']
|
38
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', *component_options]) }
|
39
|
+
assert_match /Applying.*?datamapper.*?orm/, buffer
|
40
|
+
assert_match /Applying.*?riot.*?test/, buffer
|
41
|
+
assert_match /Applying.*?mocha.*?mock/, buffer
|
42
|
+
assert_match /Applying.*?prototype.*?script/, buffer
|
43
|
+
assert_match /Applying.*?erb.*?renderer/, buffer
|
44
|
+
end
|
45
|
+
should "output gem files for base app" do
|
46
|
+
silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--script=none']) }
|
47
|
+
assert_match_in_file(/gem 'sinatra'/, '/tmp/sample_app/Gemfile')
|
48
|
+
assert_match_in_file(/gem 'sinatra_more'/, '/tmp/sample_app/Gemfile')
|
49
|
+
assert_match_in_file(/gem 'rack-flash'/, '/tmp/sample_app/Gemfile')
|
50
|
+
assert_match_in_file(/gem 'rack-test'/, '/tmp/sample_app/Gemfile')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "a generator for mock component" do
|
55
|
+
should "properly generate for rr" do
|
56
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--mock=rr', '--script=none']) }
|
57
|
+
assert_match /Applying.*?rr.*?mock/, buffer
|
58
|
+
assert_match_in_file(/gem 'rr'/, '/tmp/sample_app/Gemfile')
|
59
|
+
assert_match_in_file(/class.*?include RR::Adapters::RRMethods/m, '/tmp/sample_app/test/test_config.rb')
|
60
|
+
end
|
61
|
+
|
62
|
+
should "properly generate default for mocha" do
|
63
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--mock=mocha', '--script=none']) }
|
64
|
+
assert_match /Applying.*?mocha.*?mock/, buffer
|
65
|
+
assert_match_in_file(/gem 'mocha'/, '/tmp/sample_app/Gemfile')
|
66
|
+
assert_match_in_file(/class.*?include Mocha::API/m, '/tmp/sample_app/test/test_config.rb')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
context "the generator for orm components" do
|
72
|
+
should "properly generate for sequel" do
|
73
|
+
Sinatra::SkeletonGenerator.instance_eval("undef setup_orm if respond_to?('setup_orm')")
|
74
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=sequel', '--script=none']) }
|
75
|
+
assert_match /Applying.*?sequel.*?orm/, buffer
|
76
|
+
assert_match_in_file(/gem 'sequel'/, '/tmp/sample_app/Gemfile')
|
77
|
+
assert_match_in_file(/SequelInitializer/, '/tmp/sample_app/config/initializers/sequel.rb')
|
78
|
+
assert_match_in_file(/class User < Sequel::Model/, '/tmp/sample_app/app/models/user.rb')
|
79
|
+
end
|
80
|
+
|
81
|
+
should "properly generate for activerecord" do
|
82
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=activerecord', '--script=none']) }
|
83
|
+
assert_match /Applying.*?activerecord.*?orm/, buffer
|
84
|
+
assert_match_in_file(/gem 'activerecord'/, '/tmp/sample_app/Gemfile')
|
85
|
+
assert_match_in_file(/ActiveRecordInitializer/, '/tmp/sample_app/config/initializers/active_record.rb')
|
86
|
+
assert_match_in_file(/Migrate the database/, '/tmp/sample_app/Rakefile')
|
87
|
+
assert_match_in_file(/CreateUsers < ActiveRecord::Migration/, '/tmp/sample_app/db/migrate/001_create_users.rb')
|
88
|
+
assert_match_in_file(/class User < ActiveRecord::Base/, '/tmp/sample_app/app/models/user.rb')
|
89
|
+
end
|
90
|
+
|
91
|
+
should "properly generate default for datamapper" do
|
92
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=datamapper', '--script=none']) }
|
93
|
+
assert_match /Applying.*?datamapper.*?orm/, buffer
|
94
|
+
assert_match_in_file(/gem 'dm-core'/, '/tmp/sample_app/Gemfile')
|
95
|
+
assert_match_in_file(/DataMapperInitializer/, '/tmp/sample_app/config/initializers/data_mapper.rb')
|
96
|
+
assert_match_in_file(/class User.*?include DataMapper::Resource/m, '/tmp/sample_app/app/models/user.rb')
|
97
|
+
end
|
98
|
+
|
99
|
+
should "properly generate for mongomapper" do
|
100
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=mongomapper', '--script=none']) }
|
101
|
+
assert_match /Applying.*?mongomapper.*?orm/, buffer
|
102
|
+
assert_match_in_file(/gem 'mongo_mapper'/, '/tmp/sample_app/Gemfile')
|
103
|
+
assert_match_in_file(/MongoDbInitializer/, '/tmp/sample_app/config/initializers/mongo_db.rb')
|
104
|
+
assert_match_in_file(/class User.*?include MongoMapper::Document/m, '/tmp/sample_app/app/models/user.rb')
|
105
|
+
end
|
106
|
+
|
107
|
+
should "properly generate for couchrest" do
|
108
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=couchrest', '--script=none']) }
|
109
|
+
assert_match /Applying.*?couchrest.*?orm/, buffer
|
110
|
+
assert_match_in_file(/gem 'couchrest'/, '/tmp/sample_app/Gemfile')
|
111
|
+
assert_match_in_file(/CouchRestInitializer/, '/tmp/sample_app/config/initializers/couch_rest.rb')
|
112
|
+
assert_match_in_file(/class User < CouchRest::ExtendedDocument/m, '/tmp/sample_app/app/models/user.rb')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "the generator for renderer component" do
|
117
|
+
should "properly generate default for erb" do
|
118
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--renderer=erb', '--script=none']) }
|
119
|
+
assert_match /Applying.*?erb.*?renderer/, buffer
|
120
|
+
assert_match_in_file(/gem 'erubis'/, '/tmp/sample_app/Gemfile')
|
121
|
+
end
|
122
|
+
|
123
|
+
should "properly generate for haml" do
|
124
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--renderer=haml','--script=none']) }
|
125
|
+
assert_match /Applying.*?haml.*?renderer/, buffer
|
126
|
+
assert_match_in_file(/gem 'haml'/, '/tmp/sample_app/Gemfile')
|
127
|
+
assert_match_in_file(/SassInitializer/, '/tmp/sample_app/config/initializers/sass.rb')
|
128
|
+
assert_match_in_file(/app.use Sass::Plugin::Rack/, '/tmp/sample_app/config/initializers/sass.rb')
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "the generator for script component" do
|
133
|
+
should "properly generate for jquery" do
|
134
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--script=jquery']) }
|
135
|
+
assert_match /Applying.*?jquery.*?script/, buffer
|
136
|
+
assert File.exist?('/tmp/sample_app/public/javascripts/jquery.min.js')
|
137
|
+
end
|
138
|
+
|
139
|
+
should "properly generate for prototype" do
|
140
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--script=prototype']) }
|
141
|
+
assert_match /Applying.*?prototype.*?script/, buffer
|
142
|
+
assert File.exist?('/tmp/sample_app/public/javascripts/prototype.js')
|
143
|
+
assert File.exist?('/tmp/sample_app/public/javascripts/lowpro.js')
|
144
|
+
end
|
145
|
+
|
146
|
+
should "properly generate for rightjs" do
|
147
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--script=rightjs']) }
|
148
|
+
assert_match /Applying.*?rightjs.*?script/, buffer
|
149
|
+
assert File.exist?('/tmp/sample_app/public/javascripts/right-min.js')
|
150
|
+
assert File.exist?('/tmp/sample_app/public/javascripts/right-olds-min.js')
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "the generator for test component" do
|
155
|
+
should "properly default generate for bacon" do
|
156
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--test=bacon', '--script=none']) }
|
157
|
+
assert_match /Applying.*?bacon.*?test/, buffer
|
158
|
+
assert_match_in_file(/gem 'bacon'/, '/tmp/sample_app/Gemfile')
|
159
|
+
assert_match_in_file(/Bacon::Context/, '/tmp/sample_app/test/test_config.rb')
|
160
|
+
end
|
161
|
+
|
162
|
+
should "properly generate for riot" do
|
163
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--test=riot', '--script=none']) }
|
164
|
+
assert_match /Applying.*?riot.*?test/, buffer
|
165
|
+
assert_match_in_file(/gem 'riot'/, '/tmp/sample_app/Gemfile')
|
166
|
+
assert_match_in_file(/Riot::Situation/, '/tmp/sample_app/test/test_config.rb')
|
167
|
+
end
|
168
|
+
|
169
|
+
should "properly generate for rspec" do
|
170
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--test=rspec', '--script=none']) }
|
171
|
+
assert_match /Applying.*?rspec.*?test/, buffer
|
172
|
+
assert_match_in_file(/gem 'rspec', :require_as => "spec"/, '/tmp/sample_app/Gemfile')
|
173
|
+
assert_match_in_file(/Spec::Runner/, '/tmp/sample_app/test/test_config.rb')
|
174
|
+
end
|
175
|
+
|
176
|
+
should "properly generate for shoulda" do
|
177
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--test=shoulda', '--script=none']) }
|
178
|
+
assert_match /Applying.*?shoulda.*?test/, buffer
|
179
|
+
assert_match_in_file(/gem 'shoulda'/, '/tmp/sample_app/Gemfile')
|
180
|
+
assert_match_in_file(/Test::Unit::TestCase/, '/tmp/sample_app/test/test_config.rb')
|
181
|
+
end
|
182
|
+
|
183
|
+
should "properly generate for testspec" do
|
184
|
+
buffer = silence_logger { Sinatra::SkeletonGenerator.start(['sample_app', '/tmp', '--test=testspec', '--script=none']) }
|
185
|
+
assert_match /Applying.*?testspec.*?test/, buffer
|
186
|
+
assert_match_in_file(/gem 'test\/spec'/, '/tmp/sample_app/Gemfile')
|
187
|
+
assert_match_in_file(/Test::Unit::TestCase/, '/tmp/sample_app/test/test_config.rb')
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|