Sha256: 510ff76fde64255609535af11b1fc88c72716fe8ac4d3565ad5de697ed7e9e99

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'
require 'action_view'
require 'active_support'
require_relative '../../../app/helpers/railsstrap/navbar_helper'

include ActionView::Helpers
include ActionView::Context
include Railsstrap::NavbarHelper

describe Railsstrap::NavbarHelper, 'uri_state', type: :helper do
  before do
    allow(subject).to receive_message_chain("request.host_with_port").and_return("#{HOST}")
    allow(subject).to receive_message_chain("request.protocol").and_return("http://")
    allow(subject).to receive_message_chain("request.url").and_return("#{HOST}/a/b")
    allow(subject).to receive_message_chain("request.path").and_return('/a/b')    
  end

  it 'must return active state' do
    expect(subject.uri_state('/a/b'))
      .to be :active
    expect(subject.uri_state("#{HOST}/a/b"))
      .to be :active
  end

  it 'must not return chosen for non get method' do
    expect(subject.uri_state('/a/b', :method => 'delete')).to be :inactive
    expect(subject.uri_state("#{HOST}/a/b", :method => 'delete')).to be :inactive
    expect(subject.uri_state('/a/b', "data-method" => 'delete')).to be :inactive
    expect(subject.uri_state("#{HOST}/a/b", "data-method" => 'delete')).to be :inactive
  end

  it 'must return chosen state' do
    expect(subject.uri_state('/a')).to be :chosen
    expect(subject.uri_state("#{HOST}/a")).to be :chosen
  end

  it 'must return inactive state' do
    expect(subject.uri_state('/test')).to be :inactive
    expect(subject.uri_state("#{HOST}/test")).to be :inactive
  end

  it 'must not return chosen for root url' do
    expect(subject.uri_state('/')).to be :inactive
    expect(subject.uri_state("#{HOST}/")).to be :inactive
  end

end

HOST = "http://example.com:80"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
railsstrap-3.3.4 spec/lib/railsstrap/uri_state_spec.rb
railsstrap-3.3.2 spec/lib/railsstrap/uri_state_spec.rb