gretel 3.0.5 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Gretel
2
- VERSION = "3.0.5"
3
- end
2
+ VERSION = "4.0.0"
3
+ end
@@ -10,10 +10,6 @@ module Gretel
10
10
  def breadcrumb(key = nil, *args)
11
11
  if key.nil? || key.is_a?(Hash)
12
12
  raise ArgumentError, "The `breadcrumb` method was called with #{key.inspect} as the key. This method is used to set the breadcrumb. Maybe you meant to call the `breadcrumbs` method (with an 's' in the end) which is used to render the breadcrumbs?"
13
- elsif key.class.respond_to?(:model_name)
14
- # Enables calling `breadcrumb @product` instead of `breadcrumb :product, @product`
15
- args.unshift key
16
- key = key.class.model_name.to_s.underscore.to_sym
17
13
  end
18
14
  @_gretel_renderer = Gretel::Renderer.new(self, key, *args)
19
15
  end
@@ -48,12 +44,8 @@ module Gretel
48
44
  # <% end %>
49
45
  # <% end %>
50
46
  # <% end %>
51
- def breadcrumbs(options = {}, &block)
52
- if block_given?
53
- gretel_renderer.yield_links(options, &block)
54
- else
55
- gretel_renderer.render(options)
56
- end
47
+ def breadcrumbs(options = {})
48
+ gretel_renderer.render(options)
57
49
  end
58
50
 
59
51
  # Returns or yields parent breadcrumb (second-to-last in the trail) if it is present.
@@ -7,53 +7,8 @@ require "gretel"
7
7
 
8
8
  module Dummy
9
9
  class Application < Rails::Application
10
- # Settings in config/environments/* take precedence over those specified here.
11
- # Application configuration should go into files in config/initializers
12
- # -- all .rb files in that directory are automatically loaded.
13
-
14
- # Custom directories with classes and modules you want to be autoloadable.
15
- # config.autoload_paths += %W(#{config.root}/extras)
16
-
17
- # Only load the plugins named here, in the order given (default is alphabetical).
18
- # :all can be used as a placeholder for all plugins not explicitly named.
19
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
20
-
21
- # Activate observers that should always be running.
22
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
23
-
24
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
- # config.time_zone = 'Central Time (US & Canada)'
27
-
28
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
- # config.i18n.default_locale = :de
31
-
32
- # Configure the default encoding used in templates for Ruby 1.9.
33
- config.encoding = "utf-8"
34
-
35
- # Configure sensitive parameters which will be filtered from the log file.
36
- config.filter_parameters += [:password]
37
-
38
- # Enable escaping HTML in JSON.
39
- config.active_support.escape_html_entities_in_json = true
40
-
41
- # Use SQL instead of Active Record's schema dumper when creating the database.
42
- # This is necessary if your schema can't be completely dumped by the schema dumper,
43
- # like if you have constraints or database-specific column types
44
- # config.active_record.schema_format = :sql
45
-
46
- # Enforce whitelist mode for mass assignment.
47
- # This will create an empty whitelist of attributes available for mass-assignment for all models
48
- # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
49
- # parameters by using an attr_accessible or attr_protected declaration.
50
- config.active_record.whitelist_attributes = true
51
-
52
- # Enable the asset pipeline
53
- config.assets.enabled = true
54
-
55
- # Version of your assets, change this if you want to expire all your assets
56
- config.assets.version = '1.0'
10
+ config.secret_token = "secret token"
11
+ config.active_support.deprecation = :log
12
+ config.eager_load = false
57
13
  end
58
14
  end
59
-
@@ -77,4 +77,9 @@ end
77
77
  crumb :with_link_options do
78
78
  link "Test", about_path, title: "My Title", other: "Other Option"
79
79
  link "Other Link", some_option: "Test"
80
+ end
81
+
82
+ crumb :with_inferred_parent do
83
+ link "Test", about_path
84
+ parent Project.first
80
85
  end
@@ -1,37 +1,2 @@
1
1
  Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the web server when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
