twitter-bootstrap-rails 3.2.0 → 3.2.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of twitter-bootstrap-rails might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +85 -121
- data/app/assets/fonts/fontawesome-webfont.eot +0 -0
- data/app/assets/fonts/fontawesome-webfont.svg +479 -463
- data/app/assets/fonts/fontawesome-webfont.ttf +0 -0
- data/app/assets/fonts/fontawesome-webfont.woff +0 -0
- data/app/assets/javascripts/twitter/bootstrap/affix.js +19 -14
- data/app/assets/javascripts/twitter/bootstrap/alert.js +10 -6
- data/app/assets/javascripts/twitter/bootstrap/button.js +11 -8
- data/app/assets/javascripts/twitter/bootstrap/carousel.js +49 -31
- data/app/assets/javascripts/twitter/bootstrap/collapse.js +22 -22
- data/app/assets/javascripts/twitter/bootstrap/dropdown.js +17 -13
- data/app/assets/javascripts/twitter/bootstrap/modal.js +66 -29
- data/app/assets/javascripts/twitter/bootstrap/popover.js +10 -7
- data/app/assets/javascripts/twitter/bootstrap/scrollspy.js +40 -23
- data/app/assets/javascripts/twitter/bootstrap/tab.js +11 -8
- data/app/assets/javascripts/twitter/bootstrap/tooltip.js +115 -57
- data/app/assets/javascripts/twitter/bootstrap/transition.js +18 -7
- data/app/assets/stylesheets/twitter-bootstrap-static/fontawesome.css.erb +1670 -2
- data/app/helpers/bootstrap_flash_helper.rb +1 -1
- data/app/helpers/form_errors_helper.rb +11 -11
- data/app/helpers/glyph_helper.rb +2 -1
- data/app/helpers/modal_helper.rb +3 -3
- data/lib/generators/bootstrap/install/templates/bootstrap_and_overrides.less +6 -3
- data/lib/generators/bootstrap/layout/templates/layout.html.erb +5 -5
- data/lib/generators/bootstrap/layout/templates/layout.html.haml +3 -3
- data/lib/generators/bootstrap/layout/templates/layout.html.slim +3 -5
- data/lib/generators/bootstrap/themed/templates/_form.html.erb +12 -9
- data/lib/generators/bootstrap/themed/templates/_form.html.haml +7 -5
- data/lib/generators/bootstrap/themed/templates/_form.html.slim +8 -6
- data/lib/generators/bootstrap/themed/templates/edit.html.slim +1 -1
- data/lib/generators/bootstrap/themed/templates/index.html.slim +2 -3
- data/lib/generators/bootstrap/themed/templates/new.html.slim +1 -1
- data/lib/generators/bootstrap/themed/templates/show.html.slim +1 -1
- data/lib/twitter/bootstrap/rails/engine.rb +16 -12
- data/lib/twitter/bootstrap/rails/version.rb +1 -1
- data/spec/lib/breadcrumbs_spec.rb +2 -2
- data/spec/lib/twitter_bootstrap_rails/badge_label_helper_spec.rb +10 -4
- data/spec/lib/twitter_bootstrap_rails/form_errors_helper_spec.rb +148 -0
- data/spec/lib/twitter_bootstrap_rails/glyph_helper_spec.rb +24 -0
- data/spec/lib/twitter_bootstrap_rails/modal_helper_spec.rb +1 -1
- data/spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb +1 -1
- data/vendor/assets/stylesheets/twitter-bootstrap-static/bootstrap.css.erb +1 -3
- data/vendor/toolkit/fontawesome/core.less +3 -4
- data/vendor/toolkit/fontawesome/font-awesome.less +1 -1
- data/vendor/toolkit/fontawesome/icons.less +48 -2
- data/vendor/toolkit/fontawesome/list.less +1 -1
- data/vendor/toolkit/fontawesome/mixins.less +9 -4
- data/vendor/toolkit/fontawesome/path.less +5 -5
- data/vendor/toolkit/fontawesome/rotated-flipped.less +11 -0
- data/vendor/toolkit/fontawesome/spinning.less +15 -18
- data/vendor/toolkit/fontawesome/variables.less +49 -3
- data/vendor/toolkit/twitter/bootstrap/bootstrap.less +0 -1
- data/vendor/toolkit/twitter/bootstrap/glyphicons.less +6 -5
- metadata +59 -25
- data/app/assets/images/twitter/bootstrap/glyphicons-halflings-white.png +0 -0
- data/app/assets/images/twitter/bootstrap/glyphicons-halflings.png +0 -0
@@ -16,7 +16,7 @@ module BootstrapFlashHelper
|
|
16
16
|
Array(message).each do |msg|
|
17
17
|
text = content_tag(:div,
|
18
18
|
content_tag(:button, raw("×"), :class => "close", "data-dismiss" => "alert") +
|
19
|
-
msg, :class => "alert fade in alert-#{type} #{options[:class]}")
|
19
|
+
msg.html_safe, :class => "alert fade in alert-#{type} #{options[:class]}")
|
20
20
|
flash_messages << text if msg
|
21
21
|
end
|
22
22
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module FormErrorsHelper
|
2
|
-
|
3
|
-
attr_reader :template
|
4
|
-
attr_reader :object
|
2
|
+
include ActionView::Helpers::FormTagHelper
|
5
3
|
|
6
4
|
def error_span(attribute, options = {})
|
7
|
-
options[:
|
5
|
+
options[:span_class] ||= 'help-block'
|
6
|
+
options[:error_class] ||= 'has-error'
|
8
7
|
|
9
|
-
|
10
|
-
:
|
11
|
-
|
12
|
-
|
8
|
+
if errors_on?(attribute)
|
9
|
+
@template.content_tag( :div, :class => options[:error_class] ) do
|
10
|
+
content_tag( :span, errors_for(attribute), :class => options[:span_class] )
|
11
|
+
end
|
12
|
+
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def errors_on?(attribute)
|
16
|
-
|
16
|
+
object.errors[attribute].present? if object.respond_to?(:errors)
|
17
17
|
end
|
18
18
|
|
19
19
|
def errors_for(attribute)
|
20
|
-
|
20
|
+
object.errors[attribute].try(:join, ', ') || object.errors[attribute].try(:to_s)
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
data/app/helpers/glyph_helper.rb
CHANGED
@@ -8,7 +8,8 @@ module GlyphHelper
|
|
8
8
|
# # => <i class="icon-thumbs-up pull-left"></i>
|
9
9
|
# glyph(:lock, {tag: :span})
|
10
10
|
# # => <span class="icon-lock"></span>
|
11
|
-
def glyph(*names
|
11
|
+
def glyph(*names)
|
12
|
+
options = (names.last.kind_of?(Hash)) ? names.pop : {}
|
12
13
|
names.map! { |name| name.to_s.gsub('_','-') }
|
13
14
|
names.map! do |name|
|
14
15
|
name =~ /pull-(?:left|right)/ ? name : "glyphicon glyphicon-#{name}"
|
data/app/helpers/modal_helper.rb
CHANGED
@@ -10,9 +10,9 @@ module ModalHelper
|
|
10
10
|
content_tag :div, :id => options[:id], :class => "bootstrap-modal modal fade" do
|
11
11
|
content_tag :div, :class => "modal-dialog #{opts['size']}" do
|
12
12
|
content_tag :div, :class => "modal-content" do
|
13
|
-
modal_header(
|
14
|
-
modal_body(
|
15
|
-
modal_footer(
|
13
|
+
modal_header(options[:header], &block) +
|
14
|
+
modal_body(options[:body], &block) +
|
15
|
+
modal_footer(options[:footer], &block)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
@import "twitter/bootstrap/bootstrap";
|
2
2
|
|
3
|
-
// Set
|
4
|
-
@
|
5
|
-
@
|
3
|
+
// Set correct font paths
|
4
|
+
@glyphiconsEotPath: font-url("glyphicons-halflings-regular.eot");
|
5
|
+
@glyphiconsEotPath_iefix: font-url("glyphicons-halflings-regular.eot?#iefix");
|
6
|
+
@glyphiconsWoffPath: font-url("glyphicons-halflings-regular.woff");
|
7
|
+
@glyphiconsTtfPath: font-url("glyphicons-halflings-regular.ttf");
|
8
|
+
@glyphiconsSvgPath: font-url("glyphicons-halflings-regular.svg#glyphicons_halflingsregular");
|
6
9
|
|
7
10
|
// Set the Font Awesome (Font Awesome is default. You can disable by commenting below lines)
|
8
11
|
@fontAwesomeEotPath: font-url("fontawesome-webfont.eot");
|
@@ -7,11 +7,6 @@
|
|
7
7
|
<title><%%= content_for?(:title) ? yield(:title) : "<%= app_name %>" %></title>
|
8
8
|
<%%= csrf_meta_tags %>
|
9
9
|
|
10
|
-
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
11
|
-
<!--[if lt IE 9]>
|
12
|
-
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js" type="text/javascript"></script>
|
13
|
-
<![endif]-->
|
14
|
-
|
15
10
|
<%%= stylesheet_link_tag "application", :media => "all" %>
|
16
11
|
|
17
12
|
<!-- For third-generation iPad with high-resolution Retina display: -->
|
@@ -35,6 +30,11 @@
|
|
35
30
|
<%%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %>
|
36
31
|
|
37
32
|
<%%= javascript_include_tag "application" %>
|
33
|
+
|
34
|
+
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
35
|
+
<!--[if lt IE 9]>
|
36
|
+
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js" type="text/javascript"></script>
|
37
|
+
<![endif]-->
|
38
38
|
</head>
|
39
39
|
<body>
|
40
40
|
|
@@ -6,9 +6,6 @@
|
|
6
6
|
%meta(name="viewport" content="width=device-width, initial-scale=1.0")
|
7
7
|
%title= content_for?(:title) ? yield(:title) : "<%= app_name %>"
|
8
8
|
= csrf_meta_tags
|
9
|
-
/ Le HTML5 shim, for IE6-8 support of HTML elements
|
10
|
-
/[if lt IE 9]
|
11
|
-
= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js"
|
12
9
|
= stylesheet_link_tag "application", :media => "all"
|
13
10
|
= favicon_link_tag 'apple-touch-icon-144x144-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '144x144'
|
14
11
|
= favicon_link_tag 'apple-touch-icon-114x114-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '114x114'
|
@@ -16,6 +13,9 @@
|
|
16
13
|
= favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png'
|
17
14
|
= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon'
|
18
15
|
= javascript_include_tag "application"
|
16
|
+
/ Le HTML5 shim, for IE6-8 support of HTML elements
|
17
|
+
/[if lt IE 9]
|
18
|
+
= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"
|
19
19
|
|
20
20
|
|
21
21
|
%body
|
@@ -6,10 +6,6 @@ html lang="en"
|
|
6
6
|
meta name="viewport" content="width=device-width, initial-scale=1.0"
|
7
7
|
title= content_for?(:title) ? yield(:title) : "<%= app_name %>"
|
8
8
|
= csrf_meta_tags
|
9
|
-
|
10
|
-
/! Le HTML5 shim, for IE6-8 support of HTML elements
|
11
|
-
/[if lt IE 9]
|
12
|
-
= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js"
|
13
9
|
= stylesheet_link_tag "application", :media => "all"
|
14
10
|
= favicon_link_tag 'apple-touch-icon-144x144-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '144x144'
|
15
11
|
= favicon_link_tag 'apple-touch-icon-114x114-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '114x114'
|
@@ -17,7 +13,9 @@ html lang="en"
|
|
17
13
|
= favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png'
|
18
14
|
= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon'
|
19
15
|
= javascript_include_tag "application"
|
20
|
-
|
16
|
+
/! Le HTML5 shim, for IE6-8 support of HTML elements
|
17
|
+
/[if lt IE 9]
|
18
|
+
= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"
|
21
19
|
|
22
20
|
|
23
21
|
body
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<%%= form_for @<%= resource_name %>, :html => { :class => "form-horizontal <%= resource_name %>" } do |f| %>
|
2
2
|
|
3
|
-
|
3
|
+
<%% if @<%= resource_name %>.errors.any? %>
|
4
4
|
<div id="error_expl" class="panel panel-danger">
|
5
5
|
<div class="panel-heading">
|
6
6
|
<h3 class="panel-title"><%%= pluralize(@<%= resource_name %>.errors.count, "error") %> prohibited this <%= resource_name %> from being saved:</h3>
|
@@ -16,18 +16,21 @@
|
|
16
16
|
<%% end %>
|
17
17
|
|
18
18
|
<%- columns.each do |column| -%>
|
19
|
-
<div class="
|
20
|
-
<%%= f.label :<%= column.name %>, :class => 'control-label' %>
|
21
|
-
<div class="
|
19
|
+
<div class="form-group">
|
20
|
+
<%%= f.label :<%= column.name %>, :class => 'control-label col-lg-2' %>
|
21
|
+
<div class="col-lg-10">
|
22
22
|
<%%= f.<%= column.field_type %> :<%= column.name %>, :class => 'form-control' %>
|
23
23
|
</div>
|
24
|
-
<%%=
|
24
|
+
<%%=f.error_span(:<%= column.name %>) %>
|
25
25
|
</div>
|
26
26
|
<%- end -%>
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
<div class="form-group">
|
29
|
+
<div class="col-lg-offset-2 col-lg-10">
|
30
|
+
<%%= f.submit nil, :class => 'btn btn-primary' %>
|
31
|
+
<%%= link_to t('.cancel', :default => t("helpers.links.cancel")),
|
32
|
+
<%= controller_routing_path %>_path, :class => 'btn btn-default' %>
|
33
|
+
</div>
|
34
|
+
</div>
|
32
35
|
|
33
36
|
<%% end %>
|
@@ -1,10 +1,12 @@
|
|
1
1
|
= form_for @<%= resource_name %>, html: { class: "form form-horizontal <%= resource_name %>" } do |f|
|
2
2
|
<%- columns.each do |column| -%>
|
3
3
|
.form-group
|
4
|
-
= f.label :<%= column.name %>, class: 'control-label'
|
5
|
-
.
|
4
|
+
= f.label :<%= column.name %>, class: 'control-label col-lg-2'
|
5
|
+
.col-lg-10
|
6
6
|
= f.<%= column.field_type %> :<%= column.name %>, class: 'form-control', required: true
|
7
|
-
= error_span(
|
7
|
+
= f.error_span(:<%= column.name %>)
|
8
8
|
<%- end -%>
|
9
|
-
|
10
|
-
|
9
|
+
.form-group
|
10
|
+
.col-lg-offset-2.col-lg-10
|
11
|
+
= f.submit nil,class: 'btn btn-primary'
|
12
|
+
= link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn btn-default'
|
@@ -1,11 +1,13 @@
|
|
1
1
|
= form_for @<%= resource_name %>, html: { class: "form form-horizontal <%= resource_name %>" } do |f|
|
2
2
|
<%- columns.each do |column| -%>
|
3
3
|
.form-group
|
4
|
-
= f.label :<%= column.name %>, :class => 'control-label'
|
5
|
-
.
|
4
|
+
= f.label :<%= column.name %>, :class => 'control-label col-lg-2'
|
5
|
+
.col-lg-10
|
6
6
|
= f.<%= column.field_type %> :<%= column.name %>, :class => 'form-control'
|
7
|
-
= error_span(
|
7
|
+
= f.error_span(:<%= column.name %>)
|
8
8
|
<%- end -%>
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
.form-group
|
10
|
+
.col-lg-offset-2.col-lg-10
|
11
|
+
= f.submit nil, :class => 'btn btn-primary'
|
12
|
+
'
|
13
|
+
= link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
- model_class = <%= resource_name.classify %>
|
2
|
-
|
2
|
+
.page-header
|
3
3
|
h1=t '.title', :default => model_class.model_name.human.pluralize.titleize
|
4
|
-
table
|
4
|
+
table.table.table-striped
|
5
5
|
thead
|
6
6
|
tr
|
7
7
|
th= model_class.human_attribute_name(:id)
|
@@ -24,4 +24,3 @@ table class="table table-striped"
|
|
24
24
|
= link_to t('.destroy', :default => t("helpers.links.destroy")), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :method => :delete, :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-xs btn-danger'
|
25
25
|
|
26
26
|
= link_to t('.new', :default => t("helpers.links.new")), new_<%= singular_controller_routing_path %>_path, :class => 'btn btn-primary'
|
27
|
-
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'rails'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
require_relative 'breadcrumbs.rb'
|
4
|
+
require_relative '../../../../app/helpers/flash_block_helper.rb'
|
5
|
+
require_relative '../../../../app/helpers/modal_helper.rb'
|
6
|
+
require_relative '../../../../app/helpers/navbar_helper.rb'
|
7
|
+
require_relative '../../../../app/helpers/bootstrap_flash_helper.rb'
|
8
|
+
require_relative '../../../../app/helpers/form_errors_helper.rb'
|
8
9
|
|
9
10
|
module Twitter
|
10
11
|
module Bootstrap
|
@@ -21,14 +22,17 @@ module Twitter
|
|
21
22
|
initializer 'twitter-bootstrap-rails.setup_helpers' do |app|
|
22
23
|
app.config.to_prepare do
|
23
24
|
ActionController::Base.send :include, Breadcrumbs
|
24
|
-
ActionController::Base.send :helper, FlashBlockHelper
|
25
|
-
ActionController::Base.send :helper, BootstrapFlashHelper
|
26
|
-
ActionController::Base.send :helper, FormErrorsHelper
|
27
|
-
ActionController::Base.send :helper, ModalHelper
|
28
|
-
ActionController::Base.send :helper, NavbarHelper
|
29
|
-
ActionController::Base.send :helper, BadgeLabelHelper
|
30
|
-
#ActionController::Base.send :helper_method, :render_breadcrumbs
|
31
25
|
end
|
26
|
+
[FlashBlockHelper,
|
27
|
+
BootstrapFlashHelper,
|
28
|
+
ModalHelper,
|
29
|
+
NavbarHelper,
|
30
|
+
BadgeLabelHelper].each do |h|
|
31
|
+
app.config.to_prepare do
|
32
|
+
ActionController::Base.send :helper, h
|
33
|
+
end
|
34
|
+
end
|
35
|
+
ActionView::Helpers::FormBuilder.send :include, FormErrorsHelper
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -64,11 +64,11 @@ describe Twitter::Bootstrap::Breadcrumbs do
|
|
64
64
|
[:base, :base_i18n, :class, :class_i18n, :instance, :instance_i18n, :test_model, :symbolized].each do |name|
|
65
65
|
path = "/#{name}"
|
66
66
|
idx = @controller.breadcrumbs.index { |b| b[:name] == name.to_s && b[:url] == path }
|
67
|
-
idx.
|
67
|
+
expect(idx).to be, -> { name }
|
68
68
|
end
|
69
69
|
|
70
70
|
idx = @controller.breadcrumbs.index { |b| b[:name] == "show" && b[:url] == '' }
|
71
|
-
idx.
|
71
|
+
expect(idx).to be
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
@@ -10,15 +10,21 @@ include BadgeLabelHelper
|
|
10
10
|
|
11
11
|
describe BadgeLabelHelper, :type => :helper do
|
12
12
|
it "should return a basic bootstrap badge" do
|
13
|
-
expect(badge('
|
13
|
+
expect(badge('New!').gsub(/\s/, '').downcase)
|
14
14
|
.to eql(BASIC_BADGE.gsub(/\s/, '').downcase)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should return a bootstrap badge with class" do
|
18
|
-
expect(badge('
|
18
|
+
expect(badge('2', :warning).gsub(/\s/, '').downcase)
|
19
19
|
.to eql(BADGE_WITH_CLASS.gsub(/\s/, '').downcase)
|
20
20
|
end
|
21
|
+
|
22
|
+
it "should take a Number as its first parameter" do
|
23
|
+
expect(badge(12).gsub(/\s/, '').downcase)
|
24
|
+
.to eql(BADGE_WITH_NUMBER_PARAM.gsub(/\s/, '').downcase)
|
25
|
+
end
|
21
26
|
end
|
22
27
|
|
23
|
-
BASIC_BADGE = %{<span class="badge">
|
24
|
-
BADGE_WITH_CLASS = %{<span class="badge badge-warning">
|
28
|
+
BASIC_BADGE = %{<span class="badge">New!</span>}
|
29
|
+
BADGE_WITH_CLASS = %{<span class="badge badge-warning">2</span>}
|
30
|
+
BADGE_WITH_NUMBER_PARAM = %{<span class="badge">12</span>}
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'action_view'
|
4
|
+
require 'active_support'
|
5
|
+
require 'rspec/active_model/mocks'
|
6
|
+
|
7
|
+
require_relative '../../../app/helpers/form_errors_helper'
|
8
|
+
|
9
|
+
include ActionView::Helpers
|
10
|
+
include ActionView::Context
|
11
|
+
include FormErrorsHelper
|
12
|
+
|
13
|
+
describe FormErrorsHelper, :type => :helper do
|
14
|
+
|
15
|
+
before do
|
16
|
+
@base_errors = ['base error message', 'nasty error']
|
17
|
+
@base_error = 'one base error'
|
18
|
+
|
19
|
+
|
20
|
+
@title_errors = ["can't be blank", 'is too short (minimum is 5 characters)']
|
21
|
+
@title_error = "can't be blank"
|
22
|
+
|
23
|
+
@errors = double('errors')
|
24
|
+
@new_post = mock_model( 'Post' )
|
25
|
+
allow(@new_post).to receive_messages(:errors => @errors)
|
26
|
+
allow(self).to receive_messages(:post_path => '/post/1')
|
27
|
+
allow(self).to receive_messages(:protect_against_forgery? => false)
|
28
|
+
allow(self).to receive_messages(:polymorphic_path => '')
|
29
|
+
|
30
|
+
@default_class = 'help-block'
|
31
|
+
@default_error_class = 'has-error'
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
describe 'error[:base] is a string' do
|
36
|
+
|
37
|
+
before do
|
38
|
+
allow(@errors).to receive(:[]).with(:base).and_return(@base_error)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should render base error on :base key' do
|
42
|
+
form_for(@new_post) do |builder|
|
43
|
+
expect(builder.error_span(:base)).to have_tag("div.#{@default_error_class}") do
|
44
|
+
with_tag("span.#{@default_class}", :text => @base_error)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
describe 'when there is only one error on base' do
|
53
|
+
|
54
|
+
before do
|
55
|
+
allow(@errors).to receive(:[]).with(:base).and_return(@base_error)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should render base error on :base key' do
|
59
|
+
form_for(@new_post) do |builder|
|
60
|
+
expect(builder.error_span(:base)).to have_tag("div.#{@default_error_class}") do
|
61
|
+
with_tag("span.#{@default_class}", :text => @base_error)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'when there is only one error on title' do
|
69
|
+
|
70
|
+
before do
|
71
|
+
allow(@errors).to receive(:[]).with(:title).and_return(@title_error)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should render base errors join with comma' do
|
75
|
+
form_for(@new_post) do |builder|
|
76
|
+
expect(builder.error_span(:title)).to have_tag("div.#{@default_error_class}") do
|
77
|
+
with_tag("span.#{@default_class}", :text => @title_error)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
describe 'when there is more than one error on title' do
|
86
|
+
|
87
|
+
before do
|
88
|
+
allow(@errors).to receive(:[]).with(:title).and_return(@title_errors)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should render base errors join with comma' do
|
92
|
+
form_for(@new_post) do |builder|
|
93
|
+
expect(builder.error_span(:title)).to have_tag("div.#{@default_error_class}") do
|
94
|
+
with_tag("span.#{@default_class}", :text => @title_errors.join(', '))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
describe 'when there are no errors' do
|
102
|
+
before do
|
103
|
+
allow(@errors).to receive(:[]).with(:title).and_return(nil)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should return nil' do
|
107
|
+
form_for(@new_post) do |builder|
|
108
|
+
expect(builder.error_span(:title)).to be_nil
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'when :error_class option is passed' do
|
114
|
+
let(:error_class) { 'has_warning' }
|
115
|
+
|
116
|
+
before do
|
117
|
+
allow(@errors).to receive(:[]).with(:title).and_return(@title_error)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should render with passed error class " do
|
121
|
+
form_for(@new_post) do |builder|
|
122
|
+
expect(builder.error_span(:title, :error_class => error_class))
|
123
|
+
.to have_tag("div.#{error_class}") do
|
124
|
+
with_tag("span.#{@default_class}", :text => @title_error)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'when :error_class option is passed' do
|
131
|
+
let(:span_class) { 'help-inline' }
|
132
|
+
|
133
|
+
before do
|
134
|
+
allow(@errors).to receive(:[]).with(:title).and_return(@title_error)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should render with passed error class " do
|
138
|
+
form_for(@new_post) do |builder|
|
139
|
+
expect(builder.error_span(:title, :span_class => span_class))
|
140
|
+
.to have_tag("div.#{@default_error_class}") do
|
141
|
+
with_tag("span.#{span_class}", :text => @title_error)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|