2014-10-27 00:51:42 +00:00
|
|
|
require 'unit_spec_helper'
|
2010-12-13 22:28:59 +00:00
|
|
|
|
2014-12-24 21:37:04 +00:00
|
|
|
describe Shoulda::Matchers::ActionController::RedirectToMatcher, type: :controller do
|
2012-12-20 05:04:27 +00:00
|
|
|
context 'a controller that redirects' do
|
|
|
|
it 'accepts redirecting to that url' do
|
2014-01-17 22:01:43 +00:00
|
|
|
expect(controller_redirecting_to('/some/url')).to redirect_to('/some/url')
|
2010-12-13 22:28:59 +00:00
|
|
|
end
|
|
|
|
|
2012-12-20 05:04:27 +00:00
|
|
|
it 'rejects redirecting to a different url' do
|
2014-01-17 22:01:43 +00:00
|
|
|
expect(controller_redirecting_to('/some/url')).
|
|
|
|
not_to redirect_to('/some/other/url')
|
2010-12-13 22:28:59 +00:00
|
|
|
end
|
|
|
|
|
2012-12-20 05:04:27 +00:00
|
|
|
it 'accepts redirecting to that url in a block' do
|
2014-01-17 22:01:43 +00:00
|
|
|
expect(controller_redirecting_to('/some/url')).
|
|
|
|
to redirect_to('somewhere') { '/some/url' }
|
2010-12-13 22:28:59 +00:00
|
|
|
end
|
|
|
|
|
2012-12-20 05:04:27 +00:00
|
|
|
it 'rejects redirecting to a different url in a block' do
|
2014-01-17 22:01:43 +00:00
|
|
|
expect(controller_redirecting_to('/some/url')).
|
|
|
|
not_to redirect_to('somewhere else') { '/some/other/url' }
|
2010-12-13 22:28:59 +00:00
|
|
|
end
|
|
|
|
|
2012-12-20 05:04:27 +00:00
|
|
|
def controller_redirecting_to(url)
|
2013-12-31 19:54:21 +00:00
|
|
|
build_fake_response { redirect_to url }
|
2010-12-13 22:28:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-20 05:04:27 +00:00
|
|
|
context 'a controller that does not redirect' do
|
|
|
|
it 'rejects redirecting to a url' do
|
2013-12-31 19:54:21 +00:00
|
|
|
controller = build_fake_response { render text: 'hello' }
|
2010-12-13 22:28:59 +00:00
|
|
|
|
2014-01-17 22:01:43 +00:00
|
|
|
expect(controller).not_to redirect_to('/some/url')
|
2010-12-13 22:28:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-20 05:04:27 +00:00
|
|
|
it 'provides the correct description when provided a block' do
|
2010-12-17 16:50:49 +00:00
|
|
|
matcher = redirect_to('somewhere else') { '/some/other/url' }
|
2012-12-20 05:04:27 +00:00
|
|
|
|
2014-01-17 22:01:43 +00:00
|
|
|
expect(matcher.description).to eq 'redirect to somewhere else'
|
2010-12-17 16:50:49 +00:00
|
|
|
end
|
2010-12-13 22:28:59 +00:00
|
|
|
end
|