- config.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
15
-
16
- # Don't care if the mailer can't send
17
- config.action_mailer.raise_delivery_errors = false
18
-
19
- # Print deprecation notices to the Rails logger
20
- config.active_support.deprecation = :log
21
-
22
- # Only use best-standards-support built into browsers
23
- config.action_dispatch.best_standards_support = :builtin
24
-
25
- # Raise exception on mass assignment protection for Active Record models
26
- config.active_record.mass_assignment_sanitizer = :strict
27
-
28
- # Log the query plan for queries taking more than this (works
29
- # with SQLite, MySQL, and PostgreSQL)
30
- config.active_record.auto_explain_threshold_in_seconds = 0.5
31
-
32
- # Do not compress assets
33
- config.assets.compress = false
34
-
35
- # Expands the lines which load the assets
36
- config.assets.debug = true
37
2
  end
@@ -1,67 +1,2 @@
1
1
  Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # Code is not reloaded between requests
5
- config.cache_classes = true
6
-
7
- # Full error reports are disabled and caching is turned on
8
- config.consider_all_requests_local = false
9
- config.action_controller.perform_caching = true
10
-
11
- # Disable Rails's static asset server (Apache or nginx will already do this)
12
- config.serve_static_assets = false
13
-
14
- # Compress JavaScripts and CSS
15
- config.assets.compress = true
16
-
17
- # Don't fallback to assets pipeline if a precompiled asset is missed
18
- config.assets.compile = false
19
-
20
- # Generate digests for assets URLs
21
- config.assets.digest = true
22
-
23
- # Defaults to nil and saved in location specified by config.assets.prefix
24
- # config.assets.manifest = YOUR_PATH
25
-
26
- # Specifies the header that your server uses for sending files
27
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
29
-
30
- # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
- # config.force_ssl = true
32
-
33
- # See everything in the log (default is :info)
34
- # config.log_level = :debug
35
-
36
- # Prepend all log lines with the following tags
37
- # config.log_tags = [ :subdomain, :uuid ]
38
-
39
- # Use a different logger for distributed setups
40
- # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
41
-
42
- # Use a different cache store in production
43
- # config.cache_store = :mem_cache_store
44
-
45
- # Enable serving of images, stylesheets, and JavaScripts from an asset server
46
- # config.action_controller.asset_host = "http://assets.example.com"
47
-
48
- # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49
- # config.assets.precompile += %w( search.js )
50
-
51
- # Disable delivery errors, bad email addresses will be ignored
52
- # config.action_mailer.raise_delivery_errors = false
53
-
54
- # Enable threaded mode
55
- # config.threadsafe!
56
-
57
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
58
- # the I18n.default_locale when a translation can not be found)
59
- config.i18n.fallbacks = true
60
-
61
- # Send deprecation notices to registered listeners
62
- config.active_support.deprecation = :notify
63
-
64
- # Log the query plan for queries taking more than this (works
65
- # with SQLite, MySQL, and PostgreSQL)
66
- # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
2
  end
@@ -1,37 +1,2 @@
1
1
  Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The test environment is used exclusively to run your application's
5
- # test suite. You never need to work with it otherwise. Remember that
6
- # your test database is "scratch space" for the test suite and is wiped
7
- # and recreated between test runs. Don't rely on the data there!
8
- config.cache_classes = true
9
-
10
- # Configure static asset server for tests with Cache-Control for performance
11
- config.serve_static_assets = true
12
- config.static_cache_control = "public, max-age=3600"
13
-
14
- # Log error messages when you accidentally call methods on nil
15
- config.whiny_nils = true
16
-
17
- # Show full error reports and disable caching
18
- config.consider_all_requests_local = true
19
- config.action_controller.perform_caching = false
20
-
21
- # Raise exceptions instead of rendering exception templates
22
- config.action_dispatch.show_exceptions = false
23
-
24
- # Disable request forgery protection in test environment
25
- config.action_controller.allow_forgery_protection = false
26
-
27
- # Tell Action Mailer not to deliver emails to the real world.
28
- # The :test delivery method accumulates sent emails in the
29
- # ActionMailer::Base.deliveries array.
30
- config.action_mailer.delivery_method = :test
31
-
32
- # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
34
-
35
- # Print deprecation notices to the stderr
36
- config.active_support.deprecation = :stderr
37
2
  end
@@ -1,11 +1,11 @@
1
1
  Dummy::Application.routes.draw do
2
2
  root to: "dummy#dummy"
3
3
 
4
- match "about" => "dummy#dummy", as: :about
5
- match "about/contact" => "dummy#dummy", as: :contact
6
- match "about/contact/form" => "dummy#dummy", as: :contact_form
4
+ get "about" => "dummy#dummy", as: :about
5
+ get "about/contact" => "dummy#dummy", as: :contact
6
+ get "about/contact/form" => "dummy#dummy", as: :contact_form
7
7
 
