Skip to content

Commit

Permalink
Fix some tests for changes in rails 5
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Jun 27, 2017
1 parent 03408b6 commit 3893fd7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def login
def logout
@title = t "user.logout.title"

if params[:session] == request.session_options[:id]
if params[:session] == session.id
if session[:token]
token = UserToken.find_by(:token => session[:token])
token.destroy if token
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<%= yield :greeting %>
</li>
<li>
<%= link_to t('layouts.logout'), logout_path(:session => request.session_options[:id], :referer => request.fullpath) %>
<%= link_to t('layouts.logout'), logout_path(:session => session.id, :referer => request.fullpath) %>
</li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/user/logout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<%= form_tag :action => "logout" do %>
<%= hidden_field_tag("referer", h(params[:referer])) %>
<%= hidden_field_tag("session", request.session_options[:id]) %>
<%= hidden_field_tag("session", session.id) %>
<%= submit_tag t('user.logout.logout_button') %>
<% end %>
4 changes: 2 additions & 2 deletions test/controllers/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,11 @@ def test_index_large_area

get :index, :params => { :bbox => "-10,-10,12,12", :format => :json }
assert_response :bad_request
assert_equal "text/plain", @response.content_type
assert_equal "application/json", @response.content_type

get :index, :params => { :l => "-10", :b => "-10", :r => "12", :t => "12", :format => :json }
assert_response :bad_request
assert_equal "text/plain", @response.content_type
assert_equal "application/json", @response.content_type
end

def test_index_closed
Expand Down
13 changes: 7 additions & 6 deletions test/controllers/user_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ def test_account

# Updating the description should work
user.description = "new description"
user.preferred_editor = "default"
post :account, :params => { :display_name => user.display_name, :user => user.attributes }, :session => { :user => user }
assert_response :success
assert_template :account
Expand Down Expand Up @@ -1434,7 +1435,7 @@ def test_list_post_confirm
post :list, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
end
assert_response :redirect
assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
assert_redirected_to :action => :login, :referer => users_path
assert_equal "pending", inactive_user.reload.status
assert_equal "suspended", suspended_user.reload.status

Expand All @@ -1445,7 +1446,7 @@ def test_list_post_confirm
post :list, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
end
assert_response :redirect
assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
assert_redirected_to :action => :login, :referer => users_path
assert_equal "pending", inactive_user.reload.status
assert_equal "suspended", suspended_user.reload.status

Expand All @@ -1456,7 +1457,7 @@ def test_list_post_confirm
post :list, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
end
assert_response :redirect
assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
assert_redirected_to :action => :login, :referer => users_path
assert_equal "pending", inactive_user.reload.status
assert_equal "suspended", suspended_user.reload.status

Expand All @@ -1481,7 +1482,7 @@ def test_list_post_hide
post :list, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
end
assert_response :redirect
assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
assert_redirected_to :action => :login, :referer => users_path
assert_equal "active", normal_user.reload.status
assert_equal "confirmed", confirmed_user.reload.status

Expand All @@ -1492,7 +1493,7 @@ def test_list_post_hide
post :list, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
end
assert_response :redirect
assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
assert_redirected_to :action => :login, :referer => users_path
assert_equal "active", normal_user.reload.status
assert_equal "confirmed", confirmed_user.reload.status

Expand All @@ -1503,7 +1504,7 @@ def test_list_post_hide
post :list, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
end
assert_response :redirect
assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
assert_redirected_to :action => :login, :referer => users_path
assert_equal "active", normal_user.reload.status
assert_equal "confirmed", confirmed_user.reload.status

Expand Down
26 changes: 8 additions & 18 deletions test/integration/cors_test.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
require "test_helper"

class CORSTest < ActionDispatch::IntegrationTest
# Rails 4 adds a built-in `options` method. When we upgrade, we can remove
# this definition.
unless instance_methods.include?(:options)
def options(*args)
reset! unless integration_session
@html_document = nil
integration_session.send(:process, :options, *args).tap do
copy_session_variables!
end
end
end

def test_api_routes_allow_cross_origin_requests
options "/api/capabilities", nil,
"HTTP_ORIGIN" => "http://www.example.com",
"HTTP_ACCESS_CONTROL_REQUEST_METHOD" => "GET"
process :options, "/api/capabilities", :headers => {
"HTTP_ORIGIN" => "http://www.example.com",
"HTTP_ACCESS_CONTROL_REQUEST_METHOD" => "GET"
}

assert_response :success
assert_equal "http://www.example.com", response.headers["Access-Control-Allow-Origin"]
end

def test_non_api_routes_dont_allow_cross_origin_requests
assert_raises ActionController::RoutingError do
options "/", nil,
"HTTP_ORIGIN" => "http://www.example.com",
"HTTP_ACCESS_CONTROL_REQUEST_METHOD" => "GET"
process :options, "/", :headers => {
"HTTP_ORIGIN" => "http://www.example.com",
"HTTP_ACCESS_CONTROL_REQUEST_METHOD" => "GET"
}
end
end
end

0 comments on commit 3893fd7

Please sign in to comment.