loaf 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +9 -1
- data/lib/loaf.rb +1 -0
- data/lib/loaf/errors.rb +1 -1
- data/lib/loaf/translation.rb +1 -1
- data/lib/loaf/version.rb +1 -1
- metadata +13 -70
- data/Appraisals +0 -31
- data/Rakefile +0 -13
- data/bin/console +0 -14
- data/bin/setup +0 -9
- data/loaf.gemspec +0 -35
- data/spec/integration/breadcrumb_trail_spec.rb +0 -71
- data/spec/integration/configuration_spec.rb +0 -12
- data/spec/rails_app/Rakefile +0 -8
- data/spec/rails_app/app/controllers/application_controller.rb +0 -5
- data/spec/rails_app/app/controllers/comments_controller.rb +0 -20
- data/spec/rails_app/app/controllers/home_controller.rb +0 -4
- data/spec/rails_app/app/controllers/posts_controller.rb +0 -20
- data/spec/rails_app/app/views/comments/index.html.erb +0 -1
- data/spec/rails_app/app/views/home/index.html.erb +0 -1
- data/spec/rails_app/app/views/layouts/_breadcrumbs.html.erb +0 -12
- data/spec/rails_app/app/views/layouts/application.html.erb +0 -14
- data/spec/rails_app/app/views/posts/index.html.erb +0 -1
- data/spec/rails_app/app/views/posts/new.html.erb +0 -4
- data/spec/rails_app/app/views/posts/show.html.erb +0 -1
- data/spec/rails_app/config.ru +0 -4
- data/spec/rails_app/config/application.rb +0 -48
- data/spec/rails_app/config/boot.rb +0 -10
- data/spec/rails_app/config/database.yml +0 -25
- data/spec/rails_app/config/environment.rb +0 -5
- data/spec/rails_app/config/environments/development.rb +0 -32
- data/spec/rails_app/config/environments/production.rb +0 -62
- data/spec/rails_app/config/environments/test.rb +0 -41
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails_app/config/initializers/inflections.rb +0 -10
- data/spec/rails_app/config/initializers/mime_types.rb +0 -5
- data/spec/rails_app/config/initializers/secret_token.rb +0 -7
- data/spec/rails_app/config/initializers/session_store.rb +0 -8
- data/spec/rails_app/config/initializers/wrap_parameters.rb +0 -14
- data/spec/rails_app/config/locales/en.yml +0 -5
- data/spec/rails_app/config/locales/loaf.en.yml +0 -6
- data/spec/rails_app/config/routes.rb +0 -7
- data/spec/rails_app/config/secrets.yml +0 -22
- data/spec/rails_app/db/seeds.rb +0 -7
- data/spec/rails_app/public/404.html +0 -26
- data/spec/rails_app/public/422.html +0 -26
- data/spec/rails_app/public/500.html +0 -26
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/public/robots.txt +0 -5
- data/spec/spec_helper.rb +0 -52
- data/spec/support/capybara.rb +0 -8
- data/spec/support/dummy_controller.rb +0 -9
- data/spec/support/dummy_view.rb +0 -47
- data/spec/support/load_routes.rb +0 -4
- data/spec/unit/configuration_spec.rb +0 -33
- data/spec/unit/controller_extensions_spec.rb +0 -54
- data/spec/unit/crumb_spec.rb +0 -15
- data/spec/unit/generators/install_generator_spec.rb +0 -17
- data/spec/unit/options_validator_spec.rb +0 -15
- data/spec/unit/translation_spec.rb +0 -30
- data/spec/unit/view_extensions/breadcrumb_spec.rb +0 -22
- data/spec/unit/view_extensions/breadcrumb_trail_spec.rb +0 -244
- data/spec/unit/view_extensions/has_breadcrumbs_spec.rb +0 -10
- data/tasks/console.rake +0 -10
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
@@ -1,26 +0,0 @@
|
|
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>
|
@@ -1,26 +0,0 @@
|
|
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
|
-
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
|
24
|
-
</div>
|
25
|
-
</body>
|
26
|
-
</html>
|
File without changes
|
data/spec/spec_helper.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
if (ENV['COVERAGE'] || ENV['TRAVIS']) && RUBY_VERSION < '2.4.0'
|
4
|
-
require 'simplecov'
|
5
|
-
require 'coveralls'
|
6
|
-
|
7
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
8
|
-
SimpleCov::Formatter::HTMLFormatter,
|
9
|
-
Coveralls::SimpleCov::Formatter
|
10
|
-
])
|
11
|
-
|
12
|
-
SimpleCov.start do
|
13
|
-
command_name 'spec'
|
14
|
-
add_filter 'spec'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Configure Rails Environment
|
19
|
-
ENV["RAILS_ENV"] = "test"
|
20
|
-
|
21
|
-
require 'rails_app/config/environment.rb'
|
22
|
-
require 'rspec/rails'
|
23
|
-
require 'loaf'
|
24
|
-
|
25
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
26
|
-
|
27
|
-
RSpec.configure do |config|
|
28
|
-
config.expect_with :rspec do |expectations|
|
29
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
30
|
-
end
|
31
|
-
|
32
|
-
config.mock_with :rspec do |mocks|
|
33
|
-
mocks.verify_partial_doubles = true
|
34
|
-
end
|
35
|
-
|
36
|
-
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
37
|
-
config.disable_monkey_patching!
|
38
|
-
|
39
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
40
|
-
# be too noisy due to issues in dependencies.
|
41
|
-
config.warnings = true
|
42
|
-
|
43
|
-
if config.files_to_run.one?
|
44
|
-
config.default_formatter = 'doc'
|
45
|
-
end
|
46
|
-
|
47
|
-
config.profile_examples = 2
|
48
|
-
|
49
|
-
config.order = :random
|
50
|
-
|
51
|
-
Kernel.srand config.seed
|
52
|
-
end
|
data/spec/support/capybara.rb
DELETED
data/spec/support/dummy_view.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'action_view'
|
2
|
-
|
3
|
-
class DummyView < ActionView::Base
|
4
|
-
module FakeRequest
|
5
|
-
class Request
|
6
|
-
attr_accessor :path, :fullpath, :protocol, :host_with_port
|
7
|
-
def get?
|
8
|
-
true
|
9
|
-
end
|
10
|
-
end
|
11
|
-
def request
|
12
|
-
@request ||= Request.new
|
13
|
-
end
|
14
|
-
def params
|
15
|
-
@params ||= {}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
include FakeRequest
|
20
|
-
include ActionView::Helpers::UrlHelper
|
21
|
-
include Loaf::ViewExtensions
|
22
|
-
|
23
|
-
attr_reader :_breadcrumbs
|
24
|
-
|
25
|
-
routes = ActionDispatch::Routing::RouteSet.new
|
26
|
-
routes.draw do
|
27
|
-
get "/" => "foo#bar", :as => :home
|
28
|
-
get "/posts" => "foo#posts"
|
29
|
-
get "/posts/:title" => "foo#posts"
|
30
|
-
get "/post/:id" => "foo#post", :as => :post
|
31
|
-
get "/post/:title" => "foo#title"
|
32
|
-
get "/post/:id/comments" => "foo#comments"
|
33
|
-
|
34
|
-
namespace :blog do
|
35
|
-
get "/" => "foo#bar"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
include routes.url_helpers
|
40
|
-
|
41
|
-
def set_path(path)
|
42
|
-
request.path = path
|
43
|
-
request.fullpath = path
|
44
|
-
request.protocol = 'http://'
|
45
|
-
request.host_with_port = 'www.example.com'
|
46
|
-
end
|
47
|
-
end
|
data/spec/support/load_routes.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Loaf::Configuration do
|
4
|
-
it "allows to set and read attributes" do
|
5
|
-
config = Loaf::Configuration.new
|
6
|
-
config.match = :exact
|
7
|
-
expect(config.match).to eq(:exact)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "accepts attributes at initialization" do
|
11
|
-
options = { locales_path: '/lib', match: :exact }
|
12
|
-
config = Loaf::Configuration.new(options)
|
13
|
-
|
14
|
-
expect(config.locales_path).to eq('/lib')
|
15
|
-
expect(config.match).to eq(:exact)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "exports configuration as hash" do
|
19
|
-
config = Loaf::Configuration.new
|
20
|
-
expect(config.to_hash).to eq({
|
21
|
-
locales_path: '/',
|
22
|
-
match: :inclusive
|
23
|
-
})
|
24
|
-
end
|
25
|
-
|
26
|
-
it "yields configuration" do
|
27
|
-
conf = double(:conf)
|
28
|
-
allow(Loaf).to receive(:configuration).and_return(conf)
|
29
|
-
expect { |b|
|
30
|
-
Loaf.configure(&b)
|
31
|
-
}.to yield_with_args(conf)
|
32
|
-
end
|
33
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Loaf::ControllerExtensions do
|
4
|
-
|
5
|
-
context 'when classes extend controller_extensions' do
|
6
|
-
it { expect(DummyController).to respond_to(:add_breadcrumb) }
|
7
|
-
it { expect(DummyController).to respond_to(:breadcrumb) }
|
8
|
-
it { expect(DummyController.new).to respond_to(:add_breadcrumb) }
|
9
|
-
it { expect(DummyController.new).to respond_to(:breadcrumb) }
|
10
|
-
it { expect(DummyController.new).to respond_to(:clear_breadcrumbs) }
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'class methods' do
|
14
|
-
it 'invokes before_action' do
|
15
|
-
allow(DummyController).to receive(:before_action)
|
16
|
-
allow(DummyController).to receive(:respond_to?).and_return(true)
|
17
|
-
DummyController.breadcrumb('name', 'url_path')
|
18
|
-
expect(DummyController).to have_received(:before_action)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'delegates breadcrumb registration to controller instance' do
|
22
|
-
name = 'List objects'
|
23
|
-
url = :object_path
|
24
|
-
options = {force: true}
|
25
|
-
instance = double(:controller_instance).as_null_object
|
26
|
-
|
27
|
-
allow(DummyController).to receive(:new).and_return(instance)
|
28
|
-
DummyController.breadcrumb(name, url, options)
|
29
|
-
expect(instance).to have_received(:breadcrumb).with(name, url, options)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'instance methods' do
|
34
|
-
it 'instantiates breadcrumbs container' do
|
35
|
-
name = 'List objects'
|
36
|
-
url = :object_path
|
37
|
-
instance = DummyController.new
|
38
|
-
|
39
|
-
allow(Loaf::Crumb).to receive(:new)
|
40
|
-
instance.breadcrumb(name, url)
|
41
|
-
expect(Loaf::Crumb).to have_received(:new).with(name, url, {})
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'adds breadcrumb to collection' do
|
45
|
-
name = 'List objects'
|
46
|
-
url = :object_path
|
47
|
-
instance = DummyController.new
|
48
|
-
|
49
|
-
expect {
|
50
|
-
instance.breadcrumb(name, url)
|
51
|
-
}.to change { instance._breadcrumbs.size }.by(1)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/spec/unit/crumb_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
RSpec.describe Loaf::Crumb do
|
2
|
-
it "fails when name is nil" do
|
3
|
-
expect {
|
4
|
-
Loaf::Crumb.new(nil, 'path')
|
5
|
-
}.to raise_error(ArgumentError,
|
6
|
-
/breadcrumb first argument, `name`, cannot be nil/)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "fails when url is nil" do
|
10
|
-
expect {
|
11
|
-
Loaf::Crumb.new('name', nil)
|
12
|
-
}.to raise_error(ArgumentError,
|
13
|
-
/breadcrumb second argument, `url`, cannot be nil/)
|
14
|
-
end
|
15
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'fileutils'
|
4
|
-
require 'generators/loaf/install_generator'
|
5
|
-
|
6
|
-
RSpec.describe Loaf::Generators::InstallGenerator, type: :generator do
|
7
|
-
destination File.expand_path("../../../tmp", __FILE__)
|
8
|
-
|
9
|
-
before { prepare_destination }
|
10
|
-
|
11
|
-
it "copies loaf locales to the host application" do
|
12
|
-
run_generator
|
13
|
-
locale = file("config/locales/loaf.en.yml")
|
14
|
-
expect(locale).to exist
|
15
|
-
FileUtils.rm_rf(File.expand_path("../../../tmp", __FILE__))
|
16
|
-
end
|
17
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Loaf::OptionsValidator, '.valid?' do
|
4
|
-
let(:klass) { Class.extend Loaf::OptionsValidator }
|
5
|
-
|
6
|
-
it 'validates succesfully known option' do
|
7
|
-
expect(klass.valid?(match: :exact)).to eq(true)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'validates unknown option with an error' do
|
11
|
-
expect {
|
12
|
-
klass.valid?(invalid_param: true)
|
13
|
-
}.to raise_error(Loaf::InvalidOptions)
|
14
|
-
end
|
15
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Loaf::Translation do
|
4
|
-
|
5
|
-
before { I18n.backend = I18n::Backend::Simple.new }
|
6
|
-
|
7
|
-
after { I18n.backend.reload! }
|
8
|
-
|
9
|
-
it "doesn't translate empty title" do
|
10
|
-
expect(described_class.find_title('')).to eql('')
|
11
|
-
end
|
12
|
-
|
13
|
-
it "skips translation if doesn't find a matching scope" do
|
14
|
-
expect(described_class.find_title('unknown')).to eql('unknown')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'translates breadcrumb title' do
|
18
|
-
I18n.backend.store_translations 'en', loaf: { breadcrumbs: { home: 'Home'}}
|
19
|
-
expect(described_class.find_title('home')).to eql('Home')
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'does not translates breadcrumb name with missing scope' do
|
23
|
-
I18n.backend.store_translations 'en', breadcrumbs: {home: 'Home'}
|
24
|
-
expect(described_class.find_title('home')).to eql('home')
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'translates breadcrumb name using default option' do
|
28
|
-
expect(described_class.find_title('home', default: 'breadcrumb default name')).to eql('breadcrumb default name')
|
29
|
-
end
|
30
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Loaf::ViewExtensions, '.breadcrumb' do
|
4
|
-
|
5
|
-
it { expect(DummyView.new).to respond_to(:add_breadcrumb) }
|
6
|
-
|
7
|
-
it 'creates crumb instance' do
|
8
|
-
instance = DummyView.new
|
9
|
-
name = 'Home'
|
10
|
-
url = :home_path
|
11
|
-
allow(Loaf::Crumb).to receive(:new).with(name, url, {})
|
12
|
-
instance.breadcrumb name, url
|
13
|
-
expect(Loaf::Crumb).to have_received(:new).with(name, url, {})
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'adds crumb to breadcrumbs storage' do
|
17
|
-
instance = DummyView.new
|
18
|
-
expect {
|
19
|
-
instance.breadcrumb 'Home', :home_path
|
20
|
-
}.to change { instance._breadcrumbs.size }.by(1)
|
21
|
-
end
|
22
|
-
end
|
@@ -1,244 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe Loaf::ViewExtensions, '#breadcrumb_trail' do
|
4
|
-
it "resolves breadcrumb paths" do
|
5
|
-
view = DummyView.new
|
6
|
-
view.breadcrumb('home', :home_path)
|
7
|
-
view.breadcrumb('posts', :posts_path)
|
8
|
-
view.set_path('/posts')
|
9
|
-
|
10
|
-
yielded = []
|
11
|
-
block = -> (crumb) { yielded << crumb.to_a }
|
12
|
-
view.breadcrumb_trail(&block)
|
13
|
-
|
14
|
-
expect(yielded).to eq([
|
15
|
-
['home', '/', false],
|
16
|
-
['posts', '/posts', true]
|
17
|
-
])
|
18
|
-
end
|
19
|
-
|
20
|
-
it "matches current path with :inclusive option as default" do
|
21
|
-
view = DummyView.new
|
22
|
-
view.breadcrumb('home', :home_path)
|
23
|
-
view.breadcrumb('posts', :posts_path)
|
24
|
-
view.set_path('/posts?id=73-title')
|
25
|
-
|
26
|
-
yielded = []
|
27
|
-
block = -> (crumb) { yielded << crumb.to_a }
|
28
|
-
view.breadcrumb_trail(&block)
|
29
|
-
|
30
|
-
expect(yielded).to eq([
|
31
|
-
['home', '/', false],
|
32
|
-
['posts', '/posts', true]
|
33
|
-
])
|
34
|
-
end
|
35
|
-
|
36
|
-
it "matches current path with :inclusive when query params" do
|
37
|
-
view = DummyView.new
|
38
|
-
view.breadcrumb('posts', '/posts', match: :inclusive)
|
39
|
-
view.set_path('/posts?foo=bar')
|
40
|
-
|
41
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
42
|
-
end
|
43
|
-
|
44
|
-
it "matches current path with :inclusive when nested" do
|
45
|
-
view = DummyView.new
|
46
|
-
view.breadcrumb('posts', '/posts', match: :inclusive)
|
47
|
-
view.set_path('/posts/1/comment')
|
48
|
-
|
49
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
50
|
-
end
|
51
|
-
|
52
|
-
it "matches current path with :inclusive when nested" do
|
53
|
-
view = DummyView.new
|
54
|
-
view.breadcrumb('posts', '/posts', match: :inclusive)
|
55
|
-
view.set_path('/posts/1/comment')
|
56
|
-
|
57
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
58
|
-
end
|
59
|
-
|
60
|
-
it "doesn't match with :inclusive when unrelated path" do
|
61
|
-
view = DummyView.new
|
62
|
-
view.breadcrumb('posts', '/posts', match: :inclusive)
|
63
|
-
view.set_path('/post/1')
|
64
|
-
|
65
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', false]])
|
66
|
-
end
|
67
|
-
|
68
|
-
it "matches current path with :inclusive when extra trailing slash" do
|
69
|
-
view = DummyView.new
|
70
|
-
view.breadcrumb('posts', '/posts/', match: :inclusive)
|
71
|
-
view.set_path('/posts')
|
72
|
-
|
73
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts/', true]])
|
74
|
-
end
|
75
|
-
|
76
|
-
it "matches current path with :inclusive when absolute path" do
|
77
|
-
view = DummyView.new
|
78
|
-
view.breadcrumb('posts', 'http://www.example.com/posts/', match: :inclusive)
|
79
|
-
view.set_path('/posts')
|
80
|
-
|
81
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([
|
82
|
-
['posts', 'http://www.example.com/posts/', true]
|
83
|
-
])
|
84
|
-
end
|
85
|
-
|
86
|
-
it "matches current path with :exact when trailing slash" do
|
87
|
-
view = DummyView.new
|
88
|
-
view.breadcrumb('posts', '/posts/', match: :exact)
|
89
|
-
view.set_path('/posts')
|
90
|
-
|
91
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts/', true]])
|
92
|
-
end
|
93
|
-
|
94
|
-
it "fails to match current path with :exact when nested" do
|
95
|
-
view = DummyView.new
|
96
|
-
view.breadcrumb('posts', '/posts', match: :exact)
|
97
|
-
view.set_path('/posts/1/comment')
|
98
|
-
|
99
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', false]])
|
100
|
-
end
|
101
|
-
|
102
|
-
it "fails to match current path with :exact when query params" do
|
103
|
-
view = DummyView.new
|
104
|
-
view.breadcrumb('posts', '/posts', match: :exact)
|
105
|
-
view.set_path('/posts?foo=bar')
|
106
|
-
|
107
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', false]])
|
108
|
-
end
|
109
|
-
|
110
|
-
it "matches current path with :exclusive option when query params" do
|
111
|
-
view = DummyView.new
|
112
|
-
view.breadcrumb('posts', '/posts', match: :exclusive)
|
113
|
-
view.set_path('/posts?foo=bar')
|
114
|
-
|
115
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
116
|
-
end
|
117
|
-
|
118
|
-
it "fails to match current path with :exclusive option when nested" do
|
119
|
-
view = DummyView.new
|
120
|
-
view.breadcrumb('posts', '/posts', match: :exclusive)
|
121
|
-
view.set_path('/posts/1/comment')
|
122
|
-
|
123
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', false]])
|
124
|
-
end
|
125
|
-
|
126
|
-
it "matches current path with regex option when query params" do
|
127
|
-
view = DummyView.new
|
128
|
-
view.breadcrumb('posts', '/posts', match: %r{/po})
|
129
|
-
view.set_path('/posts?foo=bar')
|
130
|
-
|
131
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
132
|
-
end
|
133
|
-
|
134
|
-
it "matches current path with query params option" do
|
135
|
-
view = DummyView.new
|
136
|
-
view.breadcrumb('posts', '/posts', match: {foo: :bar})
|
137
|
-
view.set_path('/posts?foo=bar&baz=boo')
|
138
|
-
|
139
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', true]])
|
140
|
-
end
|
141
|
-
|
142
|
-
it "fails to match current path with query params option" do
|
143
|
-
view = DummyView.new
|
144
|
-
view.breadcrumb('posts', '/posts', match: {foo: :bar})
|
145
|
-
view.set_path('/posts?foo=2&baz=boo')
|
146
|
-
|
147
|
-
expect(view.breadcrumb_trail.map(&:to_a)).to eq([['posts', '/posts', false]])
|
148
|
-
end
|
149
|
-
|
150
|
-
it "failse to recognize the match option" do
|
151
|
-
view = DummyView.new
|
152
|
-
view.breadcrumb('posts', 'http://www.example.com/posts/', match: :boom)
|
153
|
-
view.set_path('/posts')
|
154
|
-
block = -> (*args) { }
|
155
|
-
expect {
|
156
|
-
view.breadcrumb_trail(&block)
|
157
|
-
}.to raise_error(ArgumentError, "Unknown `:boom` match option!")
|
158
|
-
end
|
159
|
-
|
160
|
-
it "forces current path" do
|
161
|
-
view = DummyView.new
|
162
|
-
view.breadcrumb('home', :home_path)
|
163
|
-
view.breadcrumb('posts', :posts_path, match: :force)
|
164
|
-
view.set_path('/')
|
165
|
-
|
166
|
-
yielded = []
|
167
|
-
block = -> (crumb) { yielded << crumb.to_a }
|
168
|
-
view.breadcrumb_trail(&block)
|
169
|
-
|
170
|
-
expect(yielded).to eq([
|
171
|
-
['home', '/', true],
|
172
|
-
['posts', '/posts', true]
|
173
|
-
])
|
174
|
-
end
|
175
|
-
|
176
|
-
it "returns enumerator without block" do
|
177
|
-
view = DummyView.new
|
178
|
-
view.breadcrumb('home', :home_path)
|
179
|
-
view.breadcrumb('posts', :posts_path)
|
180
|
-
view.set_path('/posts')
|
181
|
-
|
182
|
-
result = view.breadcrumb_trail
|
183
|
-
|
184
|
-
expect(result).to be_a(Enumerable)
|
185
|
-
expect(result.take(2).map(&:to_a)).to eq([
|
186
|
-
['home', '/', false],
|
187
|
-
['posts', '/posts', true]
|
188
|
-
])
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'validates passed options' do
|
192
|
-
view = DummyView.new
|
193
|
-
block = -> (name, url, styles) { }
|
194
|
-
expect {
|
195
|
-
view.breadcrumb_trail(unknown: true, &block)
|
196
|
-
}.to raise_error(Loaf::InvalidOptions)
|
197
|
-
end
|
198
|
-
|
199
|
-
it "permits arbitrary length crumb names" do
|
200
|
-
view = DummyView.new
|
201
|
-
view.breadcrumb('<span class="fa fa-home"></span>', :home_path)
|
202
|
-
view.set_path('/posts')
|
203
|
-
|
204
|
-
yielded = []
|
205
|
-
block = -> (crumb) { yielded << crumb.to_a }
|
206
|
-
view.breadcrumb_trail(&block)
|
207
|
-
|
208
|
-
expect(yielded).to eq([
|
209
|
-
['<span class="fa fa-home"></span>', '/', false]
|
210
|
-
])
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'uses global configuration for crumb formatting' do
|
214
|
-
view = DummyView.new
|
215
|
-
view.breadcrumb('home-sweet-home', :home_path)
|
216
|
-
view.breadcrumb('posts-for-everybody', :posts_path)
|
217
|
-
view.set_path('/posts')
|
218
|
-
|
219
|
-
yielded = []
|
220
|
-
block = -> (crumb) { yielded << crumb.to_a }
|
221
|
-
view.breadcrumb_trail(&block)
|
222
|
-
|
223
|
-
expect(yielded).to eq([
|
224
|
-
['home-sweet-home', '/', false],
|
225
|
-
['posts-for-everybody', '/posts', true]
|
226
|
-
])
|
227
|
-
end
|
228
|
-
|
229
|
-
it "allows to overwrite global configuration" do
|
230
|
-
view = DummyView.new
|
231
|
-
view.breadcrumb('home-sweet-home', :home_path)
|
232
|
-
view.breadcrumb('posts-for-everybody', :posts_path)
|
233
|
-
view.set_path('/posts')
|
234
|
-
|
235
|
-
yielded = []
|
236
|
-
block = -> (crumb) { yielded << crumb.to_a }
|
237
|
-
view.breadcrumb_trail(match: :exact, &block)
|
238
|
-
|
239
|
-
expect(yielded).to eq([
|
240
|
-
['home-sweet-home', '/', false],
|
241
|
-
['posts-for-everybody', '/posts', true]
|
242
|
-
])
|
243
|
-
end
|
244
|
-
end
|