rails-bootstrap-helpers 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +158 -0
- data/Rakefile +38 -0
- data/lib/rails-bootstrap-helpers.rb +20 -0
- data/lib/rails-bootstrap-helpers/core_ext/abstract.rb +72 -0
- data/lib/rails-bootstrap-helpers/helpers/alert_helper.rb +45 -0
- data/lib/rails-bootstrap-helpers/helpers/base_helper.rb +32 -0
- data/lib/rails-bootstrap-helpers/helpers/button_helper.rb +55 -0
- data/lib/rails-bootstrap-helpers/helpers/form_tag_helper.rb +22 -0
- data/lib/rails-bootstrap-helpers/helpers/label_helper.rb +35 -0
- data/lib/rails-bootstrap-helpers/helpers/options_helper.rb +32 -0
- data/lib/rails-bootstrap-helpers/rails/engine.rb +15 -0
- data/lib/rails-bootstrap-helpers/renderers/abstract_button_renderer.rb +86 -0
- data/lib/rails-bootstrap-helpers/renderers/button_renderer.rb +43 -0
- data/lib/rails-bootstrap-helpers/renderers/renderer.rb +14 -0
- data/lib/rails-bootstrap-helpers/version.rb +3 -0
- data/lib/tasks/bootstrap-rails-helpers_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +59 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +47 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/helpers/alert_helper_spec.rb +24 -0
- data/spec/helpers/base_helper_spec.rb +18 -0
- data/spec/helpers/button_helper_spec.rb +94 -0
- data/spec/helpers/form_tag_helper_spec.rb +43 -0
- data/spec/helpers/label_helper_spec.rb +23 -0
- data/spec/helpers/options_helper_spec.rb +47 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/matchers/helpers/alert_helper/render_bs_alert.rb +116 -0
- data/spec/support/matchers/helpers/base_helper/render_icon.rb +55 -0
- data/spec/support/matchers/helpers/button_helper/render_bs_button_to.rb +135 -0
- data/spec/support/matchers/helpers/button_helper/render_inline_button_to.rb +79 -0
- data/spec/support/matchers/helpers/form_tag_helper/render_bs_button_tag.rb +136 -0
- data/spec/support/matchers/helpers/label_helper/render_bs_label.rb +114 -0
- metadata +287 -0
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
Connecting to database specified by database.yml
|
2
|
+
Connecting to database specified by database.yml
|
3
|
+
Connecting to database specified by database.yml
|
4
|
+
Connecting to database specified by database.yml
|
5
|
+
Connecting to database specified by database.yml
|
6
|
+
Connecting to database specified by database.yml
|
7
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
8
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
9
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
10
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
11
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
12
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
13
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
14
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
15
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
16
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
17
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
18
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
19
|
+
Connecting to database specified by database.yml
|
20
|
+
Connecting to database specified by database.yml
|
21
|
+
Connecting to database specified by database.yml
|
22
|
+
Connecting to database specified by database.yml
|
23
|
+
Connecting to database specified by database.yml
|
24
|
+
Connecting to database specified by database.yml
|
25
|
+
Connecting to database specified by database.yml
|
26
|
+
Connecting to database specified by database.yml
|
27
|
+
Connecting to database specified by database.yml
|
28
|
+
Connecting to database specified by database.yml
|
29
|
+
Connecting to database specified by database.yml
|
30
|
+
Connecting to database specified by database.yml
|
31
|
+
Connecting to database specified by database.yml
|
32
|
+
Connecting to database specified by database.yml
|
33
|
+
Connecting to database specified by database.yml
|
34
|
+
Connecting to database specified by database.yml
|
35
|
+
Connecting to database specified by database.yml
|
36
|
+
Connecting to database specified by database.yml
|
37
|
+
Connecting to database specified by database.yml
|
38
|
+
Connecting to database specified by database.yml
|
39
|
+
Connecting to database specified by database.yml
|
40
|
+
Connecting to database specified by database.yml
|
41
|
+
Connecting to database specified by database.yml
|
42
|
+
Connecting to database specified by database.yml
|
43
|
+
Connecting to database specified by database.yml
|
44
|
+
Connecting to database specified by database.yml
|
45
|
+
Connecting to database specified by database.yml
|
46
|
+
Connecting to database specified by database.yml
|
47
|
+
Connecting to database specified by database.yml
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RailsBootstrapHelpers::Helpers::AlertHelper do
|
4
|
+
describe "bs_alert" do
|
5
|
+
it { should render_bs_alert("foo") }
|
6
|
+
|
7
|
+
context "with type" do
|
8
|
+
it { should render_bs_alert("foo").with_type(:error) }
|
9
|
+
it { should render_bs_alert("foo").with_type(:success) }
|
10
|
+
it { should render_bs_alert("foo").with_type(:info) }
|
11
|
+
it { should render_bs_alert("foo").with_type(:warning) }
|
12
|
+
it { should render_bs_alert("foo").with_type(:default) }
|
13
|
+
it { should render_bs_alert("foo").with_type(:notice).as_class(:success) }
|
14
|
+
|
15
|
+
context "custom" do
|
16
|
+
it { should render_bs_alert("foo").with_type(:bar) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "as block" do
|
21
|
+
it { should render_bs_alert("foo").as_block(true) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RailsBootstrapHelpers::Helpers::BaseHelper do
|
4
|
+
describe "icon" do
|
5
|
+
it { should render_icon(:edit) }
|
6
|
+
it { should render_icon("remove") }
|
7
|
+
|
8
|
+
context "with invert icon" do
|
9
|
+
it { should render_icon(:edit).inverted(true) }
|
10
|
+
it { should render_icon("remove").inverted(true) }
|
11
|
+
end
|
12
|
+
|
13
|
+
context "custom icons" do
|
14
|
+
it { should render_icon(:foo) }
|
15
|
+
it { should render_icon("bar") }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RailsBootstrapHelpers::Helpers::ButtonHelper do
|
4
|
+
describe "bs_button_to" do
|
5
|
+
context "with url" do
|
6
|
+
it { should render_bs_button_to("foo").to("bar") }
|
7
|
+
end
|
8
|
+
|
9
|
+
context "with style" do
|
10
|
+
it { should render_bs_button_to("foo") }
|
11
|
+
it { should render_bs_button_to("foo").with_style(:default) }
|
12
|
+
it { should render_bs_button_to("foo").with_style(:primary) }
|
13
|
+
it { should render_bs_button_to("foo").with_style(:info) }
|
14
|
+
it { should render_bs_button_to("foo").with_style(:success) }
|
15
|
+
it { should render_bs_button_to("foo").with_style(:warning) }
|
16
|
+
it { should render_bs_button_to("foo").with_style(:danger) }
|
17
|
+
it { should render_bs_button_to("foo").with_style(:inverse) }
|
18
|
+
it { should render_bs_button_to("foo").with_style(:link) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with size" do
|
22
|
+
it { should render_bs_button_to("foo").with_size(:default) }
|
23
|
+
it { should render_bs_button_to("foo").with_size(:large) }
|
24
|
+
it { should render_bs_button_to("foo").with_size(:small) }
|
25
|
+
it { should render_bs_button_to("foo").with_size(:mini) }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with icon" do
|
29
|
+
it { should render_bs_button_to("foo").with_icon(:ok) }
|
30
|
+
it { should render_bs_button_to("foo").with_icon(:edit) }
|
31
|
+
it { should render_bs_button_to("foo").with_icon(:none) }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with inverted icon" do
|
35
|
+
it { should render_bs_button_to("foo").with_icon(:ok).with_icon_inverted(true) }
|
36
|
+
it { should render_bs_button_to("foo").with_icon(:edit).with_icon_inverted(true) }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "with icon position" do
|
40
|
+
it { should render_bs_button_to("foo").with_icon_position(:default) }
|
41
|
+
it { should render_bs_button_to("foo").with_icon_position(:left) }
|
42
|
+
it { should render_bs_button_to("foo").with_icon_position(:right) }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "bs_inline_button_to" do
|
47
|
+
it { should render_inline_button_to("foo", "edit") }
|
48
|
+
|
49
|
+
context "with size" do
|
50
|
+
it { should render_inline_button_to("foo", "edit").with_size(:large) }
|
51
|
+
it { should render_inline_button_to("foo", "edit").with_size(:small) }
|
52
|
+
it { should render_inline_button_to("foo", "edit").with_size(:mini) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "bs_popover_button" do
|
57
|
+
let(:attributes) do
|
58
|
+
{
|
59
|
+
href: '#',
|
60
|
+
class: "btn",
|
61
|
+
:"data-content" => "bar",
|
62
|
+
:"data-placement" => "bottom",
|
63
|
+
:"data-toggle" => "popover"
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
let(:html_attributes) do
|
68
|
+
attributes.map{ |k, v| "#{k}=\"#{v}\"" }.join(" ")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should render a button with a popover" do
|
72
|
+
html = "<a #{html_attributes}>foo</a>"
|
73
|
+
|
74
|
+
helper.bs_popover_button("foo", "bar").should == html
|
75
|
+
end
|
76
|
+
|
77
|
+
context "render popover using block" do
|
78
|
+
it "should render a button with a popover" do
|
79
|
+
html = "<a #{html_attributes}>foo</a>"
|
80
|
+
|
81
|
+
helper.bs_popover_button("foo") { "bar" }.should == html
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "with custom placement" do
|
86
|
+
it "should render a button with a popover" do
|
87
|
+
attributes[:"data-placement"] = "top"
|
88
|
+
html = "<a #{html_attributes}>foo</a>"
|
89
|
+
|
90
|
+
helper.bs_popover_button("foo", "bar", placement: "top").should == html
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RailsBootstrapHelpers::Helpers::FormTagHelper do
|
4
|
+
describe "bs_button_tag" do
|
5
|
+
it { should render_bs_button_tag("foo", :submit) }
|
6
|
+
it { should render_bs_button_tag("bar", :reset) }
|
7
|
+
|
8
|
+
context "with style" do
|
9
|
+
it { should render_bs_button_tag("foo", :submit).with_style(:default) }
|
10
|
+
it { should render_bs_button_tag("foo", :submit).with_style(:primary) }
|
11
|
+
it { should render_bs_button_tag("foo", :submit).with_style(:info) }
|
12
|
+
it { should render_bs_button_tag("foo", :submit).with_style(:success) }
|
13
|
+
it { should render_bs_button_tag("foo", :submit).with_style(:warning) }
|
14
|
+
it { should render_bs_button_tag("foo", :submit).with_style(:danger) }
|
15
|
+
it { should render_bs_button_tag("foo", :submit).with_style(:inverse) }
|
16
|
+
it { should render_bs_button_tag("foo", :submit).with_style(:link) }
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with size" do
|
20
|
+
it { should render_bs_button_tag("foo", :submit).with_size(:default) }
|
21
|
+
it { should render_bs_button_tag("foo", :submit).with_size(:large) }
|
22
|
+
it { should render_bs_button_tag("foo", :submit).with_size(:small) }
|
23
|
+
it { should render_bs_button_tag("foo", :submit).with_size(:mini) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context "with icon" do
|
27
|
+
it { should render_bs_button_tag("foo", :submit).with_icon(:ok) }
|
28
|
+
it { should render_bs_button_tag("foo", :submit).with_icon(:edit) }
|
29
|
+
it { should render_bs_button_tag("foo", :submit).with_icon(:none) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with inverted icon" do
|
33
|
+
it { should render_bs_button_tag("foo", :submit).with_icon(:ok).with_icon_inverted(true) }
|
34
|
+
it { should render_bs_button_tag("foo", :submit).with_icon(:edit).with_icon_inverted(true) }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with icon position" do
|
38
|
+
it { should render_bs_button_tag("foo", :submit).with_icon_position(:default) }
|
39
|
+
it { should render_bs_button_tag("foo", :submit).with_icon_position(:left) }
|
40
|
+
it { should render_bs_button_tag("foo", :submit).with_icon_position(:right) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RailsBootstrapHelpers::Helpers::LabelHelper do
|
4
|
+
describe "bs_label" do
|
5
|
+
it { should render_bs_label("foo") }
|
6
|
+
it { should render_bs_label("foo").with_style(:success) }
|
7
|
+
it { should render_bs_label("foo").with_style(:warning) }
|
8
|
+
it { should render_bs_label("foo").with_style(:important) }
|
9
|
+
it { should render_bs_label("foo").with_style(:info) }
|
10
|
+
it { should render_bs_label("foo").with_style(:inverse) }
|
11
|
+
|
12
|
+
context "custom statuses" do
|
13
|
+
it { should render_bs_label("foo").with_style(:active).as_class("success") }
|
14
|
+
it { should render_bs_label("foo").with_style(:inactive).as_class("default") }
|
15
|
+
it { should render_bs_label("foo").with_style(:error).as_class("important") }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with tooltip" do
|
19
|
+
it { should render_bs_label("foo").with_tooltip("bar") }
|
20
|
+
it { should render_bs_label("foo").with_tooltip("bar").with_tooltip_position(:left) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RailsBootstrapHelpers::Helpers::OptionsHelper do
|
4
|
+
describe "bs_options" do
|
5
|
+
context "recognized options" do
|
6
|
+
it "should not override unrecognized options" do
|
7
|
+
expected = { :"data-toggle" => "bar", title: "text" }
|
8
|
+
options = expected.merge tooltip: "foo"
|
9
|
+
helper.bs_options(options).should == expected
|
10
|
+
end
|
11
|
+
|
12
|
+
context "tooltip" do
|
13
|
+
let(:options) do
|
14
|
+
{ tooltip: "foo" }
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:expected) do
|
18
|
+
{ :"data-toggle" => "tooltip", title: "foo" }
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should handle the :tooltip option" do
|
22
|
+
helper.bs_options(options).should == expected
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should handle the :tooltip_position option" do
|
26
|
+
options[:tooltip_position] = "left"
|
27
|
+
expected[:"data-placement"] = "left"
|
28
|
+
helper.bs_options(options).should == expected
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not handle :tooltip_position if :tooltip is not specified" do
|
32
|
+
options.delete(:tooltip)
|
33
|
+
options[:tooltip_position] = "left"
|
34
|
+
expected[:"data-placement"] = "left"
|
35
|
+
helper.bs_options(options).should_not == expected
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "unrecognized options" do
|
41
|
+
it "should leave unrecognized options intact" do
|
42
|
+
options = { a: 3, href: "foo", :"data-placement" => "left", title: "foo" }
|
43
|
+
helper.bs_options(options).should == options
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "spork"
|
3
|
+
|
4
|
+
Spork.prefork do
|
5
|
+
ENV["RAILS_ENV"] ||= 'test'
|
6
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
7
|
+
|
8
|
+
require "rspec/rails"
|
9
|
+
require "rspec/autorun"
|
10
|
+
|
11
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.order = "random"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Spork.each_run do
|
19
|
+
require "rails-bootstrap-helpers"
|
20
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
RSpec::Matchers.define :render_bs_alert do |text|
|
4
|
+
def options
|
5
|
+
@options ||= { }
|
6
|
+
end
|
7
|
+
|
8
|
+
def text
|
9
|
+
@text
|
10
|
+
end
|
11
|
+
|
12
|
+
def cls
|
13
|
+
cls = "alert"
|
14
|
+
|
15
|
+
if type?
|
16
|
+
type = options[:type].to_s
|
17
|
+
|
18
|
+
if type == "notice"
|
19
|
+
type = "success"
|
20
|
+
end
|
21
|
+
|
22
|
+
unless type == "warning" || type == "default"
|
23
|
+
cls << " alert-#{type}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if block?
|
28
|
+
cls << " alert-block"
|
29
|
+
end
|
30
|
+
|
31
|
+
cls
|
32
|
+
end
|
33
|
+
|
34
|
+
def expected
|
35
|
+
@render_alert_expected ||= begin
|
36
|
+
text = self.text
|
37
|
+
|
38
|
+
if dismiss_button?
|
39
|
+
text = text + '<button type="button" class="close" data-dismiss="alert">×</button>'
|
40
|
+
end
|
41
|
+
|
42
|
+
"<div class=\"#{cls}\">#{text}</div>"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def got
|
47
|
+
@got ||= helper.bs_alert(text, options)
|
48
|
+
end
|
49
|
+
|
50
|
+
def failure_message (is_not)
|
51
|
+
ex = is_not ? "expected not" : "expected"
|
52
|
+
"#{ex}: #{expected}\n got: #{got}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def html_class
|
56
|
+
@html_class ||= class? ? options[:class].to_s : options[:status].to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
def type?
|
60
|
+
@type_set
|
61
|
+
end
|
62
|
+
|
63
|
+
def block?
|
64
|
+
@block_set
|
65
|
+
end
|
66
|
+
|
67
|
+
def dismiss_button?
|
68
|
+
@dismiss_button_set
|
69
|
+
end
|
70
|
+
|
71
|
+
def class?
|
72
|
+
@class_set
|
73
|
+
end
|
74
|
+
|
75
|
+
chain :with_type do |type|
|
76
|
+
options[:type] = type
|
77
|
+
@type_set = true
|
78
|
+
end
|
79
|
+
|
80
|
+
chain :with_dismiss_button do |dismiss_button|
|
81
|
+
options[:dismiss_button] = dismiss_button
|
82
|
+
@dismiss_button_set = true
|
83
|
+
end
|
84
|
+
|
85
|
+
chain :as_block do |block|
|
86
|
+
options[:block] = block
|
87
|
+
@block_set = true
|
88
|
+
end
|
89
|
+
|
90
|
+
chain :as_class do |cls|
|
91
|
+
options[:class] = cls
|
92
|
+
@class_set = true
|
93
|
+
end
|
94
|
+
|
95
|
+
match do
|
96
|
+
@text = text
|
97
|
+
expected == got
|
98
|
+
end
|
99
|
+
|
100
|
+
failure_message_for_should do
|
101
|
+
failure_message(false)
|
102
|
+
end
|
103
|
+
|
104
|
+
failure_message_for_should_not do
|
105
|
+
failure_message(true)
|
106
|
+
end
|
107
|
+
|
108
|
+
description do
|
109
|
+
desc = "render an alert '#{text}'"
|
110
|
+
desc << " as block" if block?
|
111
|
+
desc << " with dismiss button" if dismiss_button?
|
112
|
+
desc << " with the type: #{options[:type]}" if type?
|
113
|
+
desc << " as the class #{html_class}" if class?
|
114
|
+
desc
|
115
|
+
end
|
116
|
+
end
|