require_relative '../lib/philtre-rails/philtre_view_helpers.rb' require_relative '../lib/philtre-rails/order_link.rb' describe PhiltreRails::PhiltreViewHelpers do def subject @subject ||= begin obj = Object.new.extend( described_class ) class << obj def raw(str); str end def link_to(text, params, html_options) html_options.merge(href: params.inspect) html_attrs = html_options.map{|k,v| %Q{#{k}="#{v}"}}.join(' ') %Q{#{text}} end end obj end end describe '#order_by' do def filter @filter ||= Philtre::Filter.new order: [:first, :second] end it 'returns label for no filter' do subject.order_by( nil, :first ).should == 'First' end it 'inverts no order' do link_str = subject.order_by( filter, :first ) link_str.should =~ />First.*? :first_asc) link_str = subject.order_by( filter, :first ) link_str.should =~ />First.*? :first_desc) link_str = subject.order_by( filter, :first ) link_str.should =~ />First.*?First.*?First.*?