Package list ruby-omniauth-twitter / 4b6122a
Override the `callback_path` method André Ligné 4 years ago
2 changed file(s) with 52 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
6161 end
6262
6363 def callback_url
64 request.params['callback_url'] || super
64 request.params['callback_url']
65 end
66
67 def callback_path
68 params = session['omniauth.params']
69
70 if params.nil? || params['callback_url'].nil?
71 super
72 else
73 URI(params['callback_url']).path
74 end
6575 end
6676
6777 private
126126
127127 it "should switch authorize_path from authenticate to authorize" do
128128 expect { subject.request_phase }.to change { subject.options.client_options.authorize_path }.from('/oauth/authenticate').to('/oauth/authorize')
129 end
130 end
131
132 context 'with a specified callback_url in the params' do
133 before do
134 params = { 'callback_url' => 'http://foo.dev/auth/twitter/foobar' }
135 allow(subject).to receive(:request) do
136 double('Request', :params => params)
137 end
138 allow(subject).to receive(:session) do
139 double('Session', :[] => { 'callback_url' => params['callback_url'] })
140 end
141 allow(subject).to receive(:old_request_phase) { :whatever }
142 end
143
144 it 'should use the callback_url' do
145 expect(subject.callback_url).to eq 'http://foo.dev/auth/twitter/foobar'
146 end
147
148 it 'should return the correct callback_path' do
149 expect(subject.callback_path).to eq '/auth/twitter/foobar'
150 end
151 end
152
153 context 'with no callback_url set' do
154 before do
155 allow(subject).to receive(:request) do
156 double('Request', :params => {})
157 end
158 allow(subject).to receive(:session) do
159 double('Session', :[] => {})
160 end
161 allow(subject).to receive(:old_request_phase) { :whatever }
162 end
163
164 it 'callback_url should return nil' do
165 expect(subject.callback_url).to be_nil
166 end
167
168 it 'should return the default callback_path value' do
169 expect(subject.callback_path).to eq '/auth/twitter/callback'
129170 end
130171 end
131172