8
8
  resources :projects do
9
9
  resources :issues
10
10
  end
11
- end
11
+ end
@@ -1,4 +1,4 @@
1
- class CreateProjects < ActiveRecord::Migration
1
+ class CreateProjects < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :projects do |t|
4
4
  t.string :name
@@ -1,4 +1,4 @@
1
- class CreateIssues < ActiveRecord::Migration
1
+ class CreateIssues < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :issues do |t|
4
4
  t.string :title
@@ -1,29 +1,28 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
5
4
  #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
5
+ # This file is the source Rails uses to define your schema when running `rails
6
+ # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
11
10
  #
12
- # It's strongly recommended to check this file into your version control system.
11
+ # It's strongly recommended that you check this file into your version control system.
13
12
 
14
- ActiveRecord::Schema.define(:version => 20130122163051) do
13
+ ActiveRecord::Schema.define(version: 2013_01_22_163051) do
15
14
 
16
- create_table "issues", :force => true do |t|
17
- t.string "title"
18
- t.integer "project_id"
19
- t.datetime "created_at", :null => false
20
- t.datetime "updated_at", :null => false
15
+ create_table "issues", force: :cascade do |t|
16
+ t.string "title"
17
+ t.integer "project_id"
18
+ t.datetime "created_at"
19
+ t.datetime "updated_at"
21
20
  end
22
21
 
23
- create_table "projects", :force => true do |t|
24
- t.string "name"
25
- t.datetime "created_at", :null => false
26
- t.datetime "updated_at", :null => false
22
+ create_table "projects", force: :cascade do |t|
23
+ t.string "name"
24
+ t.datetime "created_at"
25
+ t.datetime "updated_at"
27
26
  end
28
27
 
29
28
  end
@@ -11,7 +11,6 @@ class GretelTest < ActiveSupport::TestCase
11
11
  Rails.root.join("app", "views", "breadcrumbs", "**", "*.rb")],
12
12
  Gretel.breadcrumb_paths[-3..-1]
13
13
  assert_equal ["development"], Gretel.reload_environments
14
- assert !Gretel.suppress_deprecation_warnings?
15
14
  end
16
15
 
17
16
  test "configuration block" do
@@ -21,4 +20,4 @@ class GretelTest < ActiveSupport::TestCase
21
20
 
22
21
  assert_equal ["development", "staging"], Gretel.reload_environments
23
22
  end
24
- end
23
+ end
@@ -2,154 +2,167 @@ require 'test_helper'
2
2
 
3
3
  class HelperMethodsTest < ActionView::TestCase
4
4
  include Gretel::ViewHelpers
5
+
6
+ self.fixture_path = File.expand_path("../../test/fixtures", __FILE__)
5
7
  fixtures :all
8
+
6
9
  helper :application
7
10
 
8
11
  setup do
9
12
  Gretel.reset!
10
13
  end
11
14
 
15
+ def itemscope_value
16
+ ActionView::Helpers::TagHelper::BOOLEAN_ATTRIBUTES.include?("itemscope") ?
17
+ "itemscope" : ""
18
+ end
19
+
12
20
  # Breadcrumb generation
13
21
 
14
- test "shows basic breadcrumb" do
22
+ test "basic breadcrumb" do
15
23
  breadcrumb :basic
16
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
17
- breadcrumbs
24
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
25
+ breadcrumbs.to_s
18
26
  end
19
27
 
20
- test "shows breadcrumb with root" do
28
+ test "breadcrumb with root" do
21
29
  breadcrumb :with_root
22
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
23
- breadcrumbs
30
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
31
+ breadcrumbs.to_s
24
32
  end
25
33
 
26
- test "shows breadcrumb with parent" do
34
+ test "breadcrumb with parent" do
27
35
  breadcrumb :with_parent
28
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <span class="current">Contact</span></div>},
29
- breadcrumbs
36
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <span class="current">Contact</span></div>},
37
+ breadcrumbs.to_s
30
38
  end
31
39
 
32
- test "shows breadcrumb with autopath" do
40
+ test "breadcrumb with autopath" do
33
41
  breadcrumb :with_autopath, projects(:one)
