Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge STI model fix #27

Merged
merged 2 commits into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/passwordless/controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def reset_passwordless_redirect_location!(authenticatable_class)
private

def session_key(authenticatable_class)
:"passwordless_prev_location--#{authenticatable_class}"
:"passwordless_prev_location--#{authenticatable_class.base_class}"
end

def cookie_name(authenticatable_class)
:"#{authenticatable_class.to_s.underscore}_id"
:"#{authenticatable_class.base_class.to_s.underscore}_id"
end
end
end
18 changes: 15 additions & 3 deletions test/controllers/passwordless/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create_session_for(user)
end

test 'requesting a magic link as an existing user' do
user = User.create email: 'a@a'
User.create email: 'a@a'

get '/users/sign_in'
assert_equal 200, status
Expand Down Expand Up @@ -47,7 +47,19 @@ def create_session_for(user)

assert_equal 200, status
assert_equal '/', path
refute_nil cookies[:user_id]
assert_not_nil cookies[:user_id]
end

test 'signing in via a token as STI model' do
admin = Admin.create email: 'a@a'
session = create_session_for admin

get "/users/sign_in/#{session.token}"
follow_redirect!

assert_equal 200, status
assert_equal '/', path
assert_not_nil cookies[:user_id]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing the test! I meant to add it, but didn't get around to it in time 😄

Copy link
Owner Author

@mikker mikker Jun 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¯\_(ツ)_/¯ np

end

test 'signing in and redirecting back' do
Expand Down Expand Up @@ -99,7 +111,7 @@ def create_session_for(user)

session = create_session_for user
get "/users/sign_in/#{session.token}"
refute_nil cookies[:user_id]
assert_not_nil cookies[:user_id]

get '/users/sign_out'
follow_redirect!
Expand Down
4 changes: 4 additions & 0 deletions test/dummy/app/models/admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Admin < User
end
4 changes: 2 additions & 2 deletions test/dummy/app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<% @users.each do |user| %>
<tr>
<td><%= user.email %></td>
<td><%= link_to 'Show', user %></td>
<td><%= link_to 'Show', user_path(user) %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Destroy', user_path(user), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
Expand Down
1 change: 1 addition & 0 deletions test/dummy/db/migrate/20171104225303_create_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class CreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
t.string :email
t.string :type

t.timestamps
end
Expand Down
1 change: 1 addition & 0 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

create_table "users", force: :cascade do |t|
t.string "email"
t.string "type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Expand Down