Skip to content

Commit

Permalink
Refactor sentry-rails test app (#1721)
Browse files Browse the repository at this point in the history
* Rename spec/support to spec/dummy

* Set view_path via config

* DB connection doesn't need to be established individually
  • Loading branch information
st0012 committed Feb 12, 2022
1 parent e960d02 commit 623d046
Show file tree
Hide file tree
Showing 15 changed files with 9 additions and 27 deletions.
2 changes: 1 addition & 1 deletion sentry-rails/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/doc/
/pkg/
/spec/reports/
/spec/support/test_rails_app/db
/spec/dummy/test_rails_app/db
/tmp/

# rspec failure tracking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

ActiveSupport::Deprecation.silenced = true
ActiveRecord::Base.logger = Logger.new(nil)
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "db")

# need to init app before establish connection so sqlite can place the database file under the correct project root
class TestApp < Rails::Application
Expand All @@ -24,15 +25,15 @@ class TestApp < Rails::Application

case Gem::Version.new(Rails.version)
when -> (v) { v < v5_2 }
require "support/test_rails_app/apps/5-0"
require "dummy/test_rails_app/apps/5-0"
when -> (v) { v.between?(v5_2, v6_0) }
require "support/test_rails_app/apps/5-2"
require "dummy/test_rails_app/apps/5-2"
when -> (v) { v.between?(v6_0, v6_1) }
require "support/test_rails_app/apps/6-0"
require "dummy/test_rails_app/apps/6-0"
when -> (v) { v.between?(v6_1, v7_0) }
require "support/test_rails_app/apps/6-1"
require "dummy/test_rails_app/apps/6-1"
when -> (v) { v.between?(v7_0, v7_1) }
require "support/test_rails_app/apps/7-0"
require "dummy/test_rails_app/apps/7-0"
end

def make_basic_app(&block)
Expand All @@ -44,6 +45,7 @@ def self.name
end
end

app.config.action_controller.view_paths = "spec/dummy/test_rails_app"
app.config.hosts = nil
app.config.secret_key_base = "test"
app.config.logger = Logger.new(nil)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "db")

ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
end
Expand Down Expand Up @@ -35,8 +33,6 @@ def show
end

class HelloController < ActionController::Base
prepend_view_path "spec/support/test_rails_app"

def exception
raise "An unhandled exception!"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require "active_storage/engine"

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "db")

ActiveRecord::Schema.define do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
Expand Down Expand Up @@ -81,8 +79,6 @@ def attach
end

class HelloController < ActionController::Base
prepend_view_path "spec/support/test_rails_app"

def exception
raise "An unhandled exception!"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "active_storage/engine"
require "action_cable/engine"

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "db")

ActiveRecord::Schema.define do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
Expand Down Expand Up @@ -84,8 +82,6 @@ def attach
end

class HelloController < ActionController::Base
prepend_view_path "spec/support/test_rails_app"

def exception
raise "An unhandled exception!"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "active_storage/engine"
require "action_cable/engine"

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "db")

ActiveRecord::Schema.define do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
Expand Down Expand Up @@ -85,8 +83,6 @@ def attach
end

class HelloController < ActionController::Base
prepend_view_path "spec/support/test_rails_app"

def exception
raise "An unhandled exception!"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "active_storage/engine"
require "action_cable/engine"

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "db")

ActiveRecord::Schema.define do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
Expand Down Expand Up @@ -85,8 +83,6 @@ def attach
end

class HelloController < ActionController::Base
prepend_view_path "spec/support/test_rails_app"

def exception
raise "An unhandled exception!"
end
Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
end

# this already requires the sdk
require "support/test_rails_app/app"
require "dummy/test_rails_app/app"
# need to be required after rails is loaded from the above
require "rspec/rails"

Expand Down

0 comments on commit 623d046

Please sign in to comment.