34
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test Project</span></div>},
35
- breadcrumbs
42
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test Project</span></div>},
43
+ breadcrumbs.to_s
36
44
  end
37
45
 
38
- test "shows breadcrumb with parent object" do
46
+ test "breadcrumb with parent object" do
39
47
  breadcrumb :with_parent_object, issues(:one)
40
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/projects/1">Test Project</a> &rsaquo; <span class="current">Test Issue</span></div>},
41
- breadcrumbs
48
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/projects/1">Test Project</a> &rsaquo; <span class="current">Test Issue</span></div>},
49
+ breadcrumbs.to_s
42
50
  end
43
51
 
44
- test "shows multiple links" do
52
+ test "multiple links" do
45
53
  breadcrumb :multiple_links
46
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about/contact">Contact</a> &rsaquo; <span class="current">Contact form</span></div>},
47
- breadcrumbs
54
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about/contact">Contact</a> &rsaquo; <span class="current">Contact form</span></div>},
55
+ breadcrumbs.to_s
48
56
  end
49
57
 
50
- test "shows multiple links with parent" do
58
+ test "multiple links with parent" do
51
59
  breadcrumb :multiple_links_with_parent
52
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <a href="/about/contact">Contact</a> &rsaquo; <span class="current">Contact form</span></div>},
53
- breadcrumbs
60
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <a href="/about/contact">Contact</a> &rsaquo; <span class="current">Contact form</span></div>},
61
+ breadcrumbs.to_s
54
62
  end
55
63
 
56
- test "shows semantic breadcrumb" do
64
+ test "semantic breadcrumb" do
57
65
  breadcrumb :with_root
58
- assert_equal %{<div class="breadcrumbs"><div itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/" itemprop="url"><span itemprop="title">Home</span></a></div> &rsaquo; <div itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><span class="current" itemprop="title">About</span></div></div>},
59
- breadcrumbs(semantic: true)
66
+ assert_dom_equal %Q{<div class="breadcrumbs"><span itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/" itemprop="url"><span itemprop="title">Home</span></a></span> &rsaquo; <span itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><span class="current" itemprop="title">About</span></span></div>},
67
+ breadcrumbs(semantic: true).to_s
60
68
  end
61
69
 
62
70
  test "doesn't show root alone" do
63
71
  breadcrumb :root
64
- assert_equal "", breadcrumbs
72
+ assert_dom_equal "", breadcrumbs.to_s
65
73
  end
66
74
 
67
75
  test "displays single fragment" do
68
76
  breadcrumb :root
69
- assert_equal %{<div class="breadcrumbs"><span class="current">Home</span></div>},
70
- breadcrumbs(display_single_fragment: true)
77
+ assert_dom_equal %{<div class="breadcrumbs"><span class="current">Home</span></div>},
78
+ breadcrumbs(display_single_fragment: true).to_s
71
79
  end
72
80
 
73
81
  test "displays single non-root fragment" do
74
82
  breadcrumb :basic
75
- assert_equal %{<div class="breadcrumbs"><span class="current">About</span></div>},
76
- breadcrumbs(autoroot: false, display_single_fragment: true)
83
+ assert_dom_equal %{<div class="breadcrumbs"><span class="current">About</span></div>},
84
+ breadcrumbs(autoroot: false, display_single_fragment: true).to_s
77
85
  end
78
86
 
79
- test "shows no breadcrumb" do
80
- assert_equal "", breadcrumbs
87
+ test "no breadcrumb" do
88
+ assert_dom_equal "", breadcrumbs.to_s
81
89
  end
82
90
 
83
91
  test "links current breadcrumb" do
84
92
  breadcrumb :with_root
85
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about" class="current">About</a></div>},
86
- breadcrumbs(link_current: true)
93
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about" class="current">About</a></div>},
94
+ breadcrumbs(link_current: true).to_s
87
95
  end
88
96
 
89
- test "shows pretext" do
97
+ test "pretext" do
90
98
  breadcrumb :basic
91
- assert_equal %{<div class="breadcrumbs">You are here: <a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
92
- breadcrumbs(pretext: "You are here: ")
99
+ assert_dom_equal %{<div class="breadcrumbs"><span class="pretext">You are here:</span> <a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
100
+ breadcrumbs(pretext: "You are here:").to_s
93
101
  end
94
102
 
95
- test "shows posttext" do
103
+ test "posttext" do
96
104
  breadcrumb :basic
97
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span> - text after breadcrumbs</div>},
98
- breadcrumbs(posttext: " - text after breadcrumbs")
105
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span> <span class="posttext">text after breadcrumbs</span></div>},
106
+ breadcrumbs(posttext: "text after breadcrumbs").to_s
99
107
  end
100
108
 
101
109
  test "autoroot disabled" do
102
110
  breadcrumb :basic
103
- assert_equal "", breadcrumbs(autoroot: false)
111
+ assert_dom_equal "", breadcrumbs(autoroot: false).to_s
104
112
  end
105
113
 
106
- test "shows separator" do
114
+ test "separator" do
107
115
  breadcrumb :with_root
108
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &raquo; <span class="current">About</span></div>},
109
- breadcrumbs(separator: " &raquo; ")
116
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &raquo; <span class="current">About</span></div>},
117
+ breadcrumbs(separator: " &raquo; ").to_s
110
118
  end
