Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Or install it yourself as:
`~> 0.4.9` | `~> 3.5.2`
`~> 0.5.x`, `<= 1.0.2` | `>= 4.0.0`, `< 4.6.0`
`~> 1.1.0` | `>= 4.0.0`, `< 5.0.0`
`~> 1.2.0` | `>= 4.0.0`, `< 6.0.0`

## Usage
Create needed columns with corresponding migration:
Expand Down
16 changes: 7 additions & 9 deletions devise-token_authenticatable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]


spec.add_dependency "devise", ">= 4.0.0", "< 5.0.0"
spec.add_dependency "devise", ">= 4.0.0", "< 6.0.0"

spec.add_development_dependency "rails", "~> 4.2"
spec.add_development_dependency "rspec-rails", "~> 3.0"
spec.add_development_dependency "pry", "~> 0.10"
spec.add_development_dependency "factory_girl_rails", "~> 4.4"
spec.add_development_dependency "timecop", "~> 0.7"
spec.add_development_dependency "bundler", "~> 1.17"
spec.add_development_dependency "rails", ">= 7.0", "< 9.0"
spec.add_development_dependency "rspec-rails", ">= 6.0"
spec.add_development_dependency "pry", "~> 0.14"
spec.add_development_dependency "factory_bot_rails", "~> 6.0"
spec.add_development_dependency "timecop", "~> 0.9"

# Fix database connection with sqlite3 and jruby
if RUBY_ENGINE == 'ruby'
# Match rails's expected version constraint
spec.add_development_dependency "sqlite3", "~> 1.3.6"
spec.add_development_dependency "sqlite3", ">= 1.4"
elsif RUBY_ENGINE == 'jruby'
spec.add_development_dependency "activerecord-jdbcsqlite3-adapter"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/token_authenticatable/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Devise
module TokenAuthenticatable
VERSION = '1.1.0'.freeze
VERSION = '1.2.0'.freeze
end
end
10 changes: 5 additions & 5 deletions spec/factories/admin.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FactoryGirl.define do
FactoryBot.define do

factory :admin do
sequence(:email) { |n| "admin#{n}@domain.com" }
password 'some_password'
password_confirmation 'some_password'
password { 'some_password' }
password_confirmation { 'some_password' }

ignore do
confirm_account true
transient do
confirm_account { true }
end

after(:create) do |u, evaluator|
Expand Down
12 changes: 6 additions & 6 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FactoryGirl.define do
FactoryBot.define do

factory :user do
username 'testuser'
username { 'testuser' }
sequence(:email) { |n| "user#{n}@domain.com" }
password 'some_password'
password_confirmation 'some_password'
password { 'some_password' }
password_confirmation { 'some_password' }
facebook_token { SecureRandom.hex }

ignore do
confirm_account true
transient do
confirm_account { true }
end

after(:create) do |u, evaluator|
Expand Down
8 changes: 4 additions & 4 deletions spec/models/devise/token_authenticatable/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@
it "resets the authentication token" do
expect(entity).to receive(:reset_authentication_token).once

entity.update_attributes(created_at: Time.now)
entity.update(created_at: Time.now)
end
end

context "when the authentication token should not be reset" do
it "does not reset the authentication token" do
expect(entity).to_not receive(:reset_authentication_token)

entity.update_attributes(created_at: Time.now)
entity.update(created_at: Time.now)
end
end

Expand All @@ -169,15 +169,15 @@
it "sets the authentication token" do
expect(entity).to receive(:ensure_authentication_token).once

entity.update_attributes(created_at: Time.now)
entity.update(created_at: Time.now)
end
end

context "when the authentication token should not be ensured" do
it "does not set the authentication token" do
expect(entity).to_not receive(:ensure_authentication_token)

entity.update_attributes(created_at: Time.now)
entity.update(created_at: Time.now)
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions spec/requests/devise/token_authenticatable/strategy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
swap Devise::TokenAuthenticatable, token_authentication_key: :secret_token do
sign_in_as_new_user_with_token

expect(response).to be_success
expect(response).to be_successful
end
end

Expand All @@ -32,23 +32,23 @@

it 'should be a success' do
swap Devise::TokenAuthenticatable, token_authentication_key: :secret_token do
post exhibit_user_path(user), Devise::TokenAuthenticatable.token_authentication_key => user.authentication_token, user: { some: "data" }
post exhibit_user_path(user), params: { Devise::TokenAuthenticatable.token_authentication_key => user.authentication_token, user: { some: "data" } }

expect(response).to be_success
expect(response).to be_successful
end
end

it 'should return proper data' do
swap Devise::TokenAuthenticatable, token_authentication_key: :secret_token do
post exhibit_user_path(user), Devise::TokenAuthenticatable.token_authentication_key => user.authentication_token, user: { some: "data" }
post exhibit_user_path(user), params: { Devise::TokenAuthenticatable.token_authentication_key => user.authentication_token, user: { some: "data" } }

expect(response.body).to eq('User is authenticated')
end
end

