require 'spec_helper'
describe NeatPages::Helpers::Builder do
include ViewHelpers
describe "#b" do
context "with an empty builder" do
let(:builder) { NeatPages::Helpers::Builder.new(double, request_mock) }
context "when inserting the string 1" do
subject { builder.b '1' }
it { should eql '1' }
it { should be_html_safe }
context "and inserting another 2" do
before { builder.b '1' }
subject { builder.b '2' }
it { should eql '12' }
end
end
end
end
describe "#li" do
context "with an empty builder" do
let(:builder) { NeatPages::Helpers::Builder.new(double, request_mock) }
context "when inserting a li with the value 1" do
before { builder.li '1' }
specify { builder.b.should eql '
1' }
end
context "when inserting an hidden li with the value 1, the css_class 'active'" do
before { builder.li '1', 'active', hidden: true }
specify { builder.b.should eql '1' }
end
end
end
describe "#path_to" do
context "with a builder having a base_url http://www.test.dev" do
context "and no params" do
let(:builder) { NeatPages::Helpers::Builder.new(double, request_mock(host: 'www.test.dev')) }
context "when asking for the path_to page 6" do
specify { builder.path_to(6).should eql 'http://www.test.dev?page=6' }
end
end
context "and the params sort=1, filter=type" do
let(:request) { request_mock(host: 'www.test.dev', env: { 'action_dispatch.request.query_parameters' => { 'sort' => 1, 'filter' => 'type' } })}
let(:builder) { NeatPages::Helpers::Builder.new(double, request) }
context "when asking for the path_to page 6" do
specify { builder.path_to(6).should eql 'http://www.test.dev?sort=1&filter=type&page=6' }
end
end
context "and the params sort=1, filter=type, page=5" do
let(:request) { request_mock(host: 'www.test.dev', env: { 'action_dispatch.request.query_parameters' => { 'sort' => 1, 'filter' => 'type', 'page' => 5 } })}
let(:builder) { NeatPages::Helpers::Builder.new(double, request) }
context "when asking for the path_to page 6" do
specify { builder.path_to(6).should eql 'http://www.test.dev?sort=1&filter=type&page=6' }
end
end
context "and the params page=5" do
let(:request) { request_mock(host: 'www.test.dev', env: { 'action_dispatch.request.query_parameters' => { 'page' => 5 } })}
let(:builder) { NeatPages::Helpers::Builder.new(double, request) }
context "when asking for the path_to page 6" do
specify { builder.path_to(6).should eql 'http://www.test.dev?page=6' }
end
end
end
end
describe "#reset_builder" do
context "with an empty builder" do
let(:builder) { NeatPages::Helpers::Builder.new(double, request_mock) }
context "when resetting the builder" do
before { builder.reset_builder }
specify { builder.b.should eql '' }
end
end
context "with a builder having the value '1'" do
let(:builder) { NeatPages::Helpers::Builder.new(double, request_mock) }
before { builder.b '1' }
context "when resetting the builder" do
before { builder.reset_builder }
specify { builder.b.should eql '' }
end
end
end
end