Skip to content

Commit

Permalink
Fix more style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hoppergee committed Feb 25, 2022
1 parent 72b1590 commit ba3602e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ The `:request_methods` key accepts `:all` or an array with following values:
* `:unlink`
* `:trace`
Its default value is `%i[get head]`
It's defaults to `%i[get head]`
For example:
Here are some examples:
```ruby
request_methods: %i[get head]
Expand Down
3 changes: 1 addition & 2 deletions lib/loaf/view_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def breadcrumb_trail(options = {})
# the pattern to match on
#
# @api public
def current_crumb?(path, pattern = :inclusive, request_methods: nil)
def current_crumb?(path, pattern = :inclusive, request_methods: Loaf.configuration.request_methods)
return false unless match_request_methods(request_methods)

origin_path = URI::DEFAULT_PARSER.unescape(path).force_encoding(Encoding::BINARY)
Expand Down Expand Up @@ -139,7 +139,6 @@ def _expand_url(url)
#
# @api private
def match_request_methods(request_methods)
request_methods ||= Loaf.configuration.request_methods
return true if request_methods == :all

request_methods.any? { |method| request.try("#{method}?") }
Expand Down
70 changes: 35 additions & 35 deletions spec/integration/breadcrumb_trail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,62 @@
it "shows root breadcrumb" do
visit root_path

page.within '#breadcrumbs .selected' do
expect(page.html).to include('<a href="/">Home</a>')
within "#breadcrumbs .selected" do
expect(page).to have_link(href: "/", text: "Home")
end
end

it "inherits controller breadcrumb and adds index action breadcrumb" do
visit posts_path

page.within '#breadcrumbs' do
expect(page.html).to include('<a href="/">Home</a>')
within "#breadcrumbs" do
expect(page).to have_link(href: "/", text: "Home")
end
page.within '#breadcrumbs .selected' do
expect(page.html).to include('<a href="/posts">All Posts</a>')
within "#breadcrumbs .selected" do
expect(page).to have_link(href: "/posts", text: "All Posts")
end
end

it 'filters out controller breadcrumb and adds new action breadcrumb' do
it "filters out controller breadcrumb and adds new action breadcrumb" do
visit new_post_path

page.within '#breadcrumbs' do
expect(page).to_not have_content('Home')
expect(page).to have_content('New Post')
within "#breadcrumbs" do
expect(page).to_not have_content("Home")
expect(page).to have_content("New Post")
end
end

it "adds breadcrumb in view with path variable" do
visit post_path(1)

page.within '#breadcrumbs .selected' do
expect(page.html).to include('<a href="/posts/1">Show Post in view</a>')
within "#breadcrumbs .selected" do
expect(page).to have_link(href: "/posts/1", text: "Show Post in view")
end
end

it 'is current when forced' do
it "is current when forced" do
visit new_post_path

expect(page.current_path).to eq(new_post_path)
page.within '#breadcrumbs' do
expect(page).to have_selector('li.selected', count: 2)
expect(page.html).to include('<a href="/posts">All</a>')
expect(page.html).to include('<a href="/posts/new">New Post</a>')
within "#breadcrumbs" do
expect(page).to have_selector("li.selected", count: 2)
expect(page).to have_link(href: "/posts", text: "All")
expect(page).to have_link(href: "/posts/new", text: "New Post")
end
end

it "allows for procs in name and url" do
visit post_comments_path(1)

page.within '#breadcrumbs .selected' do
expect(page.html).to include('<a href="/posts/1/comments">Post comments</a>')
within "#breadcrumbs .selected" do
expect(page).to have_link(href: "/posts/1/comments", text: "Post comments")
end
end

it "allows for procs in name and url without supplying the controller" do
visit post_comments_path(1)

page.within "#breadcrumbs .selected" do
within "#breadcrumbs .selected" do
expect(page.html).to include(
'<a href="/posts/1/comments?no_controller=true">'\
"Post comments No Controller</a>"
Expand All @@ -75,49 +75,49 @@
visit onboard_path

expect(page).to have_selector("h1", text: "Onboard")
page.within "#breadcrumbs" do
within "#breadcrumbs" do
expect(page).to have_content("Onboard")
end

click_link "Step 1" # GET
expect(page).to have_selector("h1", text: "Step 1")
page.within "#breadcrumbs" do
expect(page.html).to include('<a href="/onboard">Onboard</a>')
within "#breadcrumbs" do
expect(page).to have_link(href: "/onboard", text: "Onboard")
end
page.within "#breadcrumbs .selected" do
expect(page.html).to include('<a href="/onboard/step/1">Step 1</a>')
within "#breadcrumbs .selected" do
expect(page).to have_link(href: "/onboard/step/1", text: "Step 1")
end

click_on "Save & Next" # POST
expect(page).to have_selector("h1", text: "Step 2")
page.within "#breadcrumbs .selected" do
expect(page.html).to include('<a href="/onboard/step/2">Step 2</a>')
within "#breadcrumbs .selected" do
expect(page).to have_link(href: "/onboard/step/2", text: "Step 2")
end

click_on "Save & Next" # PUT
expect(page).to have_selector("h1", text: "Step 3")
page.within "#breadcrumbs .selected" do
expect(page.html).to include('<a href="/onboard/step/3">Step 3</a>')
within "#breadcrumbs .selected" do
expect(page).to have_link(href: "/onboard/step/3", text: "Step 3")
end

if Rails.version >= "4.0.0"
click_on "Save & Next" # PATCH
expect(page).to have_selector("h1", text: "Step 4")
page.within '#breadcrumbs .selected' do
expect(page.html).to include('<a href="/onboard/step/4">Step 4</a>')
within '#breadcrumbs .selected' do
expect(page).to have_link(href: "/onboard/step/4", text: "Step 4")
end
end

click_on "Save & Next" # DELETE
expect(page).to have_selector("h1", text: "Step 5")
page.within "#breadcrumbs .selected" do
expect(page.html).to include('<a href="/onboard/step/5">Step 5</a>')
within "#breadcrumbs .selected" do
expect(page).to have_link(href: "/onboard/step/5", text: "Step 5")
end

click_on "Save & Next" # GET
expect(page).to have_selector("h1", text: "Step 6")
page.within "#breadcrumbs .selected" do
expect(page.html).to include('<a href="/onboard/step/6">Step 6</a>')
within "#breadcrumbs .selected" do
expect(page).to have_link(href: "/onboard/step/6", text: "Step 6")
end
end
end
2 changes: 1 addition & 1 deletion spec/integration/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe 'setting configuration options' do
it "contains 'selected' inside the breadcrumb markup" do
visit posts_path
page.within '#breadcrumbs' do
within "#breadcrumbs" do
expect(page).to have_selector('.selected')
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/view_extensions/breadcrumb_trail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
expect(view.breadcrumb_trail(match: :exact).map(&:current?)).to eq([false, false, true])
end

it "match current path with :request_methods" do
it "matches the current path with :request_methods set to custom" do
view = DummyView.new
view.breadcrumb("posts", "/posts", request_methods: %i[get post])
view.set_path("/posts")
Expand All @@ -291,7 +291,7 @@
expect(trail).to eq([["posts", "/posts", true]])
end

it "fail to match current path with :request_methods" do
it "fails to match current path with :request_methods set to default" do
view = DummyView.new
view.breadcrumb("posts", "/posts")
view.set_path("/posts")
Expand All @@ -301,7 +301,7 @@
expect(trail).to eq([["posts", "/posts", false]])
end

it "match current path with :request_methods => :all" do
it "matches current path with :request_methods set to :all" do
view = DummyView.new
view.breadcrumb("posts", "/posts", request_methods: :all)
view.set_path("/posts")
Expand Down

0 comments on commit ba3602e

Please sign in to comment.