111
119
 
112
- test "shows element id" do
120
+ test "element id" do
113
121
  breadcrumb :basic
114
- assert_equal %{<div class="breadcrumbs" id="custom_id"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
115
- breadcrumbs(id: "custom_id")
122
+ assert_dom_equal %{<div class="breadcrumbs" id="custom_id"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
123
+ breadcrumbs(id: "custom_id").to_s
116
124
  end
117
125
 
118
- test "shows custom container class" do
126
+ test "custom container class" do
119
127
  breadcrumb :basic
120
- assert_equal %{<div class="custom_class"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
121
- breadcrumbs(class: "custom_class")
128
+ assert_dom_equal %{<div class="custom_class"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
129
+ breadcrumbs(class: "custom_class").to_s
122
130
  end
123
131
 
124
- test "shows custom current class" do
132
+ test "custom fragment class" do
125
133
  breadcrumb :basic
126
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="custom_current_class">About</span></div>},
127
- breadcrumbs(current_class: "custom_current_class")
134
+ assert_dom_equal %{<div class="breadcrumbs"><a class="custom_fragment_class" href="/">Home</a> &rsaquo; <span class="custom_fragment_class current">About</span></div>},
135
+ breadcrumbs(fragment_class: "custom_fragment_class").to_s
128
136
  end
129
137
 
130
- test "unsafe html" do
131
- breadcrumb :with_unsafe_html
132
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test &lt;strong&gt;bold text&lt;/strong&gt;</span></div>},
133
- breadcrumbs
138
+ test "custom current class" do
139
+ breadcrumb :basic
140
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="custom_current_class">About</span></div>},
141
+ breadcrumbs(current_class: "custom_current_class").to_s
134
142
  end
135
143
 
136
- test "safe html" do
137
- breadcrumb :with_safe_html
138
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test <strong>bold text</strong></span></div>},
139
- breadcrumbs
144
+ test "custom pretext class" do
145
+ breadcrumb :basic
146
+ assert_dom_equal %{<div class="breadcrumbs"><span class="custom_pretext_class">You are here:</span> <a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
147
+ breadcrumbs(pretext: "You are here:", pretext_class: "custom_pretext_class").to_s
140
148
  end
141
149
 
142
- test "yields a block containing breadcrumb links array" do
143
- breadcrumb :multiple_links_with_parent
150
+ test "custom posttext class" do
151
+ breadcrumb :basic
152
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span> <span class="custom_posttext_class">after breadcrumbs</span></div>},
153
+ breadcrumbs(posttext: "after breadcrumbs", posttext_class: "custom_posttext_class").to_s
154
+ end
144
155
 
145
- out = breadcrumbs do |links|
146
- links.map { |link| [link.key, link.text, link.url] }
147
- end
156
+ test "unsafe html" do
157
+ breadcrumb :with_unsafe_html
158
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test &lt;strong&gt;bold text&lt;/strong&gt;</span></div>},
159
+ breadcrumbs.to_s
160
+ end
148
161
 
149
- assert_equal [[:root, "Home", "/"],
150
- [:basic, "About", "/about"],
151
- [:multiple_links_with_parent, "Contact", "/about/contact"],
152
- [:multiple_links_with_parent, "Contact form", "/about/contact/form"]], out
162
+ test "safe html" do
163
+ breadcrumb :with_safe_html
164
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test <strong>bold text</strong></span></div>},
165
+ breadcrumbs.to_s
153
166
  end
