2010-12-13 22:28:59 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2010-12-15 22:34:19 +00:00
|
|
|
describe Shoulda::Matchers::ActionController::RedirectToMatcher 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)
|
|
|
|
build_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
|
2014-01-17 20:20:44 +00:00
|
|
|
controller = build_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
|