diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE
new file mode 100644
index 000000000..ca97bef32
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE
@@ -0,0 +1,9 @@
+#### Do you want to request a *feature* or report a *bug*?
+
+#### What is the current behavior?
+
+*If the current behavior is a bug, please provide the steps to reproduce it and if possible a minimal demo of the problem via https://github.com/ or https://gist.github.com/*
+
+#### What is the expected behavior?
+
+#### Which versions of Ruby, Padrino, Sinatra, Rack, OS are you using? Did this work in previous versions?
diff --git a/.gitmodules b/.gitmodules
index 15e6255af..f33cef28a 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,8 @@
[submodule "padrino-gen/lib/padrino-gen/generators/templates/static"]
path = padrino-gen/lib/padrino-gen/generators/templates/static
url = git://github.com/padrino/padrino-static.git
+ branch = master
+[submodule "padrino-docs"]
+ path = padrino-docs
+ url = git://github.com/padrino/padrino-docs.git
+ branch = master
diff --git a/.travis.yml b/.travis.yml
index f27388a19..d852cc2d8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,14 +1,20 @@
-lang: ruby
-before_install: gem install bundler --pre
+language: ruby
+sudo: false
+cache: bundler
+before_install:
+ - gem install bundler
install:
- - gem update --system
- bundle update
rvm:
- - 1.9.3
- - 2.0.0
- - 2.1.1
+ - 2.2.2
+ - 2.3.0
+ - 2.3.3
+ - 2.4.3
+ - 2.5.0
+ - ruby-head
- rbx-2
- jruby
+ - jruby-head
notifications:
irc: 'irc.freenode.org#padrino'
recipients:
@@ -24,11 +30,24 @@ notifications:
branches:
only:
- master
+ - 0.12
+ - 0.14
services: mongodb
matrix:
include:
- - rvm: 2.1.1
+ - rvm: 2.3.3
env: SINATRA_EDGE=true
+ - rvm: 2.3.3
+ env: ERB_ENGINE=stdlib
+ - rvm: 2.3.3
+ env: ERB_ENGINE=erubis
+ - rvm: 2.3.3
+ env: HAML_ENGINE=hamlit
+ - rvm: 2.3.3
+ env: AS_VERSION=3.2
allow_failures:
- - rvm: 2.1.1
- env: SINATRA_EDGE=true
+ - rvm: rbx-2
+ - rvm: jruby
+ - rvm: jruby-head
+ - rvm: ruby-head
+ - env: SINATRA_EDGE=true
diff --git a/CHANGES.rdoc b/CHANGES.rdoc
index f25a043c2..21cc9f6c6 100644
--- a/CHANGES.rdoc
+++ b/CHANGES.rdoc
@@ -1,5 +1,246 @@
= CHANGES
+== 0.14.2 (2018-01-02)
+- FIX router in non-Padrino applications (@adam12)
+- FIX padrino-admin haml layout
+- FIX Datamapper tasks (@adam12)
+- FIX #1979 default test or spec task
+- FIX #2150 refuse invalid database adapters
+- FIX #2152 using open without requiring 'open-uri'
+- NEW #2161 allow array as tag attribute (@aeris)
+- FIX #2163 preserve spaces in args of padrino gen
+- update Sequel usage
+- update ActiveRecord::Migration usage (@adam12)
+
+== 0.14.1 (2017-05-16)
+- FIX syntax error in ActiveRecord tasks (@sue445)
+- NEW use hamlit if available in Gemfile
+
+== 0.14.0.2 (2017-05-08)
+- FIX #2132 use Sinatra2 IndifferentHash if available
+
+== 0.14.0.1 (2017-03-23)
+- FIX #2118 allow Logger without Extensions
+- FIX #2128 do not render default layout in partials
+
+== 0.14.0 (2017-03-15)
+- NEW #2120 enable cascading with Rack application (@namusyaka)
+- FIX lock rake < 11.0 to avoid last_comment error (@namusyaka)
+- FIX handle nil database passwords for create_db and drop_db (@phallstrom)
+- FIX #2119 add rake gem tasks to gem project Rakefile
+- NEW support Erubi ERB engine (@adam12)
+- FIX #2125 do not load in cycle files excluded from reloading
+
+== 0.14.0.rc2 (2017-01-19)
+- FIX #2109 change the format of session_id for Padrino Admin AccessControl
+- WARN #2109 Existing sessions will be dropped
+- FIX #2097 Use exe folder for application executables (@adam12)
+- FIX #2105 Run bundle with --binstubs on -b switch (@adam12)
+- FIX #2111 disallow conflicting project names
+- NEW remove deprecations planned for 0.14.0
+- NEW stop managing Ruby default encodings
+ Default Encoding.default_internal is now nil (Ruby default) instead of UTF-8 (Padrino < 0.14 default)
+- FIX #2113 properly override default values in route definitions if parameter is present (@fidalgo)
+- FIX #2116 fix plugin list `padrino g plugin -l` (@fnordfish)
+
+== 0.14.0.rc1 (2016-11-02)
+- NEW remove the requirement of ActiveSupport (export AS_VERSION=X.0 to put it back)
+
+== 0.13.3.3 (2016-11-02)
+- FIX #2075 cache actual content_type mime type
+- FIX #2081 remove -i option from pg_dump command (@dfens)
+- FIX #2083 be able to create sqlite's file to deep tree of subdirectories (@kkarakawa)
+- NEW dynamically list supported renderers (@jfredrickson)
+
+== 0.13.3.2 (2016-09-06)
+- FIX #2071 regression of #1906
+- FIX running padrino without Gemfile
+- NEW alias db:create for sequel adapter
+
+== 0.13.3.1 (2016-08-30)
+- NEW support usage of partials without view path
+
+== 0.13.3 (August 17th 2016)
+
+- FIX #1785 Nested forms and helpers with ERB and Erubis (@ujifgc)
+- FIX #1847 Shoulda on modern rubies
+- NEW #1851 Remove RightJS, Riot, Steak support (@ujifgc)
+- FIX #1872 Implement using partials without Sinatra (@ujifgc)
+- NEW #1906 Allow shortened mailer render calls with default mailer and message names (@ujifgc)
+- FIX #2013 Delegate padrino and padrino-gen to bundler binstubs (@ujifgc)
+- FIX #2016 Escape urls in link_to and form_tag (@ujifgc)
+- FIX #2042 Do not override access control object when registered in multiple apps (@nxs6)
+- FIX #2045 Prevent overwriting params by given query (@namusyaka)
+- NEW #2050 Update Moneta to 0.8.0 (@basex)
+- FIX #2052 String#humanize compatibility with AS ~3.2
+- NEW #2056 Allow Pry as Padrino console shell
+- FIX #2066 fix reloader with native jruby classes
+
+== 0.13.2 (May 9th 2016)
+
+- FIX #1789 Relax Tilt version to allow Tilt 2 (>= 1.4.1, < 3) (@ujifgc)
+- WARN #1989 Warn about coming behavior change (@ujifgc)
+- NEW #1987 Generator now failes with invalid namespace (@ujifgc)
+- NEW Remove many internal uses of ActiveSupport (@ujifgc)
+- FIX #2007 Respect Regexp#names at the time of route search (@namusyaka)
+- FIX #2004 Set default alt attribute for image_tag (@namusyaka)
+- FIX #2008 Login button on the admin app now looks as expected (@namusyaka)
+- FIX #2011 Update mongoid database configuration (@serradura)
+- FIX Remove empty rows and cols from textarea tag (@ujifgc)
+- FIX #2015 Update broken links in the README and docs (@mariozig)
+- FIX #2023 Preserve `default_builder` set in configure_apps (@ujifgc)
+- FIX #2025 Match plugin names with dashes in their names (@wikimatze)
+- WARN Notice about removing ObjectSpace.classes and ObjectSpace.new_classes in 0.14 (@ujifgc)
+- FIX #2027 Use Module#name instead of Module#to_s (@namusyaka)
+- NEW Logger option :sanitize_encoding (@ujifgc)
+- FIX #2006 load missing AR models before calling seeds.rb (@ujifgc)
+- NEW #1921 Adds `--api` option for project generator (@ujifgc)
+- NEW #2032 Adds new `config/initializers` folder loaded during boot (@ujifgc)
+- FIX #2019 Removes deprecation warning for ActiveRecord (@wikimatze)
+
+== 0.13.1 (January 17th 2016)
+
+- FIX #1978 Enable reloading of custom dependencies (@markglenfletcher)
+- FIX Remove use of ActiveSupport in tests (@ujifgc)
+- FIX #1982 Support nested query for expanding path (@namusyaka)
+- FIX #1994 Missing new line in mocha generator (@peter50216)
+- FIX #1995 Invalid german dates (@ujifgc)
+- FIX #1998 Only output a warning message if the spec task is invoked (@postmodern)
+- FIX #2000 Fix mutex handling for Ruby 2.3 (@tyabe)
+
+== 0.13.1.beta1 (October 18th 2015)
+
+- FIX #1975 Improve routing memory usage and performance (@namusyaka)
+- FIX #1882 test for selected values for select tag (@ujifgc)
+- FIX rendering exception for custom mime types (@nesquena)
+- FIX relax mail gem dependency (@ujifgc)
+- FIX minor doc typos (@lokyoung, @markglenfletcher)
+
+== 0.13.0 (October 11th 2015)
+
+- FIX #1614 Do not search for caller in bundler lib (@ujifgc)
+- FIX #1796 Save and restore layout setting (@ujifgc)
+- FIX #1882 Fix ambiguous selected items in "select_tag" (@nesquena)
+- FIX #1965 Fail properly on wrong mailer name or message (@ujifgc)
+- FIX #1959 simplify the mounter class (@dnesteryuk)
+- FIX #1916 Check key existence on caching (@namusyaka)
+- NEW #1946 Documentation fixes re default renderer is now none (@Quintasan)
+- FIX #942 remove ar:auto:upgrade (@ujifgc)
+- NEW #1919 allow configuring log file path
+- FIX #1931 render partials in mail if padrino-helpers is available (@ujifgc)
+- FIX #1950 Padrino now follows Sinatra's charset policy (@ujifgc)
+- NEW #1909 Basic project configuration engine (@ujifgc)
+- NEW #1966 sample benchmark test of padrino core (@ujifgc)
+
+== 0.13.0.beta3 (August 2nd 2015)
+
+- NEW #1908 Adds test-unit as a test component (@namusyaka)
+- FIX #1829 add absolute_url to app methods, add :base_url setting (@ujifgc)
+- FIX #1880 rendering issue by accepting string content types (@ujifgc)
+- NEW #1898 Adds missing helpers for the input html element (@namusyaka)
+- FIX AWS namespace in Dynamoid component (@namusyaka)
+- FIX Root index route incorrectly matches single-character URLs (@namusyaka)
+- NEW #1929 Alias db:migrate:down and db:migrate:up when using datamapper (@postmodern)
+- FIX #1932 Replace ConnectionManagement with ConnectionPoolManagement (@namusyaka)
+- FIX Restore AbstractFormBuilder#field\_human\_name (@namusyaka)
+- FIX #1936 Don't echo password input (@namusyaka)
+- NEW #1940 Add IdentityMap middleware to datamapper (@namusyaka)
+- FIX Cache test for moneta (@ujifgc)
+- FIX #1943 Issue with format provides in controller with wildcard accepts header (@ujifgc)
+- FIX #1942 maintain Sinatra params indifference (@ujifgc)
+- FIX properly reload classes without instances (@ujifgc)
+- FIX #1922 consider methodless constants not external (@ujifgc)
+- NEW #1945 adds community page to padrino-docs (@Quintasan)
+
+== 0.13.0.beta2 (April 11th 2015)
+
+* FIX #1870 Trigger filters if superclass responds to :filters (@namusyaka)
+* FIX #749 Trigger resource dirtiness for datamapper (@ujifgc)
+* NEW #1853 Adds wrapper for application which allows better extensibility (@namusyaka)
+* FIX #1891 Refactorings for more reliable dependency loading (@hcatlin, @namusyaka)
+* FIX Update rack-test to 0.6.3 and remove old patch (@ujifgc)
+* FIX #1895 Use compass-blueprint gem for improved compass generator (@myokoym)
+* FIX #1899 Upgrade to sinatra 1.4.6 and latest rack version (@namusyaka)
+* FIX #1886 Moves rake task loading code later in the booting process (@namusyaka)
+
+== 0.13.0.beta1 (February 22nd 2015)
+
+* FIX cleanup and refactor rake tasks (@ujifgc)
+* NEW Remove deprecated cache functionality (@minad)
+* FIX Cleanup and improve test helpers for each gem (@ujifgc)
+* FIX allow Padrino::Rendering with standard ERB (@ujifgc)
+* NEW Emulate set method in mailer context (@ujifgc)
+* FIX #1772 add button content tag to button_to block (@ujifgc)
+* NEW #1133 switch default renderer to none (@ujifgc)
+* FIX #1792 Faster code using reverse_each to iterate gems (@glaucocustodio)
+* FIX #1793 Faster code using #sub instead of #gsub (@glaucocustodio)
+* FIX #1795 load missing models for sq:seed (@ujifgc)
+* NEW Use mustermann19 in all cases now (@namusyaka)
+* FIX Remove abuse of force_encoding (@ujifgc)
+* FIX #1811 Refactor and change style of path_router within core routing (@namusyaka)
+* FIX #1803 Use relative paths for sqlite and sequel (@ujifgc)
+* NEW #1800 Support named capture on regex for router (@namusyaka)
+* FIX #1821 Don't load dependency files unless app's root is within Padrino root (@namusyaka)
+* FIX Improved docs and FAQ for helpers and core (@fwolfst, @CrowdHailer, @seanhussey, @neilang)
+* FIX #1835 Switch admin to sequel fixtures rather than datamapper (@namusyaka)
+* FIX #1828 Refactor new router and fix sinatra compatibility (@namusyaka)
+* FIX Ensure the before_filter is triggered in certain cases (@namusyaka)
+* FIX Widen the range of `default_dependency_paths` (@namusyaka)
+* NEW #1831 Implement the `mi:translate` task (@namusyaka)
+* FIX #1852 ApplicationWrapper Prerequisite Issue (@hcatlin)
+* FIX #1856 Skips loading models for the activerecord rake tasks (@namusyaka)
+* NEW #1857 Precompile routes when loading Padrino (@namusyaka)
+* NEW #1818 Implement `source_location` option for logger (@namusyaka)
+* FIX #1859 Correct issues with the admin seeds generator (@Quintasan)
+* FIX #1704 Make broken async stream callbacks work in Padrino (@jay2u)
+* FIX #1862 Re-implement `PathRouter#recognize` (@namusyaka)
+* FIX #863 Removes unsafe http_router patch (@namusyaka)
+* FIX #1867 Update ShowExceptions to suit latest rack master (@namusyaka)
+* FIX #1879 Improve access to Active Record Database Configuration (@scudelletti)
+* DELETE remove deprecations (String#undent, #link_to with :fragment, old caching,
+ old form builder, rendering #fetch_template_file, #cache_template_file!, #resolved_layout,
+ Application#load_paths, Padrino.set_load_paths, Padrino.load_paths)
+* FIX #1860 Padrino --environment switch now takes precedence over RACK_ENV environment variable
+* FIX #1849 return proper exit codes in CLI
+
+== 0.12.5 (February 22nd 2015)
+
+* FIX #1794 inheritance of global prereqs (@ujifgc)
+* FIX #1798 handling non-array `with` statement for params (@ujifgc)
+* FIX Russian translation for password (@harrykiselev)
+* FIX Prevent Padrino from overriding cache settings (@dariocravero)
+* FIX sequence of execution for configuration methods in application (@namusyaka)
+* FIX translations for admin for cs (@ortiga)
+* FIX exception raised when running the controller generator (@namusyaka)
+* FIX #1875 lock down rack to < 1.6.0 because of sinatra conflict (@ujifgc)
+
+== 0.12.4 (October 19th 2014)
+
+* FIX #1744 Corrects color support for Windows (@tyabe)
+* FIX #1736 Regression with textarea helper (@ujifgc)
+* FIX #1743 Add a padrino-gen generator for creating new Helpers (@dariocravero)
+* FIX #1746 Avoid reloading the file if its path is not started with Padrino.root (@namusyaka)
+* DELETE deprecated build_object method (@namusyaka)
+* FIX #1752 Don't set the @_use_format variable when provides method is called (@namusyaka)
+* FIX #48 Update mailer documentation and sample code (@postmodern)
+* FIX #1752 Refactor routing code to avoid weird parameter (@namusyaka)
+* FIX #1754 Adds end tags to admin erb template for index (@namusyaka)
+* FIX #1749 Replace the AR::ConnectionManagement middleware with new middleware (@namusyaka)
+* NEW #1756 Adds support for mysql2 gem in sql rake task helpers (@d6rkaiz)
+* FIX #1761 Allow passing upcased string as the app name
+* FIX #1776 improve params filtering for routes (@ujifgc)
+* FIX #1778 Various YARD doc inconsistencies or errors (@claudiob)
+* FIX #1765 Use controller's base path instead of constant name at controller test (@namusyaka)
+* FIX #1781 Removes the default_filters method setting incorrect content-type (@namusyaka)
+* FIX Sinatra compatibility for passing options to the static! method
+* FIX #1585 Update HAML to pass tests by upgrading versions (@ujifgc)
+* FIX #1782 make padrino-gen detect absolute paths on Windows (@ujifgc)
+* FIX #1779 Use expanded path to request controller's content (@namusyaka)
+* FIX Use yield and flatmap when possible to speed up performance (@ujifgc)
+* NEW #1787 Mounter now supports Rack applications (@namusyaka)
+* FIX #1788 exception that occurs when the free regex route exists (@namusyaka)
+* NEW Merges the padrino-docs guides and content directly into the main repository (@ujifgc)
+
== 0.12.3 (August 13th 2014)
* FIX #1579 Update admin deps such as font-awesome, jquery, bootstrap (@WaYdotNET)
diff --git a/Gemfile b/Gemfile
index 4cebc9455..fdf04f4cc 100644
--- a/Gemfile
+++ b/Gemfile
@@ -7,45 +7,56 @@ if ENV["AS_VERSION"]
end
group :db do
- gem "dm-core", ">=1.2"
- gem "dm-migrations", ">=1.2"
- gem "dm-validations", ">=1.2"
- gem "dm-aggregates", ">=1.2"
- gem "dm-sqlite-adapter", ">=1.2"
+ gem "sequel"
+ gem "sqlite3", :platforms => [:mri, :rbx]
+ gem "jdbc-sqlite3", "~> 3.7.2", :platform => :jruby
end
group :development do
- if ENV['SINATRA_EDGE']
+ if ENV["SINATRA_VERSION"]
+ puts "=> Using Sinatra version ~> #{ENV['SINATRA_VERSION']}"
+ gem "sinatra", "~> #{ENV['SINATRA_VERSION']}"
+ elsif ENV['SINATRA_EDGE']
puts "=> Using sinatra edge"
gem "sinatra", :git => "git://github.com/sinatra/sinatra.git"
end
- gem "nokogiri", "~> 1.5.10"
+
+ gem "slim", ">= 1.3.0"
+ gem "liquid", ">= 2.1.1"
+
+ if ENV['HAML_ENGINE'] == 'hamlit'
+ puts "=> Using Hamlit Haml engine"
+ gem "hamlit"
+ else
+ gem "haml", ">= 4.0.5"
+ end
+
+ case ENV['ERB_ENGINE']
+ when "stdlib"
+ puts "=> Using stdlib ERB engine"
+ when "erubis"
+ puts "=> Using Erubis ERB engine"
+ gem "erubis", ">= 2.7.0"
+ else
+ gem "erubi", ">= 1.6.0"
+ end
+
gem "rack", ">= 1.3.0"
- gem "rake", ">= 0.8.7"
+ gem "rake", ">= 10.5.0"
gem "yard", ">= 0.7.2"
- gem "rack-test", ">= 0.5.0"
+ gem "rack-test", "~> 0.6.3"
gem "fakeweb", ">= 1.2.8"
- gem "webrat", ">= 0.5.1"
- gem "haml", ">= 2.2.22"
- gem "erubis", ">= 2.7.0"
- gem "slim", ">= 1.3.0"
- gem "builder", ">= 2.1.2"
+ gem "oga", "~> 2.5"
+ gem "builder", ">= 2.1.2"
+ gem "mocha", ">= 0.10.0"
+ gem "minitest", ">= 4.0"
+
platforms :jruby do
gem "jruby-openssl"
end
- gem "mocha", ">= 0.10.0"
- gem "minitest", ">= 4.0"
end
-%w[
- padrino
- padrino-admin
- padrino-cache
- padrino-core
- padrino-gen
- padrino-helpers
- padrino-mailer
- padrino-support
-].each do |dep|
- gem dep, :path => File.expand_path('../' + dep, __FILE__)
+load File.expand_path('../padrino/subgems.rb', __FILE__)
+PADRINO_GEMS.each_key do |name|
+ gem name, :path => File.expand_path('../' + name, __FILE__)
end
diff --git a/README.rdoc b/README.rdoc
index 0ae1c7702..35a1ead5d 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -2,11 +2,14 @@
Padrino is the godfather of Sinatra. Follow us on
{www.padrinorb.com}[http://padrinorb.com] and on twitter
-{@padrinorb}[http://twitter.com/padrinorb]
+{@padrinorb}[http://twitter.com/padrinorb]. Join us on {gitter}[https://gitter.im/padrino/padrino-framework]
{}[http://travis-ci.org/padrino/padrino-framework]
{
}[https://gemnasium.com/padrino/padrino-framework]
{
}[https://codeclimate.com/github/padrino/padrino-framework]
+{
}[https://gitter.im/padrino/padrino-framework]
+{
}[https://www.codetriage.com/padrino/padrino-framework]
+
== Preface
Padrino is a ruby framework built upon the excellent {Sinatra Web Library}[http://www.sinatrarb.com].
@@ -34,58 +37,68 @@ Form Helpers:: Builder support such as: form_tag, form_for, field_set_tag, text_
Text Helpers:: Useful formatting like: time_ago_in_words, js_escape_html, sanitize_html.
Mailer:: Fast and simple delivery support for sending emails (akin to ActionMailer).
Caching:: Simple route and fragment caching to easily speed up your web requests.
-Admin:: Builtin Admin interface (like Django)
+Admin:: Built-in Admin interface (like Django)
Logging:: Provide a unified logger that can interact with your ORM or any library.
Reloading:: Automatically reloads server code during development.
Localization:: Full support of I18n language localization and can auto-set user's locale.
Keep in mind, developers are able to individually pull in these modular components
-{into existing Sinatra applications}[http://www.padrinorb.com/guides/standalone-usage-in-sinatra]
+{into existing Sinatra applications}[http://padrinorb.com/guides/advanced-usage/standalone-usage-in-sinatra/]
or use them altogether for a full-stack Padrino application.
== Installation
-To install the padrino framework, simply grab the latest version from gemcutter:
+To install the padrino framework, simply grab the latest version from {RubyGems}[https://rubygems.org]:
$ gem install padrino
This will install the necessary padrino gems to get you started.
-Now you are ready to use this gem to enhance your sinatra projects or to create new Padrino applications.
+Now you are ready to use this gem to enhance your Sinatra projects or to create new Padrino applications.
For a more detailed look at installing Padrino,
-check out the {Installation Guide}[http://www.padrinorb.com/guides/installation].
+check out the {Installation Guide}[http://padrinorb.com/guides/getting-started/installation/].
== Usage
Padrino is a framework which builds on the existing functionality of Sinatra and provides a variety of
-additional tools and helpers to build upon that foundation. This README and Padrino documentation in general will focus
-on the enhancements to the core Sinatra functionality. To use Padrino, one should be familiar with the basic
+additional tools and helpers to build upon that foundation. This README and Padrino documentation in general will focus on the enhancements to the core Sinatra functionality. To use Padrino, one should be familiar with the basic
usage of Sinatra itself.
-You can also check out the {Getting Started}[http://www.padrinorb.com/guides/getting-started] guide
-to learn more about how Sinatra and Padrino work together.
+You can also check out the {Why Learn Padrino?}[http://padrinorb.com/guides/introduction/why-learn-padrino/] introduction to learn more about how Sinatra and Padrino work together.
-For information on how to use a specific gem in isolation within an existing Sinatra project, checkout the guide for
-{Using Padrino within Sinatra}[http://www.padrinorb.com/guides/standalone-usage-in-sinatra].
+For information on how to use a specific gem in isolation within an existing Sinatra project, checkout the guide for {Using Padrino within Sinatra}[http://padrinorb.com/guides/advanced-usage/standalone-usage-in-sinatra/].
== Getting Started
-Once a developer understands Sinatra, Padrino is quite easy to get comfortable with since Padrino is simply a superset
-of existing sinatra functionality!
+Once a developer understands Sinatra, Padrino is quite easy to get comfortable with since Padrino is simply a superset of existing Sinatra functionality!
-First, be sure to read over the {Getting Started}[http://www.padrinorb.com/guides/getting-started] guide
+First, be sure to read over the {Getting Started}[http://padrinorb.com/guides/getting-started/overview/] guide
to learn more about how Sinatra and Padrino work together.
Best way to learn more about building Padrino applications is to read following resources:
-* {Padrino Guides}[http://www.padrinorb.com/guides] - Guides outlining the major functionality within Padrino.
-* {Blog Tutorial}[http://www.padrinorb.com/guides/blog-tutorial] - Step-by-step guide to building a blog application with Padrino.
-* {Padrino API}[http://www.padrinorb.com/api/index.html] - YARD documentation for the Padrino framework.
-* {Quick Overview}[http://www.padrinorb.com/guides/basic-projects] - Outlines basic generation commands.
+* {Padrino Guides}[http://padrinorb.com/guides] - Guides outlining the major functionality within Padrino.
+* {Blog Tutorial}[http://padrinorb.com/guides/getting-started/blog-tutorial/] - Step-by-step guide to building a blog application with Padrino.
+* {Padrino API}[http://www.rubydoc.info/github/padrino/padrino-framework] - YARD documentation for the Padrino framework.
+* {Quick Overview}[http://padrinorb.com/guides/getting-started/basic-projects/] - Outlines basic generation commands.
The individual Padrino sub-gems also contain README's which outlines their functionality.
+== Further Questions
+
+Can't find an answer in the resources above?
+
+* Ask any questions on the {gitter channel}[https://gitter.im/padrino/padrino-framework].
+
+== Bug reporting
+
+Log it onto Github by {creating a new issue}[http://github.com/padrino/padrino-framework/issues].
+
+Be sure to include all relevant information, like the versions of Padrino, Rack, Sinatra, Ruby and operating system you are using.
+
+A minimal project showing the issue published on Github with Gemfile.lock is also extremely helpful.
+
== Copyright
-Copyright (c) 2012-2013 Padrino. See LICENSE for details.
+Copyright (c) 2010-2016 Padrino. See LICENSE for details.
diff --git a/Rakefile b/Rakefile
index 53c44ca32..3ea6b33d6 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,26 +1,11 @@
# rake bump[X.X.X] && rake publish
-require 'rubygems' unless defined?(Gem)
-require 'fileutils' unless defined?(FileUtils)
+require 'fileutils'
require 'rake'
-require 'yard'
require File.expand_path("../padrino-core/lib/padrino-core/version.rb", __FILE__)
-ROOT = File.expand_path(File.dirname(__FILE__))
-GEM_NAME = 'padrino-framework'
-
-padrino_gems = %w[
- padrino-core
- padrino-support
- padrino-helpers
- padrino-mailer
- padrino-cache
- padrino-admin
- padrino-gen
- padrino-performance
- padrino
-]
-
-GEM_PATHS = padrino_gems.freeze
+load File.expand_path('../padrino/subgems.rb', __FILE__)
+GEM_PATHS = PADRINO_GEMS.keys
+ROOT = File.expand_path(File.dirname(__FILE__))
def sh_rake(command)
sh "#{Gem.ruby} -S rake #{command}", :verbose => true
@@ -47,7 +32,7 @@ end
desc "Clean pkg and other stuff"
task :uninstall do
- padrino_gems.each {|gem|
+ GEM_PATHS.each {|gem|
system("gem uninstall #{gem} --force -I -x 2>/dev/null")
}
end
@@ -70,11 +55,18 @@ end
desc "Executes a fresh install removing all padrino version and then reinstall all gems"
task :fresh => [:uninstall, :install, :clean]
-desc "Pushes repository to GitHub"
-task :push do
- say "Updating and verifying submodules"
+desc "Pulls latest commits and updates submodules"
+task :pull do
+ say "Pulling latest commits"
+ sh "git checkout master"
+ sh "git pull origin master"
+ say "Updating submodules"
sh "git submodule foreach git pull origin master"
sh "ls padrino-gen/lib/padrino-gen/generators/templates/static/README.rdoc"
+end
+
+desc "Pushes repository to GitHub"
+task :push => :pull do
say "Pushing to github..."
sh "git tag #{Padrino.version}"
sh "git push origin master"
@@ -93,31 +85,24 @@ task :release => :publish
desc "Run tests for all padrino stack gems"
task :test do
- # Omit the padrino metagem since no tests there
- GEM_PATHS[0..-2].each do |g|
+ GEM_PATHS.each do |g|
# Hardcode the 'cd' into the command and do not use Dir.chdir because this causes random tests to fail
sh "cd #{File.join(ROOT, g)} && #{Gem.ruby} -S rake test"
end
end
-padrino_gems.each do |element|
+GEM_PATHS.each do |element|
desc "Run tests for #{element} component"
task element.to_s do
sh "cd #{element} && #{Gem.ruby} -S rake test"
end
end
-desc "Run tests for all padrino stack gems"
-task :default => :test
-
desc "Generate documentation for the Padrino framework"
task :doc do
+ require 'yard'
YARD::CLI::Yardoc.new.run
end
-desc "Publish doc on padrinorb.com/api"
-task :pdoc => :doc do
- say "Publishing doc on padrinorb.com ..."
- sh "scp -r doc/* root@lps2.lipsiasoft.com:/mnt/www/apps/padrino/public/api/"
- sh "rm -rf doc"
-end
+desc "Run tests for all padrino stack gems"
+task :default => :test
diff --git a/gem_rake_helper.rb b/gem_rake_helper.rb
index 676e5c0bc..68e57e472 100644
--- a/gem_rake_helper.rb
+++ b/gem_rake_helper.rb
@@ -1,22 +1,21 @@
-require 'rubygems' unless defined?(Gem)
-require 'rake'
-require 'rake/testtask'
+require 'bundler/setup'
require 'bundler/gem_tasks'
+require 'rake/testtask'
require 'yard'
# Skip the releasing tag
class Bundler::GemHelper
- def release_gem(*args)
- guard_clean
- built_gem_path = build_gem
- rubygem_push(built_gem_path)
+ def version_tag
+ "#{version}"
end
end
Rake::TestTask.new(:test) do |test|
test.libs << 'test'
+ test.libs << '../padrino/test'
test.test_files = Dir['test/**/test_*.rb']
test.verbose = true
+ test.warning = false
end
YARD::Rake::YardocTask.new
diff --git a/load_paths.rb b/load_paths.rb
deleted file mode 100644
index e02cead5c..000000000
--- a/load_paths.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-if defined?(Gem)
- gem 'bundler'
-else
- require 'rubygems'
-end
-require 'bundler/setup'
diff --git a/padrino-admin/README.rdoc b/padrino-admin/README.rdoc
index 7d77bf8cc..6a63931ba 100644
--- a/padrino-admin/README.rdoc
+++ b/padrino-admin/README.rdoc
@@ -13,7 +13,7 @@ Access Control:: Supports authentication and role permissions for your applicati
=== Admin Dashboard Usage
For a complete look at usage of the Admin dashboard functionality, be sure to check out the
-{Padrino Admin}[http://www.padrinorb.com/guides/padrino-admin] guide.
+{Padrino Admin}[http://padrinorb.com/guides/features/padrino-admin/] guide.
Create a new project:
@@ -63,8 +63,8 @@ In this example +if+ we visit URLs that start with /+customer+/+orders+ or /+car
to our :+login_page+ "/login". Once we are correctly logged in we can visit these pages.
For a more complete look at using the Admin panel functionality and access features, be sure to check out the
-{Padrino Admin}[http://www.padrinorb.com/guides/padrino-admin] guide.
+{Padrino Admin}[http://padrinorb.com/guides/features/padrino-admin/] guide.
== Copyright
-Copyright (c) 2011-2013 Padrino. See LICENSE for details.
+Copyright (c) 2011-2015 Padrino. See LICENSE for details.
diff --git a/padrino-admin/Rakefile b/padrino-admin/Rakefile
index 8e6cc7613..e682baf84 100644
--- a/padrino-admin/Rakefile
+++ b/padrino-admin/Rakefile
@@ -1,7 +1,3 @@
-# coding:utf-8
-RAKE_ROOT = __FILE__
-
-require 'rubygems'
require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
namespace :bootstrap do
diff --git a/padrino-admin/lib/padrino-admin.rb b/padrino-admin/lib/padrino-admin.rb
index 983acf20f..97d1712bd 100644
--- a/padrino-admin/lib/padrino-admin.rb
+++ b/padrino-admin/lib/padrino-admin.rb
@@ -1,4 +1,3 @@
-require 'active_support/core_ext/array/conversions'
require 'padrino-core'
require 'padrino-helpers'
diff --git a/padrino-admin/lib/padrino-admin/access_control.rb b/padrino-admin/lib/padrino-admin/access_control.rb
index c9eb7fbcf..adc93d489 100644
--- a/padrino-admin/lib/padrino-admin/access_control.rb
+++ b/padrino-admin/lib/padrino-admin/access_control.rb
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/class/attribute_accessors'
-
module Padrino
module Admin
class AccessControlError < StandardError
@@ -14,12 +12,20 @@ class << self
#
def registered(app)
app.register Padrino::Admin unless app.extensions.include?(Padrino::Admin)
- app.set :session_id, "_padrino_#{File.basename(Padrino.root)}_#{app.app_name}".to_sym unless app.respond_to?(:session_id)
+ app.set :session_id, "_padrino_#{Padrino.env}_#{app.app_name}" unless app.respond_to?(:session_id)
app.set :admin_model, 'Account' unless app.respond_to?(:admin_model)
app.helpers Padrino::Admin::Helpers::AuthenticationHelpers
app.helpers Padrino::Admin::Helpers::ViewHelpers
app.before { login_required }
- app.send(:cattr_accessor, :access_control)
+ app.class_eval do
+ class << self
+ attr_accessor :access_control
+ end
+ def access_control
+ self.class.access_control
+ end
+ end
+
app.send(:access_control=, Padrino::Admin::AccessControl::Base.new)
end
alias :included :registered
@@ -57,7 +63,7 @@ def roles
def project_modules(account)
role = account.role.to_sym rescue :any
authorizations = @authorizations.find_all { |auth| auth.roles.include?(role) }
- authorizations.map(&:project_modules).flatten.uniq
+ authorizations.flat_map(&:project_modules).uniq
end
##
@@ -96,7 +102,7 @@ def project_modules(account)
# = link_to 'Profile', url(:accounts, :edit, :id => current_account.id)
#
def allowed?(account=nil, path=nil)
- path = "/" if path.blank?
+ path = "/" if path.nil? || path.empty?
role = account.role.to_sym rescue nil
authorizations = @authorizations.find_all { |auth| auth.roles.include?(:any) }
allowed_paths = authorizations.map(&:allowed).flatten.uniq
diff --git a/padrino-admin/lib/padrino-admin/generators/admin_app.rb b/padrino-admin/lib/padrino-admin/generators/admin_app.rb
index 99204199c..7d70d4c5b 100644
--- a/padrino-admin/lib/padrino-admin/generators/admin_app.rb
+++ b/padrino-admin/lib/padrino-admin/generators/admin_app.rb
@@ -49,7 +49,7 @@ def create_admin
tmp_ext = options[:renderer] || fetch_component_choice(:renderer)
unless supported_ext.include?(tmp_ext.to_sym)
- say "<= Your are using '#{tmp_ext}' and for admin we only support '#{supported_ext.join(', ')}'. Please use -e haml or -e erb or -e slim", :yellow
+ say "<= You are using '#{tmp_ext}' and for admin we only support '#{supported_ext.join(', ')}'. Please use #{supported_ext.map { |ext| '-e ' + ext.to_s }.join(' or ')}", :yellow
raise SystemExit
end
@@ -76,7 +76,8 @@ def create_admin
template "templates/app.rb.tt", destination_root(@admin_path + "/app.rb")
inject_into_file destination_root('config/apps.rb'), "\nPadrino.mount(\"#{@app_name}::#{@admin_name}\", :app_file => Padrino.root('#{@admin_path}/app.rb')).to(\"/#{@admin_path}\")\n", :before => /^Padrino.mount.*\.to\('\/'\)$/
unless options[:destroy]
- insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement', @admin_path if [:minirecord, :activerecord].include?(orm)
+ insert_middleware 'ConnectionPoolManagement', @admin_path if [:minirecord, :activerecord].include?(orm)
+ insert_middleware 'IdentityMap', @admin_path if orm == :datamapper
end
params = [
@@ -134,6 +135,8 @@ def create_admin
require_dependencies('bcrypt')
end
+ require_dependencies 'activesupport', :version => ">= 3.1"
+
# A nicer select box.
# TODO FIXME This doesn't make much sense in here. Review.
# gsub_file destination_root("admin/views/#{@model_plural}/_form.#{ext}"), "f.text_field :role, :class => :text_field", "f.select :role, :options => access_control.roles"
diff --git a/padrino-admin/lib/padrino-admin/generators/templates/account/datamapper.rb.tt b/padrino-admin/lib/padrino-admin/generators/templates/account/datamapper.rb.tt
index e4b18f27b..66a0e1ff5 100644
--- a/padrino-admin/lib/padrino-admin/generators/templates/account/datamapper.rb.tt
+++ b/padrino-admin/lib/padrino-admin/generators/templates/account/datamapper.rb.tt
@@ -44,6 +44,11 @@ class <%= @model_name %>
::BCrypt::Password.new(crypted_password) == password
end
+ def password=(password)
+ self.crypted_password = nil if password.present?
+ @password = password
+ end
+
private
def password_required
diff --git a/padrino-admin/lib/padrino-admin/generators/templates/account/seeds.rb.tt b/padrino-admin/lib/padrino-admin/generators/templates/account/seeds.rb.tt
index 021807872..14948eeba 100644
--- a/padrino-admin/lib/padrino-admin/generators/templates/account/seeds.rb.tt
+++ b/padrino-admin/lib/padrino-admin/generators/templates/account/seeds.rb.tt
@@ -6,21 +6,22 @@
# shell.say name
#
email = shell.ask "Which email do you want use for logging into admin?"
-password = shell.ask "Tell me the password to use:"
+password = shell.ask "Tell me the password to use:", :echo => false
shell.say ""
-account = <%= @model_name %>.create(:email => email, :name => "Foo", :surname => "Bar", :password => password, :password_confirmation => password, :role => "admin")
+account = <%= @model_name %>.new(:email => email, :name => "Foo", :surname => "Bar", :password => password, :password_confirmation => password, :role => "admin")
if account.valid?
+ account.save
shell.say "================================================================="
shell.say "<%= @model_name %> has been successfully created, now you can login with:"
shell.say "================================================================="
shell.say " email: #{email}"
- shell.say " password: #{password}"
+ shell.say " password: #{?* * password.length}"
shell.say "================================================================="
else
- shell.say "Sorry but some thing went wrong!"
+ shell.say "Sorry, but something went wrong!"
shell.say ""
account.errors.full_messages.each { |m| shell.say " - #{m}" }
end
diff --git a/padrino-admin/lib/padrino-admin/generators/templates/app.rb.tt b/padrino-admin/lib/padrino-admin/generators/templates/app.rb.tt
index 79c33c4f0..23cabd307 100644
--- a/padrino-admin/lib/padrino-admin/generators/templates/app.rb.tt
+++ b/padrino-admin/lib/padrino-admin/generators/templates/app.rb.tt
@@ -1,3 +1,6 @@
+require 'active_support/core_ext/object/blank'
+require 'active_support/core_ext/string/inflections'
+
module <%= @app_name %>
class <%= @admin_name %> < Padrino::Application
register Padrino::Mailer
diff --git a/padrino-admin/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt b/padrino-admin/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt
index fd6a8dd20..d1036d1b7 100644
--- a/padrino-admin/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt
+++ b/padrino-admin/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt
@@ -20,7 +20,7 @@
show_exceptions setting")
+ end
end
end
diff --git a/padrino-core/test/test_csrf_protection.rb b/padrino-core/test/test_csrf_protection.rb
index 4b2a8bc5e..05b5c5556 100644
--- a/padrino-core/test/test_csrf_protection.rb
+++ b/padrino-core/test/test_csrf_protection.rb
@@ -6,6 +6,7 @@
describe 'CSRF protection' do
describe "with CSRF protection on" do
before do
+ @token = Rack::Protection::AuthenticityToken.random_token rescue "a_token"
mock_app do
enable :sessions
enable :protect_from_csrf
@@ -19,25 +20,24 @@
end
it 'should allow requests with correct tokens' do
- post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "a"}
+ post "/", {"authenticity_token" => @token}, 'rack.session' => {:csrf => @token}
assert_equal 200, status
end
it 'should not allow requests with incorrect tokens' do
- post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "b"}
+ post "/", {"authenticity_token" => "b"}, 'rack.session' => {:csrf => @token}
assert_equal 403, status
end
it 'should allow requests with correct X-CSRF-TOKEN' do
- post "/", {}, 'rack.session' => {:csrf => "a"}, 'HTTP_X_CSRF_TOKEN' => "a"
+ post "/", {}, 'rack.session' => {:csrf => @token}, 'HTTP_X_CSRF_TOKEN' => @token
assert_equal 200, status
end
it 'should not allow requests with incorrect X-CSRF-TOKEN' do
- post "/", {}, 'rack.session' => {:csrf => "a"}, 'HTTP_X_CSRF_TOKEN' => "b"
+ post "/", {}, 'rack.session' => {:csrf => @token}, 'HTTP_X_CSRF_TOKEN' => "b"
assert_equal 403, status
end
-
end
describe "without CSRF protection on" do
@@ -142,6 +142,7 @@
describe "with custom protection options" do
before do
+ @token = Rack::Protection::AuthenticityToken.random_token rescue "a_token"
mock_app do
enable :sessions
set :protect_from_csrf, :authenticity_param => 'foobar', :message => 'sucker!'
@@ -150,7 +151,7 @@
end
it 'should allow configuring protection options' do
- post "/a", {"foobar" => "a"}, 'rack.session' => {:csrf => "a"}
+ post "/a", {"foobar" => @token}, 'rack.session' => {:csrf => @token}
assert_equal 200, status
end
diff --git a/padrino-core/test/test_dependencies.rb b/padrino-core/test/test_dependencies.rb
index d50790fb9..2937c0aca 100644
--- a/padrino-core/test/test_dependencies.rb
+++ b/padrino-core/test/test_dependencies.rb
@@ -53,5 +53,17 @@
assert_equal ["name"], F.fields
assert_equal "", @io.string
end
+
+ it 'should not silence LoadError raised in dependencies excluded from reloading' do
+ capture_io do
+ assert_raises(LoadError) do
+ Padrino::Reloader.exclude << Padrino.root("fixtures/dependencies/linear/h.rb")
+ Padrino.require_dependencies(
+ Padrino.root("fixtures/dependencies/linear/h.rb"),
+ Padrino.root("fixtures/dependencies/linear/i.rb"),
+ )
+ end
+ end
+ end
end
end
diff --git a/padrino-core/test/test_filters.rb b/padrino-core/test/test_filters.rb
index 6478e4ecf..40f954b7f 100644
--- a/padrino-core/test/test_filters.rb
+++ b/padrino-core/test/test_filters.rb
@@ -300,6 +300,24 @@
assert_equal 'before', test
end
+ it 'should ensure the call of before_filter at the first time' do
+ once = ''
+ mock_app do
+ before do
+ once += 'before'
+ end
+ get :index do
+ raise Exception, 'Oops'
+ end
+ post :index do
+ raise Exception, 'Oops'
+ end
+ end
+
+ post '/'
+ assert_equal 'before', once
+ end
+
it 'should call before filters only once' do
once = ''
mock_app do
@@ -319,7 +337,7 @@
end
it 'should catch exceptions in before filters' do
- doodle = nil
+ doodle = ''
mock_app do
after do
doodle = 'Been after'
@@ -337,7 +355,7 @@
get '/'
assert_equal 'We broke before', body
- assert_equal nil, doodle
+ assert_equal '', doodle
end
it 'should catch exceptions in after filters if no exceptions caught before' do
@@ -369,4 +387,14 @@
assert_equal 'Been now and after', doodle
end
+ it 'should trigger filters if superclass responds to :filters' do
+ class FilterApp < Padrino::Application
+ before { @foo = "foo" }
+ end
+ mock_app FilterApp do
+ get("/") { @foo }
+ end
+ get "/"
+ assert_equal "foo", body
+ end
end
diff --git a/padrino-core/test/test_flash.rb b/padrino-core/test/test_flash.rb
index ab5e06087..5ed3d52e3 100644
--- a/padrino-core/test/test_flash.rb
+++ b/padrino-core/test/test_flash.rb
@@ -45,7 +45,7 @@
it 'should not know the values you set right away' do
@storage[:foo] = 'bar'
- assert_nil @storage[:foo]
+ refute_includes @storage, :foo
end
it 'should knows the values you set next time' do
@@ -62,7 +62,7 @@
it 'should forgets values you set only for now next time' do
@storage.now[:foo] = 'bar'
@storage.sweep
- assert_nil @storage[:foo]
+ refute_includes @storage, :foo
end
end
diff --git a/padrino-core/test/test_locale.rb b/padrino-core/test/test_locale.rb
index 9eb9cebaa..af17ca350 100644
--- a/padrino-core/test/test_locale.rb
+++ b/padrino-core/test/test_locale.rb
@@ -6,16 +6,16 @@
name = File.basename(file, '.yml')
it "should should have correct locale for #{name}" do
base = base_original[name]['date']['formats']
- assert base['default'].present?
- assert base['short'].present?
- assert base['long'].present?
- assert base['only_day'].present?
+ assert base['default']
+ assert base['short']
+ assert base['long']
+ assert base['only_day']
base = base_original[name]['date']
- assert base['day_names'].present?
- assert base['abbr_day_names'].present?
- assert base['month_names'].present?
- assert base['abbr_month_names'].present?
- assert base['order'].present?
+ assert base['day_names']
+ assert base['abbr_day_names']
+ assert base['month_names']
+ assert base['abbr_month_names']
+ assert base['order']
end
end
end
diff --git a/padrino-core/test/test_logger.rb b/padrino-core/test/test_logger.rb
index 42d064406..e1566e25d 100644
--- a/padrino-core/test/test_logger.rb
+++ b/padrino-core/test/test_logger.rb
@@ -1,5 +1,7 @@
+#coding:utf-8
require File.expand_path(File.dirname(__FILE__) + '/helper')
require 'logger'
+require 'tempfile'
describe "PadrinoLogger" do
before do
@@ -36,6 +38,28 @@ def setup_logger(options={})
Padrino::Logger.setup!
assert_equal my_stream, Padrino.logger.log
end
+
+ it 'should use a custom file path' do
+ tempfile = Tempfile.new('app.txt')
+ path = tempfile.path
+ tempfile.unlink
+ Padrino::Logger::Config[:test][:stream] = :to_file
+ Padrino::Logger::Config[:test][:log_path] = path
+ Padrino::Logger.setup!
+ assert_file_exists path
+ File.unlink(path)
+ end
+
+ it 'should use a custom log directory' do
+ tmpdir = Dir.mktmpdir
+ Padrino::Logger::Config[:test][:stream] = :to_file
+ Padrino::Logger::Config[:test][:log_path] = tmpdir
+ Padrino::Logger.setup!
+ log_path = File.join(tmpdir, 'test.log')
+ assert_file_exists log_path
+ File.unlink(log_path)
+ Dir.rmdir(tmpdir)
+ end
end
it 'should log something' do
@@ -58,6 +82,30 @@ def setup_logger(options={})
assert_match /log via alias/, @log.string
end
+ it 'should not blow up on mixed or broken encodings' do
+ setup_logger(:log_level => :error, :auto_flush => false)
+ binary_data = "\xD0".force_encoding('BINARY')
+ utf8_data = 'фыв'
+ @logger.error binary_data
+ @logger.error utf8_data
+ @logger.flush
+ assert @log.string.include?(utf8_data)
+ assert @log.string.force_encoding('BINARY').include?(binary_data)
+ end
+
+ it 'should sanitize mixed or broken encodings if said so' do
+ encoding = 'windows-1251'
+ setup_logger(:log_level => :error, :auto_flush => false, :sanitize_encoding => encoding)
+ @log.string.encode! encoding
+ binary_data = "\xD0".force_encoding('BINARY')
+ utf8_data = 'фыв'
+ @logger.error binary_data
+ @logger.error utf8_data
+ @logger.flush
+ assert @log.string.force_encoding(encoding).include?("?\n".encode(encoding))
+ assert @log.string.force_encoding(encoding).include?(utf8_data.encode(encoding))
+ end
+
it 'should log an application' do
mock_app do
enable :logging
@@ -148,7 +196,9 @@ def add(level, text)
before do
@save_logger = Padrino.logger
@log = StringIO.new
- Padrino.logger = FancyLogger.new(@log)
+ new_logger = FancyLogger.new(@log)
+ new_logger.extend(Padrino::Logger::Extensions)
+ capture_io { Padrino.logger = new_logger }
end
after do
@@ -175,11 +225,34 @@ def add(level, text)
end
end
+describe "binary logger" do
+ before do
+ @save_logger = Padrino.logger
+ @log = StringIO.new
+ new_logger = Logger.new(@log)
+ new_logger.formatter = proc do |_, _, _, message|
+ "#{message.size}"
+ end
+ capture_io { Padrino.logger = new_logger }
+ end
+
+ after do
+ Padrino.logger = @save_logger
+ end
+
+ it 'should not convert parameters to strings before formatting' do
+ logger.info({:a => 2})
+ assert_equal "1", @log.string
+ end
+end
+
describe "alternate logger: stdlib logger" do
before do
@log = StringIO.new
@save_logger = Padrino.logger
- Padrino.logger = Logger.new(@log)
+ new_logger = Logger.new(@log)
+ new_logger.extend(Padrino::Logger::Extensions)
+ capture_io { Padrino.logger = new_logger }
end
after do
@@ -248,3 +321,48 @@ def access_to_mock_app
end
end
end
+
+describe "options :source_location" do
+ before do
+ Padrino::Logger::Config[:test][:source_location] = true
+ Padrino::Logger.setup!
+ end
+
+ def stub_root(base_path = File.expand_path("."), &block)
+ callable = proc{ |*args| File.join(base_path, *args) }
+ Padrino.stub(:root, callable, &block)
+ end
+
+ it 'should output source_location if :source_location is set to true' do
+ stub_root { Padrino.logger.debug("hello world") }
+ assert_match /\[test\/test_logger\.rb:#{__LINE__-1}\] hello world/, Padrino.logger.log.string
+ end
+
+ it 'should output source_location if file path is relative' do
+ stub_message = "test/test_logger.rb:269:in `test'"
+ Padrino::Logger.logger.stub(:caller, [stub_message]){ stub_root { Padrino.logger.debug("hello relative path") }}
+ assert_match /\[test\/test_logger\.rb:269\] hello relative path/, Padrino.logger.log.string
+ end
+
+ it 'should not output source_location if :source_location is set to false' do
+ Padrino::Logger::Config[:test][:source_location] = false
+ Padrino::Logger.setup!
+ stub_root { Padrino.logger.debug("hello world") }
+ assert_match /hello world/, Padrino.logger.log.string
+ refute_match /\[.+?\] hello world/, Padrino.logger.log.string
+ end
+
+ it 'should not output source_location unless file path is not started with Padrino.root' do
+ stub_root("/unknown/path/") { Padrino.logger.debug("hello boy") }
+ assert_match /hello boy/, Padrino.logger.log.string
+ refute_match /\[.+?\] hello boy/, Padrino.logger.log.string
+ end
+
+ it 'should not output source_location if source file path is started with Padrino.root + vendor' do
+ base_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/')
+ stub_message = File.expand_path(File.dirname(__FILE__) + '/fixtures/vendor/logger.rb') + ":291:in `test'"
+ Padrino::Logger.logger.stub(:caller, [stub_message]) { stub_root(base_path) { Padrino.logger.debug("hello vendor") } }
+ assert_match /hello vendor/, Padrino.logger.log.string
+ refute_match /\[.+?\] hello vendor/, Padrino.logger.log.string
+ end
+end
diff --git a/padrino-core/test/test_mounter.rb b/padrino-core/test/test_mounter.rb
index 0efefc08d..c122b9a26 100644
--- a/padrino-core/test/test_mounter.rb
+++ b/padrino-core/test/test_mounter.rb
@@ -181,7 +181,7 @@ class ::TwoApp < Padrino::Application
assert_equal "posts show", first_route.identifier.to_s
assert_equal "(:posts, :show)", first_route.name
assert_equal "GET", first_route.verb
- assert_equal "/posts/show/:id(.:format)", first_route.path
+ assert_equal "/posts/show/:id(.:format)?", first_route.path
another_route = Padrino.mounted_apps[1].named_routes[2]
assert_equal "users create", another_route.identifier.to_s
assert_equal "(:users, :create)", another_route.name
@@ -253,5 +253,61 @@ def spec.full_gem_path
assert_equal AppGem::App, mounter.app_obj
assert_equal Padrino.root('public'), mounter.app_obj.public_folder
end
+
+ it 'should support the Rack Application' do
+ path = File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/mountable_apps/rack_apps')
+ require path
+ Padrino.mount('rack_app', :app_class => 'RackApp', :app_file => path).to('/rack_app')
+ Padrino.mount('rack_app2', :app_class => 'RackApp2', :app_file => path).to('/rack_app2')
+ Padrino.mount('sinatra_app', :app_class => 'SinatraApp', :app_file => path).to('/sinatra_app')
+ app = Padrino.application
+ res = Rack::MockRequest.new(app).get("/rack_app")
+ assert_equal "hello rack app", res.body
+ res = Rack::MockRequest.new(app).get("/rack_app2")
+ assert_equal "hello rack app2", res.body
+ res = Rack::MockRequest.new(app).get("/sinatra_app")
+ assert_equal "hello sinatra app", res.body
+ res = Rack::MockRequest.new(app).get("/sinatra_app/static.html")
+ assert_equal "hello static file\n", res.body
+ assert_equal [], RackApp.prerequisites
+ end
+
+ it 'should support the Rack Application with cascading style' do
+ path = File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/mountable_apps/rack_apps')
+ require path
+ Padrino.mount('rack_app', :app_class => 'RackApp', :app_file => path, cascade: false).to('/rack_app')
+ Padrino.mount('sinatra_app', :app_class => 'SinatraApp', :app_file => path).to('/')
+ app = Padrino.application
+ res = Rack::MockRequest.new(app).get("/rack_app/404")
+ assert_equal "not found ;(", res.body
+ end
+
+ it 'should support the Rack Application inside padrino project' do
+ path = File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/demo_project/app')
+ api_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/demo_project/api/app')
+ require path
+ require api_path
+ Padrino.mount('api_app', :app_class => 'DemoProject::API', :app_file => api_path).to('/api')
+ Padrino.mount('main_app', :app_class => 'DemoProject::App').to('/')
+ app = Padrino.application
+ res = Rack::MockRequest.new(app).get("/")
+ assert_equal "padrino app", res.body
+ res = Rack::MockRequest.new(app).get("/api/hey")
+ assert_equal "api app", res.body
+ assert defined?(DemoProject::APILib)
+ end
+
+ it "should not load dependency files if app's root isn't started with Padrino.root" do
+ path = File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/demo_project/app')
+ fake_path = File.expand_path(File.dirname(__FILE__) + "/fixtures/apps/external_apps/fake_root")
+ require path
+ require fake_path
+ Padrino.mount("fake_root", :app_class => "FakeRoot").to('/fake_root')
+ Padrino.mount('main_app', :app_class => 'DemoProject::App').to('/')
+ Padrino.stub(:root, File.expand_path(File.dirname(__FILE__) + "/fixtures/apps/demo_project")) do
+ Padrino.application
+ end
+ assert !defined?(FakeLib)
+ end
end
end
diff --git a/padrino-core/test/test_params_protection.rb b/padrino-core/test/test_params_protection.rb
index 54f0388af..4055bcfba 100644
--- a/padrino-core/test/test_params_protection.rb
+++ b/padrino-core/test/test_params_protection.rb
@@ -1,5 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/helper')
-require 'active_support/core_ext/hash/conversions'
describe "Padrino::ParamsProtection" do
before do
@@ -7,6 +6,7 @@
@kim = { 'name' => 'Kim Bauer', 'position' => 'daughter', 'child' => @teri }
@jack = { 'name' => 'Jack Bauer', 'position' => 'terrorist', 'child' => @kim }
@family = { 'name' => 'Bauer', 'persons' => { 1 => @teri, 2 => @kim, 3 => @jack } }
+ @jack_query = Padrino::Utils.build_uri_query(@jack)
end
it 'should drop all parameters except allowed ones' do
@@ -17,7 +17,7 @@
''
end
end
- post '/basic?' + @jack.to_query
+ post '/basic?' + @jack_query
assert_equal({ 'name' => @jack['name'] }, result)
end
@@ -29,7 +29,7 @@
''
end
end
- post '/basic?' + @jack.to_query
+ post '/basic?' + @jack_query
assert_equal(@jack, result)
end
@@ -41,7 +41,7 @@
''
end
end
- post '/basic?' + @jack.to_query
+ post '/basic?' + @jack_query
assert_equal(
[
{ 'name' => @jack['name'], 'child' => { 'name' => @kim['name'], 'child' => { 'name' => @teri['name'] } } },
@@ -59,7 +59,7 @@
''
end
end
- post '/basic?' + @jack.to_query
+ post '/basic?' + @jack_query
assert_equal({ 'name' => @jack['name'], 'position' => 'anti-terrorist' }, result)
end
@@ -71,10 +71,22 @@
''
end
end
- post '/basic/24/42?' + @jack.to_query
+ post '/basic/24/42?' + @jack_query
assert_equal({ 'name' => @jack['name'], 'id' => '24', 'tag' => '42' }, result)
end
+ it 'should not fail if :with is not an Array' do
+ result = nil
+ mock_app do
+ post :basic, :with => :id, :params => [ :id ] do
+ result = params
+ ''
+ end
+ end
+ post '/basic/24?' + @jack_query
+ assert_equal({ 'id' => '24' }, result)
+ end
+
it 'should understand true or false values' do
result = nil
mock_app do
@@ -87,9 +99,9 @@
''
end
end
- get '/hide/1?' + @jack.to_query
+ get '/hide/1?' + @jack_query
assert_equal({"id"=>"1"}, result)
- get '/show/1?' + @jack.to_query
+ get '/show/1?' + @jack_query
assert_equal({"id"=>"1"}.merge(@jack), result)
end
@@ -121,13 +133,13 @@
end
end
end
- post '/persons/create?' + @jack.to_query
+ post '/persons/create?' + @jack_query
assert_equal({ 'name' => @jack['name'], 'position' => 'terrorist' }, result)
post '/persons/update/1?name=Chloe+O\'Brian&position=hacker'
assert_equal({ 'id' => '1', 'name' => 'Chloe O\'Brian' }, result)
- post '/persons/delete?' + @jack.to_query
+ post '/persons/delete?' + @jack_query
assert_equal(@jack, result)
- post '/persons/destroy/1?' + @jack.to_query
+ post '/persons/destroy/1?' + @jack_query
assert_equal({"id"=>"1"}, result)
get '/noparam?a=1;b=2'
assert_equal({}, result)
@@ -141,7 +153,7 @@
''
end
end
- post '/family?' + @family.to_query
+ post '/family?' + Padrino::Utils.build_uri_query(@family)
assert_equal({"persons" => {"3" => {"name" => @jack["name"]}, "2" => {"name" => @kim["name"]}, "1" => {"name" => @teri["name"]}}}, result)
end
@@ -153,7 +165,31 @@
''
end
end
- post '/family?names[]=Jack&names[]=Kim&names[]=Teri'
+ post '/family?' + Padrino::Utils.build_uri_query(:names => %w{Jack Kim Teri})
assert_equal({"names" => %w[Jack Kim Teri]}, result)
end
+
+ it 'should tolerate weird inflections' do
+ result = nil
+ mock_app do
+ post :i, :params => [ :gotta => [ :what ] ] do
+ result = params
+ ''
+ end
+ end
+ post '/i?' + Padrino::Utils.build_uri_query(:gotta => { :what => 'go', :who => 'self' })
+ assert_equal({"gotta" => {"what" => "go"}}, result)
+ end
+
+ it 'should drop the key if the data type does not match route configuration' do
+ result = nil
+ mock_app do
+ post :i, :params => [ :gotta => [ :what ] ] do
+ result = params
+ ''
+ end
+ end
+ post '/i?gotta=go'
+ assert_equal({}, result)
+ end
end
diff --git a/padrino-core/test/test_reloader_complex.rb b/padrino-core/test/test_reloader_complex.rb
index 7e4a696b9..ab3faa386 100644
--- a/padrino-core/test/test_reloader_complex.rb
+++ b/padrino-core/test/test_reloader_complex.rb
@@ -43,8 +43,8 @@
new_phrase = "The magick number is: #{rand(2**255)}!"
buffer = File.read(Complex1Demo.app_file)
- new_buffer = buffer.gsub(/The magick number is: \d+!/, new_phrase)
- new_buffer.gsub!(/get\(:destroy\)/, 'get(:destroy, :with => :id)')
+ new_buffer = buffer.sub(/The magick number is: \d+!/, new_phrase)
+ new_buffer.sub!(/get\(:destroy\)/, 'get(:destroy, :with => :id)')
begin
File.open(Complex1Demo.app_file, "w") { |f| f.write(new_buffer) }
Time.stub(:now, Time.now + 2) { get "/complex_2_demo" }
diff --git a/padrino-core/test/test_reloader_external.rb b/padrino-core/test/test_reloader_external.rb
new file mode 100644
index 000000000..b8f376aa7
--- /dev/null
+++ b/padrino-core/test/test_reloader_external.rb
@@ -0,0 +1,21 @@
+require File.expand_path(File.dirname(__FILE__) + '/helper')
+require File.expand_path(File.dirname(__FILE__) + '/fixtures/reloadable_apps/main/app')
+
+describe "ExternalReloader" do
+ describe "for external app" do
+ before do
+ Padrino.clear!
+ Padrino.mount("ReloadableApp::External").to("/reloadable/external")
+ Padrino.mount("ReloadableApp::Main").to("/reloadable")
+ Padrino.load!
+ end
+
+ it "should avoid reloading the file if its path is not started with Padrino.root" do
+ @app = Padrino.application
+ Padrino.stub(:root, File.expand_path(File.dirname(__FILE__) + '/fixtures/reloadable_apps/main')) do
+ get "/reloadable/external/base"
+ end
+ assert_equal "Hello External App", body
+ end
+ end
+end
diff --git a/padrino-core/test/test_reloader_simple.rb b/padrino-core/test/test_reloader_simple.rb
index 51245b5c3..99bbbc01d 100644
--- a/padrino-core/test/test_reloader_simple.rb
+++ b/padrino-core/test/test_reloader_simple.rb
@@ -61,7 +61,7 @@
assert ok?
new_phrase = "The magick number is: #{rand(2**255)}!"
buffer = File.read(SimpleDemo.app_file)
- new_buffer = buffer.gsub(/The magick number is: \d+!/, new_phrase)
+ new_buffer = buffer.sub(/The magick number is: \d+!/, new_phrase)
begin
File.open(SimpleDemo.app_file, "w") { |f| f.write(new_buffer) }
Time.stub(:now, Time.now + 2) { get "/" }
@@ -79,8 +79,8 @@
get "/rand"
assert ok?
last_body = body
- assert_equal 2, @app.filters[:before].size # one is ours the other is default_filter for content type
- assert_equal 1, @app.errors.size
+ assert_equal 1, @app.filters[:before].size
+ assert_equal 0, @app.errors.reject{ |key, _| [404, Sinatra::NotFound].include? key }.size
assert_equal 2, @app.filters[:after].size # app + content-type + padrino-flash
assert_equal 0, @app.middleware.size
assert_equal 4, @app.routes.size # GET+HEAD of "/" + GET+HEAD of "/rand" = 4
@@ -89,8 +89,8 @@
@app.reload!
get "/rand"
refute_equal last_body, body
- assert_equal 2, @app.filters[:before].size # one is ours the other is default_filter for content type
- assert_equal 1, @app.errors.size
+ assert_equal 1, @app.filters[:before].size
+ assert_equal 0, @app.errors.reject{ |key, _| [404, Sinatra::NotFound].include? key }.size
assert_equal 2, @app.filters[:after].size
assert_equal 0, @app.middleware.size
assert_equal 4, @app.routes.size # GET+HEAD of "/" = 2
diff --git a/padrino-support/test/test_support_lite.rb b/padrino-core/test/test_reloader_storage.rb
similarity index 63%
rename from padrino-support/test/test_support_lite.rb
rename to padrino-core/test/test_reloader_storage.rb
index b6fd64823..6908aa41c 100644
--- a/padrino-support/test/test_support_lite.rb
+++ b/padrino-core/test/test_reloader_storage.rb
@@ -1,19 +1,20 @@
require File.expand_path(File.dirname(__FILE__) + '/helper')
-describe "ObjectSpace" do
+describe "Padrino::Reloader::Storage" do
describe "#classes" do
it 'should take an snapshot of the current loaded classes' do
- snapshot = ObjectSpace.classes
+ snapshot = Padrino::Reloader::Storage.send(:object_classes)
assert_equal snapshot.include?(Padrino::Logger), true
end
it 'should return a Set object' do
- snapshot = ObjectSpace.classes
+ snapshot = Padrino::Reloader::Storage.send(:object_classes)
assert_equal snapshot.kind_of?(Set), true
end
it 'should be able to process a the class name given a block' do
- klasses = ObjectSpace.classes do |klass|
+ klasses = Padrino::Reloader::Storage.send(:object_classes) do |klass|
+ next unless klass.respond_to?(:name) # fix JRuby < 1.7.22
if klass.name =~ /^Padrino::/
klass
end
@@ -28,22 +29,23 @@
describe "#new_classes" do
before do
- @snapshot = ObjectSpace.classes
+ @snapshot = Padrino::Reloader::Storage.send(:object_classes)
end
it 'should return list of new classes' do
+ skip
class OSTest; end
module OSTestModule; class B; end; end
- new_classes = ObjectSpace.new_classes(@snapshot)
+ new_classes = Padrino::Reloader::Storage.send(:new_classes, @snapshot)
- assert_equal new_classes.size, 2
+ assert_equal new_classes.size, 3
assert_equal new_classes.include?(OSTest), true
assert_equal new_classes.include?(OSTestModule::B), true
end
it 'should return a Set object' do
- new_classes = ObjectSpace.new_classes(@snapshot)
+ new_classes = Padrino::Reloader::Storage.send(:new_classes, @snapshot)
assert_equal new_classes.kind_of?(Set), true
end
end
diff --git a/padrino-core/test/test_reloader_system.rb b/padrino-core/test/test_reloader_system.rb
index 22b3b7c37..fd86f36ef 100644
--- a/padrino-core/test/test_reloader_system.rb
+++ b/padrino-core/test/test_reloader_system.rb
@@ -2,6 +2,7 @@
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/kiq')
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/system')
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/static')
+require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/custom_dependencies/custom_dependencies')
describe "SystemReloader" do
describe 'for wierd and difficult reload events' do
@@ -46,16 +47,6 @@ def shmamily
end
end
- it 'should tamper with LOAD_PATH' do
- skip
- SystemDemo.load_paths.each do |lib_dir|
- assert_includes $LOAD_PATH, lib_dir
- end
- Padrino.send(:default_load_paths).each do |lib_dir|
- assert_includes $LOAD_PATH, lib_dir
- end
- end
-
it 'should not fail horribly on reload event with non-padrino apps' do
Padrino.mount("kiq").to("/")
Padrino.reload!
@@ -119,5 +110,50 @@ def instance_test
FileUtils.rm tmp_file
end
end
+
+ it 'should not fail with superclass mismatch when reloading descendant classes with no instances' do
+ Padrino.clear!
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/stealthy/app.rb')
+ @app = SystemStealthyClassDemo
+ Padrino.mount(SystemStealthyClassDemo).to("/")
+ get '/'
+ FileUtils.touch File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb')
+ Padrino.reload!
+ end
+ end
+
+ describe 'reloading custom dependencies' do
+ let(:custom_dependency_path) { File.dirname(__FILE__) + '/fixtures/apps/custom_dependencies/my_dependencies' }
+ let(:custom_dependency) { File.join(custom_dependency_path, 'my_dependency.rb') }
+
+ before do
+ @app = CustomDependencies
+ Padrino.clear!
+ Padrino.mount(CustomDependencies).to("/")
+ Padrino.dependency_paths << custom_dependency_path + '/*.rb'
+ Padrino.load!
+ get '/'
+ end
+
+ it 'should discover changed dependencies' do
+ FileUtils.touch(custom_dependency)
+ assert Padrino::Reloader.changed?, 'Change to custom dependency has not been recognised'
+ end
+ end
+
+ describe 'reloading module constants' do
+ it 'should remove constants of misdesigned modules' do
+ skip
+ Padrino.clear!
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/concerned/app.rb')
+ @app = SystemConcernedClassDemo
+ Padrino.mount(SystemConcernedClassDemo).to("/")
+ get '/'
+
+ original_value = BadModule.instance_variable_get(:@happy_global_variable)
+ FileUtils.touch File.dirname(__FILE__) + '/fixtures/apps/concerned/models/mixins/badmodule.rb'
+ Padrino.reload!
+ assert_equal original_value, BadModule.instance_variable_get(:@happy_global_variable)
+ end
end
end
diff --git a/padrino-core/test/test_restful_routing.rb b/padrino-core/test/test_restful_routing.rb
index d47eab3c7..aeb839d52 100644
--- a/padrino-core/test/test_restful_routing.rb
+++ b/padrino-core/test/test_restful_routing.rb
@@ -4,8 +4,8 @@
it 'should perform restul routing' do
mock_app do
controller :parent => :parents do
- get :index do
- "#{url_for(:index, params[:parent_id])} get"
+ get :index, :with => :asset_id do
+ "#{url_for(:index, params[:parent_id], :asset_id => params[:asset_id])} get"
end
put :index, :with => :asset_id do
@@ -21,8 +21,8 @@
end
end
end
- get "/parents/1"
- assert_equal "/parents/1 get", body
+ get "/parents/1/hi"
+ assert_equal "/parents/1/hi get", body
put "/parents/1/hi"
assert_equal "/parents/1/hi put", body
post "/parents/1/hi"
diff --git a/padrino-core/test/test_router.rb b/padrino-core/test/test_router.rb
index d0fee875f..cac3ad932 100644
--- a/padrino-core/test/test_router.rb
+++ b/padrino-core/test/test_router.rb
@@ -94,13 +94,13 @@ def setup
res = Rack::MockRequest.new(map).get("/werewolf")
assert_equal 404, res.status
- assert_equal nil, res["X-API"]
- assert_equal nil, res["X-ScriptName"]
- assert_equal nil, res["X-PathInfo"]
+ refute_includes res, "X-API"
+ refute_includes res, "X-ScriptName"
+ refute_includes res, "X-PathInfo"
res = Rack::MockRequest.new(map).get("/bar/mitzvah")
assert res.ok?
- assert_equal nil, res["X-API"]
+ refute_includes res, "X-API"
assert_equal 'text/plain', res["Content-Type"]
assert_equal "/bar", res["X-ScriptName"]
assert_equal "/mitzvah", res["X-PathInfo"]
@@ -114,7 +114,7 @@ def setup
res = Rack::MockRequest.new(map).get("/bar/scary")
assert_equal 404, res.status
- assert_equal nil, res["X-API"]
+ refute_includes res, "X-API"
assert_equal 'text/plain', res["Content-Type"]
assert_equal "/bar", res["X-ScriptName"]
assert_equal "/scary", res["X-PathInfo"]
diff --git a/padrino-core/test/test_routing.rb b/padrino-core/test/test_routing.rb
index a64cf9469..5aab6e293 100644
--- a/padrino-core/test/test_routing.rb
+++ b/padrino-core/test/test_routing.rb
@@ -3,6 +3,30 @@
class FooError < RuntimeError; end
+class RegexpLookAlike
+ # RegexpLookAlike#to_s, RegexpLookAlike#names and MatchData#names must be defined.
+ class MatchData
+ def captures
+ ["this", "is", "a", "test"]
+ end
+
+ def names
+ ["one", "two", "three", "four"]
+ end
+ end
+
+ def names
+ ["one", "two", "three", "four"]
+ end
+
+ def to_s
+ "/this/is/a/test/"
+ end
+
+ def match(string)
+ ::RegexpLookAlike::MatchData.new if string == "/this/is/a/test/"
+ end
+end
describe "Routing" do
before do
@@ -30,6 +54,22 @@ class FooError < RuntimeError; end
assert_equal headers['Cache-Control'], 'public, must-revalidate, max-age=300'
end # static max_age
+ it 'should render static files with custom status via options' do
+ mock_app do
+ set :static, true
+ set :public_folder, File.dirname(__FILE__)
+
+ post '/*' do
+ static!(:status => params[:status])
+ end
+ end
+
+ post "/#{File.basename(__FILE__)}?status=422"
+ assert_equal response.status, 422
+ assert_equal File.size(__FILE__).to_s, response['Content-Length']
+ assert response.headers.include?('Last-Modified')
+ end
+
it 'should ignore trailing delimiters for basic route' do
mock_app do
get("/foo"){ "okey" }
@@ -45,6 +85,17 @@ class FooError < RuntimeError; end
assert_equal "tester", body
end
+ it 'should recognize route even if paths are duplicated' do
+ mock_app do
+ get(:index) {}
+ get(:index, :with => :id) {}
+ get(:index, :with => :id, :provides => :json) {}
+ end
+ assert_equal "/", @app.url_for(:index)
+ assert_equal "/1234", @app.url_for(:index, :id => "1234")
+ assert_equal "/1234.json?baz=baz", @app.url_for(:index, :id => "1234", :format => "json", :baz => "baz")
+ end
+
it 'should fail with unrecognized route exception when not found' do
mock_app do
get(:index){ "okey" }
@@ -218,6 +269,8 @@ class FooError < RuntimeError; end
get(:hash, :with => :id){ url(:hash, :id => 1) }
get(:anchor) { url(:anchor, :anchor => 'comments') }
get(:fragment) { url(:anchor, :fragment => 'comments') }
+ get(:fragment2) { url(:anchor, :fragment => :comments) }
+ get(:gangsta) { url(:gangsta, :foo => { :bar => :baz }, :hoge => :fuga) }
get([:hash, :id]){ url(:hash, :id => 1) }
get(:array, :with => :id){ url(:array, 23) }
get([:array, :id]){ url(:array, 23) }
@@ -232,6 +285,7 @@ class FooError < RuntimeError; end
post(:foo, '', :with => :id){ |id| "/#{id}" }
delete(:drugs, :with => [:id, 'destroy']){ |id| "/drugs/#{id}/destroy" }
delete(:drugs, '', :with => [:id, 'destroy']){ |id| "/#{id}/destroy" }
+ get(:splatter, "/splatter/*/*"){ |a, b| url(:splatter, :splat => ["123", "456"]) }
end
get "/foo"
assert_equal "/foo", body
@@ -243,6 +297,8 @@ class FooError < RuntimeError; end
assert_equal "/anchor#comments", body
get "/fragment"
assert_equal "/anchor#comments", body
+ get "/fragment2"
+ assert_equal "/anchor#comments", body
get "/array/23"
assert_equal "/array/23", body
get "/hash_with_extra/1"
@@ -263,6 +319,10 @@ class FooError < RuntimeError; end
assert_equal "/drugs/123/destroy", body
delete "/123/destroy"
assert_equal "/123/destroy", body
+ get "/gangsta"
+ assert_equal "/gangsta?foo%5Bbar%5D=baz&hoge=fuga", body
+ get "/splatter/123/456"
+ assert_equal "/splatter/123/456", body
end
it 'should generate url with format' do
@@ -390,6 +450,16 @@ class Test < Padrino::Application
assert_equal 406, status
end
+ it 'should provide proper content when :provides is specified and Accept: `*/*` requested' do
+ mock_app do
+ get(:text, :provides => :text) { "text" }
+ end
+ header 'Accept', '*/*'
+ get "/text"
+ assert_equal 200, status
+ assert_equal "text", body
+ end
+
it 'should return 404 on file extensions it does not provide and flag is not set' do
mock_app do
get(:a, :provides => [:html, :js]){ content_type }
@@ -435,7 +505,6 @@ class Test < Padrino::Application
end
it 'should allow "." in param values' do
- skip # TODO fix this?
mock_app do
get('/id/:email', :provides => [:json]) { |email, format| [email, format] * '/' }
end
@@ -481,7 +550,7 @@ class Test < Padrino::Application
it 'should generate routes for format simple' do
mock_app do
- get(:foo, :provides => [:html, :rss]) { render :haml, "Test" }
+ get(:foo, :provides => [:html, :rss]) { "Test\n" }
end
get "/foo"
assert_equal "Test\n", body
@@ -507,14 +576,14 @@ class Test < Padrino::Application
it 'should inject the action name into the request' do
mock_app do
controller :posts do
- get('/omnomnom(/:id)') { request.action.inspect }
+ get('/omnomnom(/:id)?') { request.action.inspect }
controller :mini do
get([:a, :b, :c]) { request.action.inspect }
end
end
end
get "/posts/omnomnom"
- assert_equal "\"/omnomnom(/:id)\"", body
+ assert_equal "\"/omnomnom(/:id)?\"", body
get "/mini/a/b/c"
assert_equal ":a", body
end
@@ -595,8 +664,8 @@ class Test < Padrino::Application
it 'should generate routes for format with controller' do
mock_app do
controller :posts do
- get(:index, :provides => [:html, :rss, :atom, :js]) { render :haml, "Index.#{content_type}" }
- get(:show, :with => :id, :provides => [:html, :rss, :atom]) { render :haml, "Show.#{content_type}" }
+ get(:index, :provides => [:html, :rss, :atom, :js]) { "Index.#{content_type}\n" }
+ get(:show, :with => :id, :provides => [:html, :rss, :atom]) { "Show.#{content_type}\n" }
end
end
get "/posts"
@@ -711,12 +780,27 @@ class Test < Padrino::Application
assert_equal 'application/json', response["Content-Type"]
get "/a.foo"
assert_equal "foo", body
- assert_equal 'application/foo;charset=utf-8', response["Content-Type"]
+ assert_equal 'application/foo', response["Content-Type"]
get "/a"
assert_equal "html", body
assert_equal 'text/html;charset=utf-8', response["Content-Type"]
end
+ it 'should not drop json charset' do
+ mock_app do
+ get '/' do
+ content_type :json, :charset => 'utf-16'
+ end
+ get '/a' do
+ content_type :json, 'charset' => 'utf-16'
+ end
+ end
+ get '/'
+ assert_equal 'application/json;charset=utf-16', response["Content-Type"]
+ get '/a'
+ assert_equal 'application/json;charset=utf-16', response["Content-Type"]
+ end
+
it 'should use controllers' do
mock_app do
controller "/admin" do
@@ -955,7 +1039,7 @@ class Test < Padrino::Application
it 'should allow optionals' do
mock_app do
- get(:show, :map => "/stories/:type(/:category)") do
+ get(:show, :map => "/stories/:type(/:category)?") do
"#{params[:type]}/#{params[:category]}"
end
end
@@ -1163,6 +1247,17 @@ class Test < Padrino::Application
assert_equal "lang is en", body
end
+ it 'should override default values when parameters are passed' do
+ mock_app do
+ controller lang: :it do
+ get(:index, map: '/:lang') { "lang is #{params[:lang]}" }
+ end
+ end
+ assert_equal '/pt', @app.url(:index, lang: 'pt')
+ get '/pt'
+ assert_equal 'lang is pt', body
+ end
+
it 'should transitions to the next matching route on pass' do
mock_app do
get '/:foo' do
@@ -1503,7 +1598,7 @@ def authorize(username, password)
it 'should works with optionals params' do
mock_app do
- get("/foo(/:bar)") { params[:bar] }
+ get("/foo(/:bar)?") { params[:bar] }
end
get "/foo/bar"
@@ -1651,7 +1746,7 @@ def authorize(username, password)
it 'should use optionals params' do
mock_app do
- get(:index, :map => "/(:foo(/:bar))") { "#{params[:foo]}-#{params[:bar]}" }
+ get(:index, :map => "/:foo(/:bar)?") { "#{params[:foo]}-#{params[:bar]}" }
end
get "/foo"
assert_equal "foo-", body
@@ -1824,8 +1919,6 @@ def authorize(username, password)
end
it 'should reset provides for routes that did not use it' do
- skip
- #FIXME
mock_app do
get('/foo', :provides => :js){}
get('/bar'){}
@@ -2009,7 +2102,7 @@ def authorize(username, password)
mock_app do
get(:index) { "%s %s" % [params[:account][:name], params[:account][:surname]] }
end
- get "/?account[name]=foo&account[surname]=bar"
+ get "/?" + Padrino::Utils.build_uri_query(:account => { :name => 'foo', :surname => 'bar' })
assert_equal 'foo bar', body
get @app.url(:index, "account[name]" => "foo", "account[surname]" => "bar")
assert_equal 'foo bar', body
@@ -2067,14 +2160,14 @@ def authorize(username, password)
get(:simple, :map => "/simple/:id") { }
get(:with_format, :with => :id, :provides => :js) { }
end
- assert_equal [:"foo bar", { :id => "fantastic" }], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic))
- assert_equal [:"foo bar", { :id => "18" }], @app.recognize_path(@app.url(:foo, :bar, :id => 18))
- assert_equal [:simple, { :id => "bar" }], @app.recognize_path(@app.url(:simple, :id => "bar"))
- assert_equal [:simple, { :id => "true" }], @app.recognize_path(@app.url(:simple, :id => true))
- assert_equal [:simple, { :id => "9" }], @app.recognize_path(@app.url(:simple, :id => 9))
- assert_equal [:with_format, { :id => "bar", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => "bar", :format => :js))
- assert_equal [:with_format, { :id => "true", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => true, :format => "js"))
- assert_equal [:with_format, { :id => "9", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => 9, :format => :js))
+ assert_equal [:"foo bar", { "id" => "fantastic" }], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic))
+ assert_equal [:"foo bar", { "id" => "18" }], @app.recognize_path(@app.url(:foo, :bar, :id => 18))
+ assert_equal [:simple, { "id" => "bar" }], @app.recognize_path(@app.url(:simple, :id => "bar"))
+ assert_equal [:simple, { "id" => "true" }], @app.recognize_path(@app.url(:simple, :id => true))
+ assert_equal [:simple, { "id" => "9" }], @app.recognize_path(@app.url(:simple, :id => 9))
+ assert_equal [:with_format, { "id" => "bar", "format" => "js" }], @app.recognize_path(@app.url(:with_format, :id => "bar", :format => :js))
+ assert_equal [:with_format, { "id" => "true", "format" => "js" }], @app.recognize_path(@app.url(:with_format, :id => true, :format => "js"))
+ assert_equal [:with_format, { "id" => "9", "format" => "js" }], @app.recognize_path(@app.url(:with_format, :id => 9, :format => :js))
end
it 'should have current_path' do
@@ -2124,4 +2217,219 @@ def authorize(username, password)
get '/users//'
assert_equal 404, status
end
+
+ it "should support splat params" do
+ mock_app do
+ get "/say/*/to/*" do
+ params[:splat].inspect
+ end
+ end
+ get "/say/hello/to/world"
+ assert_equal %Q[["hello", "world"]], body
+ end
+
+ it "should recognize the route containing splat params if path is ended with slash" do
+ mock_app do
+ get "/splat/*" do
+ "slash!"
+ end
+ end
+ get "/splat"
+ assert_equal 404, status
+ get "/splat/"
+ assert_equal "slash!", body
+ end
+
+ it "should match correctly paths even if the free regex route exists" do
+ mock_app do
+ get %r{/b/(?
#
- # tag :img, :src => 'sinatra.jpg, :data => { :nsfw => false, :geo => [34.087, -118.407] }
+ # tag :img, :src => 'sinatra.jpg', :data => { :nsfw => false, :geo => [34.087, -118.407] }
# # =>
#
def tag(name, options = nil, open = false)
@@ -235,6 +235,19 @@ def tag(name, options = nil, open = false)
"<#{name}#{attributes}#{open ? '>' : ' />'}".html_safe
end
+ ##
+ # Returns an escaped document link.
+ #
+ # @example
+ # escape_link('http://example.com/spaced link')
+ # # => 'http://example.com/spaced%20link'
+ # escape_link('already%20partially escaped')
+ # # => 'already%20partially%20escaped'
+ #
+ def escape_link(link)
+ link.gsub(' ', '%20')
+ end
+
private
##
@@ -259,7 +272,8 @@ def tag_attributes(options)
# Escape tag values to their HTML/XML entities.
#
def escape_value(string)
- string.to_s.gsub(ESCAPE_REGEXP) { |char| ESCAPE_VALUES[char] }
+ string = string.collect(&:to_s).join(' ') if string.is_a?(Array)
+ string.to_s.gsub(ESCAPE_REGEXP, ESCAPE_VALUES)
end
##
@@ -267,7 +281,7 @@ def escape_value(string)
#
def nested_values(attribute, hash)
hash.inject('') do |all,(key,value)|
- attribute_with_name = "#{attribute}-#{key.to_s.dasherize}"
+ attribute_with_name = "#{attribute}-#{key.to_s.tr('_', '-')}"
all << if value.is_a?(Hash)
nested_values(attribute_with_name, value)
else
diff --git a/padrino-helpers/lib/padrino/core_ext/output_safety.rb b/padrino-helpers/lib/padrino/core_ext/output_safety.rb
new file mode 100644
index 000000000..37a11274a
--- /dev/null
+++ b/padrino-helpers/lib/padrino/core_ext/output_safety.rb
@@ -0,0 +1,25 @@
+if defined?(ActiveSupport::SafeBuffer)
+ SafeBuffer = ActiveSupport::SafeBuffer
+else
+ require 'padrino/safe_buffer'
+
+ SafeBuffer = Padrino::SafeBuffer
+
+ class String
+ def html_safe
+ SafeBuffer.new(self)
+ end
+ end
+
+ class Object
+ def html_safe?
+ false
+ end
+ end
+
+ class Numeric
+ def html_safe?
+ true
+ end
+ end
+end
diff --git a/padrino-helpers/lib/padrino/rendering.rb b/padrino-helpers/lib/padrino/rendering.rb
index ccf505d2b..37fe1676a 100644
--- a/padrino-helpers/lib/padrino/rendering.rb
+++ b/padrino-helpers/lib/padrino/rendering.rb
@@ -1,3 +1,4 @@
+require 'padrino/core_ext/output_safety'
require 'padrino-support'
require 'pathname'
@@ -34,6 +35,11 @@ class TemplateNotFound < RuntimeError
/~$/ # This is for Gedit
] unless defined?(IGNORE_FILE_PATTERN)
+ ##
+ # Defines common content-type alias mappings.
+ #
+ CONTENT_TYPE_ALIASES = { :htm => :html }
+
##
# Default options used in the resolve_template-method.
#
@@ -93,30 +99,6 @@ def layout(name=:layout, &block)
@layout = name
end
- ##
- # Returns the cached template file to render for a given url,
- # content_type and locale. Deprecated since 0.12.1
- #
- # @param [Array+ <%= f.label :datetime %> + <%= f.datetime_field :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0) %> +
++ <%= f.label :datetime_local %> + <%= f.datetime_local_field :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0) %> +
++ <%= f.label :date %> + <%= f.date_field :date, :max => DateTime.new(2000, 4, 1) %> +
++ <%= f.label :month %> + <%= f.month_field :month, :max => DateTime.new(2000, 4, 1) %> +
++ <%= f.label :week %> + <%= f.week_field :week, :max => DateTime.new(2000, 4, 1) %> +
++ <%= f.label :time %> + <%= f.time_field :time, :max => Time.new(2008, 6, 21, 13, 30, 0) %> +
++ <%= f.label :color %> + <%= f.color_field :color, :value => "#f00" %> +
<%= f.submit "Create", :class => 'success', :id => 'demo-button' %>
<%= f.image_submit "buttons/post.png", :class => 'success', :id => 'image-button' %>
<% end %> diff --git a/padrino-helpers/test/fixtures/markup_app/views/form_for.haml b/padrino-helpers/test/fixtures/markup_app/views/form_for.haml index 59e9573c6..82cd2ac11 100644 --- a/padrino-helpers/test/fixtures/markup_app/views/form_for.haml +++ b/padrino-helpers/test/fixtures/markup_app/views/form_for.haml @@ -38,6 +38,28 @@ %p = f.label :remember_me = f.check_box :remember_me, :value => "1" + %p + = f.label :datetime + = f.datetime_field :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0) + %p + = f.label :datetime_local + = f.datetime_local_field :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0) + %p + = f.label :date + = f.date_field :date, :max => DateTime.new(2000, 4, 1) + %p + = f.label :month + = f.month_field :month, :max => DateTime.new(2000, 4, 1) + %p + = f.label :week + = f.week_field :week, :max => DateTime.new(2000, 4, 1) + %p + = f.label :time + = f.time_field :time, :max => Time.new(2008, 6, 21, 13, 30, 0) + %p + = f.label :color + = f.color_field :color, :value => "#f00" + %p = f.submit "Create", :class => 'success', :id => 'demo-button' %p diff --git a/padrino-helpers/test/fixtures/markup_app/views/form_for.slim b/padrino-helpers/test/fixtures/markup_app/views/form_for.slim index cf0ad875e..5ce973514 100644 --- a/padrino-helpers/test/fixtures/markup_app/views/form_for.slim +++ b/padrino-helpers/test/fixtures/markup_app/views/form_for.slim @@ -38,6 +38,27 @@ p = f.label :remember_me = f.check_box :remember_me, :value => "1" + p + = f.label :datetime + = f.datetime_field :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0) + p + = f.label :datetime_local + = f.datetime_local_field :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0) + p + = f.label :date + = f.date_field :date, :max => DateTime.new(2000, 4, 1) + p + = f.label :month + = f.month_field :month, :max => DateTime.new(2000, 4, 1) + p + = f.label :week + = f.week_field :week, :max => DateTime.new(2000, 4, 1) + p + = f.label :time + = f.time_field :time, :max => Time.new(2008, 6, 21, 13, 30, 0) + p + = f.label :color + = f.color_field :color, :value => "#f00" p = f.submit "Create", :class => 'success', :id => 'demo-button' p diff --git a/padrino-helpers/test/fixtures/markup_app/views/form_tag.erb b/padrino-helpers/test/fixtures/markup_app/views/form_tag.erb index 9475f707d..a7f6f7f32 100644 --- a/padrino-helpers/test/fixtures/markup_app/views/form_tag.erb +++ b/padrino-helpers/test/fixtures/markup_app/views/form_tag.erb @@ -83,6 +83,27 @@ <%= range_field_tag('ranger_with_min_max', :min => 1, :max => 50) %> <%= range_field_tag('ranger_with_range', :range => 1..5) %> ++ <%= datetime_field_tag :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0) %> +
++ <%= datetime_local_field_tag :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0) %> +
++ <%= date_field_tag :date, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) %> +
++ <%= month_field_tag :month, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) %> +
++ <%= week_field_tag :week, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) %> +
++ <%= time_field_tag :time, :max => Time.new(2008, 6, 21, 13, 30, 0), :min => Time.new(1993, 2, 24, 1, 19, 12), :value => Time.new(2008, 6, 21, 13, 30, 0) %> +
++ <%= color_field_tag :color, :value => "#f00" %> +
<% end %> <% field_set_tag(:class => 'buttons') do %> <%= submit_tag "Login" %> diff --git a/padrino-helpers/test/fixtures/markup_app/views/form_tag.haml b/padrino-helpers/test/fixtures/markup_app/views/form_tag.haml index b39a31318..892dba1ff 100644 --- a/padrino-helpers/test/fixtures/markup_app/views/form_tag.haml +++ b/padrino-helpers/test/fixtures/markup_app/views/form_tag.haml @@ -69,6 +69,20 @@ %p = range_field_tag('ranger_with_min_max', :min => 1, :max => 50) = range_field_tag('ranger_with_range', :range => 1..5) + %p + = datetime_field_tag :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0) + %p + = datetime_local_field_tag :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0) + %p + = date_field_tag :date, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) + %p + = month_field_tag :month, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) + %p + = week_field_tag :week, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) + %p + = time_field_tag :time, :max => Time.new(2008, 6, 21, 13, 30, 0), :min => Time.new(1993, 2, 24, 1, 19, 12), :value => Time.new(2008, 6, 21, 13, 30, 0) + %p + = color_field_tag :color, :value => "#f00" = field_set_tag(:class => 'buttons') do = submit_tag "Login" = button_tag "Cancel" diff --git a/padrino-helpers/test/fixtures/markup_app/views/form_tag.slim b/padrino-helpers/test/fixtures/markup_app/views/form_tag.slim index ee651cb5e..3db357a7a 100644 --- a/padrino-helpers/test/fixtures/markup_app/views/form_tag.slim +++ b/padrino-helpers/test/fixtures/markup_app/views/form_tag.slim @@ -69,6 +69,20 @@ p = range_field_tag('ranger_with_min_max', :min => 1, :max => 50) = range_field_tag('ranger_with_range', :range => 1..5) + p + = datetime_field_tag :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0) + p + = datetime_local_field_tag :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0) + p + = date_field_tag :date, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) + p + = month_field_tag :month, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) + p + = week_field_tag :week, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) + p + = time_field_tag :time, :max => Time.new(2008, 6, 21, 13, 30, 0), :min => Time.new(1993, 2, 24, 1, 19, 12), :value => Time.new(2008, 6, 21, 13, 30, 0) + p + = color_field_tag :color, :value => "#f00" = field_set_tag(:class => 'buttons') do = submit_tag "Login" diff --git a/padrino-helpers/test/fixtures/render_app/app.rb b/padrino-helpers/test/fixtures/render_app/app.rb index 6fa566e44..0b71f3eee 100644 --- a/padrino-helpers/test/fixtures/render_app/app.rb +++ b/padrino-helpers/test/fixtures/render_app/app.rb @@ -91,4 +91,24 @@ class RenderDemo < Padrino::Application content_tag :div, 'go block!' end end + + helpers do + def dive_helper(ext) + # @current_engine, save = nil, @current_engine + form_result = form_tag '/' do + render "dive_inner_#{ext}" + end + # @current_engine = save + content_tag('div', form_result, :class => 'wrapper') + end + end + + get '/double_dive_:ext' do + @ext = params[:ext] + render "dive_outer_#{@ext}" + end + + get '/' do + render 'index' + end end diff --git a/padrino-helpers/test/fixtures/render_app/views/_foo.haml b/padrino-helpers/test/fixtures/render_app/views/_foo.haml new file mode 100644 index 000000000..257cc5642 --- /dev/null +++ b/padrino-helpers/test/fixtures/render_app/views/_foo.haml @@ -0,0 +1 @@ +foo diff --git a/padrino-helpers/test/fixtures/render_app/views/dive_inner_erb.erb b/padrino-helpers/test/fixtures/render_app/views/dive_inner_erb.erb new file mode 100644 index 000000000..17a472a17 --- /dev/null +++ b/padrino-helpers/test/fixtures/render_app/views/dive_inner_erb.erb @@ -0,0 +1,3 @@ +
'
+ assert_equal image_tag('/absolute/pic.gif'), '
'
end
end
@@ -237,7 +247,7 @@ def flash
time = stop_time_for_test
actual_html = stylesheet_link_tag('style')
expected_options = { :rel => "stylesheet", :type => "text/css" }
- assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}")) { actual_html }
+ assert_html_has_tag(actual_html, 'link', expected_options.merge(:href => "/stylesheets/style.css?#{time.to_i}"))
assert actual_html.html_safe?
end
@@ -245,14 +255,14 @@ def flash
time = stop_time_for_test
expected_options = { :rel => "stylesheet", :type => "text/css" }
actual_html = stylesheet_link_tag('example/demo/style')
- assert_has_tag('link', expected_options.merge(:href => "/stylesheets/example/demo/style.css?#{time.to_i}")) { actual_html }
+ assert_html_has_tag(actual_html, 'link', expected_options.merge(:href => "/stylesheets/example/demo/style.css?#{time.to_i}"))
end
it 'should display stylesheet link item with absolute path' do
time = stop_time_for_test
expected_options = { :rel => "stylesheet", :type => "text/css" }
actual_html = stylesheet_link_tag('/css/style')
- assert_has_tag('link', expected_options.merge(:href => "/css/style.css")) { actual_html }
+ assert_html_has_tag(actual_html, 'link', expected_options.merge(:href => "/css/style.css"))
end
it 'should display stylesheet link item with uri root' do
@@ -260,27 +270,27 @@ def flash
time = stop_time_for_test
expected_options = { :rel => "stylesheet", :type => "text/css" }
actual_html = stylesheet_link_tag('style')
- assert_has_tag('link', expected_options.merge(:href => "/blog/stylesheets/style.css?#{time.to_i}")) { actual_html }
+ assert_html_has_tag(actual_html, 'link', expected_options.merge(:href => "/blog/stylesheets/style.css?#{time.to_i}"))
end
it 'should display stylesheet link items' do
time = stop_time_for_test
actual_html = stylesheet_link_tag('style', 'layout.css', 'http://google.com/style.css')
- assert_has_tag('link', :rel => "stylesheet", :type => "text/css", :count => 3) { actual_html }
- assert_has_tag('link', :href => "/stylesheets/style.css?#{time.to_i}") { actual_html }
- assert_has_tag('link', :href => "/stylesheets/layout.css?#{time.to_i}") { actual_html }
- assert_has_tag('link', :href => "http://google.com/style.css") { actual_html }
+ assert_html_has_tag(actual_html, 'link', :rel => "stylesheet", :type => "text/css", :count => 3)
+ assert_html_has_tag(actual_html, 'link', :href => "/stylesheets/style.css?#{time.to_i}")
+ assert_html_has_tag(actual_html, 'link', :href => "/stylesheets/layout.css?#{time.to_i}")
+ assert_html_has_tag(actual_html, 'link', :href => "http://google.com/style.css")
assert_equal actual_html, stylesheet_link_tag(['style', 'layout.css', 'http://google.com/style.css'])
end
it 'should not use a timestamp if stamp setting is false' do
self.class.expects(:asset_stamp).returns(false)
expected_options = { :rel => "stylesheet", :type => "text/css" }
- assert_has_tag('link', expected_options.merge(:href => "/stylesheets/style.css")) { stylesheet_link_tag('style') }
+ assert_html_has_tag(stylesheet_link_tag('style'), 'link', expected_options.merge(:href => "/stylesheets/style.css"))
end
it 'should display stylesheet link used custom options' do
- assert_has_tag('link', :rel => 'stylesheet', :media => 'screen') { stylesheet_link_tag('style', :media => 'screen') }
+ assert_html_has_tag(stylesheet_link_tag('style', :media => 'screen'), 'link', :rel => 'stylesheet', :media => 'screen')
end
end
@@ -288,7 +298,7 @@ def flash
it 'should display javascript item' do
time = stop_time_for_test
actual_html = javascript_include_tag('application')
- assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
+ assert_html_has_tag(actual_html, 'script', :src => "/javascripts/application.js?#{time.to_i}", :type => "text/javascript")
assert actual_html.html_safe?
end
@@ -297,60 +307,58 @@ def flash
self.class.stubs(:js_asset_folder).returns('js')
assert_equal 'js', asset_folder_name(:js)
actual_html = javascript_include_tag('application')
- assert_has_tag('script', :src => "/js/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
+ assert_html_has_tag(actual_html, 'script', :src => "/js/application.js?#{time.to_i}", :type => "text/javascript")
end
it 'should display javascript item for long relative path' do
time = stop_time_for_test
actual_html = javascript_include_tag('example/demo/application')
- assert_has_tag('script', :src => "/javascripts/example/demo/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
+ assert_html_has_tag(actual_html, 'script', :src => "/javascripts/example/demo/application.js?#{time.to_i}", :type => "text/javascript")
end
it 'should display javascript item for path containing js' do
time = stop_time_for_test
actual_html = javascript_include_tag 'test/jquery.json'
- assert_has_tag('script', :src => "/javascripts/test/jquery.json?#{time.to_i}", :type => "text/javascript") { actual_html }
+ assert_html_has_tag(actual_html, 'script', :src => "/javascripts/test/jquery.json?#{time.to_i}", :type => "text/javascript")
end
it 'should display javascript item for path containing period' do
time = stop_time_for_test
actual_html = javascript_include_tag 'test/jquery.min'
- assert_has_tag('script', :src => "/javascripts/test/jquery.min.js?#{time.to_i}", :type => "text/javascript") { actual_html }
+ assert_html_has_tag(actual_html, 'script', :src => "/javascripts/test/jquery.min.js?#{time.to_i}", :type => "text/javascript")
end
it 'should display javascript item with absolute path' do
- time = stop_time_for_test
actual_html = javascript_include_tag('/js/application')
- assert_has_tag('script', :src => "/js/application.js", :type => "text/javascript") { actual_html }
+ assert_html_has_tag(actual_html, 'script', :src => "/js/application.js", :type => "text/javascript")
end
it 'should display javascript item with uri root' do
self.class.stubs(:uri_root).returns("/blog")
time = stop_time_for_test
actual_html = javascript_include_tag('application')
- assert_has_tag('script', :src => "/blog/javascripts/application.js?#{time.to_i}", :type => "text/javascript") { actual_html }
+ assert_html_has_tag(actual_html, 'script', :src => "/blog/javascripts/application.js?#{time.to_i}", :type => "text/javascript")
end
it 'should not append extension to absolute paths' do
- time = stop_time_for_test
actual_html = javascript_include_tag('https://maps.googleapis.com/maps/api/js?key=value&sensor=false')
- assert_has_tag('script', :src => "https://maps.googleapis.com/maps/api/js?key=value&sensor=false") { actual_html }
+ assert_html_has_tag(actual_html, 'script', :src => "https://maps.googleapis.com/maps/api/js?key=value&sensor=false")
end
it 'should display javascript items' do
time = stop_time_for_test
actual_html = javascript_include_tag('application', 'base.js', 'http://google.com/lib.js')
- assert_has_tag('script', :type => "text/javascript", :count => 3) { actual_html }
- assert_has_tag('script', :src => "/javascripts/application.js?#{time.to_i}") { actual_html }
- assert_has_tag('script', :src => "/javascripts/base.js?#{time.to_i}") { actual_html }
- assert_has_tag('script', :src => "http://google.com/lib.js") { actual_html }
+ assert_html_has_tag(actual_html, 'script', :type => "text/javascript", :count => 3)
+ assert_html_has_tag(actual_html, 'script', :src => "/javascripts/application.js?#{time.to_i}")
+ assert_html_has_tag(actual_html, 'script', :src => "/javascripts/base.js?#{time.to_i}")
+ assert_html_has_tag(actual_html, 'script', :src => "http://google.com/lib.js")
assert_equal actual_html, javascript_include_tag(['application', 'base.js', 'http://google.com/lib.js'])
end
it 'should not use a timestamp if stamp setting is false' do
self.class.expects(:asset_stamp).returns(false)
actual_html = javascript_include_tag('application')
- assert_has_tag('script', :src => "/javascripts/application.js", :type => "text/javascript") { actual_html }
+ assert_html_has_tag(actual_html, 'script', :src => "/javascripts/application.js", :type => "text/javascript")
end
end
@@ -358,33 +366,33 @@ def flash
it 'should display favicon' do
time = stop_time_for_test
actual_html = favicon_tag('icons/favicon.png')
- assert_has_tag('link', :rel => 'icon', :type => 'image/png', :href => "/images/icons/favicon.png?#{time.to_i}") { actual_html }
+ assert_html_has_tag(actual_html, 'link', :rel => 'icon', :type => 'image/png', :href => "/images/icons/favicon.png?#{time.to_i}")
end
it 'should match type with file ext' do
time = stop_time_for_test
actual_html = favicon_tag('favicon.ico')
- assert_has_tag('link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.ico?#{time.to_i}") { actual_html }
+ assert_html_has_tag(actual_html, 'link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.ico?#{time.to_i}")
end
it 'should allow option overrides' do
time = stop_time_for_test
actual_html = favicon_tag('favicon.png', :type => 'image/ico')
- assert_has_tag('link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.png?#{time.to_i}") { actual_html }
+ assert_html_has_tag(actual_html, 'link', :rel => 'icon', :type => 'image/ico', :href => "/images/favicon.png?#{time.to_i}")
end
end
describe 'for #feed_tag method' do
it 'should generate correctly link tag for rss' do
- assert_has_tag('link', :type => 'application/rss+xml', :rel => 'alternate', :href => "/blog/post.rss", :title => 'rss') { feed_tag :rss, "/blog/post.rss" }
+ assert_html_has_tag(feed_tag(:rss, "/blog/post.rss"), 'link', :type => 'application/rss+xml', :rel => 'alternate', :href => "/blog/post.rss", :title => 'rss')
end
it 'should generate correctly link tag for atom' do
- assert_has_tag('link', :type => 'application/atom+xml', :rel => 'alternate', :href => "/blog/post.atom", :title => 'atom') { feed_tag :atom, "/blog/post.atom" }
+ assert_html_has_tag(feed_tag(:atom, "/blog/post.atom"), 'link', :type => 'application/atom+xml', :rel => 'alternate', :href => "/blog/post.atom", :title => 'atom')
end
it 'should override options' do
- assert_has_tag('link', :type => 'my-type', :rel => 'my-rel', :href => "/blog/post.rss", :title => 'my-title') { feed_tag :rss, "/blog/post.rss", :type => "my-type", :rel => "my-rel", :title => "my-title" }
+ assert_html_has_tag(feed_tag(:rss, "/blog/post.rss", :type => "my-type", :rel => "my-rel", :title => "my-title"), 'link', :type => 'my-type', :rel => 'my-rel', :href => "/blog/post.rss", :title => 'my-title')
end
end
diff --git a/padrino-helpers/test/test_form_builder.rb b/padrino-helpers/test/test_form_builder.rb
index cdb4209eb..c990c3e33 100644
--- a/padrino-helpers/test/test_form_builder.rb
+++ b/padrino-helpers/test/test_form_builder.rb
@@ -31,33 +31,33 @@ def standard_builder(object=@user)
describe 'for #form_for method' do
it 'should display correct form html' do
actual_html = form_for(@user, '/register', :id => 'register', :"accept-charset" => "UTF-8", :method => 'post') { "Demo" }
- assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :id => 'register', :method => 'post', :content => "Demo") { actual_html }
- assert_has_tag('form input[type=hidden]', :name => '_method', :count => 0) { actual_html } # no method action field
+ assert_html_has_tag(actual_html, 'form', :"accept-charset" => "UTF-8", :action => '/register', :id => 'register', :method => 'post', :content => "Demo")
+ assert_html_has_tag(actual_html, 'form input[type=hidden]', :name => '_method', :count => 0) # no method action field
end
it 'should display correct form html with fake object' do
actual_html = form_for(:markup_user, '/register', :id => 'register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.text_field :username }
- assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :id => 'register', :method => 'post') { actual_html }
- assert_has_tag('form input', :type => 'text', :name => 'markup_user[username]') { actual_html }
- assert_has_tag('form input[type=hidden]', :name => '_method', :count => 0) { actual_html } # no method action field
+ assert_html_has_tag(actual_html, 'form', :"accept-charset" => "UTF-8", :action => '/register', :id => 'register', :method => 'post')
+ assert_html_has_tag(actual_html, 'form input', :type => 'text', :name => 'markup_user[username]')
+ assert_html_has_tag(actual_html, 'form input[type=hidden]', :name => '_method', :count => 0) # no method action field
end
it 'should display correct form html for namespaced object' do
actual_html = form_for(Outer::UserAccount.new, '/register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.text_field :username }
- assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :method => 'post') { actual_html }
- assert_has_tag('form input', :type => 'text', :name => 'outer_user_account[username]') { actual_html }
+ assert_html_has_tag(actual_html, 'form', :"accept-charset" => "UTF-8", :action => '/register', :method => 'post')
+ assert_html_has_tag(actual_html, 'form input', :type => 'text', :name => 'outer_user_account[username]')
end
it 'should display form specifying default builder setting' do
self.expects(:settings).returns(stub(:default_builder => 'FakeFormBuilder', :protect_from_csrf => false)).at_least_once
actual_html = form_for(@user, '/register', :id => 'register', :"accept-charset" => "UTF-8", :method => 'post') { |f| f.foo_field }
- assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :method => 'post') { actual_html }
- assert_has_tag('span', :content => "bar") { actual_html }
+ assert_html_has_tag(actual_html, 'form', :"accept-charset" => "UTF-8", :action => '/register', :method => 'post')
+ assert_html_has_tag(actual_html, 'span', :content => "bar")
end
it 'should display correct form html with remote option' do
actual_html = form_for(@user, '/update', :"accept-charset" => "UTF-8", :remote => true) { "Demo" }
- assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/update', :method => 'post', "data-remote" => 'true') { actual_html }
+ assert_html_has_tag(actual_html, 'form', :"accept-charset" => "UTF-8", :action => '/update', :method => 'post', "data-remote" => 'true')
end
it 'should display correct form html with namespace option' do
@@ -65,9 +65,9 @@ def standard_builder(object=@user)
f.text_field(:first_name) << f.fields_for(:role_types) { |role| role.text_field(:name) }
end
- assert_has_no_tag(:form, :namespace => 'foo') { actual_html }
- assert_has_tag(:input, :type => 'text', :name => 'user[first_name]', :id => 'foo_user_first_name') { actual_html }
- assert_has_tag(:input, :type => 'text', :name => 'user[role_types_attributes][0][name]', :id => 'foo_user_role_types_attributes_0_name') { actual_html }
+ assert_html_has_no_tag(actual_html, :form, :namespace => 'foo')
+ assert_html_has_tag(actual_html, :input, :type => 'text', :name => 'user[first_name]', :id => 'foo_user_first_name')
+ assert_html_has_tag(actual_html, :input, :type => 'text', :name => 'user[role_types_attributes][0][name]', :id => 'foo_user_role_types_attributes_0_name')
end
it 'should display correct form html with :as option' do
@@ -75,32 +75,32 @@ def standard_builder(object=@user)
f.text_field(:first_name) << f.fields_for(:role_types) { |role| role.text_field(:name) }
end
- assert_has_no_tag(:form, :as => 'customer') { actual_html }
- assert_has_tag(:input, :type => 'text', :name => 'customer[first_name]', :id => 'customer_first_name') { actual_html }
- assert_has_tag(:input, :type => 'text', :name => 'customer[role_types_attributes][0][name]', :id => 'customer_role_types_attributes_0_name') { actual_html }
+ assert_html_has_no_tag(actual_html, :form, :as => 'customer')
+ assert_html_has_tag(actual_html, :input, :type => 'text', :name => 'customer[first_name]', :id => 'customer_first_name')
+ assert_html_has_tag(actual_html, :input, :type => 'text', :name => 'customer[role_types_attributes][0][name]', :id => 'customer_role_types_attributes_0_name')
end
it 'should display correct form html with remote option and method put' do
actual_html = form_for(@user, '/update', :"accept-charset" => "UTF-8", :remote => true, :method => 'put') { "Demo" }
- assert_has_tag('form', :"accept-charset" => "UTF-8", :method => 'post', "data-remote" => 'true') { actual_html }
- assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
+ assert_html_has_tag(actual_html, 'form', :"accept-charset" => "UTF-8", :method => 'post', "data-remote" => 'true')
+ assert_html_has_tag(actual_html, 'form input', :type => 'hidden', :name => "_method", :value => 'put')
end
it 'should display correct form html with method :put' do
actual_html = form_for(@user, '/update', :"accept-charset" => "UTF-8", :method => 'put') { "Demo" }
- assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/update', :method => 'post') { actual_html }
- assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
+ assert_html_has_tag(actual_html, 'form', :"accept-charset" => "UTF-8", :action => '/update', :method => 'post')
+ assert_html_has_tag(actual_html, 'form input', :type => 'hidden', :name => "_method", :value => 'put')
end
it 'should display correct form html with method :delete' do
actual_html = form_for(@user, '/destroy', :"accept-charset" => "UTF-8", :method => 'delete') { "Demo" }
- assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/destroy', :method => 'post') { actual_html }
- assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'delete') { actual_html }
+ assert_html_has_tag(actual_html, 'form', :"accept-charset" => "UTF-8", :action => '/destroy', :method => 'post')
+ assert_html_has_tag(actual_html, 'form input', :type => 'hidden', :name => "_method", :value => 'delete')
end
it 'should display correct form html with multipart' do
actual_html = form_for(@user, '/register', :"accept-charset" => "UTF-8", :multipart => true) { "Demo" }
- assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :enctype => "multipart/form-data") { actual_html }
+ assert_html_has_tag(actual_html, 'form', :"accept-charset" => "UTF-8", :action => '/register', :enctype => "multipart/form-data")
end
it 'should support changing form builder type' do
@@ -110,7 +110,7 @@ def standard_builder(object=@user)
it 'should support using default standard builder' do
actual_html = form_for(@user, '/register') { |f| f.text_field_block(:name) }
- assert_has_tag('form p input[type=text]') { actual_html }
+ assert_html_has_tag(actual_html, 'form p input[type=text]')
end
it 'should display fail for form with nil object' do
@@ -118,49 +118,49 @@ def standard_builder(object=@user)
end
it 'should display correct form in haml' do
- visit '/haml/form_for'
- assert_have_selector :form, :action => '/demo', :id => 'demo'
- assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
- assert_have_selector :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
- assert_have_selector :input, :name => 'authenticity_token'
+ get "/haml/form_for"
+ assert_response_has_tag :form, :action => '/demo', :id => 'demo'
+ assert_response_has_tag :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
+ assert_response_has_tag :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
+ assert_response_has_tag :input, :name => 'authenticity_token'
end
it 'should display correct form in erb' do
- visit '/erb/form_for'
- assert_have_selector :form, :action => '/demo', :id => 'demo'
- assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
- assert_have_selector :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
- assert_have_selector :input, :name => 'authenticity_token'
+ get "/erb/form_for"
+ assert_response_has_tag :form, :action => '/demo', :id => 'demo'
+ assert_response_has_tag :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
+ assert_response_has_tag :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
+ assert_response_has_tag :input, :name => 'authenticity_token'
end
it 'should display correct form in slim' do
- visit '/slim/form_for'
- assert_have_selector :form, :action => '/demo', :id => 'demo'
- assert_have_selector :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
- assert_have_selector :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
- assert_have_selector :input, :name => 'authenticity_token'
+ get "/slim/form_for"
+ assert_response_has_tag :form, :action => '/demo', :id => 'demo'
+ assert_response_has_tag :form, :action => '/another_demo', :id => 'demo2', :method => 'get'
+ assert_response_has_tag :form, :action => '/third_demo', :id => 'demo3', :method => 'get'
+ assert_response_has_tag :input, :name => 'authenticity_token'
end
it 'should have a class of "invalid" for fields with errors' do
actual_html = form_for(@user, '/register') {|f| f.text_field(:email) }
- assert_has_tag(:input, :type => 'text', :name => 'user[email]', :id => 'user_email', :class => 'invalid') {actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'text', :name => 'user[email]', :id => 'user_email', :class => 'invalid')
end
it 'should not have a class of "invalid" for fields with no errors' do
actual_html = form_for(@user, '/register') {|f| f.text_field(:first_name) }
- assert_has_no_tag(:input, :type => 'text', :name => 'user[first_name]', :id => 'user_first_name', :class => 'invalid') {actual_html }
+ assert_html_has_no_tag(actual_html, :input, :type => 'text', :name => 'user[first_name]', :id => 'user_first_name', :class => 'invalid')
end
end
describe 'for #fields_for method' do
it 'should display correct fields html' do
actual_html = fields_for(@user) { |f| f.text_field(:first_name) }
- assert_has_tag(:input, :type => 'text', :name => 'user[first_name]', :id => 'user_first_name') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'text', :name => 'user[first_name]', :id => 'user_first_name')
end
it 'should display correct fields html with symbol object' do
actual_html = fields_for(:markup_user) { |f| f.text_field(:first_name) }
- assert_has_tag(:input, :type => 'text', :name => 'markup_user[first_name]', :id => 'markup_user_first_name') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'text', :name => 'markup_user[first_name]', :id => 'markup_user_first_name')
end
it 'should display fail for nil object' do
@@ -178,27 +178,27 @@ def standard_builder(object=@user)
end
it 'should display correct simple fields in haml' do
- visit '/haml/fields_for'
- assert_have_selector :form, :action => '/demo1', :id => 'demo-fields-for'
- assert_have_selector '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
- assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
- assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
+ get "/haml/fields_for"
+ assert_response_has_tag :form, :action => '/demo1', :id => 'demo-fields-for'
+ assert_response_has_tag '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
+ assert_response_has_tag '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
+ assert_response_has_tag '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
end
it 'should display correct simple fields in erb' do
- visit '/erb/fields_for'
- assert_have_selector :form, :action => '/demo1', :id => 'demo-fields-for'
- assert_have_selector '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
- assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
- assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
+ get "/erb/fields_for"
+ assert_response_has_tag :form, :action => '/demo1', :id => 'demo-fields-for'
+ assert_response_has_tag '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
+ assert_response_has_tag '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
+ assert_response_has_tag '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
end
it 'should display correct simple fields in slim' do
- visit '/slim/fields_for'
- assert_have_selector :form, :action => '/demo1', :id => 'demo-fields-for'
- assert_have_selector '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
- assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
- assert_have_selector '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
+ get "/slim/fields_for"
+ assert_response_has_tag :form, :action => '/demo1', :id => 'demo-fields-for'
+ assert_response_has_tag '#demo-fields-for input', :type => 'text', :name => 'markup_user[gender]', :value => 'male'
+ assert_response_has_tag '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_edit]', :value => '1', :checked => 'checked'
+ assert_response_has_tag '#demo-fields-for input', :type => 'checkbox', :name => 'permission[can_delete]'
end
end
@@ -209,491 +209,491 @@ def standard_builder(object=@user)
describe 'for #error_messages method' do
it 'should display correct form html with no record' do
actual_html = standard_builder(@user_none).error_messages(:header_message => "Demo form cannot be saved")
- assert actual_html.blank?
+ assert_empty actual_html
end
it 'should display correct form html with valid record' do
actual_html = standard_builder.error_messages(:header_message => "Demo form cannot be saved", :style => "foo:bar", :class => "mine")
- assert_has_tag('#field-errors h2', :content => "Demo form cannot be saved") { actual_html }
- assert_has_tag('#field-errors ul li', :content => "B must be valid") { actual_html }
- assert_has_tag('#field-errors ul li', :content => "A must be present") { actual_html }
- assert_has_tag('#field-errors', :style => "foo:bar") { actual_html }
- assert_has_tag('#field-errors', :class => "mine") { actual_html }
+ assert_html_has_tag(actual_html, '#field-errors h2', :content => "Demo form cannot be saved")
+ assert_html_has_tag(actual_html, '#field-errors ul li', :content => "B must be valid")
+ assert_html_has_tag(actual_html, '#field-errors ul li', :content => "A must be present")
+ assert_html_has_tag(actual_html, '#field-errors', :style => "foo:bar")
+ assert_html_has_tag(actual_html, '#field-errors', :class => "mine")
end
it 'should display correct form in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
- assert_have_selector '#demo div.field-errors ul li', :content => "Fake must be valid"
- assert_have_selector '#demo div.field-errors ul li', :content => "Second must be present"
- assert_have_selector '#demo div.field-errors ul li', :content => "Third must be a number"
- assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
- assert_have_selector '#demo2 div.field-errors ul li', :content => "Fake must be valid"
- assert_have_selector '#demo2 div.field-errors ul li', :content => "Second must be present"
- assert_have_selector '#demo2 div.field-errors ul li', :content => "Third must be a number"
- assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'string invalid'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
+ assert_response_has_tag '#demo div.field-errors ul li', :content => "Fake must be valid"
+ assert_response_has_tag '#demo div.field-errors ul li', :content => "Second must be present"
+ assert_response_has_tag '#demo div.field-errors ul li', :content => "Third must be a number"
+ assert_response_has_tag '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
+ assert_response_has_tag '#demo2 div.field-errors ul li', :content => "Fake must be valid"
+ assert_response_has_tag '#demo2 div.field-errors ul li', :content => "Second must be present"
+ assert_response_has_tag '#demo2 div.field-errors ul li', :content => "Third must be a number"
+ assert_response_has_tag '#demo input', :name => 'markup_user[email]', :class => 'string invalid'
end
it 'should display correct form in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
- assert_have_selector '#demo div.field-errors ul li', :content => "Fake must be valid"
- assert_have_selector '#demo div.field-errors ul li', :content => "Second must be present"
- assert_have_selector '#demo div.field-errors ul li', :content => "Third must be a number"
- assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
- assert_have_selector '#demo2 div.field-errors ul li', :content => "Fake must be valid"
- assert_have_selector '#demo2 div.field-errors ul li', :content => "Second must be present"
- assert_have_selector '#demo2 div.field-errors ul li', :content => "Third must be a number"
- assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'string invalid'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
+ assert_response_has_tag '#demo div.field-errors ul li', :content => "Fake must be valid"
+ assert_response_has_tag '#demo div.field-errors ul li', :content => "Second must be present"
+ assert_response_has_tag '#demo div.field-errors ul li', :content => "Third must be a number"
+ assert_response_has_tag '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
+ assert_response_has_tag '#demo2 div.field-errors ul li', :content => "Fake must be valid"
+ assert_response_has_tag '#demo2 div.field-errors ul li', :content => "Second must be present"
+ assert_response_has_tag '#demo2 div.field-errors ul li', :content => "Third must be a number"
+ assert_response_has_tag '#demo input', :name => 'markup_user[email]', :class => 'string invalid'
end
it 'should display correct form in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
- assert_have_selector '#demo div.field-errors ul li', :content => "Fake must be valid"
- assert_have_selector '#demo div.field-errors ul li', :content => "Second must be present"
- assert_have_selector '#demo div.field-errors ul li', :content => "Third must be a number"
- assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
- assert_have_selector '#demo2 div.field-errors ul li', :content => "Fake must be valid"
- assert_have_selector '#demo2 div.field-errors ul li', :content => "Second must be present"
- assert_have_selector '#demo2 div.field-errors ul li', :content => "Third must be a number"
- assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'string invalid'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
+ assert_response_has_tag '#demo div.field-errors ul li', :content => "Fake must be valid"
+ assert_response_has_tag '#demo div.field-errors ul li', :content => "Second must be present"
+ assert_response_has_tag '#demo div.field-errors ul li', :content => "Third must be a number"
+ assert_response_has_tag '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
+ assert_response_has_tag '#demo2 div.field-errors ul li', :content => "Fake must be valid"
+ assert_response_has_tag '#demo2 div.field-errors ul li', :content => "Second must be present"
+ assert_response_has_tag '#demo2 div.field-errors ul li', :content => "Third must be a number"
+ assert_response_has_tag '#demo input', :name => 'markup_user[email]', :class => 'string invalid'
end
end
describe 'for #error_message_on method' do
it 'should display correct form html with no record' do
actual_html = standard_builder(@user_none).error_message_on(:name)
- assert actual_html.blank?
+ assert_empty actual_html
end
it 'should display error for specified invalid object' do
actual_html = standard_builder(@user).error_message_on(:a, :prepend => "foo", :append => "bar")
- assert_has_tag('span.error', :content => "foo must be present bar") { actual_html }
+ assert_html_has_tag(actual_html, 'span.error', :content => "foo must be present bar")
end
it 'should display error for specified invalid object not matching class name' do
@bob = mock_model("User", :first_name => "Frank", :errors => { :foo => "must be bob" })
actual_html = standard_builder(@bob).error_message_on(:foo, :prepend => "foo", :append => "bar")
- assert_has_tag('span.error', :content => "foo must be bob bar") { actual_html }
+ assert_html_has_tag(actual_html, 'span.error', :content => "foo must be bob bar")
end
end
describe 'for #label method' do
it 'should display correct label html' do
actual_html = standard_builder.label(:first_name, :class => 'large', :caption => "F. Name: ")
- assert_has_tag('label', :class => 'large', :for => 'user_first_name', :content => "F. Name: ") { actual_html }
- assert_has_no_tag('label#user_first_name') { actual_html }
+ assert_html_has_tag(actual_html, 'label', :class => 'large', :for => 'user_first_name', :content => "F. Name: ")
+ assert_html_has_no_tag(actual_html, 'label#user_first_name')
end
it 'should set specific content inside the label if a block was provided' do
actual_html = standard_builder.label(:admin, :class => 'large') { input_tag :checkbox }
- assert_has_tag('label', :class => 'large', :for => 'user_admin', :content => "Admin: ") { actual_html }
- assert_has_tag('label input[type=checkbox]') { actual_html }
+ assert_html_has_tag(actual_html, 'label', :class => 'large', :for => 'user_admin', :content => "Admin: ")
+ assert_html_has_tag(actual_html, 'label input[type=checkbox]')
end
it 'should display correct label in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
- assert_have_selector '#demo label', :content => "About Me: "
- assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo label', :content => "Login: ", :class => 'user-label'
+ assert_response_has_tag '#demo label', :content => "About Me: "
+ assert_response_has_tag '#demo2 label', :content => "Nickname: ", :class => 'label'
end
it 'should display correct label in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
- assert_have_selector '#demo label', :content => "About Me: "
- assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo label', :content => "Login: ", :class => 'user-label'
+ assert_response_has_tag '#demo label', :content => "About Me: "
+ assert_response_has_tag '#demo2 label', :content => "Nickname: ", :class => 'label'
end
it 'should display correct label in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo label', :content => "Login: ", :class => 'user-label'
- assert_have_selector '#demo label', :content => "About Me: "
- assert_have_selector '#demo2 label', :content => "Nickname: ", :class => 'label'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo label', :content => "Login: ", :class => 'user-label'
+ assert_response_has_tag '#demo label', :content => "About Me: "
+ assert_response_has_tag '#demo2 label', :content => "Nickname: ", :class => 'label'
end
end
describe 'for #hidden_field method' do
it 'should display correct hidden field html' do
actual_html = standard_builder.hidden_field(:session_id, :class => 'hidden')
- assert_has_tag('input.hidden[type=hidden]', :value => "54", :id => 'user_session_id', :name => 'user[session_id]') { actual_html }
+ assert_html_has_tag(actual_html, 'input.hidden[type=hidden]', :value => "54", :id => 'user_session_id', :name => 'user[session_id]')
end
it 'should display correct hidden field in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
- assert_have_selector '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
+ assert_response_has_tag '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
end
it 'should display correct hidden field in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
- assert_have_selector '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
+ assert_response_has_tag '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
end
it 'should display correct hidden field in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
- assert_have_selector '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input[type=hidden]', :id => 'markup_user_session_id', :value => "45"
+ assert_response_has_tag '#demo2 input', :type => 'hidden', :name => 'markup_user[session_id]'
end
end
describe 'for #text_field method' do
it 'should display correct text field html' do
actual_html = standard_builder.text_field(:first_name, :class => 'large')
- assert_has_tag('input.large[type=text]', :value => "Joe", :id => 'user_first_name', :name => 'user[first_name]') { actual_html }
+ assert_html_has_tag(actual_html, 'input.large[type=text]', :value => "Joe", :id => 'user_first_name', :name => 'user[first_name]')
end
it 'should display correct text field in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
- assert_have_selector '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
+ assert_response_has_tag '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
end
it 'should display correct text field in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
- assert_have_selector '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
+ assert_response_has_tag '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
end
it 'should display correct text field in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
- assert_have_selector '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input.user-text[type=text]', :id => 'markup_user_username', :value => "John"
+ assert_response_has_tag '#demo2 input', :type => 'text', :class => 'input', :name => 'markup_user[username]'
end
end
describe 'for #number_field method' do
it 'should display correct number field html' do
actual_html = standard_builder.number_field(:age, :class => 'numeric')
- assert_has_tag('input.numeric[type=number]', :id => 'user_age', :name => 'user[age]') { actual_html }
+ assert_html_has_tag(actual_html, 'input.numeric[type=number]', :id => 'user_age', :name => 'user[age]')
end
it 'should display correct number field in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input.numeric[type=number]', :id => 'markup_user_age'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input.numeric[type=number]', :id => 'markup_user_age'
end
it 'should display correct number field in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input.numeric[type=number]', :id => 'markup_user_age'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input.numeric[type=number]', :id => 'markup_user_age'
end
it 'should display correct number field in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input.numeric[type=number]', :id => 'markup_user_age'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input.numeric[type=number]', :id => 'markup_user_age'
end
end
describe 'for #telephone_field method' do
it 'should display correct telephone field html' do
actual_html = standard_builder.telephone_field(:telephone, :class => 'numeric')
- assert_has_tag('input.numeric[type=tel]', :id => 'user_telephone', :name => 'user[telephone]') { actual_html }
+ assert_html_has_tag(actual_html, 'input.numeric[type=tel]', :id => 'user_telephone', :name => 'user[telephone]')
end
it 'should display correct telephone field in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input.numeric[type=tel]', :id => 'markup_user_telephone'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input.numeric[type=tel]', :id => 'markup_user_telephone'
end
it 'should display correct telephone field in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input.numeric[type=tel]', :id => 'markup_user_telephone'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input.numeric[type=tel]', :id => 'markup_user_telephone'
end
it 'should display correct telephone field in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input.numeric[type=tel]', :id => 'markup_user_telephone'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input.numeric[type=tel]', :id => 'markup_user_telephone'
end
end
describe 'for #search_field method' do
it 'should display correct search field html' do
actual_html = standard_builder.search_field(:search, :class => 'string')
- assert_has_tag('input.string[type=search]', :id => 'user_search', :name => 'user[search]') { actual_html }
+ assert_html_has_tag(actual_html, 'input.string[type=search]', :id => 'user_search', :name => 'user[search]')
end
it 'should display correct search field in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input.string[type=search]', :id => 'markup_user_search'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input.string[type=search]', :id => 'markup_user_search'
end
it 'should display correct search field in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input.string[type=search]', :id => 'markup_user_search'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input.string[type=search]', :id => 'markup_user_search'
end
it 'should display correct search field in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input.string[type=search]', :id => 'markup_user_search'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input.string[type=search]', :id => 'markup_user_search'
end
end
describe 'for #email_field method' do
it 'should display correct email field html' do
actual_html = standard_builder.email_field(:email, :class => 'string')
- assert_has_tag('input.string[type=email]', :id => 'user_email', :name => 'user[email]') { actual_html }
+ assert_html_has_tag(actual_html, 'input.string[type=email]', :id => 'user_email', :name => 'user[email]')
end
it 'should display correct email field in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input.string[type=email]', :id => 'markup_user_email'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input.string[type=email]', :id => 'markup_user_email'
end
it 'should display correct email field in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input.string[type=email]', :id => 'markup_user_email'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input.string[type=email]', :id => 'markup_user_email'
end
it 'should display correct email field in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input.string[type=email]', :id => 'markup_user_email'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input.string[type=email]', :id => 'markup_user_email'
end
end
describe 'for #url_field method' do
it 'should display correct url field html' do
actual_html = standard_builder.url_field(:webpage, :class => 'string')
- assert_has_tag('input.string[type=url]', :id => 'user_webpage', :name => 'user[webpage]') { actual_html }
+ assert_html_has_tag(actual_html, 'input.string[type=url]', :id => 'user_webpage', :name => 'user[webpage]')
end
it 'should display correct url field in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input.string[type=url]', :id => 'markup_user_webpage'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input.string[type=url]', :id => 'markup_user_webpage'
end
it 'should display correct url field in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input.string[type=url]', :id => 'markup_user_webpage'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input.string[type=url]', :id => 'markup_user_webpage'
end
it 'should display correct url field in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input.string[type=url]', :id => 'markup_user_webpage'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input.string[type=url]', :id => 'markup_user_webpage'
end
end
describe 'for #check_box method' do
it 'should display correct checkbox html' do
actual_html = standard_builder.check_box(:confirm_destroy, :class => 'large')
- assert_has_tag('input.large[type=checkbox]', :id => 'user_confirm_destroy', :name => 'user[confirm_destroy]') { actual_html }
- assert_has_tag('input[type=hidden]', :name => 'user[confirm_destroy]', :value => '0') { actual_html }
+ assert_html_has_tag(actual_html, 'input.large[type=checkbox]', :id => 'user_confirm_destroy', :name => 'user[confirm_destroy]')
+ assert_html_has_tag(actual_html, 'input[type=hidden]', :name => 'user[confirm_destroy]', :value => '0')
end
it 'should display correct checkbox html when checked' do
actual_html = standard_builder.check_box(:confirm_destroy, :checked => true)
- assert_has_tag('input[type=checkbox]', :checked => 'checked', :name => 'user[confirm_destroy]') { actual_html }
+ assert_html_has_tag(actual_html, 'input[type=checkbox]', :checked => 'checked', :name => 'user[confirm_destroy]')
end
it 'should display correct checkbox html as checked when object value matches' do
@user.stubs(:show_favorites => 'human')
actual_html = standard_builder.check_box(:show_favorites, :value => 'human')
- assert_has_tag('input[type=checkbox]', :checked => 'checked', :name => 'user[show_favorites]') { actual_html }
+ assert_html_has_tag(actual_html, 'input[type=checkbox]', :checked => 'checked', :name => 'user[show_favorites]')
end
it 'should display correct checkbox html as checked when object value is true' do
@user.stubs(:show_favorites => true)
actual_html = standard_builder.check_box(:show_favorites, :value => '1')
- assert_has_tag('input[type=checkbox]', :checked => 'checked', :name => 'user[show_favorites]') { actual_html }
+ assert_html_has_tag(actual_html, 'input[type=checkbox]', :checked => 'checked', :name => 'user[show_favorites]')
end
it 'should display correct checkbox html as unchecked when object value does not match' do
@user.stubs(:show_favorites => 'alien')
actual_html = standard_builder.check_box(:show_favorites, :value => 'human')
- assert_has_no_tag('input[type=checkbox]', :checked => 'checked') { actual_html }
+ assert_html_has_no_tag(actual_html, 'input[type=checkbox]', :checked => 'checked')
end
it 'should display correct checkbox html as unchecked when object value is false' do
@user.stubs(:show_favorites => false)
actual_html = standard_builder.check_box(:show_favorites, :value => '1')
- assert_has_no_tag('input[type=checkbox]', :checked => 'checked') { actual_html }
+ assert_html_has_no_tag(actual_html, 'input[type=checkbox]', :checked => 'checked')
end
it 'should display correct unchecked hidden field when specified' do
actual_html = standard_builder.check_box(:show_favorites, :value => 'female', :uncheck_value => 'false')
- assert_has_tag('input[type=hidden]', :name => 'user[show_favorites]', :value => 'false') { actual_html }
+ assert_html_has_tag(actual_html, 'input[type=hidden]', :name => 'user[show_favorites]', :value => 'false')
end
it 'should display correct checkbox in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
end
it 'should display correct checkbox in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
end
it 'should display correct checkbox in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input[type=checkbox]', :checked => 'checked', :id => 'markup_user_remember_me', :name => 'markup_user[remember_me]'
end
end
describe 'for #check_box_group and #radio_button_group methods' do
it 'should display checkbox group html' do
checkboxes = standard_builder.check_box_group(:role, :collection => @user.role_types, :fields => [:name, :id], :selected => [2,3])
- assert_has_tag('input[type=checkbox]', :value => '1') { checkboxes }
- assert_has_no_tag('input[type=checkbox][checked]', :value => '1') { checkboxes }
- assert_has_tag('input[type=checkbox]', :checked => 'checked', :value => '2') { checkboxes }
- assert_has_tag('label[for=user_role_3] input[name="user[role][]"][value="3"][checked]') { checkboxes }
+ assert_html_has_tag(checkboxes, 'input[type=checkbox]', :value => '1')
+ assert_html_has_no_tag(checkboxes, 'input[type=checkbox][checked]', :value => '1')
+ assert_html_has_tag(checkboxes, 'input[type=checkbox]', :checked => 'checked', :value => '2')
+ assert_html_has_tag(checkboxes, 'label[for=user_role_3] input[name="user[role][]"][value="3"][checked]')
end
it 'should display checkbox group html and extract selected values from the object' do
checkboxes = standard_builder.check_box_group(:roles, :collection => @user.role_types, :fields => [:name, :id])
- assert_has_tag('input[type=checkbox][name="user[roles][]"][value="1"][checked]') { checkboxes }
- assert_has_tag('input[type=checkbox][name="user[roles][]"][value="3"][checked]') { checkboxes }
- assert_has_no_tag('input[type=checkbox][name="user[roles][]"][value="2"][checked]') { checkboxes }
+ assert_html_has_tag(checkboxes, 'input[type=checkbox][name="user[roles][]"][value="1"][checked]')
+ assert_html_has_tag(checkboxes, 'input[type=checkbox][name="user[roles][]"][value="3"][checked]')
+ assert_html_has_no_tag(checkboxes, 'input[type=checkbox][name="user[roles][]"][value="2"][checked]')
end
it 'should display radio group html' do
radios = standard_builder.radio_button_group(:role, :options => %W(red yellow blue), :selected => 'yellow')
- assert_has_tag('input[type=radio]', :value => 'red') { radios }
- assert_has_no_tag('input[type=radio][checked]', :value => 'red') { radios }
- assert_has_tag('input[type=radio]', :checked => 'checked', :value => 'yellow') { radios }
- assert_has_tag('label[for=user_role_blue] input[name="user[role]"][value=blue]') { radios }
+ assert_html_has_tag(radios, 'input[type=radio]', :value => 'red')
+ assert_html_has_no_tag(radios, 'input[type=radio][checked]', :value => 'red')
+ assert_html_has_tag(radios, 'input[type=radio]', :checked => 'checked', :value => 'yellow')
+ assert_html_has_tag(radios, 'label[for=user_role_blue] input[name="user[role]"][value=blue]')
end
it 'should display radio group html and extract selected value from the object' do
radios = standard_builder.radio_button_group(:role, :collection => @user.role_types)
- assert_has_tag('input[type=radio][value="1"][checked]') { radios }
- assert_has_no_tag('input[type=radio][value="2"][checked]') { radios }
+ assert_html_has_tag(radios, 'input[type=radio][value="1"][checked]')
+ assert_html_has_no_tag(radios, 'input[type=radio][value="2"][checked]')
end
end
describe 'for #radio_button method' do
it 'should display correct radio button html' do
actual_html = standard_builder.radio_button(:gender, :value => 'male', :class => 'large')
- assert_has_tag('input.large[type=radio]', :id => 'user_gender_male', :name => 'user[gender]', :value => 'male') { actual_html }
+ assert_html_has_tag(actual_html, 'input.large[type=radio]', :id => 'user_gender_male', :name => 'user[gender]', :value => 'male')
end
it 'should display correct radio button html when checked' do
actual_html = standard_builder.radio_button(:gender, :checked => true)
- assert_has_tag('input[type=radio]', :checked => 'checked', :name => 'user[gender]') { actual_html }
+ assert_html_has_tag(actual_html, 'input[type=radio]', :checked => 'checked', :name => 'user[gender]')
end
it 'should display correct radio button html as checked when object value matches' do
@user.stubs(:gender => 'male')
actual_html = standard_builder.radio_button(:gender, :value => 'male')
- assert_has_tag('input[type=radio]', :checked => 'checked', :name => 'user[gender]') { actual_html }
+ assert_html_has_tag(actual_html, 'input[type=radio]', :checked => 'checked', :name => 'user[gender]')
end
it 'should display correct radio button html as unchecked when object value does not match' do
@user.stubs(:gender => 'male')
actual_html = standard_builder.radio_button(:gender, :value => 'female')
- assert_has_no_tag('input[type=radio]', :checked => 'checked') { actual_html }
+ assert_html_has_no_tag(actual_html, 'input[type=radio]', :checked => 'checked')
end
it 'should display correct radio button in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
- assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
- assert_have_selector '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
+ assert_response_has_tag '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
+ assert_response_has_tag '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
end
it 'should display correct radio button in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
- assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
- assert_have_selector '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
+ assert_response_has_tag '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
+ assert_response_has_tag '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
end
it 'should display correct radio button in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
- assert_have_selector '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
- assert_have_selector '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input[type=radio]', :id => 'markup_user_gender_male', :name => 'markup_user[gender]', :value => 'male'
+ assert_response_has_tag '#demo input[type=radio]', :id => 'markup_user_gender_female', :name => 'markup_user[gender]', :value => 'female'
+ assert_response_has_tag '#demo input[type=radio][checked=checked]', :id => 'markup_user_gender_male'
end
end
describe 'for #text_area method' do
it 'should display correct text_area html' do
actual_html = standard_builder.text_area(:about, :class => 'large')
- assert_has_tag('textarea.large', :id => 'user_about', :name => 'user[about]') { actual_html }
+ assert_html_has_tag(actual_html, 'textarea.large', :id => 'user_about', :name => 'user[about]')
end
it 'should display correct text_area html and content' do
actual_html = standard_builder.text_area(:about, :value => "Demo", :rows => '5', :cols => '6')
- assert_has_tag('textarea', :id => 'user_about', :content => 'Demo', :rows => '5', :cols => '6') { actual_html }
+ assert_html_has_tag(actual_html, 'textarea', :id => 'user_about', :content => 'Demo', :rows => '5', :cols => '6')
end
it 'should display correct text_area in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
- assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
+ assert_response_has_tag '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
end
it 'should display correct text_area in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
- assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
+ assert_response_has_tag '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
end
it 'should display correct text_area in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
- assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
+ assert_response_has_tag '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
end
end
describe 'for #password_field method' do
it 'should display correct password_field html' do
actual_html = standard_builder.password_field(:code, :class => 'large')
- assert_has_tag('input.large[type=password]', :id => 'user_code', :name => 'user[code]') { actual_html }
+ assert_html_has_tag(actual_html, 'input.large[type=password]', :id => 'user_code', :name => 'user[code]')
end
it 'should display correct password_field in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
- assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
+ assert_response_has_tag '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
end
it 'should display correct password_field in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
- assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
+ assert_response_has_tag '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
end
it 'should display correct password_field in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
- assert_have_selector '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input', :type => 'password', :class => 'user-password', :value => 'secret'
+ assert_response_has_tag '#demo2 input', :type => 'password', :class => 'input', :name => 'markup_user[code]'
end
end
describe 'for #file_field method' do
it 'should display correct file_field html' do
actual_html = standard_builder.file_field(:photo, :class => 'large')
- assert_has_tag('input.large[type=file]', :id => 'user_photo', :name => 'user[photo]') { actual_html }
+ assert_html_has_tag(actual_html, 'input.large[type=file]', :id => 'user_photo', :name => 'user[photo]')
end
it 'should display correct file_field in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
- assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
+ assert_response_has_tag '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
end
it 'should display correct file_field in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
- assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
+ assert_response_has_tag '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
end
it 'should display correct file_field in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
- assert_have_selector '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input.user-photo', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
+ assert_response_has_tag '#demo2 input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
end
it 'should display correct form html with multipart, even if no multipart option is specified' do
actual_html = form_for(@user, '/register', :"accept-charset" => "UTF-8") { |f| f.file_field :photo }
- assert_has_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :enctype => "multipart/form-data") { actual_html }
+ assert_html_has_tag(actual_html, 'form', :"accept-charset" => "UTF-8", :action => '/register', :enctype => "multipart/form-data")
end
it 'should display correct form html without multipart, if multipart option is specified false' do
actual_html = form_for(@user, '/register', :"accept-charset" => "UTF-8", :multipart => false) { |f| f.file_field :photo }
- assert_has_no_tag('form', :"accept-charset" => "UTF-8", :action => '/register', :enctype => "multipart/form-data") { actual_html }
+ assert_html_has_no_tag(actual_html, 'form', :"accept-charset" => "UTF-8", :action => '/register', :enctype => "multipart/form-data")
end
end
@@ -701,28 +701,28 @@ def standard_builder(object=@user)
describe 'for #select method' do
it 'should display correct select html' do
actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'], :class => 'selecty')
- assert_has_tag('select.selecty', :id => 'user_state', :name => 'user[state]') { actual_html }
- assert_has_tag('select.selecty option', :count => 3) { actual_html }
- assert_has_tag('select.selecty option', :value => 'California', :content => 'California') { actual_html }
- assert_has_tag('select.selecty option', :value => 'Texas', :content => 'Texas') { actual_html }
- assert_has_tag('select.selecty option', :value => 'Wyoming', :content => 'Wyoming') { actual_html }
+ assert_html_has_tag(actual_html, 'select.selecty', :id => 'user_state', :name => 'user[state]')
+ assert_html_has_tag(actual_html, 'select.selecty option', :count => 3)
+ assert_html_has_tag(actual_html, 'select.selecty option', :value => 'California', :content => 'California')
+ assert_html_has_tag(actual_html, 'select.selecty option', :value => 'Texas', :content => 'Texas')
+ assert_html_has_tag(actual_html, 'select.selecty option', :value => 'Wyoming', :content => 'Wyoming')
end
it 'should display correct select html with selected item if it matches value' do
@user.stubs(:state => 'California')
actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'])
- assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
- assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
- assert_has_tag('select option', :value => 'California', :selected => 'selected') { actual_html }
+ assert_html_has_tag(actual_html, 'select', :id => 'user_state', :name => 'user[state]')
+ assert_html_has_tag(actual_html, 'select option', :selected => 'selected', :count => 1)
+ assert_html_has_tag(actual_html, 'select option', :value => 'California', :selected => 'selected')
end
it 'should display correct select html with selected item if it matches full value' do
@user.stubs(:state => 'Cali')
actual_html = standard_builder.select(:state, :options => ['Cali', 'California', 'Texas', 'Wyoming'])
- assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
- assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
- assert_has_tag('select option', :value => 'Cali', :selected => 'selected') { actual_html }
- assert_has_tag('select option', :value => 'California') { actual_html }
+ assert_html_has_tag(actual_html, 'select', :id => 'user_state', :name => 'user[state]')
+ assert_html_has_tag(actual_html, 'select option', :selected => 'selected', :count => 1)
+ assert_html_has_tag(actual_html, 'select option', :value => 'Cali', :selected => 'selected')
+ assert_html_has_tag(actual_html, 'select option', :value => 'California')
end
it 'should display correct select html with multiple selected items' do
@@ -730,92 +730,95 @@ def standard_builder(object=@user)
actual_html = standard_builder.select(
:pickles, :options => [ ['Foo', 'foo'], ['Bar', 'bar'], ['Baz', 'baz'], ['Bar Buz', 'bar buz'] ]
)
- assert_has_tag('option', :value => 'foo', :content => 'Foo', :selected => 'selected') { actual_html }
- assert_has_tag('option', :value => 'bar', :content => 'Bar', :selected => 'selected') { actual_html }
- assert_has_tag('option', :value => 'baz', :content => 'Baz') { actual_html }
- assert_has_tag('option', :value => 'bar buz', :content => 'Bar Buz') { actual_html }
+ assert_html_has_tag(actual_html, 'option', :value => 'foo', :content => 'Foo', :selected => 'selected')
+ assert_html_has_tag(actual_html, 'option', :value => 'bar', :content => 'Bar', :selected => 'selected')
+ assert_html_has_tag(actual_html, 'option', :value => 'baz', :content => 'Baz')
+ assert_html_has_tag(actual_html, 'option', :value => 'bar buz', :content => 'Bar Buz')
end
- it 'should display correct select html with include_blank' do
+ it 'should display correct select html with include_blank true' do
actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'], :include_blank => true)
- assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
- assert_has_tag('select option', :count => 4) { actual_html }
- assert_has_tag('select option:first-child', :content => '') { actual_html }
- assert_has_tag('select option:first-child', :value => '') { actual_html }
+ assert_html_has_tag(actual_html, 'select', :id => 'user_state', :name => 'user[state]')
+ assert_html_has_tag(actual_html, 'select option', :count => 4)
+ assert_html_has_tag(actual_html, 'select option:first-child', :content => '')
+ assert_html_has_tag(actual_html, 'select option:first-child', :value => '')
+ end
+
+ it 'should display correct select html with include_blank string' do
actual_html = standard_builder.select(:state, :options => ['California', 'Texas', 'Wyoming'], :include_blank => 'Select')
- assert_has_tag('select', :id => 'user_state', :name => 'user[state]') { actual_html }
- assert_has_tag('select option', :count => 4) { actual_html }
- assert_has_tag('select option:first-child', :content => 'Select') { actual_html }
- assert_has_tag('select option:first-child', :value => '') { actual_html }
+ assert_html_has_tag(actual_html, 'select', :id => 'user_state', :name => 'user[state]')
+ assert_html_has_tag(actual_html, 'select option', :count => 4)
+ assert_html_has_tag(actual_html, 'select option:first-child', :content => 'Select')
+ assert_html_has_tag(actual_html, 'select option:first-child', :value => '')
end
it 'should display correct select html with collection passed in' do
actual_html = standard_builder.select(:role, :collection => @user.role_types, :fields => [:name, :id])
- assert_has_tag('select', :id => 'user_role', :name => 'user[role]') { actual_html }
- assert_has_tag('select option', :count => 3) { actual_html }
- assert_has_tag('select option', :value => '1', :content => 'Admin', :selected => 'selected') { actual_html }
- assert_has_tag('select option', :value => '2', :content => 'Moderate') { actual_html }
- assert_has_tag('select option', :value => '3', :content => 'Limited') { actual_html }
+ assert_html_has_tag(actual_html, 'select', :id => 'user_role', :name => 'user[role]')
+ assert_html_has_tag(actual_html, 'select option', :count => 3)
+ assert_html_has_tag(actual_html, 'select option', :value => '1', :content => 'Admin', :selected => 'selected')
+ assert_html_has_tag(actual_html, 'select option', :value => '2', :content => 'Moderate')
+ assert_html_has_tag(actual_html, 'select option', :value => '3', :content => 'Limited')
end
it 'should display correct select in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
- assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
+ assert_response_has_tag '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
end
it 'should display correct select in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
- assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
+ assert_response_has_tag '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
end
it 'should display correct select in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
- assert_have_selector '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
+ assert_response_has_tag '#demo2 textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'textarea'
end
end
describe 'for #submit method' do
it 'should display correct submit button html with no options' do
actual_html = standard_builder.submit
- assert_has_tag('input[type=submit]', :value => "Submit") { actual_html }
+ assert_html_has_tag(actual_html, 'input[type=submit]', :value => "Submit")
end
it 'should display correct submit button html with no caption' do
actual_html = standard_builder.submit(:class => 'btn')
- assert_has_tag('input.btn[type=submit]', :value => "Submit") { actual_html }
+ assert_html_has_tag(actual_html, 'input.btn[type=submit]', :value => "Submit")
end
it 'should display correct submit button html with nil caption' do
actual_html = standard_builder.submit(nil, :class => 'btn')
- assert_has_tag('input.btn[type=submit]') { actual_html }
+ assert_html_has_tag(actual_html, 'input.btn[type=submit]')
assert actual_html !~ %r{ value \* = }x
end
it 'should display correct submit button html' do
actual_html = standard_builder.submit("Commit", :class => 'large')
- assert_has_tag('input.large[type=submit]', :value => "Commit") { actual_html }
+ assert_html_has_tag(actual_html, 'input.large[type=submit]', :value => "Commit")
end
it 'should display correct submit button in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
- assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
+ assert_response_has_tag '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
end
it 'should display correct submit button in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
- assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
+ assert_response_has_tag '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
end
it 'should display correct submit button in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
- assert_have_selector '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input', :type => 'submit', :id => 'demo-button', :class => 'success'
+ assert_response_has_tag '#demo2 input', :type => 'submit', :class => 'button', :value => "Create"
end
end
@@ -826,30 +829,30 @@ def standard_builder(object=@user)
it 'should display correct image submit button html with no options' do
actual_html = standard_builder.image_submit('buttons/ok.png')
- assert_has_tag('input[type=image]', :src => "/images/buttons/ok.png?#{@stamp}") { actual_html }
+ assert_html_has_tag(actual_html, 'input[type=image]', :src => "/images/buttons/ok.png?#{@stamp}")
end
it 'should display correct image submit button html' do
actual_html = standard_builder.image_submit('/system/ok.png', :class => 'large')
- assert_has_tag('input.large[type=image]', :src => "/system/ok.png") { actual_html }
+ assert_html_has_tag(actual_html, 'input.large[type=image]', :src => "/system/ok.png")
end
it 'should display correct image submit button in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
- assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
+ assert_response_has_tag '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
end
it 'should display correct image submit button in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
- assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
+ assert_response_has_tag '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
end
it 'should display correct image submit button in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
- assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input', :type => 'image', :id => 'image-button', :src => "/images/buttons/post.png?#{@stamp}"
+ assert_response_has_tag '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
end
end
@@ -870,10 +873,10 @@ def standard_builder(object=@user)
child_form.text_field(:number) +
child_form.check_box('_destroy')
end
- assert_has_tag('label', :for => 'user_telephone_attributes_number') { actual_html }
- assert_has_tag('input', :type => 'text', :id => 'user_telephone_attributes_number', :name => 'user[telephone_attributes][number]', :value => "4568769876") { actual_html }
- assert_has_tag('input', :type => 'hidden', :name => 'user[telephone_attributes][_destroy]', :value => '0') { actual_html }
- assert_has_tag('input', :type => 'checkbox', :id => 'user_telephone_attributes__destroy', :name => 'user[telephone_attributes][_destroy]', :value => '1') { actual_html }
+ assert_html_has_tag(actual_html, 'label', :for => 'user_telephone_attributes_number')
+ assert_html_has_tag(actual_html, 'input', :type => 'text', :id => 'user_telephone_attributes_number', :name => 'user[telephone_attributes][number]', :value => "4568769876")
+ assert_html_has_tag(actual_html, 'input', :type => 'hidden', :name => 'user[telephone_attributes][_destroy]', :value => '0')
+ assert_html_has_tag(actual_html, 'input', :type => 'checkbox', :id => 'user_telephone_attributes__destroy', :name => 'user[telephone_attributes][_destroy]', :value => '1')
end
it 'should display nested children fields one-to-many within form' do
@@ -883,15 +886,15 @@ def standard_builder(object=@user)
html << child_form.text_field(:name)
end
# Address 1 (Saved)
- assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '20') { actual_html }
- assert_has_tag('label', :for => 'user_addresses_attributes_0_name', :content => 'Name') { actual_html }
- assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]') { actual_html }
- assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]') { actual_html }
+ assert_html_has_tag(actual_html, 'input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '20')
+ assert_html_has_tag(actual_html, 'label', :for => 'user_addresses_attributes_0_name', :content => 'Name')
+ assert_html_has_tag(actual_html, 'input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]')
+ assert_html_has_tag(actual_html, 'input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]')
# Address 2 (New)
- assert_has_no_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_1_id') { actual_html }
- assert_has_tag('label', :for => 'user_addresses_attributes_1_name', :content => 'Name') { actual_html }
- assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_1_name', :name => 'user[addresses_attributes][1][name]') { actual_html }
- assert_has_no_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_1__destroy') { actual_html }
+ assert_html_has_no_tag(actual_html, 'input', :type => 'hidden', :id => 'user_addresses_attributes_1_id')
+ assert_html_has_tag(actual_html, 'label', :for => 'user_addresses_attributes_1_name', :content => 'Name')
+ assert_html_has_tag(actual_html, 'input', :type => 'text', :id => 'user_addresses_attributes_1_name', :name => 'user[addresses_attributes][1][name]')
+ assert_html_has_no_tag(actual_html, 'input', :type => 'checkbox', :id => 'user_addresses_attributes_1__destroy')
end
it 'should display fields for explicit instance object' do
@@ -901,10 +904,10 @@ def standard_builder(object=@user)
html << child_form.text_field(:name)
html << child_form.check_box('_destroy')
end
- assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '40') { actual_html }
- assert_has_tag('label', :for => 'user_addresses_attributes_0_name', :content => 'Name') { actual_html }
- assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]', :value => "Page") { actual_html }
- assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]', :value => '1') { actual_html }
+ assert_html_has_tag(actual_html, 'input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '40')
+ assert_html_has_tag(actual_html, 'label', :for => 'user_addresses_attributes_0_name', :content => 'Name')
+ assert_html_has_tag(actual_html, 'input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]', :value => "Page")
+ assert_html_has_tag(actual_html, 'input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]', :value => '1')
end
it 'should display fields for collection object' do
@@ -915,15 +918,15 @@ def standard_builder(object=@user)
child_form.check_box('_destroy')
end
# Address 1
- assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '20') { actual_html }
- assert_has_tag('label', :for => 'user_addresses_attributes_0_name', :content => 'Name') { actual_html }
- assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]', :value => "Foo") { actual_html }
- assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]') { actual_html }
+ assert_html_has_tag(actual_html, 'input', :type => 'hidden', :id => 'user_addresses_attributes_0_id', :name => "user[addresses_attributes][0][id]", :value => '20')
+ assert_html_has_tag(actual_html, 'label', :for => 'user_addresses_attributes_0_name', :content => 'Name')
+ assert_html_has_tag(actual_html, 'input', :type => 'text', :id => 'user_addresses_attributes_0_name', :name => 'user[addresses_attributes][0][name]', :value => "Foo")
+ assert_html_has_tag(actual_html, 'input', :type => 'checkbox', :id => 'user_addresses_attributes_0__destroy', :name => 'user[addresses_attributes][0][_destroy]')
# Address 3
- assert_has_tag('input', :type => 'hidden', :id => 'user_addresses_attributes_2_id', :value => '50') { actual_html }
- assert_has_tag('label', :for => 'user_addresses_attributes_2_name', :content => 'Name') { actual_html }
- assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_2_name', :name => 'user[addresses_attributes][2][name]', :value => "Walter") { actual_html }
- assert_has_tag('input', :type => 'checkbox', :id => 'user_addresses_attributes_2__destroy') { actual_html }
+ assert_html_has_tag(actual_html, 'input', :type => 'hidden', :id => 'user_addresses_attributes_2_id', :value => '50')
+ assert_html_has_tag(actual_html, 'label', :for => 'user_addresses_attributes_2_name', :content => 'Name')
+ assert_html_has_tag(actual_html, 'input', :type => 'text', :id => 'user_addresses_attributes_2_name', :name => 'user[addresses_attributes][2][name]', :value => "Walter")
+ assert_html_has_tag(actual_html, 'input', :type => 'checkbox', :id => 'user_addresses_attributes_2__destroy')
end
it 'should display fields for arbitrarily deep nested forms' do
@@ -934,8 +937,8 @@ def standard_builder(object=@user)
second_child_form.check_box('_destroy')
end
end
- assert_has_tag('label', :for => 'user_addresses_attributes_1_businesses_attributes_0_name', :content => 'Name') { actual_html }
- assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_1_businesses_attributes_0_name', :name => 'user[addresses_attributes][1][businesses_attributes][0][name]') { actual_html }
+ assert_html_has_tag(actual_html, 'label', :for => 'user_addresses_attributes_1_businesses_attributes_0_name', :content => 'Name')
+ assert_html_has_tag(actual_html, 'input', :type => 'text', :id => 'user_addresses_attributes_1_businesses_attributes_0_name', :name => 'user[addresses_attributes][1][businesses_attributes][0][name]')
end
it 'should display fields for nested forms with custom indices' do
@@ -951,59 +954,59 @@ def standard_builder(object=@user)
html
end
- assert_has_tag('label', :for => 'user_addresses_attributes_1_businesses_attributes_a_name', :content => 'Name') { actual_html }
- assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_1_businesses_attributes_a_name', :name => 'user[addresses_attributes][1][businesses_attributes][a][name]') { actual_html }
+ assert_html_has_tag(actual_html, 'label', :for => 'user_addresses_attributes_1_businesses_attributes_a_name', :content => 'Name')
+ assert_html_has_tag(actual_html, 'input', :type => 'text', :id => 'user_addresses_attributes_1_businesses_attributes_a_name', :name => 'user[addresses_attributes][1][businesses_attributes][a][name]')
end
it 'should display nested children fields in erb' do
- visit '/erb/fields_for'
+ get "/erb/fields_for"
# Telephone
- assert_have_selector('label', :for => 'markup_user_telephone_attributes_number')
- assert_have_selector('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
+ assert_response_has_tag('label', :for => 'markup_user_telephone_attributes_number')
+ assert_response_has_tag('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
# Address 1 (Saved)
- assert_have_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
- assert_have_selector('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
- assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
- assert_have_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
+ assert_response_has_tag('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
+ assert_response_has_tag('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
+ assert_response_has_tag('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
+ assert_response_has_tag('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
# Address 2 (New)
- assert_have_no_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
- assert_have_selector('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
- assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
- assert_have_no_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
+ assert_response_has_no_tag('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
+ assert_response_has_tag('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
+ assert_response_has_tag('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
+ assert_response_has_no_tag('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
end
it 'should display nested children fields in haml' do
- visit '/haml/fields_for'
+ get "/haml/fields_for"
# Telephone
- assert_have_selector('label', :for => 'markup_user_telephone_attributes_number')
- assert_have_selector('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
+ assert_response_has_tag('label', :for => 'markup_user_telephone_attributes_number')
+ assert_response_has_tag('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
# Address 1 (Saved)
- assert_have_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
- assert_have_selector('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
- assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
- assert_have_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
+ assert_response_has_tag('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
+ assert_response_has_tag('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
+ assert_response_has_tag('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
+ assert_response_has_tag('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
# Address 2 (New)
- assert_have_no_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
- assert_have_selector('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
- assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
- assert_have_no_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
+ assert_response_has_no_tag('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
+ assert_response_has_tag('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
+ assert_response_has_tag('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
+ assert_response_has_no_tag('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
end
it 'should display nested children fields in slim' do
- visit '/slim/fields_for'
+ get "/slim/fields_for"
# Telephone
- assert_have_selector('label', :for => 'markup_user_telephone_attributes_number')
- assert_have_selector('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
+ assert_response_has_tag('label', :for => 'markup_user_telephone_attributes_number')
+ assert_response_has_tag('input', :type => 'text', :id => 'markup_user_telephone_attributes_number', :name => 'markup_user[telephone_attributes][number]', :value => "62634576545")
# Address 1 (Saved)
- assert_have_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
- assert_have_selector('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
- assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
- assert_have_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
+ assert_response_has_tag('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_0_id', :name => "markup_user[addresses_attributes][0][id]", :value => '25')
+ assert_response_has_tag('label', :for => 'markup_user_addresses_attributes_0_name', :content => 'Name')
+ assert_response_has_tag('input', :type => 'text', :id => 'markup_user_addresses_attributes_0_name', :name => 'markup_user[addresses_attributes][0][name]')
+ assert_response_has_tag('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_0__destroy', :name => 'markup_user[addresses_attributes][0][_destroy]')
# Address 2 (New)
- assert_have_no_selector('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
- assert_have_selector('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
- assert_have_selector('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
- assert_have_no_selector('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
+ assert_response_has_no_tag('input', :type => 'hidden', :id => 'markup_user_addresses_attributes_1_id')
+ assert_response_has_tag('label', :for => 'markup_user_addresses_attributes_1_name', :content => 'Name')
+ assert_response_has_tag('input', :type => 'text', :id => 'markup_user_addresses_attributes_1_name', :name => 'markup_user[addresses_attributes][1][name]')
+ assert_response_has_no_tag('input', :type => 'checkbox', :id => 'markup_user_addresses_attributes_1__destroy')
end
end
@@ -1014,182 +1017,182 @@ def standard_builder(object=@user)
describe 'for #text_field_block method' do
it 'should display correct text field block html' do
actual_html = standard_builder.text_field_block(:first_name, :class => 'large', :caption => "FName")
- assert_has_tag('p label', :for => 'user_first_name', :content => "FName") { actual_html }
- assert_has_tag('p input.large[type=text]', :value => "Joe", :id => 'user_first_name', :name => 'user[first_name]') { actual_html }
+ assert_html_has_tag(actual_html, 'p label', :for => 'user_first_name', :content => "FName")
+ assert_html_has_tag(actual_html, 'p input.large[type=text]', :value => "Joe", :id => 'user_first_name', :name => 'user[first_name]')
end
it 'should display correct text field block in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
- assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
+ assert_response_has_tag '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
end
it 'should display correct text field block in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
- assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
+ assert_response_has_tag '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
end
it 'should display correct text field block in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
- assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_username', :content => "Nickname: ", :class => 'label'
+ assert_response_has_tag '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
end
end
describe 'for #text_area_block method' do
it 'should display correct text area block html' do
actual_html = standard_builder.text_area_block(:about, :class => 'large', :caption => "About Me")
- assert_has_tag('p label', :for => 'user_about', :content => "About Me") { actual_html }
- assert_has_tag('p textarea', :id => 'user_about', :name => 'user[about]') { actual_html }
+ assert_html_has_tag(actual_html, 'p label', :for => 'user_about', :content => "About Me")
+ assert_html_has_tag(actual_html, 'p textarea', :id => 'user_about', :name => 'user[about]')
end
it 'should display correct text area block in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
- assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_about', :content => "About: "
+ assert_response_has_tag '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
end
it 'should display correct text area block in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
- assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_about', :content => "About: "
+ assert_response_has_tag '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
end
it 'should display correct text area block in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_about', :content => "About: "
- assert_have_selector '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_about', :content => "About: "
+ assert_response_has_tag '#demo2 p textarea', :name => 'markup_user[about]', :id => 'markup_user_about'
end
end
describe 'for #password_field_block method' do
it 'should display correct password field block html' do
actual_html = standard_builder.password_field_block(:keycode, :class => 'large', :caption => "Code: ")
- assert_has_tag('p label', :for => 'user_keycode', :content => "Code: ") { actual_html }
- assert_has_tag('p input.large[type=password]', :id => 'user_keycode', :name => 'user[keycode]') { actual_html }
+ assert_html_has_tag(actual_html, 'p label', :for => 'user_keycode', :content => "Code: ")
+ assert_html_has_tag(actual_html, 'p input.large[type=password]', :id => 'user_keycode', :name => 'user[keycode]')
end
it 'should display correct password field block in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
- assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
+ assert_response_has_tag '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
end
it 'should display correct password field block in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
- assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
+ assert_response_has_tag '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
end
it 'should display correct password field block in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
- assert_have_selector '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_code', :content => "Code: "
+ assert_response_has_tag '#demo2 p input', :type => 'password', :name => 'markup_user[code]', :id => 'markup_user_code'
end
end
describe 'for #file_field_block method' do
it 'should display correct file field block html' do
actual_html = standard_builder.file_field_block(:photo, :class => 'large', :caption => "Photo: ")
- assert_has_tag('p label', :for => 'user_photo', :content => "Photo: ") { actual_html }
- assert_has_tag('p input.large[type=file]', :id => 'user_photo', :name => 'user[photo]') { actual_html }
+ assert_html_has_tag(actual_html, 'p label', :for => 'user_photo', :content => "Photo: ")
+ assert_html_has_tag(actual_html, 'p input.large[type=file]', :id => 'user_photo', :name => 'user[photo]')
end
it 'should display correct file field block in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
- assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
+ assert_response_has_tag '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
end
it 'should display correct file field block in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
- assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
+ assert_response_has_tag '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
end
it 'should display correct file field block in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
- assert_have_selector '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_photo', :content => "Photo: "
+ assert_response_has_tag '#demo2 p input.upload', :type => 'file', :name => 'markup_user[photo]', :id => 'markup_user_photo'
end
end
describe 'for #check_box_block method' do
it 'should display correct check box block html' do
actual_html = standard_builder.check_box_block(:remember_me, :class => 'large', :caption => "Remember session?")
- assert_has_tag('p label', :for => 'user_remember_me', :content => "Remember session?") { actual_html }
- assert_has_tag('p input.large[type=checkbox]', :id => 'user_remember_me', :name => 'user[remember_me]') { actual_html }
+ assert_html_has_tag(actual_html, 'p label', :for => 'user_remember_me', :content => "Remember session?")
+ assert_html_has_tag(actual_html, 'p input.large[type=checkbox]', :id => 'user_remember_me', :name => 'user[remember_me]')
end
it 'should display correct check box block in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
- assert_have_selector '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
+ assert_response_has_tag '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
end
it 'should display correct check box block in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
- assert_have_selector '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
+ assert_response_has_tag '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
end
it 'should display correct check box block in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
- assert_have_selector '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_remember_me', :content => "Remember me: "
+ assert_response_has_tag '#demo2 p input.checker', :type => 'checkbox', :name => 'markup_user[remember_me]'
end
end
describe 'for #select_block method' do
it 'should display correct select_block block html' do
actual_html = standard_builder.select_block(:country, :options => ['USA', 'Canada'], :class => 'large', :caption => "Your country")
- assert_has_tag('p label', :for => 'user_country', :content => "Your country") { actual_html }
- assert_has_tag('p select', :id => 'user_country', :name => 'user[country]') { actual_html }
- assert_has_tag('p select option', :content => 'USA') { actual_html }
- assert_has_tag('p select option', :content => 'Canada') { actual_html }
+ assert_html_has_tag(actual_html, 'p label', :for => 'user_country', :content => "Your country")
+ assert_html_has_tag(actual_html, 'p select', :id => 'user_country', :name => 'user[country]')
+ assert_html_has_tag(actual_html, 'p select option', :content => 'USA')
+ assert_html_has_tag(actual_html, 'p select option', :content => 'Canada')
end
it 'should display correct select_block block in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_state', :content => "State: "
- assert_have_selector '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
- assert_have_selector '#demo2 p select option', :content => 'California'
- assert_have_selector '#demo2 p select option', :content => 'Texas'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_state', :content => "State: "
+ assert_response_has_tag '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
+ assert_response_has_tag '#demo2 p select option', :content => 'California'
+ assert_response_has_tag '#demo2 p select option', :content => 'Texas'
end
it 'should display correct select_block block in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_state', :content => "State: "
- assert_have_selector '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_state', :content => "State: "
+ assert_response_has_tag '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
end
it 'should display correct select_block block in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo2 p label', :for => 'markup_user_state', :content => "State: "
- assert_have_selector '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo2 p label', :for => 'markup_user_state', :content => "State: "
+ assert_response_has_tag '#demo2 p select', :name => 'markup_user[state]', :id => 'markup_user_state'
end
end
describe 'for #submit_block method' do
it 'should display correct submit block html' do
actual_html = standard_builder.submit_block("Update", :class => 'large')
- assert_has_tag('p input.large[type=submit]', :value => 'Update') { actual_html }
+ assert_html_has_tag(actual_html, 'p input.large[type=submit]', :value => 'Update')
end
it 'should display correct submit block in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
+ get "/haml/form_for"
+ assert_response_has_tag '#demo2 p input', :type => 'submit', :class => 'button'
end
it 'should display correct submit block in erb' do
- visit '/erb/form_for'
- assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
+ get "/erb/form_for"
+ assert_response_has_tag '#demo2 p input', :type => 'submit', :class => 'button'
end
it 'should display correct submit block in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
+ get "/slim/form_for"
+ assert_response_has_tag '#demo2 p input', :type => 'submit', :class => 'button'
end
end
@@ -1200,17 +1203,255 @@ def standard_builder(object=@user)
it 'should display correct image submit block html' do
actual_html = standard_builder.image_submit_block("buttons/ok.png", :class => 'large')
- assert_has_tag('p input.large[type=image]', :src => "/images/buttons/ok.png?#{@stamp}") { actual_html }
+ assert_html_has_tag(actual_html, 'p input.large[type=image]', :src => "/images/buttons/ok.png?#{@stamp}")
end
it 'should display correct image submit block in haml' do
- visit '/haml/form_for'
- assert_have_selector '#demo2 p input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
+ get "/haml/form_for"
+ assert_response_has_tag '#demo2 p input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
end
it 'should display correct image submit block in slim' do
- visit '/slim/form_for'
- assert_have_selector '#demo2 p input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
+ get "/slim/form_for"
+ assert_response_has_tag '#demo2 p input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
+ end
+ end
+
+ describe 'for #datetime_field method' do
+ it 'should display correct datetime field html' do
+ actual_html = standard_builder.datetime_field(:datetime)
+ assert_html_has_tag(actual_html, 'input[type=datetime]', :id => 'user_datetime', :name => 'user[datetime]')
+ end
+
+ it 'should format DateTime to correct value if min and max and value options exist' do
+ max = DateTime.new(2000, 4, 1, 12, 0, 0)
+ min = DateTime.new(1993, 2, 24, 12, 30, 45)
+ value = DateTime.new(2000, 4, 1, 12, 0, 0)
+ actual_html = standard_builder.datetime_field(:datetime, :max => max, :min => min, :value => value)
+ expected = {
+ :id => 'user_datetime',
+ :max => "2000-04-01T12:00:00.000+0000",
+ :min => "1993-02-24T12:30:45.000+0000",
+ :value => "2000-04-01T12:00:00.000+0000"
+ }
+ assert_html_has_tag(actual_html, 'input[type=datetime]', expected)
+ end
+
+ it 'should display correct datetime field in haml' do
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input[type=datetime]', :id => 'markup_user_datetime', :max => "2000-04-01T12:00:00.000+0000"
+ end
+
+ it 'should display correct datetime field in erb' do
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input[type=datetime]', :id => 'markup_user_datetime', :max => "2000-04-01T12:00:00.000+0000"
+ end
+
+ it 'should display correct datetime field in slim' do
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input[type=datetime]', :id => 'markup_user_datetime', :max => "2000-04-01T12:00:00.000+0000"
+ end
+ end
+
+ describe 'for #datetime_local_field method' do
+ it 'should display correct datetime-local field html' do
+ actual_html = standard_builder.datetime_local_field(:datetime_local)
+ assert_html_has_tag(actual_html, 'input[type=datetime-local]', :id => 'user_datetime_local', :name => 'user[datetime_local]')
+ end
+
+ it 'should format DateTime to correct value if min and max and value options exist' do
+ max = DateTime.new(2000, 4, 1, 12, 0, 0)
+ min = DateTime.new(1993, 2, 24, 12, 30, 45)
+ value = DateTime.new(2000, 4, 1, 12, 0, 0)
+ actual_html = standard_builder.datetime_local_field(:datetime_local, :max => max, :min => min, :value => value)
+ expected = {
+ :id => 'user_datetime_local',
+ :max => "2000-04-01T12:00:00",
+ :min => "1993-02-24T12:30:45",
+ :value => "2000-04-01T12:00:00"
+ }
+ assert_html_has_tag(actual_html, 'input[type=datetime-local]', expected)
+ end
+
+ it 'should display correct datetime-local field in haml' do
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input[type=datetime-local]', :id => 'markup_user_datetime_local'
+ end
+
+ it 'should display correct datetime-local field in erb' do
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input[type=datetime-local]', :id => 'markup_user_datetime_local'
+ end
+
+ it 'should display correct datetime-local field in slim' do
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input[type=datetime-local]', :id => 'markup_user_datetime_local'
+ end
+ end
+
+ describe 'for #date_field method' do
+ it 'should display correct date field html' do
+ actual_html = standard_builder.date_field(:date)
+ assert_html_has_tag(actual_html, 'input[type=date]', :id => 'user_date', :name => 'user[date]')
+ end
+
+ it 'should format DateTime to correct value if min and max and value options exist' do
+ max = DateTime.new(2000, 4, 1)
+ min = DateTime.new(1993, 2, 24)
+ value = DateTime.new(2000, 4, 1)
+ actual_html = standard_builder.date_field(:date, :max => max, :min => min, :value => value)
+ expected = {
+ :id => 'user_date',
+ :max => "2000-04-01",
+ :min => "1993-02-24",
+ :value => "2000-04-01"
+ }
+ assert_html_has_tag(actual_html, 'input[type=date]', expected)
+ end
+
+ it 'should display correct date field in haml' do
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input[type=date]', :id => 'markup_user_date'
+ end
+
+ it 'should display correct date field in erb' do
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input[type=date]', :id => 'markup_user_date'
+ end
+
+ it 'should display correct date field in slim' do
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input[type=date]', :id => 'markup_user_date'
+ end
+ end
+
+ describe 'for #month_field method' do
+ it 'should display correct month field html' do
+ actual_html = standard_builder.month_field(:month)
+ assert_html_has_tag(actual_html, 'input[type=month]', :id => 'user_month', :name => 'user[month]')
+ end
+
+ it 'should format DateTime to correct value if min and max and value options exist' do
+ max = DateTime.new(2000, 4, 1)
+ min = DateTime.new(1993, 2, 24)
+ value = DateTime.new(2000, 4, 1)
+ actual_html = standard_builder.month_field(:month, :max => max, :min => min, :value => value)
+ expected = {
+ :id => 'user_month',
+ :max => "2000-04",
+ :min => "1993-02",
+ :value => "2000-04"
+ }
+ assert_html_has_tag(actual_html, 'input[type=month]', expected)
+ end
+
+ it 'should display correct month field in haml' do
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input[type=month]', :id => 'markup_user_month'
+ end
+
+ it 'should display correct month field in erb' do
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input[type=month]', :id => 'markup_user_month'
+ end
+
+ it 'should display correct month field in slim' do
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input[type=month]', :id => 'markup_user_month'
+ end
+ end
+
+ describe 'for #week_field method' do
+ it 'should display correct week field html' do
+ actual_html = standard_builder.week_field(:week)
+ assert_html_has_tag(actual_html, 'input[type=week]', :id => 'user_week', :name => 'user[week]')
+ end
+
+ it 'should format DateTime to correct value if min and max and value options exist' do
+ max = DateTime.new(2000, 4, 1)
+ min = DateTime.new(1993, 2, 24)
+ value = DateTime.new(2000, 4, 1)
+ actual_html = standard_builder.week_field(:week, :max => max, :min => min, :value => value)
+ expected = {
+ :id => 'user_week',
+ :max => "2000-W13",
+ :min => "1993-W08",
+ :value => "2000-W13"
+ }
+ assert_html_has_tag(actual_html, 'input[type=week]', expected)
+ end
+
+ it 'should display correct week field in haml' do
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input[type=week]', :id => 'markup_user_week'
+ end
+
+ it 'should display correct week field in erb' do
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input[type=week]', :id => 'markup_user_week'
+ end
+
+ it 'should display correct week field in slim' do
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input[type=week]', :id => 'markup_user_week'
+ end
+ end
+
+ describe 'for #time_field method' do
+ it 'should display correct time field html' do
+ actual_html = standard_builder.time_field(:time)
+ assert_html_has_tag(actual_html, 'input[type=time]', :id => 'user_time', :name => 'user[time]')
+ end
+
+ it 'should format DateTime to correct value if min and max and value options exist' do
+ max = Time.new(2008, 6, 21, 13, 30, 0)
+ min = Time.new(1993, 2, 24, 1, 19, 12)
+ value = Time.new(2008, 6, 21, 13, 30, 0)
+ actual_html = standard_builder.time_field(:time, :max => max, :min => min, :value => value)
+ expected = {
+ :id => 'user_time',
+ :max => "13:30:00.000",
+ :min => "01:19:12.000",
+ :value => "13:30:00.000"
+ }
+ assert_html_has_tag(actual_html, 'input[type=time]', expected)
+ end
+
+ it 'should display correct time field in haml' do
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input[type=time]', :id => 'markup_user_time'
+ end
+
+ it 'should display correct time field in erb' do
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input[type=time]', :id => 'markup_user_time'
+ end
+
+ it 'should display correct time field in slim' do
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input[type=time]', :id => 'markup_user_time'
+ end
+ end
+
+ describe 'for #color_field method' do
+ it 'should display correct color field html' do
+ actual_html = standard_builder.color_field(:color)
+ assert_html_has_tag(actual_html, 'input[type=color]', :id => 'user_color', :name => 'user[color]')
+ end
+
+ it 'should display correct color field in haml' do
+ get "/haml/form_for"
+ assert_response_has_tag '#demo input[type=color]', :id => 'markup_user_color', :value => "#ff0000"
+ end
+
+ it 'should display correct color field in erb' do
+ get "/erb/form_for"
+ assert_response_has_tag '#demo input[type=color]', :id => 'markup_user_color', :value => "#ff0000"
+ end
+
+ it 'should display correct color field in slim' do
+ get "/slim/form_for"
+ assert_response_has_tag '#demo input[type=color]', :id => 'markup_user_color', :value => "#ff0000"
end
end
end
diff --git a/padrino-helpers/test/test_form_helpers.rb b/padrino-helpers/test/test_form_helpers.rb
index 86ab8754f..76f7a75db 100644
--- a/padrino-helpers/test/test_form_helpers.rb
+++ b/padrino-helpers/test/test_form_helpers.rb
@@ -15,664 +15,665 @@ def protect_from_csrf; false; end
describe 'for #form_tag method' do
it 'should display correct forms in ruby' do
actual_html = form_tag('/register', :"accept-charset" => "UTF-8", :class => 'test', :method => "post") { "Demo" }
- assert_has_tag(:form, :"accept-charset" => "UTF-8", :class => "test") { actual_html }
- assert_has_tag('form input', :type => 'hidden', :name => '_method', :count => 0) { actual_html }
+ assert_html_has_tag(actual_html, :form, :"accept-charset" => "UTF-8", :class => "test")
+ assert_html_has_tag(actual_html, 'form input', :type => 'hidden', :name => '_method', :count => 0)
end
it 'should display correct text inputs within form_tag' do
actual_html = form_tag('/register', :"accept-charset" => "UTF-8", :class => 'test') { text_field_tag(:username) }
- assert_has_tag('form input', :type => 'text', :name => "username") { actual_html }
+ assert_html_has_tag(actual_html, 'form input', :type => 'text', :name => "username")
+ assert_html_has_no_tag(actual_html, 'form input', :type => 'hidden', :name => "_method")
end
it 'should display correct form with remote' do
actual_html = form_tag('/update', :"accept-charset" => "UTF-8", :class => 'put-form', :remote => true) { "Demo" }
- assert_has_tag(:form, :class => "put-form", :"accept-charset" => "UTF-8", :"data-remote" => 'true') { actual_html }
- assert_has_no_tag(:form, "data-method" => 'post') { actual_html }
+ assert_html_has_tag(actual_html, :form, :class => "put-form", :"accept-charset" => "UTF-8", :"data-remote" => 'true')
+ assert_html_has_no_tag(actual_html, :form, "data-method" => 'post')
end
it 'should display correct form with remote and method is put' do
actual_html = form_tag('/update', :"accept-charset" => "UTF-8", :method => 'put', :remote => true) { "Demo" }
- assert_has_tag(:form, "data-remote" => 'true', :"accept-charset" => "UTF-8") { actual_html }
- assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
+ assert_html_has_tag(actual_html, :form, "data-remote" => 'true', :"accept-charset" => "UTF-8")
+ assert_html_has_tag(actual_html, 'form input', :type => 'hidden', :name => "_method", :value => 'put')
end
it 'should display correct form with method :put' do
actual_html = form_tag('/update', :"accept-charset" => "UTF-8", :class => 'put-form', :method => "put") { "Demo" }
- assert_has_tag(:form, :class => "put-form", :"accept-charset" => "UTF-8", :method => 'post') { actual_html }
- assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'put') { actual_html }
+ assert_html_has_tag(actual_html, :form, :class => "put-form", :"accept-charset" => "UTF-8", :method => 'post')
+ assert_html_has_tag(actual_html, 'form input', :type => 'hidden', :name => "_method", :value => 'put')
end
it 'should display correct form with method :delete and charset' do
actual_html = form_tag('/remove', :"accept-charset" => "UTF-8", :class => 'delete-form', :method => "delete") { "Demo" }
- assert_has_tag(:form, :class => "delete-form", :"accept-charset" => "UTF-8", :method => 'post') { actual_html }
- assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'delete') { actual_html }
+ assert_html_has_tag(actual_html, :form, :class => "delete-form", :"accept-charset" => "UTF-8", :method => 'post')
+ assert_html_has_tag(actual_html, 'form input', :type => 'hidden', :name => "_method", :value => 'delete')
end
it 'should display correct form with charset' do
actual_html = form_tag('/charset', :"accept-charset" => "UTF-8", :class => 'charset-form') { "Demo" }
- assert_has_tag(:form, :class => "charset-form", :"accept-charset" => "UTF-8", :method => 'post') { actual_html }
+ assert_html_has_tag(actual_html, :form, :class => "charset-form", :"accept-charset" => "UTF-8", :method => 'post')
end
it 'should display correct form with multipart encoding' do
actual_html = form_tag('/remove', :"accept-charset" => "UTF-8", :multipart => true) { "Demo" }
- assert_has_tag(:form, :enctype => "multipart/form-data") { actual_html }
+ assert_html_has_tag(actual_html, :form, :enctype => "multipart/form-data")
end
it 'should have an authenticity_token for method :post, :put or :delete' do
%w(post put delete).each do |method|
actual_html = form_tag('/modify', :method => method) { "Demo" }
- assert_has_tag(:input, :name => 'authenticity_token') { actual_html }
+ assert_html_has_tag(actual_html, :input, :name => 'authenticity_token')
end
end
it 'should not have an authenticity_token if method: :get' do
actual_html = form_tag('/get', :method => :get) { "Demo" }
- assert_has_no_tag(:input, :name => 'authenticity_token') { actual_html }
+ assert_html_has_no_tag(actual_html, :input, :name => 'authenticity_token')
end
it 'should have an authenticity_token by default' do
actual_html = form_tag('/superadmindelete') { "Demo" }
- assert_has_tag(:input, :name => 'authenticity_token') { actual_html }
+ assert_html_has_tag(actual_html, :input, :name => 'authenticity_token')
end
it 'should create csrf meta tags with token and param - #csrf_meta_tags' do
actual_html = csrf_meta_tags
- assert_has_tag(:meta, :name => 'csrf-param') { actual_html }
- assert_has_tag(:meta, :name => 'csrf-token') { actual_html }
+ assert_html_has_tag(actual_html, :meta, :name => 'csrf-param')
+ assert_html_has_tag(actual_html, :meta, :name => 'csrf-token')
end
it 'should have an authenticity_token by default' do
actual_html = form_tag('/superadmindelete') { "Demo" }
- assert_has_tag(:input, :name => 'authenticity_token') { actual_html }
+ assert_html_has_tag(actual_html, :input, :name => 'authenticity_token')
end
it 'should not have an authenticity_token if passing protect_from_csrf: false' do
actual_html = form_tag('/superadmindelete', :protect_from_csrf => false) { "Demo" }
- assert_has_no_tag(:input, :name => 'authenticity_token') { actual_html }
+ assert_html_has_no_tag(actual_html, :input, :name => 'authenticity_token')
end
it 'should not have an authenticity_token if protect_from_csrf is false on app settings' do
self.expects(:settings).returns(UnprotectedApp.new)
actual_html = form_tag('/superadmindelete') { "Demo" }
- assert_has_no_tag(:input, :name => 'authenticity_token') { actual_html }
+ assert_html_has_no_tag(actual_html, :input, :name => 'authenticity_token')
end
it 'should not include protect_from_csrf as an attribute of form element' do
actual_html = form_tag('/superadmindelete', :protect_from_csrf => true){ "Demo" }
- assert_has_no_tag(:form, protect_from_csrf: "true"){ actual_html }
+ assert_html_has_no_tag(actual_html, :form, protect_from_csrf: "true")
end
it 'should display correct forms in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form', :action => '/simple'
- assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
- assert_have_selector 'form.simple-form input', :name => 'authenticity_token'
- assert_have_no_selector 'form.no-protection input', :name => 'authenticity_token'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form', :action => '/simple'
+ assert_response_has_tag 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
+ assert_response_has_tag 'form.simple-form input', :name => 'authenticity_token'
+ assert_response_has_no_tag 'form.no-protection input', :name => 'authenticity_token'
end
it 'should display correct forms in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form', :action => '/simple'
- assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
- assert_have_selector 'form.simple-form input', :name => 'authenticity_token'
- assert_have_no_selector 'form.no-protection input', :name => 'authenticity_token'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form', :action => '/simple'
+ assert_response_has_tag 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
+ assert_response_has_tag 'form.simple-form input', :name => 'authenticity_token'
+ assert_response_has_no_tag 'form.no-protection input', :name => 'authenticity_token'
end
it 'should display correct forms in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form', :action => '/simple'
- assert_have_selector 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
- assert_have_selector 'form.simple-form input', :name => 'authenticity_token'
- assert_have_no_selector 'form.no-protection input', :name => 'authenticity_token'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form', :action => '/simple'
+ assert_response_has_tag 'form.advanced-form', :action => '/advanced', :id => 'advanced', :method => 'get'
+ assert_response_has_tag 'form.simple-form input', :name => 'authenticity_token'
+ assert_response_has_no_tag 'form.no-protection input', :name => 'authenticity_token'
end
end
describe 'for #field_set_tag method' do
it 'should display correct field_sets in ruby' do
actual_html = field_set_tag("Basic", :class => 'basic') { "Demo" }
- assert_has_tag(:fieldset, :class => 'basic') { actual_html }
- assert_has_tag('fieldset legend', :content => "Basic") { actual_html }
+ assert_html_has_tag(actual_html, :fieldset, :class => 'basic')
+ assert_html_has_tag(actual_html, 'fieldset legend', :content => "Basic")
end
it 'should display correct field_sets in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form fieldset', :count => 1
- assert_have_no_selector 'form.simple-form fieldset legend'
- assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
- assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form fieldset', :count => 1
+ assert_response_has_no_tag 'form.simple-form fieldset legend'
+ assert_response_has_tag 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
+ assert_response_has_tag 'form.advanced-form fieldset legend', :content => "Advanced"
end
it 'should display correct field_sets in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form fieldset', :count => 1
- assert_have_no_selector 'form.simple-form fieldset legend'
- assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
- assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form fieldset', :count => 1
+ assert_response_has_no_tag 'form.simple-form fieldset legend'
+ assert_response_has_tag 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
+ assert_response_has_tag 'form.advanced-form fieldset legend', :content => "Advanced"
end
it 'should display correct field_sets in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form fieldset', :count => 1
- assert_have_no_selector 'form.simple-form fieldset legend'
- assert_have_selector 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
- assert_have_selector 'form.advanced-form fieldset legend', :content => "Advanced"
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form fieldset', :count => 1
+ assert_response_has_no_tag 'form.simple-form fieldset legend'
+ assert_response_has_tag 'form.advanced-form fieldset', :count => 1, :class => 'advanced-field-set'
+ assert_response_has_tag 'form.advanced-form fieldset legend', :content => "Advanced"
end
end
describe 'for #error_messages_for method' do
it 'should display correct error messages list in ruby' do
- user = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
+ user = mock_model("User", :errors => { :a => "1", :b => "2" })
actual_html = error_messages_for(user)
- assert_has_tag('div.field-errors') { actual_html }
- assert_has_tag('div.field-errors h2', :content => "2 errors prohibited this User from being saved") { actual_html }
- assert_has_tag('div.field-errors p', :content => "There were problems with the following fields:") { actual_html }
- assert_has_tag('div.field-errors ul') { actual_html }
- assert_has_tag('div.field-errors ul li', :count => 2) { actual_html }
+ assert_html_has_tag(actual_html, 'div.field-errors')
+ assert_html_has_tag(actual_html, 'div.field-errors h2', :content => "2 errors prohibited this User from being saved")
+ assert_html_has_tag(actual_html, 'div.field-errors p', :content => "There were problems with the following fields:")
+ assert_html_has_tag(actual_html, 'div.field-errors ul')
+ assert_html_has_tag(actual_html, 'div.field-errors ul li', :count => 2)
end
it 'should display correct error messages list in erb' do
- visit '/erb/form_tag'
- assert_have_no_selector 'form.simple-form .field-errors'
- assert_have_selector 'form.advanced-form .field-errors'
- assert_have_selector 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
- assert_have_selector 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
- assert_have_selector 'form.advanced-form .field-errors ul'
- assert_have_selector 'form.advanced-form .field-errors ul li', :count => 4
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Email must be an email"
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Fake must be valid"
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Second must be present"
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Third must be a number"
+ get "/erb/form_tag"
+ assert_response_has_no_tag 'form.simple-form .field-errors'
+ assert_response_has_tag 'form.advanced-form .field-errors'
+ assert_response_has_tag 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
+ assert_response_has_tag 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
+ assert_response_has_tag 'form.advanced-form .field-errors ul'
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :count => 4
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Email must be an email"
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Fake must be valid"
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Second must be present"
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Third must be a number"
end
it 'should display correct error messages list in haml' do
- visit '/haml/form_tag'
- assert_have_no_selector 'form.simple-form .field-errors'
- assert_have_selector 'form.advanced-form .field-errors'
- assert_have_selector 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
- assert_have_selector 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
- assert_have_selector 'form.advanced-form .field-errors ul'
- assert_have_selector 'form.advanced-form .field-errors ul li', :count => 4
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Email must be an email"
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Fake must be valid"
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Second must be present"
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Third must be a number"
+ get "/haml/form_tag"
+ assert_response_has_no_tag 'form.simple-form .field-errors'
+ assert_response_has_tag 'form.advanced-form .field-errors'
+ assert_response_has_tag 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
+ assert_response_has_tag 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
+ assert_response_has_tag 'form.advanced-form .field-errors ul'
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :count => 4
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Email must be an email"
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Fake must be valid"
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Second must be present"
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Third must be a number"
end
it 'should display correct error messages list in slim' do
- visit '/slim/form_tag'
- assert_have_no_selector 'form.simple-form .field-errors'
- assert_have_selector 'form.advanced-form .field-errors'
- assert_have_selector 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
- assert_have_selector 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
- assert_have_selector 'form.advanced-form .field-errors ul'
- assert_have_selector 'form.advanced-form .field-errors ul li', :count => 4
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Email must be an email"
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Fake must be valid"
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Second must be present"
- assert_have_selector 'form.advanced-form .field-errors ul li', :content => "Third must be a number"
+ get "/slim/form_tag"
+ assert_response_has_no_tag 'form.simple-form .field-errors'
+ assert_response_has_tag 'form.advanced-form .field-errors'
+ assert_response_has_tag 'form.advanced-form .field-errors h2', :content => "There are problems with saving user!"
+ assert_response_has_tag 'form.advanced-form .field-errors p', :content => "There were problems with the following fields:"
+ assert_response_has_tag 'form.advanced-form .field-errors ul'
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :count => 4
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Email must be an email"
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Fake must be valid"
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Second must be present"
+ assert_response_has_tag 'form.advanced-form .field-errors ul li', :content => "Third must be a number"
end
end
describe 'for #error_message_on method' do
it 'should display correct error message on specified model name in ruby' do
- @user = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
+ @user = mock_model("User", :errors => { :a => "1", :b => "2" })
actual_html = error_message_on(:user, :a, :prepend => "foo", :append => "bar")
- assert_has_tag('span.error', :content => "foo 1 bar") { actual_html }
+ assert_html_has_tag(actual_html, 'span.error', :content => "foo 1 bar")
end
it 'should display correct error message on specified object in ruby' do
- @bob = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
+ @bob = mock_model("User", :errors => { :a => "1", :b => "2" })
actual_html = error_message_on(@bob, :a, :prepend => "foo", :append => "bar")
- assert_has_tag('span.error', :content => "foo 1 bar") { actual_html }
+ assert_html_has_tag(actual_html, 'span.error', :content => "foo 1 bar")
end
it 'should display no message when error is not present' do
- @user = mock_model("User", :errors => { :a => "1", :b => "2" }, :blank? => false)
+ @user = mock_model("User", :errors => { :a => "1", :b => "2" })
actual_html = error_message_on(:user, :fake, :prepend => "foo", :append => "bar")
- assert actual_html.blank?
+ assert_empty actual_html
end
it 'should display no message when error is not present in an Array' do
- @user = mock_model("User", :errors => { :a => [], :b => "2" }, :blank? => false)
+ @user = mock_model("User", :errors => { :a => [], :b => "2" })
actual_html = error_message_on(:user, :a, :prepend => "foo", :append => "bar")
- assert actual_html.blank?
+ assert_empty actual_html
end
end
describe 'for #label_tag method' do
it 'should display label tag in ruby' do
actual_html = label_tag(:username, :class => 'long-label', :caption => "Nickname")
- assert_has_tag(:label, :for => 'username', :class => 'long-label', :content => "Nickname") { actual_html }
+ assert_html_has_tag(actual_html, :label, :for => 'username', :class => 'long-label', :content => "Nickname")
end
it 'should display label tag in ruby with required' do
actual_html = label_tag(:username, :caption => "Nickname", :required => true)
- assert_has_tag(:label, :for => 'username', :content => 'Nickname') { actual_html }
- assert_has_tag('label[for=username] span.required', :content => "*") { actual_html }
+ assert_html_has_tag(actual_html, :label, :for => 'username', :content => 'Nickname')
+ assert_html_has_tag(actual_html, 'label[for=username] span.required', :content => "*")
end
it 'should display label tag in ruby with a block' do
actual_html = label_tag(:admin, :class => 'long-label') { input_tag :checkbox }
- assert_has_tag(:label, :for => 'admin', :class => 'long-label', :content => "Admin") { actual_html }
- assert_has_tag('label input[type=checkbox]') { actual_html }
+ assert_html_has_tag(actual_html, :label, :for => 'admin', :class => 'long-label', :content => "Admin")
+ assert_html_has_tag(actual_html, 'label input[type=checkbox]')
end
it 'should display label tag in erb for simple form' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form label', :count => 9
- assert_have_selector 'form.simple-form label', :content => "Username", :for => 'username'
- assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
- assert_have_selector 'form.simple-form label', :content => "Gender", :for => 'gender'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form label', :count => 9
+ assert_response_has_tag 'form.simple-form label', :content => "Username", :for => 'username'
+ assert_response_has_tag 'form.simple-form label', :content => "Password", :for => 'password'
+ assert_response_has_tag 'form.simple-form label', :content => "Gender", :for => 'gender'
end
it 'should display label tag in erb for advanced form' do
- visit '/erb/form_tag'
- assert_have_selector 'form.advanced-form label', :count => 11
- assert_have_selector 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
- assert_have_selector 'form.advanced-form label.first', :content => "Password", :for => 'password'
- assert_have_selector 'form.advanced-form label.about', :content => "About Me", :for => 'about'
- assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
- assert_have_selector 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.advanced-form label', :count => 11
+ assert_response_has_tag 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
+ assert_response_has_tag 'form.advanced-form label.first', :content => "Password", :for => 'password'
+ assert_response_has_tag 'form.advanced-form label.about', :content => "About Me", :for => 'about'
+ assert_response_has_tag 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
+ assert_response_has_tag 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
end
it 'should display label tag in haml for simple form' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form label', :count => 9
- assert_have_selector 'form.simple-form label', :content => "Username", :for => 'username'
- assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
- assert_have_selector 'form.simple-form label', :content => "Gender", :for => 'gender'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form label', :count => 9
+ assert_response_has_tag 'form.simple-form label', :content => "Username", :for => 'username'
+ assert_response_has_tag 'form.simple-form label', :content => "Password", :for => 'password'
+ assert_response_has_tag 'form.simple-form label', :content => "Gender", :for => 'gender'
end
it 'should display label tag in haml for advanced form' do
- visit '/haml/form_tag'
- assert_have_selector 'form.advanced-form label', :count => 11
- assert_have_selector 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
- assert_have_selector 'form.advanced-form label.first', :content => "Password", :for => 'password'
- assert_have_selector 'form.advanced-form label.about', :content => "About Me", :for => 'about'
- assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
- assert_have_selector 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.advanced-form label', :count => 11
+ assert_response_has_tag 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
+ assert_response_has_tag 'form.advanced-form label.first', :content => "Password", :for => 'password'
+ assert_response_has_tag 'form.advanced-form label.about', :content => "About Me", :for => 'about'
+ assert_response_has_tag 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
+ assert_response_has_tag 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
end
it 'should display label tag in slim for simple form' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form label', :count => 9
- assert_have_selector 'form.simple-form label', :content => "Username", :for => 'username'
- assert_have_selector 'form.simple-form label', :content => "Password", :for => 'password'
- assert_have_selector 'form.simple-form label', :content => "Gender", :for => 'gender'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form label', :count => 9
+ assert_response_has_tag 'form.simple-form label', :content => "Username", :for => 'username'
+ assert_response_has_tag 'form.simple-form label', :content => "Password", :for => 'password'
+ assert_response_has_tag 'form.simple-form label', :content => "Gender", :for => 'gender'
end
it 'should display label tag in slim for advanced form' do
- visit '/slim/form_tag'
- assert_have_selector 'form.advanced-form label', :count => 11
- assert_have_selector 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
- assert_have_selector 'form.advanced-form label.first', :content => "Password", :for => 'password'
- assert_have_selector 'form.advanced-form label.about', :content => "About Me", :for => 'about'
- assert_have_selector 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
- assert_have_selector 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.advanced-form label', :count => 11
+ assert_response_has_tag 'form.advanced-form label.first', :content => "Nickname", :for => 'username'
+ assert_response_has_tag 'form.advanced-form label.first', :content => "Password", :for => 'password'
+ assert_response_has_tag 'form.advanced-form label.about', :content => "About Me", :for => 'about'
+ assert_response_has_tag 'form.advanced-form label.photo', :content => "Photo" , :for => 'photo'
+ assert_response_has_tag 'form.advanced-form label.gender', :content => "Gender" , :for => 'gender'
end
end
describe 'for #hidden_field_tag method' do
it 'should display hidden field in ruby' do
actual_html = hidden_field_tag(:session_key, :id => 'session_id', :value => '56768')
- assert_has_tag(:input, :type => 'hidden', :id => "session_id", :name => 'session_key', :value => '56768') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'hidden', :id => "session_id", :name => 'session_key', :value => '56768')
end
it 'should display hidden field in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
- assert_have_selector 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
+ assert_response_has_tag 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
end
it 'should display hidden field in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
- assert_have_selector 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
+ assert_response_has_tag 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
end
it 'should display hidden field in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
- assert_have_selector 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
+ assert_response_has_tag 'form.advanced-form input[type=hidden]', :count => 1, :name => 'session_id', :value => "__secret__"
end
end
describe 'for #text_field_tag method' do
it 'should display text field in ruby' do
actual_html = text_field_tag(:username, :class => 'long')
- assert_has_tag(:input, :type => 'text', :class => "long", :name => 'username') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'text', :class => "long", :name => 'username')
end
it 'should display text field in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
- assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=text]', :count => 1, :name => 'username'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
end
it 'should display text field in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
- assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=text]', :count => 1, :name => 'username'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
end
it 'should display text field in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form input[type=text]', :count => 1, :name => 'username'
- assert_have_selector 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=text]', :count => 1, :name => 'username'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=text]', :count => 1, :name => 'username', :id => 'the_username'
end
end
describe 'for #number_field_tag method' do
it 'should display number field in ruby' do
actual_html = number_field_tag(:age, :class => 'numeric')
- assert_has_tag(:input, :type => 'number', :class => 'numeric', :name => 'age') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'number', :class => 'numeric', :name => 'age')
end
it 'should display number field in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form input[type=number]', :count => 1, :name => 'age'
- assert_have_selector 'form.advanced-form fieldset input[type=number]', :count => 1, :name => 'age', :class => 'numeric'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=number]', :count => 1, :name => 'age'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=number]', :count => 1, :name => 'age', :class => 'numeric'
end
it 'should display number field in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form input[type=number]', :count => 1, :name => 'age'
- assert_have_selector 'form.advanced-form fieldset input[type=number]', :count => 1, :name => 'age', :class => 'numeric'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=number]', :count => 1, :name => 'age'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=number]', :count => 1, :name => 'age', :class => 'numeric'
end
it 'should display number field in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form input[type=number]', :count => 1, :name => 'age'
- assert_have_selector 'form.advanced-form fieldset input[type=number]', :count => 1, :name => 'age', :class => 'numeric'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=number]', :count => 1, :name => 'age'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=number]', :count => 1, :name => 'age', :class => 'numeric'
end
end
describe 'for #telephone_field_tag method' do
it 'should display number field in ruby' do
actual_html = telephone_field_tag(:telephone, :class => 'numeric')
- assert_has_tag(:input, :type => 'tel', :class => 'numeric', :name => 'telephone') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'tel', :class => 'numeric', :name => 'telephone')
end
it 'should display telephone field in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form input[type=tel]', :count => 1, :name => 'telephone'
- assert_have_selector 'form.advanced-form fieldset input[type=tel]', :count => 1, :name => 'telephone', :class => 'numeric'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=tel]', :count => 1, :name => 'telephone'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=tel]', :count => 1, :name => 'telephone', :class => 'numeric'
end
it 'should display telephone field in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form input[type=tel]', :count => 1, :name => 'telephone'
- assert_have_selector 'form.advanced-form fieldset input[type=tel]', :count => 1, :name => 'telephone', :class => 'numeric'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=tel]', :count => 1, :name => 'telephone'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=tel]', :count => 1, :name => 'telephone', :class => 'numeric'
end
it 'should display telephone field in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form input[type=tel]', :count => 1, :name => 'telephone'
- assert_have_selector 'form.advanced-form fieldset input[type=tel]', :count => 1, :name => 'telephone', :class => 'numeric'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=tel]', :count => 1, :name => 'telephone'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=tel]', :count => 1, :name => 'telephone', :class => 'numeric'
end
end
describe 'for #search_field_tag method' do
it 'should display search field in ruby' do
actual_html = search_field_tag(:search, :class => 'string')
- assert_has_tag(:input, :type => 'search', :class => 'string', :name => 'search') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'search', :class => 'string', :name => 'search')
end
it 'should display search field in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form input[type=search]', :count => 1, :name => 'search'
- assert_have_selector 'form.advanced-form fieldset input[type=search]', :count => 1, :name => 'search', :class => 'string'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=search]', :count => 1, :name => 'search'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=search]', :count => 1, :name => 'search', :class => 'string'
end
it 'should display search field in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form input[type=search]', :count => 1, :name => 'search'
- assert_have_selector 'form.advanced-form fieldset input[type=search]', :count => 1, :name => 'search', :class => 'string'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=search]', :count => 1, :name => 'search'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=search]', :count => 1, :name => 'search', :class => 'string'
end
it 'should display search field in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form input[type=search]', :count => 1, :name => 'search'
- assert_have_selector 'form.advanced-form fieldset input[type=search]', :count => 1, :name => 'search', :class => 'string'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=search]', :count => 1, :name => 'search'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=search]', :count => 1, :name => 'search', :class => 'string'
end
end
describe 'for #email_field_tag method' do
it 'should display email field in ruby' do
actual_html = email_field_tag(:email, :class => 'string')
- assert_has_tag(:input, :type => 'email', :class => 'string', :name => 'email') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'email', :class => 'string', :name => 'email')
end
it 'should display email field in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form input[type=email]', :count => 1, :name => 'email'
- assert_have_selector 'form.advanced-form fieldset input[type=email]', :count => 1, :name => 'email', :class => 'string'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=email]', :count => 1, :name => 'email'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=email]', :count => 1, :name => 'email', :class => 'string'
end
it 'should display email field in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form input[type=email]', :count => 1, :name => 'email'
- assert_have_selector 'form.advanced-form fieldset input[type=email]', :count => 1, :name => 'email', :class => 'string'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=email]', :count => 1, :name => 'email'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=email]', :count => 1, :name => 'email', :class => 'string'
end
it 'should display email field in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form input[type=email]', :count => 1, :name => 'email'
- assert_have_selector 'form.advanced-form fieldset input[type=email]', :count => 1, :name => 'email', :class => 'string'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=email]', :count => 1, :name => 'email'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=email]', :count => 1, :name => 'email', :class => 'string'
end
end
describe 'for #url_field_tag method' do
it 'should display url field in ruby' do
actual_html = url_field_tag(:webpage, :class => 'string')
- assert_has_tag(:input, :type => 'url', :class => 'string', :name => 'webpage') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'url', :class => 'string', :name => 'webpage')
end
it 'should display url field in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form input[type=url]', :count => 1, :name => 'webpage'
- assert_have_selector 'form.advanced-form fieldset input[type=url]', :count => 1, :name => 'webpage', :class => 'string'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=url]', :count => 1, :name => 'webpage'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=url]', :count => 1, :name => 'webpage', :class => 'string'
end
it 'should display url field in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form input[type=url]', :count => 1, :name => 'webpage'
- assert_have_selector 'form.advanced-form fieldset input[type=url]', :count => 1, :name => 'webpage', :class => 'string'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=url]', :count => 1, :name => 'webpage'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=url]', :count => 1, :name => 'webpage', :class => 'string'
end
it 'should display url field in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form input[type=url]', :count => 1, :name => 'webpage'
- assert_have_selector 'form.advanced-form fieldset input[type=url]', :count => 1, :name => 'webpage', :class => 'string'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=url]', :count => 1, :name => 'webpage'
+ assert_response_has_tag 'form.advanced-form fieldset input[type=url]', :count => 1, :name => 'webpage', :class => 'string'
end
end
describe 'for #text_area_tag method' do
it 'should display text area in ruby' do
actual_html = text_area_tag(:about, :class => 'long')
- assert_has_tag(:textarea, :class => "long", :name => 'about') { actual_html }
+ assert_html_has_tag(actual_html, :textarea, :class => "long", :name => 'about')
end
it 'should display text area in ruby with specified content' do
actual_html = text_area_tag(:about, :value => "a test", :rows => 5, :cols => 6)
- assert_has_tag(:textarea, :content => "a test", :name => 'about', :rows => "5", :cols => "6") { actual_html }
+ assert_html_has_tag(actual_html, :textarea, :content => "a test", :name => 'about', :rows => "5", :cols => "6")
end
it 'should insert newline to before of content' do
- actual_html = text_area_tag(:about, :value => "\na test")
- assert_has_tag(:textarea, :content => "\na test", :name => 'about') { actual_html }
- assert_match(%r{}, actual_html)
+ actual_html = text_area_tag(:about, :value => "\na test&".html_safe)
+ assert_html_has_tag(actual_html, :textarea, :content => "\na test&".html_safe, :name => 'about')
+ assert_match(%r{}, actual_html)
end
it 'should display text area in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
end
it 'should display text area in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
end
it 'should display text area in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
end
end
describe 'for #password_field_tag method' do
it 'should display password field in ruby' do
actual_html = password_field_tag(:password, :class => 'long')
- assert_has_tag(:input, :type => 'password', :class => "long", :name => 'password') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'password', :class => "long", :name => 'password')
end
it 'should display password field in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
- assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=password]', :count => 1, :name => 'password'
+ assert_response_has_tag 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
end
it 'should display password field in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
- assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=password]', :count => 1, :name => 'password'
+ assert_response_has_tag 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
end
it 'should display password field in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form input[type=password]', :count => 1, :name => 'password'
- assert_have_selector 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=password]', :count => 1, :name => 'password'
+ assert_response_has_tag 'form.advanced-form input[type=password]', :count => 1, :name => 'password'
end
end
describe 'for #file_field_tag method' do
it 'should display file field in ruby' do
actual_html = file_field_tag(:photo, :class => 'photo')
- assert_has_tag(:input, :type => 'file', :class => "photo", :name => 'photo') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'file', :class => "photo", :name => 'photo')
end
it 'should have an array name with multiple option' do
actual_html = file_field_tag(:photos, :multiple => true)
- assert_has_tag(:input, :name => 'photos[]') { actual_html }
+ assert_html_has_tag(actual_html, :input, :name => 'photos[]')
end
it 'should display file field in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
end
it 'should display file field in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
end
it 'should display file field in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.advanced-form input[type=file]', :count => 1, :name => 'photo', :class => 'upload'
end
end
describe "for #check_box_tag method" do
it 'should display check_box tag in ruby' do
actual_html = check_box_tag("clear_session")
- assert_has_tag(:input, :type => 'checkbox', :value => '1', :name => 'clear_session') { actual_html }
- assert_has_no_tag(:input, :type => 'hidden') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'checkbox', :value => '1', :name => 'clear_session')
+ assert_html_has_no_tag(actual_html, :input, :type => 'hidden')
end
it 'should display check_box tag in ruby with extended attributes' do
actual_html = check_box_tag("clear_session", :disabled => true, :checked => true)
- assert_has_tag(:input, :type => 'checkbox', :disabled => 'disabled', :checked => 'checked') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'checkbox', :disabled => 'disabled', :checked => 'checked')
end
it 'should display check_box tag in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form input[type=checkbox]', :count => 1
- assert_have_selector 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=checkbox]', :count => 1
+ assert_response_has_tag 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
end
it 'should display check_box tag in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form input[type=checkbox]', :count => 1
- assert_have_selector 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=checkbox]', :count => 1
+ assert_response_has_tag 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
end
it 'should display check_box tag in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form input[type=checkbox]', :count => 1
- assert_have_selector 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=checkbox]', :count => 1
+ assert_response_has_tag 'form.advanced-form input[type=checkbox]', :value => "1", :checked => 'checked'
end
end
describe "for #radio_button_tag method" do
it 'should display radio_button tag in ruby' do
actual_html = radio_button_tag("gender", :value => 'male')
- assert_has_tag(:input, :type => 'radio', :value => 'male', :name => 'gender') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'radio', :value => 'male', :name => 'gender')
end
it 'should display radio_button tag in ruby with extended attributes' do
actual_html = radio_button_tag("gender", :disabled => true, :checked => true)
- assert_has_tag(:input, :type => 'radio', :disabled => 'disabled', :checked => 'checked') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'radio', :disabled => 'disabled', :checked => 'checked')
end
it 'should display radio_button tag in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
- assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
- assert_have_selector 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
- assert_have_selector 'form.advanced-form input[type=radio]', :value => "female"
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
+ assert_response_has_tag 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
+ assert_response_has_tag 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
+ assert_response_has_tag 'form.advanced-form input[type=radio]', :value => "female"
end
it 'should display radio_button tag in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
- assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
- assert_have_selector 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
- assert_have_selector 'form.advanced-form input[type=radio]', :value => "female"
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
+ assert_response_has_tag 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
+ assert_response_has_tag 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
+ assert_response_has_tag 'form.advanced-form input[type=radio]', :value => "female"
end
it 'should display radio_button tag in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
- assert_have_selector 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
- assert_have_selector 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
- assert_have_selector 'form.advanced-form input[type=radio]', :value => "female"
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=radio]', :count => 1, :value => 'male'
+ assert_response_has_tag 'form.simple-form input[type=radio]', :count => 1, :value => 'female'
+ assert_response_has_tag 'form.advanced-form input[type=radio]', :value => "male", :checked => 'checked'
+ assert_response_has_tag 'form.advanced-form input[type=radio]', :value => "female"
end
end
describe "for #select_tag method" do
it 'should display select tag in ruby' do
actual_html = select_tag(:favorite_color, :options => ['green', 'blue', 'black'], :include_blank => true)
- assert_has_tag(:select, :name => 'favorite_color') { actual_html }
- assert_has_tag('select option:first-child', :content => '') { actual_html }
- assert_has_tag('select option', :content => 'green', :value => 'green') { actual_html }
- assert_has_tag('select option', :content => 'blue', :value => 'blue') { actual_html }
- assert_has_tag('select option', :content => 'black', :value => 'black') { actual_html }
+ assert_html_has_tag(actual_html, :select, :name => 'favorite_color')
+ assert_html_has_tag(actual_html, 'select option:first-child', :content => '')
+ assert_html_has_tag(actual_html, 'select option', :content => 'green', :value => 'green')
+ assert_html_has_tag(actual_html, 'select option', :content => 'blue', :value => 'blue')
+ assert_html_has_tag(actual_html, 'select option', :content => 'black', :value => 'black')
end
it 'should display select tag in ruby with extended attributes' do
actual_html = select_tag(:favorite_color, :disabled => true, :options => ['only', 'option'])
- assert_has_tag(:select, :disabled => 'disabled') { actual_html }
+ assert_html_has_tag(actual_html, :select, :disabled => 'disabled')
end
it 'should take a range as a collection for options' do
actual_html = select_tag(:favorite_color, :options => (1..3))
- assert_has_tag(:select) { actual_html }
- assert_has_tag('select option', :content => '1', :value => '1') { actual_html }
- assert_has_tag('select option', :content => '2', :value => '2') { actual_html }
- assert_has_tag('select option', :content => '3', :value => '3') { actual_html }
+ assert_html_has_tag(actual_html, :select)
+ assert_html_has_tag(actual_html, 'select option', :content => '1', :value => '1')
+ assert_html_has_tag(actual_html, 'select option', :content => '2', :value => '2')
+ assert_html_has_tag(actual_html, 'select option', :content => '3', :value => '3')
end
it 'should include blank for grouped options' do
opts = { "Red" => ["Rose","Fire"], "Blue" => ["Sky","Sea"] }
actual_html = select_tag( 'color', :grouped_options => opts, :include_blank => true )
- assert_has_tag('select option:first-child', :value => "", :content => "") { actual_html }
+ assert_html_has_tag(actual_html, 'select option:first-child', :value => "", :content => "")
end
it 'should include blank as caption' do
opts = { "Red" => ["Rose","Fire"], "Blue" => ["Sky","Sea"] }
actual_html = select_tag( 'color', :grouped_options => opts, :include_blank => 'Choose your destiny' )
- assert_has_tag('select option:first-child', :value => "", :content => "Choose your destiny") { actual_html }
- assert_has_no_tag('select[include_blank]') { actual_html }
+ assert_html_has_tag(actual_html, 'select option:first-child', :value => "", :content => "Choose your destiny")
+ assert_html_has_no_tag(actual_html, 'select[include_blank]')
end
it 'should display select tag with grouped options for a nested array' do
@@ -681,13 +682,13 @@ def protect_from_csrf; false; end
["Enemies", ["Palpatine",['Darth Vader',3]]]
]
actual_html = select_tag( 'name', :grouped_options => opts )
- assert_has_tag(:select, :name => "name") { actual_html }
- assert_has_tag(:optgroup, :label => "Friends") { actual_html }
- assert_has_tag(:option, :value => "Yoda", :content => "Yoda") { actual_html }
- assert_has_tag(:option, :value => "2", :content => "Obiwan") { actual_html }
- assert_has_tag(:optgroup, :label => "Enemies") { actual_html }
- assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine") { actual_html }
- assert_has_tag(:option, :value => "3", :content => "Darth Vader") { actual_html }
+ assert_html_has_tag(actual_html, :select, :name => "name")
+ assert_html_has_tag(actual_html, :optgroup, :label => "Friends")
+ assert_html_has_tag(actual_html, :option, :value => "Yoda", :content => "Yoda")
+ assert_html_has_tag(actual_html, :option, :value => "2", :content => "Obiwan")
+ assert_html_has_tag(actual_html, :optgroup, :label => "Enemies")
+ assert_html_has_tag(actual_html, :option, :value => "Palpatine", :content => "Palpatine")
+ assert_html_has_tag(actual_html, :option, :value => "3", :content => "Darth Vader")
end
it 'should display select tag with grouped options for a nested array and accept disabled groups' do
@@ -696,10 +697,10 @@ def protect_from_csrf; false; end
["Enemies", ["Palpatine",['Darth Vader',3]], {:disabled => true}]
]
actual_html = select_tag( 'name', :grouped_options => opts )
- assert_has_tag(:select, :name => "name") { actual_html }
- assert_has_tag(:option, :disabled => 'disabled', :count => 0) { actual_html }
- assert_has_tag(:optgroup, :disabled => 'disabled', :count => 1) { actual_html }
- assert_has_tag(:optgroup, :label => "Enemies", :disabled => 'disabled') { actual_html }
+ assert_html_has_tag(actual_html, :select, :name => "name")
+ assert_html_has_tag(actual_html, :option, :disabled => 'disabled', :count => 0)
+ assert_html_has_tag(actual_html, :optgroup, :disabled => 'disabled', :count => 1)
+ assert_html_has_tag(actual_html, :optgroup, :label => "Enemies", :disabled => 'disabled')
end
it 'should display select tag with grouped options for a nested array and accept disabled groups and/or with disabled options' do
@@ -708,12 +709,12 @@ def protect_from_csrf; false; end
["Enemies", [["Palpatine", "Palpatine", {:disabled => true}],['Darth Vader',3]], {:disabled => true}]
]
actual_html = select_tag( 'name', :grouped_options => opts )
- assert_has_tag(:select, :name => "name") { actual_html }
- assert_has_tag(:option, :disabled => 'disabled', :count => 2) { actual_html }
- assert_has_tag(:optgroup, :disabled => 'disabled', :count => 1) { actual_html }
- assert_has_tag(:option, :content => "Obiwan", :disabled => 'disabled') { actual_html }
- assert_has_tag(:optgroup, :label => "Enemies", :disabled => 'disabled') { actual_html }
- assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine", :disabled => 'disabled') { actual_html }
+ assert_html_has_tag(actual_html, :select, :name => "name")
+ assert_html_has_tag(actual_html, :option, :disabled => 'disabled', :count => 2)
+ assert_html_has_tag(actual_html, :optgroup, :disabled => 'disabled', :count => 1)
+ assert_html_has_tag(actual_html, :option, :content => "Obiwan", :disabled => 'disabled')
+ assert_html_has_tag(actual_html, :optgroup, :label => "Enemies", :disabled => 'disabled')
+ assert_html_has_tag(actual_html, :option, :value => "Palpatine", :content => "Palpatine", :disabled => 'disabled')
end
it 'should display select tag with grouped options for a hash' do
@@ -722,13 +723,13 @@ def protect_from_csrf; false; end
"Enemies" => ["Palpatine",['Darth Vader',3]]
}
actual_html = select_tag( 'name', :grouped_options => opts )
- assert_has_tag(:select, :name => "name") { actual_html }
- assert_has_tag(:optgroup, :label => "Friends") { actual_html }
- assert_has_tag(:option, :value => "Yoda", :content => "Yoda") { actual_html }
- assert_has_tag(:option, :value => "2", :content => "Obiwan") { actual_html }
- assert_has_tag(:optgroup, :label => "Enemies") { actual_html }
- assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine") { actual_html }
- assert_has_tag(:option, :value => "3", :content => "Darth Vader") { actual_html }
+ assert_html_has_tag(actual_html, :select, :name => "name")
+ assert_html_has_tag(actual_html, :optgroup, :label => "Friends")
+ assert_html_has_tag(actual_html, :option, :value => "Yoda", :content => "Yoda")
+ assert_html_has_tag(actual_html, :option, :value => "2", :content => "Obiwan")
+ assert_html_has_tag(actual_html, :optgroup, :label => "Enemies")
+ assert_html_has_tag(actual_html, :option, :value => "Palpatine", :content => "Palpatine")
+ assert_html_has_tag(actual_html, :option, :value => "3", :content => "Darth Vader")
end
it 'should display select tag with grouped options for a hash and accept disabled groups and/or with disabled options' do
@@ -737,12 +738,12 @@ def protect_from_csrf; false; end
"Enemies" => [["Palpatine","Palpatine",{:disabled => true}],["Darth Vader",3], {:disabled => true}]
}
actual_html = select_tag( 'name', :grouped_options => opts )
- assert_has_tag(:select, :name => "name") { actual_html }
- assert_has_tag(:option, :disabled => 'disabled', :count => 2) { actual_html }
- assert_has_tag(:optgroup, :disabled => 'disabled', :count => 1) { actual_html }
- assert_has_tag(:option, :content => "Obiwan", :disabled => 'disabled') { actual_html }
- assert_has_tag(:optgroup, :label => "Enemies", :disabled => 'disabled') { actual_html }
- assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine", :disabled => 'disabled') { actual_html }
+ assert_html_has_tag(actual_html, :select, :name => "name")
+ assert_html_has_tag(actual_html, :option, :disabled => 'disabled', :count => 2)
+ assert_html_has_tag(actual_html, :optgroup, :disabled => 'disabled', :count => 1)
+ assert_html_has_tag(actual_html, :option, :content => "Obiwan", :disabled => 'disabled')
+ assert_html_has_tag(actual_html, :optgroup, :label => "Enemies", :disabled => 'disabled')
+ assert_html_has_tag(actual_html, :option, :value => "Palpatine", :content => "Palpatine", :disabled => 'disabled')
end
it 'should display select tag with grouped options for a rails-style attribute hash' do
@@ -751,171 +752,185 @@ def protect_from_csrf; false; end
"Enemies" => [["Palpatine","Palpatine",{:scary=>'yes',:old=>'yes'}],["Darth Vader",3,{:disabled=>true}]]
}
actual_html = select_tag( 'name', :grouped_options => opts, :disabled_options => [2], :selected => ['Yoda'] )
- assert_has_tag(:optgroup, :label => "Friends", :lame => 'yes') { actual_html }
- assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine", :scary => 'yes', :old => 'yes') { actual_html }
- assert_has_tag(:option, :content => "Darth Vader", :disabled => 'disabled') { actual_html }
- assert_has_tag(:option, :content => "Obiwan", :disabled => 'disabled') { actual_html }
- assert_has_tag(:option, :content => "Yoda", :selected => 'selected') { actual_html }
+ assert_html_has_tag(actual_html, :optgroup, :label => "Friends", :lame => 'yes')
+ assert_html_has_tag(actual_html, :option, :value => "Palpatine", :content => "Palpatine", :scary => 'yes', :old => 'yes')
+ assert_html_has_tag(actual_html, :option, :content => "Darth Vader", :disabled => 'disabled')
+ assert_html_has_tag(actual_html, :option, :content => "Obiwan", :disabled => 'disabled')
+ assert_html_has_tag(actual_html, :option, :content => "Yoda", :selected => 'selected')
end
it 'should display select tag in ruby with multiple attribute' do
actual_html = select_tag(:favorite_color, :multiple => true, :options => ['only', 'option'])
- assert_has_tag(:select, :multiple => 'multiple', :name => 'favorite_color[]') { actual_html }
+ assert_html_has_tag(actual_html, :select, :multiple => 'multiple', :name => 'favorite_color[]')
end
it 'should display options with values and single selected' do
options = [['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
actual_html = select_tag(:favorite_color, :options => options, :selected => 'green1')
- assert_has_tag(:select, :name => 'favorite_color') { actual_html }
- assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
- assert_has_tag('select option', :content => 'Green', :value => 'green1', :selected => 'selected') { actual_html }
- assert_has_tag('select option', :content => 'Blue', :value => 'blue1') { actual_html }
- assert_has_tag('select option', :content => 'Black', :value => 'black1') { actual_html }
+ assert_html_has_tag(actual_html, :select, :name => 'favorite_color')
+ assert_html_has_tag(actual_html, 'select option', :selected => 'selected', :count => 1)
+ assert_html_has_tag(actual_html, 'select option', :content => 'Green', :value => 'green1', :selected => 'selected')
+ assert_html_has_tag(actual_html, 'select option', :content => 'Blue', :value => 'blue1')
+ assert_html_has_tag(actual_html, 'select option', :content => 'Black', :value => 'black1')
+ end
+
+ it 'should display selected options first based on values not content' do
+ options = [['First', 'one'], ['one', 'two'], ['three', 'three']]
+ actual_html = select_tag(:number, :options => options, :selected => 'one')
+ assert_html_has_tag(actual_html, 'select option', :selected => 'selected', :count => 1)
+ assert_html_has_tag(actual_html, 'select option', :content => 'First', :value => 'one', :selected => 'selected')
+ end
+
+ it 'should display selected options falling back to checking content' do
+ options = [['one', nil, :value => nil], ['two', nil, :value => nil], ['three', 'three']]
+ actual_html = select_tag(:number, :options => options, :selected => 'one')
+ assert_html_has_tag(actual_html, 'select option', :selected => 'selected', :count => 1)
+ assert_html_has_tag(actual_html, 'select option', :content => 'one', :selected => 'selected')
end
it 'should display options with values and accept disabled options' do
options = [['Green', 'green1', {:disabled => true}], ['Blue', 'blue1'], ['Black', "black1"]]
actual_html = select_tag(:favorite_color, :options => options)
- assert_has_tag(:select, :name => 'favorite_color') { actual_html }
- assert_has_tag('select option', :disabled => 'disabled', :count => 1) { actual_html }
- assert_has_tag('select option', :content => 'Green', :value => 'green1', :disabled => 'disabled') { actual_html }
- assert_has_tag('select option', :content => 'Blue', :value => 'blue1') { actual_html }
- assert_has_tag('select option', :content => 'Black', :value => 'black1') { actual_html }
+ assert_html_has_tag(actual_html, :select, :name => 'favorite_color')
+ assert_html_has_tag(actual_html, 'select option', :disabled => 'disabled', :count => 1)
+ assert_html_has_tag(actual_html, 'select option', :content => 'Green', :value => 'green1', :disabled => 'disabled')
+ assert_html_has_tag(actual_html, 'select option', :content => 'Blue', :value => 'blue1')
+ assert_html_has_tag(actual_html, 'select option', :content => 'Black', :value => 'black1')
end
it 'should display option with values and multiple selected' do
options = [['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
- actual_html = select_tag(:favorite_color, :options => options, :selected => ['green1', 'Black'])
- assert_has_tag(:select, :name => 'favorite_color') { actual_html }
- assert_has_tag('select option', :selected => 'selected', :count => 2) { actual_html }
- assert_has_tag('select option', :content => 'Green', :value => 'green1', :selected => 'selected') { actual_html }
- assert_has_tag('select option', :content => 'Blue', :value => 'blue1') { actual_html }
- assert_has_tag('select option', :content => 'Black', :value => 'black1', :selected => 'selected') { actual_html }
+ actual_html = select_tag(:favorite_color, :options => options, :selected => ['green1', 'black1'])
+ assert_html_has_tag(actual_html, :select, :name => 'favorite_color')
+ assert_html_has_tag(actual_html, 'select option', :selected => 'selected', :count => 2)
+ assert_html_has_tag(actual_html, 'select option', :content => 'Green', :value => 'green1', :selected => 'selected')
+ assert_html_has_tag(actual_html, 'select option', :content => 'Blue', :value => 'blue1')
+ assert_html_has_tag(actual_html, 'select option', :content => 'Black', :value => 'black1', :selected => 'selected')
end
it 'should not misselect options with default value' do
options = ['Green', 'Blue']
actual_html = select_tag(:favorite_color, :options => options, :selected => ['Green', ''])
- assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
- assert_has_tag('select option', :content => 'Green', :value => 'Green', :selected => 'selected') { actual_html }
+ assert_html_has_tag(actual_html, 'select option', :selected => 'selected', :count => 1)
+ assert_html_has_tag(actual_html, 'select option', :content => 'Green', :value => 'Green', :selected => 'selected')
end
it 'should display options selected only for exact match' do
options = [['One', '1'], ['1', '10'], ['Two', "-1"]]
actual_html = select_tag(:range, :options => options, :selected => '-1')
- assert_has_tag(:select, :name => 'range') { actual_html }
- assert_has_tag('select option', :selected => 'selected', :count => 1) { actual_html }
- assert_has_tag('select option', :content => 'Two', :value => '-1', :selected => 'selected') { actual_html }
+ assert_html_has_tag(actual_html, :select, :name => 'range')
+ assert_html_has_tag(actual_html, 'select option', :selected => 'selected', :count => 1)
+ assert_html_has_tag(actual_html, 'select option', :content => 'Two', :value => '-1', :selected => 'selected')
end
it 'should display select tag in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form select', :count => 1, :name => 'color'
- assert_have_selector('select option', :content => 'green', :value => 'green')
- assert_have_selector('select option', :content => 'orange', :value => 'orange')
- assert_have_selector('select option', :content => 'purple', :value => 'purple')
- assert_have_selector('form.advanced-form select', :name => 'fav_color')
- assert_have_selector('select option', :content => 'green', :value => '1')
- assert_have_selector('select option', :content => 'orange', :value => '2', :selected => 'selected')
- assert_have_selector('select option', :content => 'purple', :value => '3')
- assert_have_selector('select optgroup', :label => 'foo')
- assert_have_selector('select optgroup', :label => 'bar')
- assert_have_selector('select optgroup option', :content => 'foo', :value => 'foo')
- assert_have_selector('select optgroup option', :content => 'bar', :value => 'bar')
- assert_have_selector('select optgroup', :label => 'Friends')
- assert_have_selector('select optgroup', :label => 'Enemies')
- assert_have_selector('select optgroup option', :content => 'Yoda', :value => 'Yoda')
- assert_have_selector('select optgroup option', :content => 'Obiwan', :value => '1')
- assert_have_selector('select optgroup option', :content => 'Palpatine', :value => 'Palpatine')
- assert_have_selector('select optgroup option', :content => 'Darth Vader', :value => '3')
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form select', :count => 1, :name => 'color'
+ assert_response_has_tag('select option', :content => 'green', :value => 'green')
+ assert_response_has_tag('select option', :content => 'orange', :value => 'orange')
+ assert_response_has_tag('select option', :content => 'purple', :value => 'purple')
+ assert_response_has_tag('form.advanced-form select', :name => 'fav_color')
+ assert_response_has_tag('select option', :content => 'green', :value => '1')
+ assert_response_has_tag('select option', :content => 'orange', :value => '2', :selected => 'selected')
+ assert_response_has_tag('select option', :content => 'purple', :value => '3')
+ assert_response_has_tag('select optgroup', :label => 'foo')
+ assert_response_has_tag('select optgroup', :label => 'bar')
+ assert_response_has_tag('select optgroup option', :content => 'foo', :value => 'foo')
+ assert_response_has_tag('select optgroup option', :content => 'bar', :value => 'bar')
+ assert_response_has_tag('select optgroup', :label => 'Friends')
+ assert_response_has_tag('select optgroup', :label => 'Enemies')
+ assert_response_has_tag('select optgroup option', :content => 'Yoda', :value => 'Yoda')
+ assert_response_has_tag('select optgroup option', :content => 'Obiwan', :value => '1')
+ assert_response_has_tag('select optgroup option', :content => 'Palpatine', :value => 'Palpatine')
+ assert_response_has_tag('select optgroup option', :content => 'Darth Vader', :value => '3')
end
it 'should display select tag in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form select', :count => 1, :name => 'color'
- assert_have_selector('select option', :content => 'green', :value => 'green')
- assert_have_selector('select option', :content => 'orange', :value => 'orange')
- assert_have_selector('select option', :content => 'purple', :value => 'purple')
- assert_have_selector('form.advanced-form select', :name => 'fav_color')
- assert_have_selector('select option', :content => 'green', :value => '1')
- assert_have_selector('select option', :content => 'orange', :value => '2', :selected => 'selected')
- assert_have_selector('select option', :content => 'purple', :value => '3')
- assert_have_selector('select optgroup', :label => 'foo')
- assert_have_selector('select optgroup', :label => 'bar')
- assert_have_selector('select optgroup option', :content => 'foo', :value => 'foo')
- assert_have_selector('select optgroup option', :content => 'bar', :value => 'bar')
- assert_have_selector('select optgroup', :label => 'Friends')
- assert_have_selector('select optgroup', :label => 'Enemies')
- assert_have_selector('select optgroup option', :content => 'Yoda', :value => 'Yoda')
- assert_have_selector('select optgroup option', :content => 'Obiwan', :value => '1')
- assert_have_selector('select optgroup option', :content => 'Palpatine', :value => 'Palpatine')
- assert_have_selector('select optgroup option', :content => 'Darth Vader', :value => '3')
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form select', :count => 1, :name => 'color'
+ assert_response_has_tag('select option', :content => 'green', :value => 'green')
+ assert_response_has_tag('select option', :content => 'orange', :value => 'orange')
+ assert_response_has_tag('select option', :content => 'purple', :value => 'purple')
+ assert_response_has_tag('form.advanced-form select', :name => 'fav_color')
+ assert_response_has_tag('select option', :content => 'green', :value => '1')
+ assert_response_has_tag('select option', :content => 'orange', :value => '2', :selected => 'selected')
+ assert_response_has_tag('select option', :content => 'purple', :value => '3')
+ assert_response_has_tag('select optgroup', :label => 'foo')
+ assert_response_has_tag('select optgroup', :label => 'bar')
+ assert_response_has_tag('select optgroup option', :content => 'foo', :value => 'foo')
+ assert_response_has_tag('select optgroup option', :content => 'bar', :value => 'bar')
+ assert_response_has_tag('select optgroup', :label => 'Friends')
+ assert_response_has_tag('select optgroup', :label => 'Enemies')
+ assert_response_has_tag('select optgroup option', :content => 'Yoda', :value => 'Yoda')
+ assert_response_has_tag('select optgroup option', :content => 'Obiwan', :value => '1')
+ assert_response_has_tag('select optgroup option', :content => 'Palpatine', :value => 'Palpatine')
+ assert_response_has_tag('select optgroup option', :content => 'Darth Vader', :value => '3')
end
it 'should display select tag in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form select', :count => 1, :name => 'color'
- assert_have_selector('select option', :content => 'green', :value => 'green')
- assert_have_selector('select option', :content => 'orange', :value => 'orange')
- assert_have_selector('select option', :content => 'purple', :value => 'purple')
- assert_have_selector('form.advanced-form select', :name => 'fav_color')
- assert_have_selector('select option', :content => 'green', :value => '1')
- assert_have_selector('select option', :content => 'orange', :value => '2', :selected => 'selected')
- assert_have_selector('select option', :content => 'purple', :value => '3')
- assert_have_selector('select optgroup', :label => 'foo')
- assert_have_selector('select optgroup', :label => 'bar')
- assert_have_selector('select optgroup option', :content => 'foo', :value => 'foo')
- assert_have_selector('select optgroup option', :content => 'bar', :value => 'bar')
- assert_have_selector('select optgroup', :label => 'Friends')
- assert_have_selector('select optgroup', :label => 'Enemies')
- assert_have_selector('select optgroup option', :content => 'Yoda', :value => 'Yoda')
- assert_have_selector('select optgroup option', :content => 'Obiwan', :value => '1')
- assert_have_selector('select optgroup option', :content => 'Palpatine', :value => 'Palpatine')
- assert_have_selector('select optgroup option', :content => 'Darth Vader', :value => '3')
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form select', :count => 1, :name => 'color'
+ assert_response_has_tag('select option', :content => 'green', :value => 'green')
+ assert_response_has_tag('select option', :content => 'orange', :value => 'orange')
+ assert_response_has_tag('select option', :content => 'purple', :value => 'purple')
+ assert_response_has_tag('form.advanced-form select', :name => 'fav_color')
+ assert_response_has_tag('select option', :content => 'green', :value => '1')
+ assert_response_has_tag('select option', :content => 'orange', :value => '2', :selected => 'selected')
+ assert_response_has_tag('select option', :content => 'purple', :value => '3')
+ assert_response_has_tag('select optgroup', :label => 'foo')
+ assert_response_has_tag('select optgroup', :label => 'bar')
+ assert_response_has_tag('select optgroup option', :content => 'foo', :value => 'foo')
+ assert_response_has_tag('select optgroup option', :content => 'bar', :value => 'bar')
+ assert_response_has_tag('select optgroup', :label => 'Friends')
+ assert_response_has_tag('select optgroup', :label => 'Enemies')
+ assert_response_has_tag('select optgroup option', :content => 'Yoda', :value => 'Yoda')
+ assert_response_has_tag('select optgroup option', :content => 'Obiwan', :value => '1')
+ assert_response_has_tag('select optgroup option', :content => 'Palpatine', :value => 'Palpatine')
+ assert_response_has_tag('select optgroup option', :content => 'Darth Vader', :value => '3')
end
end
describe 'for #submit_tag method' do
it 'should display submit tag in ruby' do
actual_html = submit_tag("Update", :class => 'success')
- assert_has_tag(:input, :type => 'submit', :class => "success", :value => 'Update') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'submit', :class => "success", :value => 'Update')
end
it 'should display submit tag in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
- assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
+ assert_response_has_tag 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
end
it 'should display submit tag in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
- assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
+ assert_response_has_tag 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
end
it 'should display submit tag in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
- assert_have_selector 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.simple-form input[type=submit]', :count => 1, :value => "Submit"
+ assert_response_has_tag 'form.advanced-form input[type=submit]', :count => 1, :value => "Login"
end
describe 'for omitted args' do
it 'should display submit tag with default caption' do
actual_html = submit_tag()
- assert_has_tag(:input, :type => 'submit', :value => 'Submit') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'submit', :value => 'Submit')
end
end
describe 'for omitted caption arg' do
it 'should display submit tag with default caption' do
actual_html = submit_tag(:class => 'success')
- assert_has_tag(:input, :type => 'submit', :class => 'success', :value => 'Submit') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'submit', :class => 'success', :value => 'Submit')
end
it 'should display submit tag without caption value when nil' do
actual_html = submit_tag(nil, :class => 'success')
- assert_has_tag(:input, :type => 'submit', :class => 'success') { actual_html }
- assert_has_no_tag(:input, :type => 'submit', :class => 'success', :value => 'Submit') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'submit', :class => 'success')
+ assert_html_has_no_tag(actual_html, :input, :type => 'submit', :class => 'success', :value => 'Submit')
end
end
end
@@ -923,22 +938,22 @@ def protect_from_csrf; false; end
describe 'for #button_tag method' do
it 'should display submit tag in ruby' do
actual_html = button_tag("Cancel", :class => 'clear')
- assert_has_tag(:input, :type => 'button', :class => "clear", :value => 'Cancel') { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'button', :class => "clear", :value => 'Cancel')
end
it 'should display submit tag in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
end
it 'should display submit tag in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
end
it 'should display submit tag in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.advanced-form input[type=button]', :count => 1, :value => "Cancel"
end
end
@@ -949,108 +964,406 @@ def protect_from_csrf; false; end
it 'should display image submit tag in ruby with relative path' do
actual_html = image_submit_tag('buttons/ok.png', :class => 'success')
- assert_has_tag(:input, :type => 'image', :class => "success", :src => "/images/buttons/ok.png?#{@stamp}") { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'image', :class => "success", :src => "/images/buttons/ok.png?#{@stamp}")
end
it 'should display image submit tag in ruby with absolute path' do
actual_html = image_submit_tag('/system/ok.png', :class => 'success')
- assert_has_tag(:input, :type => 'image', :class => "success", :src => "/system/ok.png") { actual_html }
+ assert_html_has_tag(actual_html, :input, :type => 'image', :class => "success", :src => "/system/ok.png")
end
it 'should display image submit tag in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
+ get "/erb/form_tag"
+ assert_response_has_tag 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
end
it 'should display image submit tag in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
+ get "/haml/form_tag"
+ assert_response_has_tag 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
end
it 'should display image submit tag in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
+ get "/slim/form_tag"
+ assert_response_has_tag 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png?#{@stamp}"
end
end
describe 'for #button_to method' do
it 'should have a form and set the method properly' do
actual_html = button_to('Delete', '/users/1', :method => :delete)
- assert_has_tag('form', :action => '/users/1') { actual_html }
- assert_has_tag('form input', :type => 'hidden', :name => "_method", :value => 'delete') { actual_html }
- assert_has_tag('form input', :type => 'hidden', :name => "authenticity_token") { actual_html }
+ assert_html_has_tag(actual_html, 'form', :action => '/users/1')
+ assert_html_has_tag(actual_html, 'form input', :type => 'hidden', :name => "_method", :value => 'delete')
+ assert_html_has_tag(actual_html, 'form input', :type => 'hidden', :name => "authenticity_token")
end
it 'should add a submit button by default if no content is specified' do
actual_html = button_to('My Delete Button', '/users/1', :method => :delete)
- assert_has_tag('form input', :type => 'submit', :value => 'My Delete Button') { actual_html }
+ assert_html_has_tag(actual_html, 'form input', :type => 'submit', :value => 'My Delete Button')
end
it 'should set specific content inside the form if a block was sent' do
actual_html = button_to('My Delete Button', '/users/1', :method => :delete) do
content_tag :button, "My button's content", :type => :submit, :title => "My button"
end
- assert_has_tag('form button', :type => 'submit', :content => "My button's content", :title => "My button") { actual_html }
+ assert_html_has_tag(actual_html, 'form button', :type => 'submit', :content => "My button's content", :title => "My button")
end
it 'should pass options on submit button when submit_options are given' do
actual_html = button_to("Fancy button", '/users/1', :submit_options => { :class => :fancy })
- assert_has_tag('form input', :type => 'submit', :value => 'Fancy button', :class => 'fancy') { actual_html }
- assert_has_no_tag('form', :"submit_options-class" => 'fancy'){ actual_html }
+ assert_html_has_tag(actual_html, 'form input', :type => 'submit', :value => 'Fancy button', :class => 'fancy')
+ assert_html_has_no_tag(actual_html, 'form', :"submit_options-class" => 'fancy')
end
it 'should display correct button_to in erb' do
- visit '/erb/button_to'
- assert_have_selector('form', :action => '/foo')
- assert_have_selector('form label', :for => 'username', :content => 'Username: ')
- assert_have_selector('form', :action => '/bar')
- assert_have_selector('#test-point ~ form > input[type=submit]', :value => 'Bar button')
+ get "/erb/button_to"
+ assert_response_has_tag('form', :action => '/foo')
+ assert_response_has_tag('form button label', :for => 'username', :content => 'Username: ')
+ assert_response_has_tag('form', :action => '/bar')
+ assert_response_has_tag('#test-point ~ form > input[type=submit]', :value => 'Bar button')
end
it 'should display correct button_to in haml' do
- visit '/haml/button_to'
- assert_have_selector('form', :action => '/foo')
- assert_have_selector('form label', :for => 'username', :content => 'Username: ')
- assert_have_selector('form', :action => '/bar')
- assert_have_selector('#test-point ~ form > input[type=submit]', :value => 'Bar button')
+ get "/haml/button_to"
+ assert_response_has_tag('form', :action => '/foo')
+ assert_response_has_tag('form button label', :for => 'username', :content => 'Username: ')
+ assert_response_has_tag('form', :action => '/bar')
+ assert_response_has_tag('#test-point ~ form > input[type=submit]', :value => 'Bar button')
end
it 'should display correct button_to in slim' do
- visit '/slim/button_to'
- assert_have_selector('form', :action => '/foo')
- assert_have_selector('form label', :for => 'username', :content => 'Username: ')
- assert_have_selector('form', :action => '/bar')
- assert_have_selector('#test-point ~ form > input[type=submit]', :value => 'Bar button')
+ get "/slim/button_to"
+ assert_response_has_tag('form', :action => '/foo')
+ assert_response_has_tag('form button label', :for => 'username', :content => 'Username: ')
+ assert_response_has_tag('form', :action => '/bar')
+ assert_response_has_tag('#test-point ~ form > input[type=submit]', :value => 'Bar button')
end
end
describe 'for #range_field_tag' do
it 'should create an input tag with min and max options' do
actual_html = range_field_tag('ranger', :min => 20, :max => 50)
- assert_has_tag('input', :type => 'range', :name => 'ranger', :min => '20', :max => '50') { actual_html }
+ assert_html_has_tag(actual_html, 'input', :type => 'range', :name => 'ranger', :min => '20', :max => '50')
end
it 'should create an input tag with range' do
actual_html = range_field_tag('ranger', :range => 1..20)
- assert_has_tag('input', :min => '1', :max => '20') { actual_html }
+ assert_html_has_tag(actual_html, 'input', :min => '1', :max => '20')
end
it 'should display correct range_field_tag in erb' do
- visit '/erb/form_tag'
- assert_have_selector 'input', :type => 'range', :name => 'ranger_with_min_max', :min => '1', :max => '50', :count => 1
- assert_have_selector 'input', :type => 'range', :name => 'ranger_with_range', :min => '1', :max => '5', :count => 1
+ get "/erb/form_tag"
+ assert_response_has_tag 'input', :type => 'range', :name => 'ranger_with_min_max', :min => '1', :max => '50', :count => 1
+ assert_response_has_tag 'input', :type => 'range', :name => 'ranger_with_range', :min => '1', :max => '5', :count => 1
end
it 'should display correct range_field_tag in haml' do
- visit '/haml/form_tag'
- assert_have_selector 'input', :type => 'range', :name => 'ranger_with_min_max', :min => '1', :max => '50', :count => 1
- assert_have_selector 'input', :type => 'range', :name => 'ranger_with_range', :min => '1', :max => '5', :count => 1
+ get "/haml/form_tag"
+ assert_response_has_tag 'input', :type => 'range', :name => 'ranger_with_min_max', :min => '1', :max => '50', :count => 1
+ assert_response_has_tag 'input', :type => 'range', :name => 'ranger_with_range', :min => '1', :max => '5', :count => 1
end
it 'should display correct range_field_tag in slim' do
- visit '/slim/form_tag'
- assert_have_selector 'input', :type => 'range', :name => 'ranger_with_min_max', :min => '1', :max => '50', :count => 1
- assert_have_selector 'input', :type => 'range', :name => 'ranger_with_range', :min => '1', :max => '5', :count => 1
+ get "/slim/form_tag"
+ assert_response_has_tag 'input', :type => 'range', :name => 'ranger_with_min_max', :min => '1', :max => '50', :count => 1
+ assert_response_has_tag 'input', :type => 'range', :name => 'ranger_with_range', :min => '1', :max => '5', :count => 1
+ end
+ end
+
+ describe 'for #datetime_field_tag' do
+ before do
+ @expected = {
+ :name => 'datetime',
+ :max => "2000-04-01T12:00:00.000+0000",
+ :min => "1993-02-24T12:30:45.000+0000",
+ :value => "2000-04-01T12:00:00.000+0000"
+ }
+ end
+
+ it 'should create an input tag with min and max and value options' do
+ max = DateTime.new(2000, 4, 1, 12, 0, 0)
+ min = DateTime.new(1993, 2, 24, 12, 30, 45)
+ value = DateTime.new(2000, 4, 1, 12, 0, 0)
+ actual_html = datetime_field_tag('datetime', :max => max, :min => min, :value => value)
+ assert_html_has_tag(actual_html, 'input', @expected)
+ end
+
+ it 'should create an input tag with datetime' do
+ actual_html = datetime_field_tag('datetime')
+ assert_html_has_tag(actual_html, 'input[type=datetime]')
+ end
+
+ it 'should create an input tag when the format string passed as datetime option value' do
+ actual_html = datetime_field_tag('datetime', :value => '1993-02-24T12:30:45+00:00')
+ assert_html_has_tag(actual_html, 'input[type=datetime]', :value => "1993-02-24T12:30:45.000+0000")
+ end
+
+ it 'should display correct datetime_field_tag in erb' do
+ get "/erb/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct datetime_field_tag in haml' do
+ get "/haml/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct datetime_field_tag in slim' do
+ get "/slim/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+ end
+
+ describe 'for #datetime_local_field_tag' do
+ before do
+ @expected = {
+ :name => 'datetime_local',
+ :max => "2000-04-01T12:00:00",
+ :min => "1993-02-24T12:30:45",
+ :value => "2000-04-01T12:00:00"
+ }
+ end
+
+ it 'should create an input tag with min and max and value options' do
+ max = DateTime.new(2000, 4, 1, 12, 0, 0)
+ min = DateTime.new(1993, 2, 24, 12, 30, 45)
+ value = DateTime.new(2000, 4, 1, 12, 0, 0)
+ actual_html = datetime_local_field_tag('datetime_local', :max => max, :min => min, :value => value)
+ assert_html_has_tag(actual_html, 'input', @expected)
+ end
+
+ it 'should create an input tag with datetime-local' do
+ actual_html = datetime_local_field_tag('datetime_local')
+ assert_html_has_tag(actual_html, 'input[type="datetime-local"]')
+ end
+
+ it 'should create an input tag when the format string passed as datetime-local option value' do
+ actual_html = datetime_local_field_tag('datetime_local', :value => '1993-02-24T12:30:45')
+ assert_html_has_tag(actual_html, 'input[type="datetime-local"]', :value => "1993-02-24T12:30:45")
+ end
+
+ it 'should display correct datetime_local_field_tag in erb' do
+ get "/erb/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct datetime_local_field_tag in haml' do
+ get "/haml/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct datetime_local_field_tag in slim' do
+ get "/slim/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+ end
+
+ describe 'for #date_field_tag' do
+ before do
+ @expected = {
+ :name => 'date',
+ :max => "2000-04-01",
+ :min => "1993-02-24",
+ :value => "2000-04-01"
+ }
+ end
+
+ it 'should create an input tag with min and max and value options' do
+ max = DateTime.new(2000, 4, 1)
+ min = DateTime.new(1993, 2, 24)
+ value = DateTime.new(2000, 4, 1)
+ actual_html = date_field_tag('date', :max => max, :min => min, :value => value)
+ assert_html_has_tag(actual_html, 'input', @expected)
+ end
+
+ it 'should create an input tag with date' do
+ actual_html = date_field_tag('date')
+ assert_html_has_tag(actual_html, 'input[type="date"]')
+ end
+
+ it 'should create an input tag when the format string passed as date option value' do
+ actual_html = date_field_tag('date', :value => '1993-02-24')
+ assert_html_has_tag(actual_html, 'input[type="date"]', :value => "1993-02-24")
+ end
+
+ it 'should display correct date_field_tag in erb' do
+ get "/erb/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct date_field_tag in haml' do
+ get "/haml/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct date_field_tag in slim' do
+ get "/slim/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+ end
+
+ describe 'for #month_field_tag' do
+ before do
+ @expected = {
+ :name => 'month',
+ :max => "2000-04",
+ :min => "1993-02",
+ :value => "2000-04"
+ }
+ end
+
+ it 'should create an input tag with min and max and value options' do
+ max = DateTime.new(2000, 4, 1)
+ min = DateTime.new(1993, 2, 24)
+ value = DateTime.new(2000, 4, 1)
+ actual_html = month_field_tag('month', :max => max, :min => min, :value => value)
+ assert_html_has_tag(actual_html, 'input', @expected)
+ end
+
+ it 'should create an input tag with month' do
+ actual_html = month_field_tag('month')
+ assert_html_has_tag(actual_html, 'input[type="month"]')
+ end
+
+ it 'should create an input tag when the format string passed as month option value' do
+ actual_html = month_field_tag('month', :value => '1993-02-24')
+ assert_html_has_tag(actual_html, 'input[type="month"]', :value => "1993-02")
+ end
+
+ it 'should display correct month_field_tag in erb' do
+ get "/erb/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct month_field_tag in haml' do
+ get "/haml/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct month_field_tag in slim' do
+ get "/slim/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+ end
+
+ describe 'for #week_field_tag' do
+ before do
+ @expected = {
+ :name => 'week',
+ :max => "2000-W13",
+ :min => "1993-W08",
+ :value => "2000-W13"
+ }
+ end
+
+ it 'should create an input tag with min and max and value options' do
+ max = DateTime.new(2000, 4, 1)
+ min = DateTime.new(1993, 2, 24)
+ value = DateTime.new(2000, 4, 1)
+ actual_html = week_field_tag('week', :max => max, :min => min, :value => value)
+ assert_html_has_tag(actual_html, 'input', @expected)
+ end
+
+ it 'should create an input tag with week' do
+ actual_html = week_field_tag('week')
+ assert_html_has_tag(actual_html, 'input[type="week"]')
+ end
+
+ it 'should create an input tag when the format string passed as week option value' do
+ actual_html = week_field_tag('week', :value => '1993-02-24')
+ assert_html_has_tag(actual_html, 'input[type="week"]', :value => "1993-W08")
+ end
+
+ it 'should display correct week_field_tag in erb' do
+ get "/erb/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct week_field_tag in haml' do
+ get "/haml/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct week_field_tag in slim' do
+ get "/slim/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+ end
+
+ describe 'for #time_field_tag' do
+ before do
+ @expected = {
+ :name => 'time',
+ :max => "13:30:00.000",
+ :min => "01:19:12.000",
+ :value => "13:30:00.000"
+ }
+ end
+
+ it 'should create an input tag with min and max and value options' do
+ max = Time.new(2008, 6, 21, 13, 30, 0)
+ min = Time.new(1993, 2, 24, 1, 19, 12)
+ value = Time.new(2008, 6, 21, 13, 30, 0)
+ actual_html = time_field_tag('time', :max => max, :min => min, :value => value)
+ assert_html_has_tag(actual_html, 'input', @expected)
+ end
+
+ it 'should create an input tag with time' do
+ actual_html = time_field_tag('time')
+ assert_html_has_tag(actual_html, 'input[type="time"]')
+ end
+
+ it 'should create an input tag when the format string passed as time option value' do
+ actual_html = time_field_tag('time', :value => '1993-02-24 01:19:12')
+ assert_html_has_tag(actual_html, 'input[type="time"]', :value => "01:19:12.000")
+ end
+
+ it 'should display correct time_field_tag in erb' do
+ get "/erb/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct time_field_tag in haml' do
+ get "/haml/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct time_field_tag in slim' do
+ get "/slim/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+ end
+
+ describe 'for #color_field_tag' do
+ before do
+ @expected = {
+ :name => 'color',
+ :value => '#ff0000'
+ }
+ end
+
+ it 'should create an input tag with value option' do
+ actual_html = color_field_tag('color', :value => "#ff0000")
+ assert_html_has_tag(actual_html, 'input[type="color"]', @expected)
+ end
+
+ it 'should create an input tag with short color code' do
+ actual_html = color_field_tag('color', :value => "#f00")
+ assert_html_has_tag(actual_html, 'input[type="color"]', @expected)
+ end
+
+ it 'should display correct color_field_tag in erb' do
+ get "/erb/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct color_field_tag in haml' do
+ get "/haml/form_tag"
+ assert_response_has_tag 'input', @expected
+ end
+
+ it 'should display correct color_field_tag in slim' do
+ get "/slim/form_tag"
+ assert_response_has_tag 'input', @expected
end
end
end
diff --git a/padrino-helpers/test/test_format_helpers.rb b/padrino-helpers/test/test_format_helpers.rb
index 7fe2a3715..e716c3462 100644
--- a/padrino-helpers/test/test_format_helpers.rb
+++ b/padrino-helpers/test/test_format_helpers.rb
@@ -57,25 +57,6 @@ def setup
end
end
- describe 'for #pluralize method' do
- it 'should return singular count for 1 item collections' do
- actual_text = pluralize(1, 'person')
- assert_equal '1 person', actual_text
- end
- it 'should return plural count for empty collections' do
- actual_text = pluralize(0, 'person')
- assert_equal '0 people', actual_text
- end
- it 'should return plural count for many collections' do
- actual_text = pluralize(2, 'person')
- assert_equal '2 people', actual_text
- end
- it 'should return pluralized word specified as argument' do
- actual_text = pluralize(3, 'person', 'users')
- assert_equal '3 users', actual_text
- end
- end
-
describe 'for #word_wrap method' do
it 'should return proper formatting for 8 max width' do
actual_text = word_wrap('Once upon a time', :line_width => 8)
@@ -158,6 +139,8 @@ def setup
end
describe 'for #time_ago_in_words method' do
+ _DAY = 24*60*60
+
it 'should less than 5 seconds' do
assert_equal 'less than 5 seconds', time_ago_in_words(Time.now, true)
end
@@ -177,75 +160,72 @@ def setup
assert_equal 'less than a minute', time_ago_in_words(Time.now)
end
it 'should display yesterday' do
- assert_equal '1 day', time_ago_in_words(1.day.ago)
+ assert_equal '1 day', time_ago_in_words(Time.now - _DAY)
end
it 'should display tomorrow' do
- assert_equal '1 day', time_ago_in_words(1.day.from_now)
+ assert_equal '1 day', time_ago_in_words(Time.now + _DAY)
end
it 'should return future number of days' do
- assert_equal '4 days', time_ago_in_words(4.days.from_now)
+ assert_equal '4 days', time_ago_in_words(Time.now + 4*_DAY)
end
it 'should return past days ago' do
- assert_equal '4 days', time_ago_in_words(4.days.ago)
+ assert_equal '4 days', time_ago_in_words(Time.now - 4*_DAY)
end
it 'should return formatted archived date' do
- assert_equal '3 months', time_ago_in_words(100.days.ago)
+ assert_equal '3 months', time_ago_in_words(Time.now - 100*_DAY)
end
it 'should return formatted archived year date' do
- assert_equal 'over 1 year', time_ago_in_words(500.days.ago)
+ assert_equal 'over 1 year', time_ago_in_words(Time.now - 500*_DAY)
end
it 'should display now as a minute ago' do
- assert_equal '1 minute', time_ago_in_words(1.minute.ago)
+ assert_equal '1 minute', time_ago_in_words(Time.now - 60)
end
it 'should display a few minutes ago' do
- assert_equal '4 minutes', time_ago_in_words(4.minute.ago)
+ assert_equal '4 minutes', time_ago_in_words(Time.now - 4*60)
end
it 'should display an hour ago' do
- assert_equal 'about 1 hour', time_ago_in_words(1.hour.ago + 5.minutes.ago.sec)
+ assert_equal 'about 1 hour', time_ago_in_words(Time.now - 60*60 + 5)
end
it 'should display a few hours ago' do
- assert_equal 'about 3 hours', time_ago_in_words(3.hour.ago + 5.minutes.ago.sec)
- end
- it 'should display a day ago' do
- assert_equal '1 day', time_ago_in_words(1.day.ago)
+ assert_equal 'about 3 hours', time_ago_in_words(Time.now - 3*60*60 + 5*60)
end
it 'should display a few days ago' do
- assert_equal '5 days', time_ago_in_words(5.days.ago - 5.minutes.ago.sec)
+ assert_equal '5 days', time_ago_in_words(Time.now - 5*_DAY - 5*60)
end
it 'should display a month ago' do
- assert_equal 'about 1 month', time_ago_in_words(32.days.ago + 5.minutes.ago.sec)
+ assert_equal 'about 1 month', time_ago_in_words(Time.now - 32*_DAY + 5*60)
end
it 'should display a few months ago' do
- assert_equal '6 months', time_ago_in_words(180.days.ago - 5.minutes.ago.sec)
+ assert_equal '6 months', time_ago_in_words(Time.now - 180*_DAY - 5*60)
end
it 'should display a year ago' do
- assert_equal 'about 1 year', time_ago_in_words(365.days.ago - 5.minutes.ago.sec)
+ assert_equal 'about 1 year', time_ago_in_words(Time.now - 365*_DAY - 5*60)
end
it 'should display a few years ago' do
- assert_equal 'over 7 years', time_ago_in_words(2800.days.ago - 5.minutes.ago.sec)
+ assert_equal 'over 7 years', time_ago_in_words(Time.now - 2800*_DAY - 5*60)
end
end
describe 'for #js_escape_html method' do
it 'should escape double quotes' do
assert_equal "\\\"hello\\\"", js_escape_html('"hello"')
- assert_equal "\\\"hello\\\"", js_escape_html(ActiveSupport::SafeBuffer.new('"hello"'))
+ assert_equal "\\\"hello\\\"", js_escape_html(SafeBuffer.new('"hello"'))
end
it 'should escape single quotes' do
assert_equal "\\'hello\\'", js_escape_html("'hello'")
- assert_equal "\\'hello\\'", js_escape_html(ActiveSupport::SafeBuffer.new("'hello'"))
+ assert_equal "\\'hello\\'", js_escape_html(SafeBuffer.new("'hello'"))
end
it 'should escape html tags and breaks' do
assert_equal "\\n\\nhello<\\/p>\\n", js_escape_html("\n\r
hello
\r\n") - assert_equal "\\n\\nhello<\\/p>\\n", js_escape_html(ActiveSupport::SafeBuffer.new("\n\r
hello
\r\n")) + assert_equal "\\n\\nhello<\\/p>\\n", js_escape_html(SafeBuffer.new("\n\r
hello
\r\n")) end it 'should escape data-confirm attribute' do assert_equal "Yay Joey & Charlotte!
\nYou have been married 16 years
") + :body => "Yay Joey & Charlotte!
\nYou have been married 16 years
") end it 'should be able to deliver a basic email using app settings' do @@ -53,8 +49,7 @@ :subject => 'Test Email', :body => 'Test Body', :via => :test) assert_email_sent(:to => 'john@apple.com', :from => 'joe@smith.com', - :subject => 'Test Email', :body => 'Test Body', - :delivery_method => @app.delivery_method) + :subject => 'Test Email', :body => 'Test Body') end end @@ -65,7 +60,7 @@ post '/deliver/inline' assert_equal 'mail delivered', body assert_email_sent(:to => 'john@apple.com', :from => 'joe@smith.com', - :delivery_method => @app.delivery_method, :subject => 'Test Email', + :subject => 'Test Email', :body => 'Test Body') end @@ -73,7 +68,7 @@ post '/deliver/plain' assert_equal 'mail delivered', body assert_email_sent(:to => 'john@fake.com', :from => 'noreply@birthday.com', - :delivery_method => @app.delivery_method, :subject => "Happy Birthday!", + :subject => "Happy Birthday!", :body => "Happy Birthday Joey!\nYou are turning 21") end @@ -81,7 +76,7 @@ post '/deliver/custom' assert_equal 'mail delivered', body assert_email_sent(:template => 'mailers/sample/foo_message', :to => 'john@fake.com', - :from => 'noreply@custom.com', :delivery_method => @app.delivery_method, + :from => 'noreply@custom.com', :subject => 'Welcome Message!', :body => 'Hello to Bobby') end @@ -89,8 +84,13 @@ post '/deliver/html' assert_equal 'mail delivered', body assert_email_sent(:to => 'julie@fake.com', :from => 'noreply@anniversary.com', - :content_type => 'text/html', :delivery_method => @app.delivery_method, - :subject => 'Happy anniversary!', :body => "Yay Joey & Charlotte!
\nYou have been married 16 years
") + :content_type => 'text/html', + :subject => 'Happy anniversary!', :body => "Yay Joey & Charlotte!
\nYou have been married 16 years
") + end + + it 'should be able to deliver emails with views in custom-named folders' do + post '/deliver/external' + assert_equal 'mail delivered', body end it 'should be able to deliver a basic email using app settings' do @@ -98,8 +98,7 @@ :subject => 'Test Email', :body => 'Test Body', :via => :test) assert_email_sent(:to => 'john@apple.com', :from => 'joe@smith.com', - :subject => 'Test Email', :body => 'Test Body', - :delivery_method => @app.delivery_method) + :subject => 'Test Email', :body => 'Test Body') end it 'should be able to deliver a basic email using Padrino::Helpers' do @@ -107,8 +106,36 @@ post '/deliver/helper' assert_equal 'mail delivered', body assert_email_sent(:to => 'jim@fake.com', :from => 'noreply@custom.com', - :content_type => 'text/html', :delivery_method => @app.delivery_method, + :content_type => 'text/html', :subject => 'Welcome Helper!', :body => "jim") end + + it 'should fail with proper message if mailer is not registered' do + error = assert_raises RuntimeError do + post '/deliver/failing_mailer' + end + assert_match /is not registered/, error.message + end + + it 'should fail with proper message if message does not exist' do + error = assert_raises RuntimeError do + post '/deliver/failing_message' + end + assert_match /has no message/, error.message + end + + it 'should be able to render default mailer names' do + post '/deliver/default_mailer_name' + assert_equal 'mail delivered', body + assert_email_sent(:to => 'jim@fake.com', :from => 'noreply@custom.com', + :content_type => 'text/plain', :body => "dmn") + end + + it 'should be able to render default mailer email names' do + post '/deliver/default_mailer_email_name' + assert_equal 'mail delivered', body + assert_email_sent(:to => 'jim@fake.com', :from => 'noreply@custom.com', + :content_type => 'text/plain', :body => "dmen") + end end end diff --git a/padrino-mailer/test/test_part.rb b/padrino-mailer/test/test_part.rb index fbea65b09..04fe6d6b3 100644 --- a/padrino-mailer/test/test_part.rb +++ b/padrino-mailer/test/test_part.rb @@ -33,7 +33,6 @@ assert_equal 'other', message.parts[2].body.decoded assert_equal 'This is a foo message in mailers/sample dir', message.html_part.body.decoded.chomp - assert_equal 'plain text', message.text_part.body.decoded end it 'should works with multipart templates' do diff --git a/padrino-performance/Rakefile b/padrino-performance/Rakefile index f33347d26..64fa66b28 100644 --- a/padrino-performance/Rakefile +++ b/padrino-performance/Rakefile @@ -1,5 +1,11 @@ -# coding:utf-8 -RAKE_ROOT = __FILE__ +require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper') -require 'rubygems' -require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper') \ No newline at end of file +Rake::TestTask.new(:bench) do |test| + test.libs << 'test' + test.test_files = Dir['test/**/bench_*.rb'] +end + +Rake::TestTask.new(:mem) do |test| + test.libs << 'test' + test.test_files = Dir['test/**/mem_*.rb'] +end diff --git a/padrino-performance/lib/padrino-performance/version.rb b/padrino-performance/lib/padrino-performance/version.rb index 5ac4d79a2..d9554963b 100644 --- a/padrino-performance/lib/padrino-performance/version.rb +++ b/padrino-performance/lib/padrino-performance/version.rb @@ -1,7 +1,7 @@ module Padrino module Performance # The version constant for the current version of Padrino. - VERSION = '0.12.2' unless defined?(Padrino::VERSION) + VERSION = '0.13.2' unless defined?(Padrino::VERSION) # # The current Padrino version. diff --git a/padrino-performance/test/bench_core.rb b/padrino-performance/test/bench_core.rb new file mode 100644 index 000000000..ef8bb4136 --- /dev/null +++ b/padrino-performance/test/bench_core.rb @@ -0,0 +1,186 @@ +ENV['RACK_ENV'] = 'test' + +require 'padrino-core' + +require 'minitest/autorun' +require 'minitest/benchmark' +require 'rack/test' + +module MockBenchmark + include Rack::Test::Methods + + module Settings + def bench_range + [20, 80, 320, 1280, 5120] + end + + def run(*) + puts 'Running ' + self.name + super + end + end + + def self.paths + @paths ||= (1..100).map{ rand(36**8).to_s(36) } + end + + def self.included(base) + base.extend Settings + end + + def result_code + '' + end + + def app + @app + end + + module BenchmarkRouting + def bench_calling_404 + assert_performance_linear 0.99 do |n| + n.times do + get "/#{@paths.sample}_not_found" + end + end + assert_equal 404, last_response.status + end + + def bench_calling_one_path + assert_performance_linear 0.99 do |n| + n.times do + get '/foo' + end + end + assert_equal 200, last_response.status + end + + def bench_calling_sample + assert_performance_linear 0.99 do |n| + n.times do + get "/#{@paths.sample}" + end + end + assert_equal 200, last_response.status + end + + def bench_calling_params + assert_performance_linear 0.99 do |n| + n.times do + get "/foo?foo=bar&zoo=#{@paths.sample}" + end + end + assert_equal 200, last_response.status + end + + def bench_sample_and_params + assert_performance_linear 0.99 do |n| + n.times do + get "/#{@paths.sample}?foo=bar&zoo=#{@paths.sample}" + end + end + assert_equal 200, last_response.status + end + end +end + +class Padrino::CoreBenchmark < Minitest::Benchmark + include MockBenchmark + include MockBenchmark::BenchmarkRouting + + def setup + Padrino.clear! + + @app = Sinatra.new Padrino::Application do + get("/foo") { "okey" } + + MockBenchmark.paths.each do |p| + get("/#{p}") { p.to_s } + end + end + + @paths = MockBenchmark.paths + + get '/' + end +end + +class SinatraBenchmark < Minitest::Benchmark + include MockBenchmark + include MockBenchmark::BenchmarkRouting + + def setup + @app = Sinatra.new do + get("/foo") { "okey" } + + MockBenchmark.paths.each do |p| + get("/#{p}") { p.to_s } + end + end + + @paths = MockBenchmark.paths + + get '/' + end +end + +class Padrino::MounterBenchmark < Minitest::Benchmark + include MockBenchmark + + class TestApp < Padrino::Application + get '/' do + 'OK' + end + end + + def setup + Padrino.clear! + + MockBenchmark.paths.each do |p| + Padrino.mount(TestApp).to("/#{p}") + end + + @paths = MockBenchmark.paths + end + + def bench_mounted_sample + request = Rack::MockRequest.new(Padrino.application) + response = nil + assert_performance_linear 0.99 do |n| + n.times do + response = request.get("/#{@paths.sample}") + end + end + assert_equal 200, response.status + end +end + +class Padrino::HugeRouterBenchmark < Minitest::Benchmark + include MockBenchmark + + def setup + @apps = {} + @pathss = {} + @requests = {} + self.class.bench_range.each do |n| + @pathss[n] = paths = (1..n/20).map{ rand(36**8).to_s(36) } + @apps[n] = Sinatra.new Padrino::Application do + paths.each do |p| + get("/#{p}") { p.to_s } + end + end + @requests[n] = Rack::MockRequest.new(@apps[n]) + @requests[n].get('/') + end + end + + def bench_calling_sample + response = nil + assert_performance_linear 0.99 do |n| + n.times do + response = @requests[n].get("/#{@pathss[n].sample}") + end + end + assert_equal 200, response.status + end +end diff --git a/padrino-performance/test/helper.rb b/padrino-performance/test/helper.rb index a5f468582..fcb5443b6 100644 --- a/padrino-performance/test/helper.rb +++ b/padrino-performance/test/helper.rb @@ -1,12 +1,4 @@ -require File.expand_path('../../../load_paths', __FILE__) - require 'minitest/autorun' require 'minitest/pride' -require 'padrino-core' -require 'padrino-performance' -require 'rack' require 'rack/test' - -class MiniTest::Spec - include Rack::Test::Methods -end +require 'padrino-performance' diff --git a/padrino-performance/test/mem_core.rb b/padrino-performance/test/mem_core.rb new file mode 100644 index 000000000..3d1c838f0 --- /dev/null +++ b/padrino-performance/test/mem_core.rb @@ -0,0 +1,66 @@ +ENV['RACK_ENV'] = 'test' + +require 'padrino-core' + +require 'minitest/autorun' +require 'minitest/benchmark' +require 'rack/test' + +module MockBenchmark + include Rack::Test::Methods + + module Settings + def bench_range + [20, 80, 320, 1280, 5120] + end + + def run(*) + puts 'Running ' + self.name + puts `pmap -x #{$$} | tail -1` + super + puts `pmap -x #{$$} | tail -1` + end + end + + def self.included(base) + base.extend Settings + end + + def result_code + '' + end + + def app + @app + end +end + +class Padrino::HugeRouterBenchmark < Minitest::Benchmark + include MockBenchmark + + def setup + @apps = {} + @pathss = {} + @requests = {} + self.class.bench_range.each do |n| + @pathss[n] = paths = (1..n/5).map{ rand(36**8).to_s(36) } + @apps[n] = Sinatra.new Padrino::Application do + paths.each do |p| + get("/#{p}") { p.to_s } + end + end + @requests[n] = Rack::MockRequest.new(@apps[n]) + @requests[n].get('/') + end + end + + def bench_calling_sample + response = nil + assert_performance_linear 0.99 do |n| + n.times do + response = @requests[n].get("/#{@pathss[n].sample}") + end + end + assert_equal 200, response.status + end +end diff --git a/padrino-performance/test/test_os.rb b/padrino-performance/test/test_os.rb index 9ed80de52..01e8ae344 100644 --- a/padrino-performance/test/test_os.rb +++ b/padrino-performance/test/test_os.rb @@ -57,5 +57,4 @@ refute(Padrino::Performance::OS.linux?, 'We a darwin operation system.') end end - end diff --git a/padrino-support/Rakefile b/padrino-support/Rakefile index e747a64e7..da75d43e2 100644 --- a/padrino-support/Rakefile +++ b/padrino-support/Rakefile @@ -1,5 +1 @@ -# coding:utf-8 -RAKE_ROOT = __FILE__ - -require 'rubygems' require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper') diff --git a/padrino-support/lib/padrino-support.rb b/padrino-support/lib/padrino-support.rb index 43fc7f5d6..d7f642b61 100644 --- a/padrino-support/lib/padrino-support.rb +++ b/padrino-support/lib/padrino-support.rb @@ -1,21 +1,26 @@ ## -# This file loads certain extensions required by Padrino from ActiveSupport. +# This file loads certain extensions required by Padrino. # -require 'active_support/core_ext/module/aliasing' # alias_method_chain -require 'active_support/core_ext/hash/reverse_merge' # reverse_merge -require 'active_support/core_ext/hash/keys' # symbolize_keys -require 'active_support/core_ext/hash/indifferent_access' # params[:foo] -require 'active_support/core_ext/hash/slice' # slice -require 'active_support/core_ext/array/extract_options' # Array#extract_options! -require 'active_support/core_ext/object/blank' # present? -require 'active_support/core_ext/string/output_safety' # SafeBuffer and html_safe - -require 'padrino-support/core_ext/string/inflections' require 'padrino-support/core_ext/string/colorize' -require 'padrino-support/core_ext/string/undent' # deprecated -require 'padrino-support/core_ext/object_space' require 'padrino-support/file_set' +require 'padrino-support/utils' +if ENV["AS_VERSION"] + # require ActiveSupport features for tests or legacy projects + require 'active_support/core_ext/string/output_safety' # SafeBuffer and html_safe + require 'active_support/core_ext/object/blank' # present? + require 'active_support/core_ext/hash/keys' # symbolize_keys + require 'active_support/core_ext/hash/indifferent_access' # params[:foo] + require 'active_support/core_ext/hash/reverse_merge' # reverse_merge + require 'active_support/core_ext/module/aliasing' # alias_method_chain + require 'active_support/core_ext/array/extract_options' # Array#extract_options! + require 'active_support/core_ext/hash/slice' # slice + begin + require 'active_support/core_ext/object/deep_dup' # AS 4.1 + rescue LoadError + require 'active_support/core_ext/hash/deep_dup' # AS >= 3.1 + end +end ## # Loads our locale configuration files @@ -30,5 +35,5 @@ # In reloader for accessing class_name Foo._orig_klass_name # class Module - alias :_orig_klass_name :to_s + alias :_orig_klass_name :name end diff --git a/padrino-support/lib/padrino-support/core_ext/object_space.rb b/padrino-support/lib/padrino-support/core_ext/object_space.rb deleted file mode 100644 index 04c0c917d..000000000 --- a/padrino-support/lib/padrino-support/core_ext/object_space.rb +++ /dev/null @@ -1,49 +0,0 @@ -module ObjectSpace - class << self - ## - # Returns all the classes in the object space. - # Optionally, a block can be passed, for example the following code - # would return the classes that start with the character "A": - # - # ObjectSpace.classes do |klass| - # if klass.to_s[0] == "A" - # klass - # end - # end - # - def classes(&block) - rs = Set.new - - ObjectSpace.each_object(Class).each do |klass| - if block - if r = block.call(klass) - # add the returned value if the block returns something - rs << r - end - else - rs << klass - end - end - - rs - end - - ## - # Returns a list of existing classes that are not included in "snapshot" - # This method is useful to get the list of new classes that were loaded - # after an event like requiring a file. - # Usage: - # - # snapshot = ObjectSpace.classes - # # require a file - # ObjectSpace.new_classes(snapshot) - # - def new_classes(snapshot) - self.classes do |klass| - if !snapshot.include?(klass) - klass - end - end - end - end -end diff --git a/padrino-support/lib/padrino-support/core_ext/string/colorize.rb b/padrino-support/lib/padrino-support/core_ext/string/colorize.rb index d8739e77b..f347a73ed 100644 --- a/padrino-support/lib/padrino-support/core_ext/string/colorize.rb +++ b/padrino-support/lib/padrino-support/core_ext/string/colorize.rb @@ -1,5 +1,3 @@ -require 'win32console' if RUBY_PLATFORM =~ /(win|m)32/ # ruby color support for win - ## # Add colors # diff --git a/padrino-support/lib/padrino-support/core_ext/string/inflections.rb b/padrino-support/lib/padrino-support/core_ext/string/inflections.rb deleted file mode 100644 index b6af3d54a..000000000 --- a/padrino-support/lib/padrino-support/core_ext/string/inflections.rb +++ /dev/null @@ -1,98 +0,0 @@ -require 'active_support/inflections' # load default inflections -require 'active_support/inflector/methods' # constantize -require 'active_support/inflector/inflections' # pluralize - -## -# This is an adapted version of active_support/core_ext/string/inflections.rb -# to prevent loading several dependencies including I18n gem. -# -# Issue: https://github.com/rails/rails/issues/1526 -# -class String - ## - # Returns the plural form of the word in the string. - # - # "post".pluralize # => "posts" - # "octopus".pluralize # => "octopi" - # "sheep".pluralize # => "sheep" - # "words".pluralize # => "words" - # "the blue mailman".pluralize # => "the blue mailmen" - # "CamelOctopus".pluralize # => "CamelOctopi" - # - def pluralize - ActiveSupport::Inflector.pluralize(self) - end - - ## - # Returns the singular form of the word in the string. - # - # "posts".singularize # => "post" - # "octopi".singularize # => "octopus" - # "sheep".singularize # => "sheep" - # "words".singularize # => "word" - # "the blue mailmen".singularize # => "the blue mailman" - # "CamelOctopi".singularize # => "CamelOctopus" - # - def singularize - ActiveSupport::Inflector.singularize(self) - end - - ## - # +constantize+ tries to find a declared constant with the name specified - # in the string. It raises a NameError when the name is not in CamelCase - # or is not initialized. - # - # "Module".constantize # => Module - # "Class".constantize # => Class - # - def constantize - ActiveSupport::Inflector.constantize(self) - end - - ## - # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string. - # - # +underscore+ will also change '::' to '/' to convert namespaces to paths. - # - # "ActiveRecord".underscore # => "active_record" - # "ActiveRecord::Errors".underscore # => active_record/errors - # - def underscore - ActiveSupport::Inflector.underscore(self) - end - - ## - # By default, +camelize+ converts strings to UpperCamelCase. If the argument to camelize - # is set to :lower then camelize produces lowerCamelCase. - # - # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces. - # - # "active_record".camelize # => "ActiveRecord" - # "active_record".camelize(:lower) # => "activeRecord" - # "active_record/errors".camelize # => "ActiveRecord::Errors" - # "active_record/errors".camelize(:lower) # => "activeRecord::Errors" - # - def camelize(first_letter = :upper) - case first_letter - when :upper then ActiveSupport::Inflector.camelize(self, true) - when :lower then ActiveSupport::Inflector.camelize(self, false) - end - end - alias_method :camelcase, :camelize - - ## - # Create a class name from a plural table name like Rails does for table names to models. - # Note that this returns a string and not a class. (To convert to an actual class - # follow +classify+ with +constantize+.) - # - # "egg_and_hams".classify # => "EggAndHam" - # "posts".classify # => "Post" - # - # Singular names are not handled correctly. - # - # "business".classify # => "Busines" - # - def classify - ActiveSupport::Inflector.classify(self) - end -end diff --git a/padrino-support/lib/padrino-support/core_ext/string/undent.rb b/padrino-support/lib/padrino-support/core_ext/string/undent.rb deleted file mode 100644 index bb705a92f..000000000 --- a/padrino-support/lib/padrino-support/core_ext/string/undent.rb +++ /dev/null @@ -1,19 +0,0 @@ -## -# Removes indentation -# -# @example -# help <<-EOS.undent -# Here my help usage -# sample_code -# -# Fix -# EOS -# puts help.red.bold -# -class String - # Strip unnecessary indentation of the front of a string - def undent - warn "##{__method__} is deprecated" - gsub(/^.{#{slice(/^ +/).size}}/, '') - end -end diff --git a/padrino-support/lib/padrino-support/default_inflections.rb b/padrino-support/lib/padrino-support/default_inflections.rb new file mode 100644 index 000000000..65f2b2663 --- /dev/null +++ b/padrino-support/lib/padrino-support/default_inflections.rb @@ -0,0 +1,50 @@ +# frozen-string-literal: true +## +# This module is based on Sequel 5.4.0 +# sequel-5.4.0/lib/sequel/model/default_inflections.rb +# +module Padrino + # Proc that is instance evaled to create the default inflections for both the + # model inflector and the inflector extension. + DEFAULT_INFLECTIONS_PROC = proc do + plural(/$/, 's') + plural(/s$/i, 's') + plural(/(alias|(?:stat|octop|vir|b)us)$/i, '\1es') + plural(/(buffal|tomat)o$/i, '\1oes') + plural(/([ti])um$/i, '\1a') + plural(/sis$/i, 'ses') + plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves') + plural(/(hive)$/i, '\1s') + plural(/([^aeiouy]|qu)y$/i, '\1ies') + plural(/(x|ch|ss|sh)$/i, '\1es') + plural(/(matr|vert|ind)ix|ex$/i, '\1ices') + plural(/([m|l])ouse$/i, '\1ice') + + singular(/s$/i, '') + singular(/([ti])a$/i, '\1um') + singular(/(analy|ba|cri|diagno|parenthe|progno|synop|the)ses$/i, '\1sis') + singular(/([^f])ves$/i, '\1fe') + singular(/([h|t]ive)s$/i, '\1') + singular(/([lr])ves$/i, '\1f') + singular(/([^aeiouy]|qu)ies$/i, '\1y') + singular(/(m)ovies$/i, '\1ovie') + singular(/(x|ch|ss|sh)es$/i, '\1') + singular(/([m|l])ice$/i, '\1ouse') + singular(/buses$/i, 'bus') + singular(/oes$/i, 'o') + singular(/shoes$/i, 'shoe') + singular(/(alias|(?:stat|octop|vir|b)us)es$/i, '\1') + singular(/(vert|ind)ices$/i, '\1ex') + singular(/matrices$/i, 'matrix') + + irregular('person', 'people') + irregular('man', 'men') + irregular('child', 'children') + irregular('sex', 'sexes') + irregular('move', 'moves') + irregular('quiz', 'quizzes') + irregular('testis', 'testes') + + uncountable(%w(equipment information rice money species series fish sheep news)) + end +end diff --git a/padrino-support/lib/padrino-support/file_set.rb b/padrino-support/lib/padrino-support/file_set.rb index c146b0ea6..6111583e8 100644 --- a/padrino-support/lib/padrino-support/file_set.rb +++ b/padrino-support/lib/padrino-support/file_set.rb @@ -8,10 +8,10 @@ module FileSet # Returns the list of files matching the glob pattern # FileSet.glob('padrino-core/application/*.rb', __FILE__) { |file| load file } # - def glob(glob_pattern, file_path=nil, &block) + def glob(glob_pattern, file_path=nil) glob_pattern = File.join(File.dirname(file_path), glob_pattern) if file_path file_list = Dir.glob(glob_pattern).sort - file_list.each { |file| block.call(file) } + file_list.each{ |file| yield(file) } file_list end diff --git a/padrino-support/lib/padrino-support/inflections.rb b/padrino-support/lib/padrino-support/inflections.rb new file mode 100644 index 000000000..14b77939e --- /dev/null +++ b/padrino-support/lib/padrino-support/inflections.rb @@ -0,0 +1,179 @@ +## +# This module is based on Sequel 4.27.0 +# sequel-4.27.0/lib/sequel/model/inflections.rb +# +require 'padrino-support/default_inflections' + +module Padrino + # This module acts as a singleton returned/yielded by Sequel.inflections, + # which is used to override or specify additional inflection rules + # for Sequel. Examples: + # + # Sequel.inflections do |inflect| + # inflect.plural /^(ox)$/i, '\1\2en' + # inflect.singular /^(ox)en/i, '\1' + # + # inflect.irregular 'octopus', 'octopi' + # + # inflect.uncountable "equipment" + # end + # + # New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the + # pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may + # already have been loaded. + module Inflections + CAMELIZE_CONVERT_REGEXP = /(^|_)(.)/.freeze + CAMELIZE_MODULE_REGEXP = /\/(.?)/.freeze + DASH = '-'.freeze + DEMODULIZE_CONVERT_REGEXP = /^.*::/.freeze + EMPTY_STRING= ''.freeze + SLASH = '/'.freeze + VALID_CONSTANT_NAME_REGEXP = /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/.freeze + UNDERSCORE = '_'.freeze + UNDERSCORE_CONVERT_REGEXP1 = /([A-Z]+)([A-Z][a-z])/.freeze + UNDERSCORE_CONVERT_REGEXP2 = /([a-z\d])([A-Z])/.freeze + UNDERSCORE_CONVERT_REPLACE = '\1_\2'.freeze + UNDERSCORE_MODULE_REGEXP = /::/.freeze + + @plurals, @singulars, @uncountables = [], [], [] + + class << self + # Array of two element arrays, first containing a regex, and the second containing a substitution pattern, used for plurization. + attr_reader :plurals + + # Array of two element arrays, first containing a regex, and the second containing a substitution pattern, used for singularization. + attr_reader :singulars + + # Array of strings for words were the singular form is the same as the plural form + attr_reader :uncountables + end + + # Clears the loaded inflections within a given scope (default is :all). Give the scope as a symbol of the inflection type, + # the options are: :plurals, :singulars, :uncountables + # + # Examples: + # clear :all + # clear :plurals + def self.clear(scope = :all) + case scope + when :all + @plurals, @singulars, @uncountables = [], [], [] + else + instance_variable_set("@#{scope}", []) + end + end + + # Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used + # for strings, not regular expressions. You simply pass the irregular in singular and plural form. + # + # Examples: + # irregular 'octopus', 'octopi' + # irregular 'person', 'people' + def self.irregular(singular, plural) + plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) + singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1]) + end + + # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression. + # The replacement should always be a string that may include references to the matched data from the rule. + # + # Example: + # plural(/(x|ch|ss|sh)$/i, '\1es') + def self.plural(rule, replacement) + @plurals.insert(0, [rule, replacement]) + end + + # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression. + # The replacement should always be a string that may include references to the matched data from the rule. + # + # Example: + # singular(/([^aeiouy]|qu)ies$/i, '\1y') + def self.singular(rule, replacement) + @singulars.insert(0, [rule, replacement]) + end + + # Add uncountable words that shouldn't be attempted inflected. + # + # Examples: + # uncountable "money" + # uncountable "money", "information" + # uncountable %w( money information rice ) + def self.uncountable(*words) + (@uncountables << words).flatten! + end + + instance_eval(&DEFAULT_INFLECTIONS_PROC) + + extend self + + # Convert the given string to CamelCase. Will also convert '/' to '::' which is useful for converting paths to namespaces. + def camelize(s) + s = s.to_s + return s.camelize if s.respond_to?(:camelize) + s = s.gsub(CAMELIZE_MODULE_REGEXP){|x| "::#{x[-1..-1].upcase unless x == SLASH}"}.gsub(CAMELIZE_CONVERT_REGEXP){|x| x[-1..-1].upcase} + s + end + + # Tries to find a declared constant with the name specified + # in the string. It raises a NameError when the name is not in CamelCase + # or is not initialized. + def constantize(s) + s = s.to_s + return s.constantize if s.respond_to?(:constantize) + raise(NameError, "#{s.inspect} is not a valid constant name!") unless m = VALID_CONSTANT_NAME_REGEXP.match(s) + Object.module_eval("::#{m[1]}", __FILE__, __LINE__) + end + + # Removes the module part from the expression in the string + def demodulize(s) + s = s.to_s + return s.demodulize if s.respond_to?(:demodulize) + s.gsub(DEMODULIZE_CONVERT_REGEXP, EMPTY_STRING) + end + + # Returns the plural form of the word in the string. + def pluralize(s) + s = s.to_s + return s.pluralize if s.respond_to?(:pluralize) + result = s.dup + Inflections.plurals.each{|(rule, replacement)| break if result.gsub!(rule, replacement)} unless Inflections.uncountables.include?(s.downcase) + result + end + + # The reverse of pluralize, returns the singular form of a word in a string. + def singularize(s) + s = s.to_s + return s.singularize if s.respond_to?(:singularize) + result = s.dup + Inflections.singulars.each{|(rule, replacement)| break if result.gsub!(rule, replacement)} unless Inflections.uncountables.include?(s.downcase) + result + end + + # The reverse of camelize. Makes an underscored form from the expression in the string. + # Also changes '::' to '/' to convert namespaces to paths. + def underscore(s) + s = s.to_s + return s.underscore if s.respond_to?(:underscore) + s.gsub(UNDERSCORE_MODULE_REGEXP, SLASH).gsub(UNDERSCORE_CONVERT_REGEXP1, UNDERSCORE_CONVERT_REPLACE). + gsub(UNDERSCORE_CONVERT_REGEXP2, UNDERSCORE_CONVERT_REPLACE).tr(DASH, UNDERSCORE).downcase + end + + ## + # Capitalizes the first word, turns underscores into spaces, and strips a trailing '_id' if present. + # + def humanize(s) + s = s.to_s + return s.humanize if s.respond_to?(:humanize) + s.gsub(/_id$/, '').tr('_', ' ').capitalize + end + + ## + # Create a class name from a plural table name like Rails does for table names to models. + # + def classify(s) + s = s.to_s + return s.classify if s.respond_to?(:classify) + camelize(singularize(s.sub(/.*\./, ''))) + end + end +end diff --git a/padrino-support/lib/padrino-support/locale/de.yml b/padrino-support/lib/padrino-support/locale/de.yml index a7c757be6..2626536e7 100644 --- a/padrino-support/lib/padrino-support/locale/de.yml +++ b/padrino-support/lib/padrino-support/locale/de.yml @@ -4,7 +4,7 @@ de: # Benutze die strftime Parameter für die Formatierung # Wenn keine Formate angegeben werden, wird "default" benutzt. # Du kannst auch weitere Formate hinzufügen, wenn Du möchtest. - default: "&d.&m.%Y" + default: "%d.%m.%Y" short: "%d. %b" long: "%d. %B %Y" only_day: "%e" diff --git a/padrino-support/lib/padrino-support/utils.rb b/padrino-support/lib/padrino-support/utils.rb new file mode 100644 index 000000000..48cb3e1c7 --- /dev/null +++ b/padrino-support/lib/padrino-support/utils.rb @@ -0,0 +1,68 @@ +require 'cgi' + +module Padrino + module Utils + extend self + + ## + # Builds an URI query from a Hash or any Object. + # + # Examples (~ marks here that output is actually escaped by CGI): + # + # Utils.build_uri_query(:a => 1, :b => 2) #=> "a=1&b=2" + # Utils.build_uri_query(:a => [1, 2]) #=> ~"a[]=1&a[]=2" + # Utils.build_uri_query([1, 2], 'namespace') #=> ~"namespace[]=1&namespace[]=2" + # Utils.build_uri_query(:a => { :d => 2 }, :b => 3) #=> ~"a[d]=2&b=3" + # + def build_uri_query(object, namespace = nil) + case object + when Hash + object.map do |key, value| + next if value == {} || value == [] + build_uri_query(value, namespace ? "#{namespace}[#{key}]" : key) + end.compact.join('&') + when Array + fail ArgumentError, 'namespace is missing' unless namespace + (object.empty? ? [''] : object).map do |value| + build_uri_query(value, "#{namespace}[]") + end.join('&') + else + fail ArgumentError, 'namespace is missing' unless namespace + "#{CGI.escape(namespace.to_s)}=#{CGI.escape(object.to_s)}" + end + end + + ## + # Recursively duplicates the passed object. + # + def deep_dup(object) + case object + when Array + object.map{ |value| deep_dup(value) } + when Hash + object.each_with_object(object.dup.clear) do |(key, value), new_hash| + new_hash[deep_dup(key)] = deep_dup(value) + end + when NilClass, FalseClass, TrueClass, Symbol, Numeric, Method + object + else + begin + object.dup + rescue TypeError + object + end + end + end + + ## + # Returns a Hash with keys turned into symbols. + # + def symbolize_keys(hash) + result = hash.class.new + hash.each_key do |key| + result[(key.to_sym rescue key)] = hash[key] + end + result + end + end +end diff --git a/padrino-support/padrino-support.gemspec b/padrino-support/padrino-support.gemspec index 4528ee26a..8435222f8 100644 --- a/padrino-support/padrino-support.gemspec +++ b/padrino-support/padrino-support.gemspec @@ -22,6 +22,4 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] s.rdoc_options = ["--charset=UTF-8"] - - s.add_dependency("activesupport", ">= 3.1") end diff --git a/padrino-support/test/helper.rb b/padrino-support/test/helper.rb index 025717008..25f5fa5c9 100644 --- a/padrino-support/test/helper.rb +++ b/padrino-support/test/helper.rb @@ -1,7 +1,6 @@ ENV['RACK_ENV'] = 'test' PADRINO_ROOT = File.dirname(__FILE__) unless defined?(PADRINO_ROOT) -require File.expand_path('../../../load_paths', __FILE__) require 'minitest/autorun' require 'minitest/pride' require 'padrino-support' diff --git a/padrino-support/test/test_utils.rb b/padrino-support/test/test_utils.rb new file mode 100644 index 000000000..d02d3bdee --- /dev/null +++ b/padrino-support/test/test_utils.rb @@ -0,0 +1,124 @@ +require File.expand_path(File.dirname(__FILE__) + '/helper') + +class MiniTest::Spec + def assert_query_equal(expected, actual, namespace=nil) + assert_equal expected.split('&').sort, Padrino::Utils.build_uri_query(actual, namespace).split('&').sort + end +end + +describe 'Padrino::Utils.build_uri_query' do + it 'should do simple conversion' do + assert_query_equal 'a=10', :a => 10 + end + + it 'should do cgi escaping' do + assert_query_equal 'a%3Ab=c+d', 'a:b' => 'c d' + end + + it 'should expand nested hashes' do + assert_query_equal 'person%5Blogin%5D=seckar&person%5Bname%5D=Nicholas', + :person => { :login => 'seckar', :name => 'Nicholas' } + end + + it 'should expand deeply nested hashes' do + assert_query_equal 'account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10', + { :account => { :person => { :id => 20 } }, :person => {:id => 10} } + end + + it 'should accept arrays' do + assert_query_equal 'person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20', + :person => {:id => [10, 20]} + end + + it 'should accept empty arrays' do + assert_query_equal "person%5B%5D=", + [], + 'person' + end + + it 'should expand nested hashes' do + assert_query_equal '', + {} + assert_query_equal 'a=1&b%5Bc%5D=3', + { a: 1, b: { c: 3, d: {} } } + assert_query_equal '', + { a: {b: {c: {}}} } + assert_query_equal 'b%5Bc%5D=false&b%5Be%5D=&b%5Bf%5D=&p=12', + { p: 12, b: { c: false, e: nil, f: '' } } + assert_query_equal 'b%5Bc%5D=3&b%5Bf%5D=', + { b: { c: 3, k: {}, f: '' } } + assert_query_equal 'b=3', + {a: [], b: 3} + end + + it 'should accept namespace for hashes' do + assert_query_equal "user%5Bname%5D=Nakshay&user%5Bnationality%5D=Indian", + { name: 'Nakshay', nationality: 'Indian' }, + 'user' + end +end + +describe 'Padrino::Utils.deep_dup' do + it 'should recursively dup array' do + array = [1, [2, 3]] + dup = Padrino::Utils.deep_dup(array) + dup[1][2] = 4 + assert_equal 2, array[1].size + assert_equal 4, dup[1][2] + end + + it 'should recursively dup hash' do + hash = { :a => { :b => 'b' } } + dup = Padrino::Utils.deep_dup(hash) + dup[:a][:c] = 'c' + refute_includes hash[:a], :c + assert_equal 'c', dup[:a][:c] + end + + it 'should recursively dup array with hash' do + array = [1, { :a => 2, :b => 3 } ] + dup = Padrino::Utils.deep_dup(array) + dup[1][:c] = 4 + refute_includes array[1], :c + assert_equal 4, dup[1][:c] + end + + it 'should recursively dup hash with array' do + hash = { :a => [1, 2] } + dup = Padrino::Utils.deep_dup(hash) + dup[:a][2] = 'c' + assert_equal 2, hash[:a].size + assert_equal 'c', dup[:a][2] + end + + it 'should dup initial hash values' do + zero_hash = Hash.new 0 + hash = { :a => zero_hash } + dup = Padrino::Utils.deep_dup(hash) + assert_equal 0, dup[:a][44] + end + + it 'should properly dup objects' do + object = Object.new + dup = Padrino::Utils.deep_dup(object) + dup.instance_variable_set(:@a, 1) + assert !object.instance_variable_defined?(:@a) + assert dup.instance_variable_defined?(:@a) + end + + it 'should not double the frozen keys' do + hash = { 'a'.freeze => 1 } + dup = Padrino::Utils.deep_dup(hash) + assert_equal 1, dup.keys.length + end +end + +describe 'Padrino::Utils.symbolize_keys' do + it 'should symbolize string keys' do + assert_equal({ :a => 1, :b => 2 }, Padrino::Utils.symbolize_keys('a' => 1, 'b' => 2)) + end + + it 'should not fail on non-symbolizable keys' do + assert_equal({ Object => 1, true => 2 }, Padrino::Utils.symbolize_keys(Object => 1, true => 2)) + end +end diff --git a/padrino/Rakefile b/padrino/Rakefile index 45ceeeb88..14fe0a7aa 100644 --- a/padrino/Rakefile +++ b/padrino/Rakefile @@ -1,32 +1,16 @@ -# coding:utf-8 -RAKE_ROOT = __FILE__ - -require 'rubygems' require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper') ########### CUSTOM TASKS ########## -gemspec = ::Gem::Specification.load(File.expand_path(File.dirname(__FILE__) + "/padrino.gemspec")) -subgems = [ - ["padrino-core", "= #{gemspec.version}"], - ["padrino-helpers", "= #{gemspec.version}"], - ["padrino-mailer", "= #{gemspec.version}"], - ["padrino-gen", "= #{gemspec.version}"], - ["padrino-admin", "= #{gemspec.version}"], - ["padrino-cache", "= #{gemspec.version}"], - ["padrino-support", "= #{gemspec.version}"], -] - task :package => "lib/padrino.rb" desc "Create padrino.rb" task "lib/padrino.rb" do - mkdir_p "lib" + FileUtils.mkdir_p "lib" File.open("lib/padrino.rb","w+") do |file| - file.puts "### AUTOMATICALLY GENERATED. DO NOT EDIT!" - subgems.each do |pair| - g, _ = pair - file.puts "require '#{g}'" unless g =~ /padrino-gen/ + file.puts "# Automatically generated from 'padrino.gemspec' by `rake lib/padrino.rb`" + PADRINO_SUBGEMS.each_key do |name| + file.puts "require '#{name}'" unless name =~ /padrino-(gen|performance)/ end end -end \ No newline at end of file +end diff --git a/padrino/lib/padrino.rb b/padrino/lib/padrino.rb index ab5458d2b..2fb8496f4 100644 --- a/padrino/lib/padrino.rb +++ b/padrino/lib/padrino.rb @@ -1,7 +1,7 @@ -### AUTOMATICALLY GENERATED. DO NOT EDIT! +# Automatically generated from 'padrino.gemspec' by `rake lib/padrino.rb` require 'padrino-support' require 'padrino-core' -require 'padrino-mailer' require 'padrino-helpers' -require 'padrino-admin' require 'padrino-cache' +require 'padrino-mailer' +require 'padrino-admin' diff --git a/padrino/padrino.gemspec b/padrino/padrino.gemspec index a0920f195..8638748e6 100644 --- a/padrino/padrino.gemspec +++ b/padrino/padrino.gemspec @@ -24,11 +24,13 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.rdoc_options = ["--charset=UTF-8"] - s.add_dependency("padrino-core", Padrino.version) s.add_dependency("padrino-support", Padrino.version) + s.add_dependency("padrino-core", Padrino.version) s.add_dependency("padrino-helpers", Padrino.version) + s.add_dependency("padrino-cache", Padrino.version) s.add_dependency("padrino-mailer", Padrino.version) s.add_dependency("padrino-gen", Padrino.version) - s.add_dependency("padrino-cache", Padrino.version) s.add_dependency("padrino-admin", Padrino.version) + + # add independent padrino gems to 'subgems.rb' end diff --git a/padrino/subgems.rb b/padrino/subgems.rb new file mode 100644 index 000000000..695e2db4e --- /dev/null +++ b/padrino/subgems.rb @@ -0,0 +1,9 @@ +padrino_gemspec = ::Gem::Specification.load(File.expand_path(File.dirname(__FILE__) + "/padrino.gemspec")) +performance_gemspec = ::Gem::Specification.load(File.expand_path(File.dirname(__FILE__) + "/../padrino-performance/padrino-performance.gemspec")) + +PADRINO_SUBGEMS ||= Hash[padrino_gemspec.dependencies.map{ |gem| [gem.name, gem.requirement.to_s] }] + +PADRINO_GEMS ||= PADRINO_SUBGEMS.merge( + 'padrino' => padrino_gemspec.version.to_s, + 'padrino-performance' => performance_gemspec.version.to_s, +) diff --git a/padrino/test/ext/fakeweb-ruby24.rb b/padrino/test/ext/fakeweb-ruby24.rb new file mode 100644 index 000000000..dcc80bc65 --- /dev/null +++ b/padrino/test/ext/fakeweb-ruby24.rb @@ -0,0 +1,5 @@ +# FakeWeb is dead. Ruby 2.4 apparently calls #close even if a socked is already closed. +class FakeWeb::StubSocket + def close + end +end diff --git a/padrino/test/ext/minitest-spec.rb b/padrino/test/ext/minitest-spec.rb new file mode 100644 index 000000000..e55f9acac --- /dev/null +++ b/padrino/test/ext/minitest-spec.rb @@ -0,0 +1,30 @@ +class MiniTest::Spec + # Assert_file_exists('/tmp/app') + def assert_file_exists(file_path) + assert File.file?(file_path), "File at path '#{file_path}' does not exist!" + end + + # Assert_no_file_exists('/tmp/app') + def assert_no_file_exists(file_path) + assert !File.exist?(file_path), "File should not exist at path '#{file_path}' but was found!" + end + + # assert_dir_exists('/tmp/app') + def assert_dir_exists(file_path) + assert File.directory?(file_path), "Folder at path '#{file_path}' does not exist" + end + + # assert_no_dir_exists('/tmp/app') + def assert_no_dir_exists(file_path) + assert !File.exist?(file_path), "Folder should not exist at path '#{file_path}' but was found" + end + + # Asserts that a file matches the pattern + def assert_match_in_file(pattern, file) + File.file?(file) ? assert_match(pattern, File.read(file)) : assert_file_exists(file) + end + + def assert_no_match_in_file(pattern, file) + File.file?(file) ? refute_match(pattern, File.read(file)) : assert_file_exists(file) + end +end diff --git a/padrino/test/ext/rack-test-methods.rb b/padrino/test/ext/rack-test-methods.rb new file mode 100644 index 000000000..b8d3f93e5 --- /dev/null +++ b/padrino/test/ext/rack-test-methods.rb @@ -0,0 +1,10 @@ +module Rack::Test::Methods + # Delegate some methods to the last response + alias_method :response, :last_response + + [:status, :headers, :body, :content_type, :ok?, :forbidden?].each do |method_name| + define_method method_name do + last_response.send(method_name) + end + end +end diff --git a/padrino/test/helper.rb b/padrino/test/helper.rb deleted file mode 100644 index 8c6ffc3b2..000000000 --- a/padrino/test/helper.rb +++ /dev/null @@ -1,6 +0,0 @@ -require File.expand_path('../../../load_paths', __FILE__) -require File.join(File.dirname(__FILE__), '..', '..', 'padrino-core', 'test', 'mini_shoulda') - -class MiniTest::Spec - # Nothing to see here -end diff --git a/padrino/test/padrino/test-methods.rb b/padrino/test/padrino/test-methods.rb new file mode 100644 index 000000000..f804d8b1f --- /dev/null +++ b/padrino/test/padrino/test-methods.rb @@ -0,0 +1,55 @@ +require 'oga' + +module Padrino + module TestMethods + def assert_html_has_tag(html, tag, attributes={}) + assert html.html_safe?, 'output in not #html_safe?' + assert_has_selector(html, tag, attributes) + end + + def assert_html_has_no_tag(html, tag, attributes={}) + assert html.html_safe?, 'output in not #html_safe?' + assert_has_no_selector(html, tag, attributes) + end + + def assert_response_has_tag(tag, attributes={}) + assert_has_selector(last_response.body, tag, attributes) + end + + def assert_response_has_no_tag(tag, attributes={}) + assert_has_no_selector(last_response.body, tag, attributes) + end + + def assert_has_selector(html, selector, attributes) + count_requirement = attributes.delete(:count) + message = "'#{selector}' with attributes #{attributes} in html\n#{html}" + matched_count = html_matched_tags(html, selector.to_s, attributes) + if count_requirement + assert_equal count_requirement, matched_count, "count of tags #{message}" + else + assert matched_count > 0, "expected a tag #{message}" + end + end + + def assert_has_no_selector(html, selector, attributes) + message = "'#{selector}' with attributes #{attributes} in html\n#{html}" + matched_count = html_matched_tags(html, selector.to_s, attributes) + assert matched_count == 0, "expected no tags #{message}" + end + + private + + def html_matched_tags(html, selector, attributes) + @dom ||= Oga.parse_html(html) + content_requirement = attributes.delete(:content) + attributes.each do |name, value| + selector += %{[#{name}="#{value}"]} + end + tags = @dom.css(selector.to_s.gsub(/\[([^"']*?)=([^'"]*?)\]/, '[\1="\2"]')) + if content_requirement + tags = tags.select{ |tag| (tag.get('content') || tag.text).index(content_requirement) } + end + tags.count + end + end +end diff --git a/padrino/test/test_padrino.rb b/padrino/test/test_padrino.rb index 78e249b24..e631e00aa 100644 --- a/padrino/test/test_padrino.rb +++ b/padrino/test/test_padrino.rb @@ -1,11 +1,12 @@ -require File.expand_path(File.dirname(__FILE__) + '/helper') +require 'minitest/autorun' +require 'minitest/pride' describe "Padrino" do - should "be a metagem that requires subgems" do - assert_nil defined?(Padrino::Mailer) - assert_nil defined?(Padrino::Helpers) + it "should be a metagem that requires subgems" do + refute defined?(Padrino::Mailer) + refute defined?(Padrino::Helpers) require File.expand_path('../../lib/padrino.rb', __FILE__) - assert_not_nil defined?(Padrino::Mailer) - assert_not_nil defined?(Padrino::Helpers) + assert defined?(Padrino::Mailer) + assert defined?(Padrino::Helpers) end end