Sha256: 394c0cb8d5b6101a8aec5fbb1ccac95141c7a66ae84323cb54d982383637b54b

Contents?: true

Size: 1.75 KB

Versions: 4

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

module Ransack
  module Helpers
    describe FormHelper do

      router = ActionDispatch::Routing::RouteSet.new
      router.draw do
        resources :people
        match ':controller(/:action(/:id(.:format)))'
      end

      include router.url_helpers

      # FIXME: figure out a cleaner way to get this behavior
      before do
        @controller = ActionView::TestCase::TestController.new
        @controller.instance_variable_set(:@_routes, router)
        @controller.class_eval do
          include router.url_helpers
        end

        @controller.view_context_class.class_eval do
          include router.url_helpers
        end
      end

      describe '#sort_link with default search_key' do
        subject { @controller.view_context.sort_link([:main_app, Person.search(:sorts => ['name desc'])], :name, :controller => 'people') }
        it { should match /people\?q%5Bs%5D=name\+asc/ }
        it { should match /sort_link desc/ }
        it { should match /Full Name ▼/ }
      end

      describe '#sort_link with default search_key defined as symbol' do
        subject { @controller.view_context.sort_link(Person.search({:sorts => ['name desc']}, :search_key => :people_search),
                                                     :name, :controller => 'people') }

        it { should match /people\?people_search%5Bs%5D=name\+asc/ }
      end

      describe '#sort_link with default search_key defined as string' do
        subject { @controller.view_context.sort_link(Person.search({:sorts => ['name desc']}, :search_key => 'people_search'),
                                                       :name, :controller => 'people') }

        it { should match /people\?people_search%5Bs%5D=name\+asc/ }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
ransack-0.7.2 spec/ransack/helpers/form_helper_spec.rb
ransack-0.7.1 spec/ransack/helpers/form_helper_spec.rb
ransack_ffcrm-0.7.1 spec/ransack/helpers/form_helper_spec.rb
ransack-0.7.0 spec/ransack/helpers/form_helper_spec.rb