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,63 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fixtures/markup_app/app'
|
3
|
+
|
4
|
+
class TestOutputHelpers < Test::Unit::TestCase
|
5
|
+
def app
|
6
|
+
MarkupDemo.tap { |app| app.set :environment, :test }
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'for #content_for method' do
|
10
|
+
should 'work for erb templates' do
|
11
|
+
visit '/erb/content_for'
|
12
|
+
assert_have_selector '.demo h1', :content => "This is content yielded from a content_for"
|
13
|
+
assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith"
|
14
|
+
end
|
15
|
+
|
16
|
+
should "work for haml templates" do
|
17
|
+
visit '/haml/content_for'
|
18
|
+
assert_have_selector '.demo h1', :content => "This is content yielded from a content_for"
|
19
|
+
assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'for #capture_html method' do
|
24
|
+
should "work for erb templates" do
|
25
|
+
visit '/erb/capture_concat'
|
26
|
+
assert_have_selector 'p span', :content => "Captured Line 1"
|
27
|
+
assert_have_selector 'p span', :content => "Captured Line 2"
|
28
|
+
end
|
29
|
+
|
30
|
+
should "work for haml templates" do
|
31
|
+
visit '/haml/capture_concat'
|
32
|
+
assert_have_selector 'p span', :content => "Captured Line 1"
|
33
|
+
assert_have_selector 'p span', :content => "Captured Line 2"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'for #concat_content method' do
|
38
|
+
should "work for erb templates" do
|
39
|
+
visit '/erb/capture_concat'
|
40
|
+
assert_have_selector 'p', :content => "Concat Line 3", :count => 1
|
41
|
+
end
|
42
|
+
|
43
|
+
should "work for haml templates" do
|
44
|
+
visit '/haml/capture_concat'
|
45
|
+
assert_have_selector 'p', :content => "Concat Line 3", :count => 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'for #block_is_template?' do
|
50
|
+
should "work for erb templates" do
|
51
|
+
visit '/erb/capture_concat'
|
52
|
+
assert_have_selector 'p', :content => "The erb block passed in is a template", :class => 'is_template'
|
53
|
+
# TODO Get ERB template detection working (fix block_is_erb? method)
|
54
|
+
# assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template'
|
55
|
+
end
|
56
|
+
|
57
|
+
should "work for haml templates" do
|
58
|
+
visit '/haml/capture_concat'
|
59
|
+
assert_have_selector 'p', :content => "The haml block passed in is a template", :class => 'is_template'
|
60
|
+
assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fixtures/markup_app/app'
|
3
|
+
|
4
|
+
class TestTagHelpers < Test::Unit::TestCase
|
5
|
+
def app
|
6
|
+
MarkupDemo.tap { |app| app.set :environment, :test }
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'for #tag method' do
|
10
|
+
should("support tags with no content no attributes") do
|
11
|
+
assert_has_tag(:br) { tag(:br) }
|
12
|
+
end
|
13
|
+
should("support tags with no content with attributes") do
|
14
|
+
actual_html = tag(:br, :style => 'clear:both', :class => 'yellow')
|
15
|
+
assert_has_tag(:br, :class => 'yellow', :style=>'clear:both') { actual_html }
|
16
|
+
end
|
17
|
+
should "support selected attribute by using 'selected' if true" do
|
18
|
+
actual_html = tag(:option, :selected => true)
|
19
|
+
assert_has_tag('option', :selected => 'selected') { actual_html }
|
20
|
+
end
|
21
|
+
should "support tags with content no attributes" do
|
22
|
+
assert_has_tag(:p, :content => "Demo String") { tag(:p, :content => "Demo String") }
|
23
|
+
end
|
24
|
+
should "support tags with content and attributes" do
|
25
|
+
actual_html = tag(:p, :content => "Demo", :class => 'large', :id => 'intro')
|
26
|
+
assert_has_tag('p#intro.large', :content => "Demo") { actual_html }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'for #content_tag method' do
|
31
|
+
should "support tags with content as parameter" do
|
32
|
+
actual_html = content_tag(:p, "Demo", :class => 'large', :id => 'thing')
|
33
|
+
assert_has_tag('p.large#thing', :content => "Demo") { actual_html }
|
34
|
+
end
|
35
|
+
should "support tags with content as block" do
|
36
|
+
actual_html = content_tag(:p, :class => 'large', :id => 'star') { "Demo" }
|
37
|
+
assert_has_tag('p.large#star', :content => "Demo") { actual_html }
|
38
|
+
end
|
39
|
+
should "support tags with erb" do
|
40
|
+
visit '/erb/content_tag'
|
41
|
+
assert_have_selector :p, :content => "Test 1", :class => 'test', :id => 'test1'
|
42
|
+
assert_have_selector :p, :content => "Test 2"
|
43
|
+
assert_have_selector :p, :content => "Test 3"
|
44
|
+
assert_have_selector :p, :content => "Test 4"
|
45
|
+
end
|
46
|
+
should "support tags with haml" do
|
47
|
+
visit '/haml/content_tag'
|
48
|
+
assert_have_selector :p, :content => "Test 1", :class => 'test', :id => 'test1'
|
49
|
+
assert_have_selector :p, :content => "Test 2"
|
50
|
+
assert_have_selector :p, :content => "Test 3", :class => 'test', :id => 'test3'
|
51
|
+
assert_have_selector :p, :content => "Test 4"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'for #input_tag method' do
|
56
|
+
should "support field with type" do
|
57
|
+
assert_has_tag('input[type=text]') { input_tag(:text) }
|
58
|
+
end
|
59
|
+
should "support field with type and options" do
|
60
|
+
actual_html = input_tag(:text, :class => "first", :id => 'texter')
|
61
|
+
assert_has_tag('input.first#texter[type=text]') { actual_html }
|
62
|
+
end
|
63
|
+
should "support checked attribute by using 'checked' if true" do
|
64
|
+
actual_html = input_tag(:checkbox, :checked => true)
|
65
|
+
assert_has_tag('input[type=checkbox]', :checked => 'checked') { actual_html }
|
66
|
+
end
|
67
|
+
should "support disabled attribute by using 'disabled' if true" do
|
68
|
+
actual_html = input_tag(:checkbox, :disabled => true)
|
69
|
+
assert_has_tag('input[type=checkbox]', :disabled => 'disabled') { actual_html }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fixtures/mailer_app/app'
|
3
|
+
|
4
|
+
class TestMailerPlugin < Test::Unit::TestCase
|
5
|
+
def app
|
6
|
+
MailerDemo.tap { |app| app.set :environment, :test }
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'for mail delivery in sample application' do
|
10
|
+
setup { MailerDemo::SampleMailer.smtp_settings = MailerDemo.smtp_settings }
|
11
|
+
|
12
|
+
should 'be able to deliver plain text emails' do
|
13
|
+
assert_email_sent(:to => 'john@fake.com', :from => 'noreply@birthday.com', :via => :smtp,
|
14
|
+
:subject => "Happy Birthday!", :body => "Happy Birthday Joey! \nYou are turning 21")
|
15
|
+
visit '/deliver/plain', :post
|
16
|
+
assert_equal 'mail delivered', last_response.body
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'be able to deliver html emails' do
|
20
|
+
assert_email_sent(:to => 'julie@fake.com', :from => 'noreply@anniversary.com', :type => 'html', :via => :smtp,
|
21
|
+
:subject => "Happy anniversary!", :body => "<p>Yay Joey & Charlotte!</p>\n<p>You have been married 16 years</p>")
|
22
|
+
visit '/deliver/html', :post
|
23
|
+
assert_equal 'mail delivered', last_response.body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def assert_email_sent(mail_attributes)
|
30
|
+
delivery_attributes = mail_attributes.merge(:smtp => MailerDemo.smtp_settings)
|
31
|
+
Sinatra::MailerPlugin::MailObject.any_instance.expects(:send_mail).with(delivery_attributes).once.returns(true)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fixtures/render_app/app'
|
3
|
+
|
4
|
+
class TestRenderPlugin < Test::Unit::TestCase
|
5
|
+
def app
|
6
|
+
RenderDemo.tap { |app| app.set :environment, :test }
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'for #haml_template method' do
|
10
|
+
setup { visit '/render_haml' }
|
11
|
+
should('render template properly') do
|
12
|
+
assert_have_selector "h1", :content => "This is a haml template!"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'for #erb_template method' do
|
17
|
+
setup { visit '/render_erb' }
|
18
|
+
should('render template properly') do
|
19
|
+
assert_have_selector "h1", :content => "This is a erb template!"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'for #render_template method with explicit engine' do
|
24
|
+
setup { visit '/render_template/haml' }
|
25
|
+
should('render template properly') do
|
26
|
+
assert_have_selector "h1", :content => "This is a haml template sent from render_template!"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'for #render_template method without explicit engine' do
|
31
|
+
setup { visit '/render_template' }
|
32
|
+
should('render template properly') do
|
33
|
+
assert_have_selector "h1", :content => "This is a haml template which was detected!"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'for #partial method and object' do
|
38
|
+
setup { visit '/partial/object' }
|
39
|
+
should "render partial html with object" do
|
40
|
+
assert_have_selector "h1", :content => "User name is John"
|
41
|
+
end
|
42
|
+
should "have no counter index for single item" do
|
43
|
+
assert_have_no_selector "p", :content => "My counter is 1", :count => 1
|
44
|
+
end
|
45
|
+
should "include extra locals information" do
|
46
|
+
assert_have_selector 'p', :content => "Extra is bar"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'for #partial method and collection' do
|
51
|
+
setup { visit '/partial/collection' }
|
52
|
+
should "render partial html with collection" do
|
53
|
+
assert_have_selector "h1", :content => "User name is John"
|
54
|
+
assert_have_selector "h1", :content => "User name is Billy"
|
55
|
+
end
|
56
|
+
should "include counter which contains item index" do
|
57
|
+
assert_have_selector "p", :content => "My counter is 1"
|
58
|
+
assert_have_selector "p", :content => "My counter is 2"
|
59
|
+
end
|
60
|
+
should "include extra locals information" do
|
61
|
+
assert_have_selector 'p', :content => "Extra is bar"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'for #partial method and locals' do
|
66
|
+
setup { visit '/partial/locals' }
|
67
|
+
should "render partial html with locals" do
|
68
|
+
assert_have_selector "h1", :content => "User name is John"
|
69
|
+
end
|
70
|
+
should "have no counter index for single item" do
|
71
|
+
assert_have_no_selector "p", :content => "My counter is 1", :count => 1
|
72
|
+
end
|
73
|
+
should "include extra locals information" do
|
74
|
+
assert_have_selector 'p', :content => "Extra is bar"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fixtures/routing_app/app'
|
3
|
+
|
4
|
+
class TestRoutingPlugin < Test::Unit::TestCase
|
5
|
+
def app
|
6
|
+
RoutingDemo.tap { |app| app.set :environment, :test }.tap { |app| app.set :uri_root, '/blog' }
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'for links list displaying routes' do
|
10
|
+
setup { visit '/links' }
|
11
|
+
should 'display account route links' do
|
12
|
+
assert_have_selector :p, :class => 'account_url', :content => '/the/accounts/foobar/path/10/end'
|
13
|
+
assert_have_selector :p, :class => 'accounts_index', :content => '/the/accounts/index'
|
14
|
+
end
|
15
|
+
should "display admin route links" do
|
16
|
+
assert_have_selector :p, :class => 'admin_url', :content => '/admin/25/show'
|
17
|
+
assert_have_selector :p, :class => 'admin_url2', :content => '/admin/10/update/test'
|
18
|
+
assert_have_selector :p, :class => 'admin_url3', :content => '/admin/12/destroy'
|
19
|
+
end
|
20
|
+
should "support app namespaces" do
|
21
|
+
assert_have_selector :p, :class => 'app_accounts_index', :content => '/the/accounts/index'
|
22
|
+
assert_have_selector :p, :class => 'app_admin_url', :content => '/admin/25/show'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'for mounted application' do
|
27
|
+
should "support changing uri root no mount" do
|
28
|
+
demo = app.new
|
29
|
+
demo.class.stubs(:uri_root).returns("/")
|
30
|
+
demo.class.map(:demo).to('/demo')
|
31
|
+
assert_equal "/demo", demo.class.named_paths[[:routing_demo, :demo]]
|
32
|
+
assert_equal "/demo", demo.url_for(:demo)
|
33
|
+
end
|
34
|
+
should "support changing uri root with mount" do
|
35
|
+
demo = app.new
|
36
|
+
demo.class.stubs(:uri_root).returns("/blog")
|
37
|
+
demo.class.map(:demo).to('/demo')
|
38
|
+
assert_equal "/demo", demo.class.named_paths[[:routing_demo, :demo]]
|
39
|
+
assert_equal "/blog/demo", demo.url_for(:demo)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'for failed or missing routes' do
|
44
|
+
should "properly not raise when found" do
|
45
|
+
assert_nothing_raised { app.new.url_for(:accounts) }
|
46
|
+
assert_nothing_raised { app.new.url_for(:routing_demo, :admin, :show, :id => 5) }
|
47
|
+
end
|
48
|
+
should "properly raise not found exception" do
|
49
|
+
assert_raises(Sinatra::RouteNotFound) { visit '/failed_route' }
|
50
|
+
assert_raises(Sinatra::RouteNotFound) { app.new.url_for(:admin, :fake) }
|
51
|
+
end
|
52
|
+
should "properly raise about an invalid alias for route definition" do
|
53
|
+
assert_raises(Sinatra::RouteNotFound) { app.get(:fake) }
|
54
|
+
end
|
55
|
+
should "properly work when alias is used in proper route definition" do
|
56
|
+
assert_nothing_raised { app.get(:accounts) do; end }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'for no namespaced account route' do
|
61
|
+
setup { visit '/the/accounts/demo/path/5/end'}
|
62
|
+
should "return proper account text" do
|
63
|
+
assert_have_selector :h1, :content => "the account url for demo and id 5"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'for no namespaced accounts index route' do
|
68
|
+
setup { visit '/the/accounts/index/'}
|
69
|
+
should "return proper account text" do
|
70
|
+
assert_have_selector :h1, :content => "the accounts index"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'for admin show url' do
|
75
|
+
setup { visit '/admin/50/show' }
|
76
|
+
should "return proper admin test" do
|
77
|
+
assert_have_selector :p, :content => "admin show for id 50"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'for admin update url' do
|
82
|
+
setup { visit '/admin/15/update/demo' }
|
83
|
+
should "return proper update text" do
|
84
|
+
assert_have_selector :p, :content => "updated admin with id 15 and name demo"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'for admin destroy url' do
|
89
|
+
setup { visit '/admin/60/destroy' }
|
90
|
+
should "return proper destroy text" do
|
91
|
+
assert_have_selector :p, :content => "destroy admin with id 60"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fixtures/warden_app/app'
|
3
|
+
|
4
|
+
class TestWardenPlugin < Test::Unit::TestCase
|
5
|
+
def app
|
6
|
+
WardenDemo.tap { |app| app.set :environment, :test }
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'for authenticate_user! helper' do
|
10
|
+
setup do
|
11
|
+
visit '/login', :post, :username => 'john21', :password => 'secret'
|
12
|
+
visit '/current_user'
|
13
|
+
end
|
14
|
+
should "return name of logged_in user" do
|
15
|
+
assert_have_selector :h1, :content => "John"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'for logout_user! helper' do
|
20
|
+
setup do
|
21
|
+
visit '/login', :post, :username => 'john21', :password => 'secret'
|
22
|
+
visit '/logout'
|
23
|
+
visit '/current_user'
|
24
|
+
end
|
25
|
+
should "return name of logged_in user" do
|
26
|
+
assert_have_selector :h2, :content => "Not logged in"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'for logged_in? helper when logged in' do
|
31
|
+
setup do
|
32
|
+
visit '/login', :post, :username => 'john21', :password => 'secret'
|
33
|
+
visit '/logged_in'
|
34
|
+
end
|
35
|
+
should "be logged in" do
|
36
|
+
assert_have_selector :h1, :content => 'logged_in? true'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'for logged_in? helper when logged out' do
|
41
|
+
setup do
|
42
|
+
visit '/logged_in'
|
43
|
+
end
|
44
|
+
should "not be logged in" do
|
45
|
+
assert_have_selector :h1, :content => 'logged_in? false'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'for authenticated? helper when logged in' do
|
50
|
+
setup do
|
51
|
+
visit '/login', :post, :username => 'john21', :password => 'secret'
|
52
|
+
visit '/authenticated'
|
53
|
+
end
|
54
|
+
should "reveal authorized content" do
|
55
|
+
assert_have_selector :p, :content => "Dashboard, You are logged in!"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'for authenticated? helper when logged out' do
|
60
|
+
setup do
|
61
|
+
visit '/authenticated'
|
62
|
+
end
|
63
|
+
should "hide authorized content" do
|
64
|
+
assert_have_no_selector :p, :content => "Dashboard, You are logged in!"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'for unregistered? helper when logged in' do
|
69
|
+
setup do
|
70
|
+
visit '/login', :post, :username => 'john21', :password => 'secret'
|
71
|
+
visit '/unregistered'
|
72
|
+
end
|
73
|
+
should "hide unregistered content" do
|
74
|
+
assert_have_no_selector :p, :content => "Dashboard, You are unregistered!"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'for unregistered? helper when logged out' do
|
79
|
+
setup do
|
80
|
+
visit '/unregistered'
|
81
|
+
end
|
82
|
+
should "reveal unregistered content" do
|
83
|
+
assert_have_selector :p, :content => "Dashboard, You are unregistered!"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'for must_be_authorized! helper with valid login' do
|
88
|
+
setup do
|
89
|
+
visit '/login', :post, :username => 'john21', :password => 'secret'
|
90
|
+
visit '/must_be_authorized'
|
91
|
+
end
|
92
|
+
should "be able to view page" do
|
93
|
+
assert_have_selector :h1, :content => "Valid Authorized Page"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'for must_be_authorized! helper when not logged in' do
|
98
|
+
setup do
|
99
|
+
visit '/must_be_authorized'
|
100
|
+
end
|
101
|
+
should "be forced to login" do
|
102
|
+
assert_have_selector :h1, :content => "Please login!"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|