Skip to content

Commit

Permalink
test: Use default settings of Rails version under test
Browse files Browse the repository at this point in the history
  • Loading branch information
hasghari committed Aug 18, 2024
1 parent 500aace commit 38901d7
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 179 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:

- name: "Reset app database"
run: |
bundle exec rake dummy:db:drop
bundle exec rake dummy:db:setup
bundle exec rake db:drop
bundle exec rake db:setup
- name: "Run tests"
run: bundle exec rake
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
*.swp
*~
.bundle
db/*.sqlite3
.idea
.tool-versions
spec/dummy/db/*.sqlite3*
spec/dummy/log
gemfiles/*.lock
gemfiles/vendor/
log/*.log
Expand Down
10 changes: 10 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
appraise "rails_6.1" do
gem "railties", "~> 6.1.0"
gem "net-smtp", require: false # not bundled in ruby 3.1
# The following gems will not be bundled with Ruby 3.4
gem "base64", require: false
gem "bigdecimal", require: false
gem "drb", require: false
gem "mutex_m", require: false
end

appraise "rails_7.0" do
gem "railties", "~> 7.0.0"
# The following gems will not be bundled with Ruby 3.4
gem "base64", require: false
gem "bigdecimal", require: false
gem "drb", require: false
gem "mutex_m", require: false
end

appraise "rails_7.1" do
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ GEM
method_source (1.1.0)
mini_mime (1.1.5)
mini_portile2 (2.8.7)
minitest (5.24.1)
minitest (5.25.1)
net-imap (0.4.14)
date
net-protocol
Expand All @@ -159,7 +159,7 @@ GEM
nokogiri (1.16.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
parallel (1.26.2)
parallel (1.26.3)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
Expand Down Expand Up @@ -214,7 +214,7 @@ GEM
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (6.1.3)
rspec-rails (6.1.4)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
Expand All @@ -234,11 +234,11 @@ GEM
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.0)
rubocop-ast (1.32.1)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
securerandom (0.3.1)
shoulda-matchers (6.3.1)
shoulda-matchers (6.4.0)
activesupport (>= 5.2.0)
smart_properties (1.17.0)
sqlite3 (1.7.3)
Expand Down
11 changes: 4 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
require "rubygems"
require "bundler/setup"

APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
load "rails/tasks/engine.rake"

require "bundler/gem_tasks"

require "rake"
require "rspec/core/rake_task"

namespace :dummy do
require_relative "spec/dummy/application"
Dummy::Application.load_tasks
end

desc "Run specs other than spec/acceptance"
RSpec::Core::RakeTask.new("spec") do |task|
task.exclude_pattern = "spec/acceptance/**/*_spec.rb"
Expand Down
4 changes: 2 additions & 2 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ if [ -z "$CI" ]; then
fi

# Set up database for the application that Clearance tests against
RAILS_ENV=test bundle exec rake dummy:db:drop
RAILS_ENV=test bundle exec rake dummy:db:setup
RAILS_ENV=test bundle exec rake db:drop
RAILS_ENV=test bundle exec rake db:setup
3 changes: 1 addition & 2 deletions clearance.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'clearance/version'
require_relative 'lib/clearance/version'

Gem::Specification.new do |s|
s.add_dependency 'bcrypt', '>= 3.1.1'
Expand Down
28 changes: 0 additions & 28 deletions db/schema.rb

This file was deleted.

4 changes: 4 additions & 0 deletions gemfiles/rails_6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ gem "sqlite3", "~> 1.7"
gem "timecop"
gem "railties", "~> 6.1.0"
gem "net-smtp", require: false
gem "base64", require: false
gem "bigdecimal", require: false
gem "drb", require: false
gem "mutex_m", require: false

gemspec path: "../"
4 changes: 4 additions & 0 deletions gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ gem "shoulda-matchers"
gem "sqlite3", "~> 1.7"
gem "timecop"
gem "railties", "~> 7.0.0"
gem "base64", require: false
gem "bigdecimal", require: false
gem "drb", require: false
gem "mutex_m", require: false

gemspec path: "../"
6 changes: 6 additions & 0 deletions spec/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative "config/application"

Rails.application.load_tasks
Empty file.
40 changes: 0 additions & 40 deletions spec/dummy/application.rb

This file was deleted.

6 changes: 6 additions & 0 deletions spec/dummy/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file is used by Rack-based servers to start the application.

require_relative "config/environment"

run Rails.application
Rails.application.load_server
13 changes: 13 additions & 0 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require_relative "boot"

require "rails/all"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Dummy
class Application < Rails::Application
config.load_defaults Rails::VERSION::STRING.to_f
end
end
5 changes: 5 additions & 0 deletions spec/dummy/config/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Set up gems listed in the Gemfile.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)

require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
5 changes: 5 additions & 0 deletions spec/dummy/config/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Load the Rails application.
require_relative "application"

# Initialize the Rails application.
Rails.application.initialize!
31 changes: 31 additions & 0 deletions spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
config.enable_reloading = false

config.eager_load = ENV["CI"].present?

config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{1.hour.to_i}" }

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store

config.action_dispatch.show_exceptions = :rescuable

config.action_controller.allow_forgery_protection = false

config.action_mailer.perform_caching = false
config.action_mailer.delivery_method = :test

config.action_mailer.default_url_options = { host: "www.example.com" }

config.active_support.deprecation = :stderr
config.active_support.disallowed_deprecation = :raise
config.active_support.disallowed_deprecation_warnings = []

config.factory_bot.definition_file_paths = [File.expand_path('../../../factories', __dir__)]

config.middleware.use Clearance::BackDoor
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateClearanceUsers < ActiveRecord::Migration
class CreateClearanceUsers < ActiveRecord::Migration[Rails::VERSION::STRING.to_f]
def self.up
create_table :users do |t|
t.timestamps null: false
Expand All @@ -9,7 +9,8 @@ def self.up
end

add_index :users, :email
add_index :users, :remember_token
add_index :users, :confirmation_token, unique: true
add_index :users, :remember_token, unique: true
end

def self.down
Expand Down
25 changes: 25 additions & 0 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2011_01_11_224543) do
create_table "users", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "email", null: false
t.string "encrypted_password", limit: 128, null: false
t.string "confirmation_token", limit: 128
t.string "remember_token", limit: 128, null: false
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email"
t.index ["remember_token"], name: "index_users_on_remember_token", unique: true
end
end
File renamed without changes.
6 changes: 1 addition & 5 deletions spec/requests/csrf_rotation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
original_token = csrf_token

post session_path, params: {
session: session_params(user, "password"),
authenticity_token: csrf_token, session: { email: user.email, password: "password" }
}

expect(csrf_token).not_to eq original_token
Expand All @@ -28,8 +28,4 @@
def csrf_token
session[:_csrf_token]
end

def session_params(user, password)
{ email: user.email, password: password, authenticity_token: csrf_token }
end
end
14 changes: 3 additions & 11 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
ENV["RAILS_ENV"] ||= "test"
require_relative "dummy/config/environment"

require "rails/all"
require "dummy/application"

require "clearance/rspec"
require "factory_bot_rails"
require "rails-controller-testing"
require "rspec/rails"
require "shoulda-matchers"
require "timecop"

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
require "clearance/rspec"

Dummy::Application.initialize!
Dir[File.expand_path("spec/support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
Expand Down
Loading

0 comments on commit 38901d7

Please sign in to comment.