154
167
 
155
168
  test "parent breadcrumb" do
@@ -186,27 +199,36 @@ class HelperMethodsTest < ActionView::TestCase
186
199
  assert_nil out
187
200
  end
188
201
 
189
- test "sets current on last link in array" do
190
- breadcrumb :multiple_links_with_parent
202
+ test "link keys" do
203
+ breadcrumb :basic
204
+ assert_equal [:root, :basic], breadcrumbs.keys
205
+ end
191
206
 
192
- out = breadcrumbs do |links|
193
- links.map(&:current?)
207
+ test "using breadcrumbs as array" do
208
+ breadcrumb :basic
209
+
210
+ breadcrumbs.tap do |links|
211
+ assert_kind_of Array, links
212
+ assert_equal 2, links.count
194
213
  end
214
+ end
195
215
 
196
- assert_equal [false, false, false, true], out
216
+ test "sets current on last link in array" do
217
+ breadcrumb :multiple_links_with_parent
218
+ assert_equal [false, false, false, true], breadcrumbs.map(&:current?)
197
219
  end
198
220
 
199
221
  test "passing options to links" do
200
222
  breadcrumb :with_link_options
201
223
 
202
- breadcrumbs(autoroot: false) do |links|
224
+ breadcrumbs(autoroot: false).tap do |links|
203
225
  links[0].tap do |link|
204
226
  assert link.title?
205
227
  assert_equal "My Title", link.title
206
-
228
+
207
229
  assert link.other?
208
230
  assert_equal "Other Option", link.other
209
-
231
+
210
232
  assert !link.nonexistent?
211
233
  assert_nil link.nonexistent
212
234
  end
@@ -217,54 +239,54 @@ class HelperMethodsTest < ActionView::TestCase
217
239
  end
218
240
  end
219
241
 
220
- assert_equal %{<div class="breadcrumbs"><a href="/about">Test</a> &rsaquo; <span class="current">Other Link</span></div>},
221
- breadcrumbs(autoroot: false)
242
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/about">Test</a> &rsaquo; <span class="current">Other Link</span></div>},
243
+ breadcrumbs(autoroot: false).to_s
222
244
  end
223
245
 
224
246
  test "without link" do
225
247
  breadcrumb :without_link
226
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; Also without link &rsaquo; <span class="current">Without link</span></div>},
227
- breadcrumbs
248
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; Also without link &rsaquo; <span class="current">Without link</span></div>},
249
+ breadcrumbs.to_s
228
250
  end
229
251
 
230
252
  test "view context" do
231
253
  breadcrumb :using_view_helper
232
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">TestTest</span></div>},
233
- breadcrumbs
254
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">TestTest</span></div>},
255
+ breadcrumbs.to_s
234
256
  end
235
257
 
236
258
  test "multiple arguments" do
237
259
  breadcrumb :with_multiple_arguments, "One", "Two", "Three"
238
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">First OneOne then TwoTwo then ThreeThree</a> &rsaquo; <span class="current">One and Two and Three</span></div>},
239
- breadcrumbs
260
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">First OneOne then TwoTwo then ThreeThree</a> &rsaquo; <span class="current">One and Two and Three</span></div>},
261
+ breadcrumbs.to_s
240
262
  end
241
263
 
242
264
  test "from views folder" do
243
265
  breadcrumb :from_views
244
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Breadcrumb From View</span></div>},
245
- breadcrumbs
266
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Breadcrumb From View</span></div>},
267
+ breadcrumbs.to_s
246
268
  end
247
269
 
248
270
  test "with_breadcrumb" do
249
271
  breadcrumb :basic
250
-
251
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
252
- breadcrumbs
272
+
273
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
274
+ breadcrumbs.to_s
253
275
 
254
276
  with_breadcrumb(:with_parent_object, issues(:one)) do
255
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/projects/1">Test Project</a> &rsaquo; <span class="current">Test Issue</span></div>},
256
- breadcrumbs
257
- end
258
-
259
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
260
- breadcrumbs
277
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/projects/1">Test Project</a> &rsaquo; <span class="current">Test Issue</span></div>},
278
+ breadcrumbs.to_s
279
+ end
280
+
281
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
282
+ breadcrumbs.to_s
261
283
  end
262
284
 
263
285
  test "calling breadcrumbs helper twice" do
