Skip to content

Commit

Permalink
Tests: more AR versioning and update routes for Rails 3 + 4
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatack committed Aug 6, 2013
1 parent cb2ff12 commit fc5fbcf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
8 changes: 6 additions & 2 deletions spec/ransack/helpers/form_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Helpers
router = ActionDispatch::Routing::RouteSet.new
router.draw do
resources :people
match ':controller(/:action(/:id(.:format)))'
get ':controller(/:action(/:id(.:format)))'
end

include router.url_helpers
Expand Down Expand Up @@ -50,7 +50,11 @@ module Helpers
describe '#sort_link' do
it 'sort_link for ransack attribute' do
sort_link = @f.sort_link :name, :controller => 'people'
sort_link.should match /people\?q%5Bs%5D=name\+asc/
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
sort_link.should match /people\?q%5Bs%5D=name\+asc/
else
sort_link.should match /people\?q(%5B|\[)s(%5D|\])=name\+asc/
end
sort_link.should match /sort_link/
sort_link.should match /Full Name<\/a>/
end
Expand Down
51 changes: 40 additions & 11 deletions spec/ransack/helpers/form_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Helpers
router = ActionDispatch::Routing::RouteSet.new
router.draw do
resources :people
match ':controller(/:action(/:id(.:format)))'
get ':controller(/:action(/:id(.:format)))'
end

include router.url_helpers
Expand All @@ -26,24 +26,53 @@ module Helpers
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/ }
subject {
@controller.view_context.sort_link(
[:main_app, Person.search(sorts: ['name desc'])],
:name, controller: 'people'
)
}
it { should match (
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
/people\?q%5Bs%5D=name\+asc/
else
/people\?q(%5B|\[)s(%5D|\])=name\+asc/
end)
}
it { should match /sort_link desc/ }
it { should match /Full Name &#9660;/ }
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/ }
subject { @controller.
view_context.sort_link(
Person.search({ sorts: ['name desc'] }, search_key: :people_search),
:name, controller: 'people'
)
}
it { should match (
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
/people\?people_search%5Bs%5D=name\+asc/
else
/people\?people_search(%5B|\[)s(%5D|\])=name\+asc/
end)
}
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/ }
subject {
@controller.view_context.sort_link(
Person.search({ sorts: ['name desc'] }, search_key: 'people_search'),
:name, controller: 'people'
)
}
it { should match (
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
/people\?people_search%5Bs%5D=name\+asc/
else
/people\?people_search(%5B|\[)s(%5D|\])=name\+asc/
end)
}
end


Expand Down

0 comments on commit fc5fbcf

Please sign in to comment.