Skip to content

Commit

Permalink
Automatically create user in development
Browse files Browse the repository at this point in the history
  • Loading branch information
dentarg committed Dec 5, 2024
1 parent 3031b26 commit 920fc14
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/controllers/authorize_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ class AuthorizeController < BaseController
end

get '/dev' do
halt 404 unless App.development?
halt 404 unless (App.development? || App.test?)

session[:login] = "development"
session[:user_id] = -1
github_id = 1337
login = ENV.fetch("USER", "user_created_in_dev")
user = Authorize.create_or_update_user({ id: github_id, login: })

session[:login] = login
session[:user_id] = user.id
session[:starkast] = true

redirect "/"
end
Expand Down
16 changes: 16 additions & 0 deletions test/integration/empty_app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ def test_root
assert last_response.ok?
end

def test_dev_authorize
login = "user_created_in_test"

assert_nil User[login:]

ClimateControl.modify(USER: login) do
get "/authorize/dev"
end

redirect_location = last_response["location"]

assert User[login:]
assert_equal 302, last_response.status
assert_equal "http://#{Rack::Test::DEFAULT_HOST}/", redirect_location
end

def test_root_logged_in
env "rack.session", { login: "not used", user_id: rand(100) }
get "/"
Expand Down

0 comments on commit 920fc14

Please sign in to comment.