264
286
  breadcrumb :with_parent
265
287
  2.times do
266
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <span class="current">Contact</span></div>},
267
- breadcrumbs
288
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/about">About</a> &rsaquo; <span class="current">Contact</span></div>},
289
+ breadcrumbs.to_s
268
290
  end
269
291
  end
270
292
 
@@ -279,7 +301,14 @@ class HelperMethodsTest < ActionView::TestCase
279
301
  self.request = OpenStruct.new(fullpath: "/testpath?a=1&b=2")
280
302
 
281
303
  breadcrumb :basic
282
- assert_equal "/testpath?a=1&b=2", breadcrumbs { |links| links.last.url }
304
+ assert_equal "/testpath?a=1&b=2", breadcrumbs.last.url
305
+ end
306
+
307
+ test "current link url is not set to fullpath using link_current_to_request_path=false" do
308
+ self.request = OpenStruct.new(fullpath: "/testpath?a=1&b=2")
309
+
310
+ breadcrumb :basic
311
+ assert_equal "/about", breadcrumbs(:link_current_to_request_path => false).last.url
283
312
  end
284
313
 
285
314
  test "calling the breadcrumb method with wrong arguments" do
@@ -298,52 +327,65 @@ class HelperMethodsTest < ActionView::TestCase
298
327
 
299
328
  test "inferred breadcrumb" do
300
329
  breadcrumb Project.first
301
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test Project</span></div>},
302
- breadcrumbs
330
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">Test Project</span></div>},
331
+ breadcrumbs.to_s
332
+ end
333
+
334
+ test "inferred parent" do
335
+ breadcrumb :with_inferred_parent
336
+
337
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <a href="/projects/1">Test Project</a> &rsaquo; <span class="current">Test</span></div>},
338
+ breadcrumbs.to_s
303
339
  end
304
340
 
305
341
  # Styles
306
342
 
307
343
  test "default style" do
308
344
  breadcrumb :basic
309
- assert_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
310
- breadcrumbs
345
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home</a> &rsaquo; <span class="current">About</span></div>},
346
+ breadcrumbs.to_s
311
347
  end
312
348
 
313
349
  test "ordered list style" do
314
350
  breadcrumb :basic
315
- assert_equal %{<ol class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ol>},
316
- breadcrumbs(style: :ol)
351
+ assert_dom_equal %{<ol class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ol>},
352
+ breadcrumbs(style: :ol).to_s
317
353
  end
318
354
 
319
355
  test "unordered list style" do
320
356
  breadcrumb :basic
321
- assert_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
322
- breadcrumbs(style: :ul)
357
+ assert_dom_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
358
+ breadcrumbs(style: :ul).to_s
323
359
  end
324
360
 
325
361
  test "bootstrap style" do
326
362
  breadcrumb :basic
327
- assert_equal %{<ol class="breadcrumb"><li><a href="/">Home</a></li><li class="active">About</li></ol>},
328
- breadcrumbs(style: :bootstrap)
363
+ assert_dom_equal %{<ol class="breadcrumb"><li><a href="/">Home</a></li><li class="active">About</li></ol>},
364
+ breadcrumbs(style: :bootstrap).to_s
365
+ end
366
+
367
+ test "bootstrap4 style" do
368
+ breadcrumb :basic
369
+ assert_dom_equal %{<ol class="breadcrumb"><li class="breadcrumb-item"><a href="/">Home</a></li><li class="breadcrumb-item active">About</li></ol>},
370
+ breadcrumbs(style: :bootstrap4).to_s
329
371
  end
330
372
 
331
373
  test "foundation5 style" do
332
374
  breadcrumb :basic
333
- assert_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
334
- breadcrumbs(style: :foundation5)
375
+ assert_dom_equal %{<ul class="breadcrumbs"><li><a href="/">Home</a></li><li class="current">About</li></ul>},
376
+ breadcrumbs(style: :foundation5).to_s
335
377
  end
336
378
 
337
379
  test "custom container and fragment tags" do
338
380
  breadcrumb :basic
339
- assert_equal %{<c class="breadcrumbs"><f><a href="/">Home</a></f> &rsaquo; <f class="current">About</f></c>},
340
- breadcrumbs(container_tag: :c, fragment_tag: :f)
381
+ assert_dom_equal %{<c class="breadcrumbs"><f><a href="/">Home</a></f> &rsaquo; <f class="current">About</f></c>},
382
+ breadcrumbs(container_tag: :c, fragment_tag: :f).to_s
341
383
  end