it 'should authenticate user' do
swap Devise::TokenAuthenticatable, token_authentication_key: :secret_token do
post exhibit_user_path(user), Devise::TokenAuthenticatable.token_authentication_key => user.authentication_token, user: { some: "data" }
post exhibit_user_path(user), params: { Devise::TokenAuthenticatable.token_authentication_key => user.authentication_token, user: { some: "data" } }

expect(warden).to be_authenticated(:user)
end
Expand Down Expand Up @@ -150,7 +150,7 @@
swap Devise, http_authenticatable: true do
sign_in_as_new_user_with_token(http_auth: true)

expect(response).to be_success
expect(response).to be_successful
end
end
end
Expand Down Expand Up @@ -194,7 +194,7 @@
swap Devise, http_authenticatable: true do
sign_in_as_new_user_with_token(token_auth: true)

expect(response).to be_success
expect(response).to be_successful
end
end
end
Expand Down Expand Up @@ -227,7 +227,7 @@
swap Devise, http_authenticatable: [:token] do
sign_in_as_new_user_with_token(token_auth: true, token_options: { signature: signature, nonce: 'def' })

expect(response).to be_success
expect(response).to be_successful
end
end
end
Expand Down
9 changes: 5 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
require 'support/integration'
require 'support/session_helper'

# factory_girl_rails has to be required after the test rails app
# factory_bot_rails has to be required after the test rails app
# as it sets the right application root path
require 'factory_girl_rails'
require 'factory_bot_rails'

# Do not show migration output
ActiveRecord::Migration.verbose = false
Expand All @@ -27,12 +27,13 @@
config.use_transactional_fixtures = true
config.run_all_when_everything_filtered = true

config.include FactoryGirl::Syntax::Methods
config.include FactoryBot::Syntax::Methods

config.infer_spec_type_from_file_location!

config.before(:suite) do
# Do initial migration
ActiveRecord::Migrator.migrate(File.expand_path("support/rails_app/db/migrate/", File.dirname(__FILE__)))
migration_paths = [File.expand_path("support/rails_app/db/migrate/", File.dirname(__FILE__))]
ActiveRecord::MigrationContext.new(migration_paths).migrate
end
end
4 changes: 2 additions & 2 deletions spec/support/rails_app/app/controllers/admins_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class AdminsController < ApplicationController
before_filter :authenticate_admin!
before_action :authenticate_admin!

def index
end

def expire
admin_session['last_request_at'] = 31.minutes.ago.utc
render text: 'Admin will be expired on next request'
render plain: 'Admin will be expired on next request'
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :current_user, unless: :devise_controller?
before_filter :authenticate_user!, if: :devise_controller?
respond_to *Mime::SET.map(&:to_sym)
before_action :current_user, unless: :devise_controller?
before_action :authenticate_user!, if: :devise_controller?
respond_to :html, :xml, :json
end
2 changes: 1 addition & 1 deletion spec/support/rails_app/app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ def set
end

def unauthenticated
render text: "unauthenticated", status: :unauthorized
render plain: "unauthenticated", status: :unauthorized
end
end
15 changes: 9 additions & 6 deletions spec/support/rails_app/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
class UsersController < ApplicationController
prepend_before_filter :current_user, only: :exhibit
before_filter :authenticate_user!, except: [:accept, :exhibit]
prepend_before_action :current_user, only: :exhibit
before_action :authenticate_user!, except: [:accept, :exhibit]

respond_to :html, :xml

def index
user_session[:cart] = "Cart"
respond_with(current_user)
respond_to do |format|
format.html
format.xml { render xml: "<user/>" }
end
end

def edit_form
user_session['last_request_at'] = 31.minutes.ago.utc
end

def update_form
render text: 'Update'
render plain: 'Update'
end

def accept
@current_user = current_user
end

def exhibit
render text: current_user ? "User is authenticated" : "User is not authenticated"
render plain: current_user ? "User is authenticated" : "User is not authenticated"
end

def expire
user_session['last_request_at'] = 31.minutes.ago.utc
render text: 'User will be expired on next request'
render plain: 'User will be expired on next request'
end
end
2 changes: 1 addition & 1 deletion spec/support/rails_app/config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateTables < ActiveRecord::Migration
class CreateTables < ActiveRecord::Migration[7.0]
def self.up
create_table :users do |t|
t.string :username
Expand Down
4 changes: 2 additions & 2 deletions spec/support/session_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def sign_in_as_new_user_with_token(options = {})

if options[:http_auth]
header = "Basic #{Base64.encode64("#{options[:auth_token]}:X")}"
get users_path(format: :xml), {}, "HTTP_AUTHORIZATION" => header
get users_path(format: :xml), headers: { "HTTP_AUTHORIZATION" => header }
elsif options[:token_auth]
token_options = options[:token_options] || {}
header = ActionController::HttpAuthentication::Token.encode_credentials(options[:auth_token], token_options)
get users_path(format: :xml), {}, "HTTP_AUTHORIZATION" => header
get users_path(format: :xml), headers: { "HTTP_AUTHORIZATION" => header }
else
get users_path(options[:auth_token_key].to_sym => options[:auth_token])
end
Expand Down