342
384
 
343
385
  test "custom semantic container and fragment tags" do
344
386
  breadcrumb :basic
345
- assert_equal %{<c class="breadcrumbs"><f itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/" itemprop="url"><span itemprop="title">Home</span></a></f> &rsaquo; <f class="current" itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title">About</span></f></c>},
346
- breadcrumbs(container_tag: :c, fragment_tag: :f, semantic: true)
387
+ assert_dom_equal %Q{<c class="breadcrumbs"><f itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><a itemprop="url" href="/"><span itemprop="title">Home</span></a></f> &rsaquo; <f class="current" itemscope="#{itemscope_value}" itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title">About</span><meta itemprop="url" content="http://test.host/about" /></f></c>},
388
+ breadcrumbs(container_tag: :c, fragment_tag: :f, semantic: true).to_s
347
389
  end
348
390
 
349
391
  test "unknown style" do
@@ -355,11 +397,11 @@ class HelperMethodsTest < ActionView::TestCase
355
397
 
356
398
  test "register style" do
357
399
  Gretel.register_style :test_style, { container_tag: :one, fragment_tag: :two }
358
-
400
+
359
401
  breadcrumb :basic
360
402
 
361
- assert_equal %{<one class="breadcrumbs"><two><a href="/">Home</a></two><two class="current">About</two></one>},
362
- breadcrumbs(style: :test_style)
403
+ assert_dom_equal %{<one class="breadcrumbs"><two><a href="/">Home</a></two><two class="current">About</two></one>},
404
+ breadcrumbs(style: :test_style).to_s
363
405
  end
364
406
 
365
407
  # Configuration reload
@@ -380,7 +422,7 @@ class HelperMethodsTest < ActionView::TestCase
380
422
  end
381
423
 
382
424
  breadcrumb :about
383
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
425
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
384
426
 
385
427
  sleep 1 # File change interval is 1 second
386
428
 
@@ -396,7 +438,7 @@ class HelperMethodsTest < ActionView::TestCase
396
438
  end
397
439
 
398
440
  breadcrumb :about
399
- assert_equal %{<div class="breadcrumbs"><a href="/test">Home (reloaded)</a> &rsaquo; <span class="current">About (reloaded)</span></div>}, breadcrumbs
441
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/test">Home (reloaded)</a> &rsaquo; <span class="current">About (reloaded)</span></div>}, breadcrumbs.to_s
400
442
  end
401
443
 
402
444
  test "reload configuration when file is added" do
@@ -425,7 +467,7 @@ class HelperMethodsTest < ActionView::TestCase
425
467
  end
426
468
 
427
469
  breadcrumb :about
428
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
470
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
429
471
  end
430
472
 
431
473
  test "reload configuration when file is deleted" do
@@ -453,7 +495,7 @@ class HelperMethodsTest < ActionView::TestCase
453
495
  end
454
496
 
455
497
  breadcrumb :contact
456
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <a href="/about">About (loaded)</a> &rsaquo; <span class="current">Contact (loaded)</span></div>}, breadcrumbs
498
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <a href="/about">About (loaded)</a> &rsaquo; <span class="current">Contact (loaded)</span></div>}, breadcrumbs.to_s
457
499
 
458
500
  File.delete path.join("pages.rb")
459
501
 
@@ -463,7 +505,7 @@ class HelperMethodsTest < ActionView::TestCase
463
505
  end
464
506
 
465
507
  breadcrumb :about
466
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
508
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
467
509
  end
468
510
 
469
511
  test "reloads only in development environment" do
@@ -483,7 +525,7 @@ class HelperMethodsTest < ActionView::TestCase
483
525
  end
484
526
 
485
527
  breadcrumb :about
486
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
528
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
487
529
 
488
530
  sleep 1
489
531
 
@@ -499,7 +541,7 @@ class HelperMethodsTest < ActionView::TestCase
499
541
  end
500
542
 
501
543
  breadcrumb :about
502
- assert_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs
544
+ assert_dom_equal %{<div class="breadcrumbs"><a href="/">Home (loaded)</a> &rsaquo; <span class="current">About (loaded)</span></div>}, breadcrumbs.to_s
503
545
  end
504
546
 
505
547
  private