Skip to content

Commit

Permalink
Add controllers to rails8 fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
Cawllec committed Dec 9, 2024
1 parent e9428fd commit 768d497
Show file tree
Hide file tree
Showing 32 changed files with 642 additions and 1 deletion.
4 changes: 3 additions & 1 deletion features/fixtures/rails8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ COPY app/ /usr/src/app

RUN bundle exec rake db:migrate

RUN bundle exec rake app:update:bin
RUN mv /usr/src/app/bin-copy /usr/src/app/bin

# RUN bundle exec rake rails:update:bin

CMD ["bundle", "exec", "bin/rails", "s", "-b", "0.0.0.0"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class ActiveJobController < ActionController::Base
protect_from_forgery

def handled
NotifyJob.perform_later(1, "hello", { a: "a", b: "b" }, keyword: true)

render json: {}
end

def unhandled
UnhandledJob.perform_later(123, { abc: "xyz" }, "abcxyz")

render json: {}
end
end
16 changes: 16 additions & 0 deletions features/fixtures/rails8/app/app/controllers/api_key_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class ApiKeyController < ActionController::Base
protect_from_forgery

def environment
Bugsnag.notify("handled string")
render json: {}
end

def changing
Bugsnag.configure do |conf|
conf.api_key = params[:api_key]
end
Bugsnag.notify("handled string")
render json: {}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class AppTypeController < ActionController::Base
protect_from_forgery

def handled
raise "Handled error"
rescue StandardError => e
Bugsnag.notify(e)
render json: {}
end

def unhandled
raise "Unhandled error"
end

def initializer
Bugsnag.notify("handled string")
render json: {}
end

def after
Bugsnag.configure do |conf|
conf.app_type = params[:type]
end
Bugsnag.notify("handled string")
render json: {}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class AppVersionController < ActionController::Base
protect_from_forgery

def default
Bugsnag.notify("handled string")
render json: {}
end

def initializer
Bugsnag.notify("handled string")
render json: {}
end

def after
Bugsnag.configure do |conf|
conf.app_version = params[:version]
end
Bugsnag.notify("handled string")
render json: {}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class AutoNotifyController < ActionController::Base
protect_from_forgery

def unhandled
generate_unhandled_error
end

def handled
Bugsnag.notify("handled string")
render json: {}
end

def unhandled_after
Bugsnag.configure do |conf|
conf.auto_notify = false
end
generate_unhandled_error
end

def handled_after
Bugsnag.configure do |conf|
conf.auto_notify = false
end
Bugsnag.notify("handled string")
render json: {}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class BeforeNotifyController < ActionController::Base
protect_from_forgery
before_bugsnag_notify :add_diagnostics_to_bugsnag

def handled
Bugsnag.before_notify_callbacks << Proc.new do |report|
report.add_tab(:before_notify, {
:source => "rails_before_handled"
})
end
Bugsnag.notify("handled string")
render json: {}
end

def unhandled
Bugsnag.before_notify_callbacks << Proc.new do |report|
report.add_tab(:before_notify, {
:source => "rails_before_unhandled"
})
end
generate_unhandled_error
end

def inline
Bugsnag.notify("handled string") do |report|
report.add_tab(:before_notify, {
:source => "rails_inline"
})
end
render json: {}
end

private

def add_diagnostics_to_bugsnag(report)
report.add_tab(:controller, {
:name => "BeforeNotifyController"
})
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class BreadcrumbsController < ApplicationController
def handled
Bugsnag.notify("Request breadcrumb")
render json: {}
end

def sql_breadcrumb
User.find_by(email: "foo")
Bugsnag.notify("SQL breadcrumb")
render json: {}
end

def active_job
NotifyJob.perform_later
render json: {}
end

def cache_read
Rails.cache.write('test', true)
Rails.cache.read('test')
Bugsnag.notify("Cache breadcrumb")
render json: {}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class ClearanceController < Clearance::BaseController
protect_from_forgery
def create
user = User.find_by(:email => "[email protected]")
User.new({
:email => "[email protected]",
:name => "Clearance User",
:first_name => "Clearance",
:last_name => "User",
:password => "Password"
}).save if user.nil?
render json: {}
end

def unhandled
user = User.find_by(:email => "[email protected]")
unless user.nil?
@current_user = user
cookies['remember_token'] = user.remember_token
end
generate_unhandled_error
end

def handled
user = User.find_by(:email => "[email protected]")
unless user.nil?
@current_user = user
cookies['remember_token'] = user.remember_token
end
Bugsnag.notify("handled string")
render json: {}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class FeatureFlagsController < ActionController::Base
protect_from_forgery

before_bugsnag_notify :add_feature_flags

def unhandled
Bugsnag.add_feature_flag('unhandled')

raise 'oh no'
end

def handled
Bugsnag.add_feature_flag('handled')

Bugsnag.notify(RuntimeError.new('ahhh'))
end

private

def add_feature_flags(event)
params['flags'].each do |key, value|
event.add_feature_flag(key, value)
end

if params.key?('clear_all_flags')
event.add_metadata(:clear_all_flags, :a, 1)
else
event.clear_feature_flag('should be removed!')
end
end
end
22 changes: 22 additions & 0 deletions features/fixtures/rails8/app/app/controllers/handled_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class HandledController < ActionController::Base
protect_from_forgery with: :exception

def unthrown
Bugsnag.notify(RuntimeError.new("handled unthrown error"))
render json: {}
end

def thrown
begin
generate_unhandled_error
rescue Exception => e
Bugsnag.notify(e)
end
render json: {}
end

def string_notify
Bugsnag.notify("handled string")
render json: {}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class IgnoredError < RuntimeError
end

class IgnoreClassesController < ActionController::Base
protect_from_forgery

def initializer
Bugsnag.notify(IgnoredError.new)
render json: {}
end

def after
Bugsnag.configure do |conf|
conf.ignore_classes << Kernel.const_get(params[:ignore])
end
Bugsnag.notify(IgnoredError.new)
render json: {}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class MetadataFiltersController < ActionController::Base
protect_from_forgery

def filter
Bugsnag.notify("handled string") do |report|
report.add_tab(:my_specific_filter, {
:foo => "bar"
})
end
render json: {}
end
end
22 changes: 22 additions & 0 deletions features/fixtures/rails8/app/app/controllers/mongo_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class MongoController < ApplicationController
def success_crash
doc = MongoModel.create(string_field: "String")
doc.save
"Statement".prepnd("Failing")
end

def get_crash
MongoModel.where(string_field: true).as_json
MongoModel.any_of({string_field: true}, {numeric_field: 123}).as_json
"Statement".prepnd("Failing")
end

def failure_crash
begin
Mongoid::Clients.default.database.command(:bogus => 1)
rescue
end

"Statement".prepnd("Failing")
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class ProjectRootController < ActionController::Base
protect_from_forgery

def default
Bugsnag.notify("handled string")
render json: {}
end

def initializer
Bugsnag.notify("handled string")
render json: {}
end

def after
Bugsnag.configure do |conf|
conf.project_root = '/test/root/here'
end
Bugsnag.notify("handled string")
render json: {}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class ReleaseStageController < ActionController::Base
protect_from_forgery

def default
Bugsnag.notify("handled string")
render json: {}
end

def after
Bugsnag.configure do |conf|
conf.release_stage = params[:stage]
end
Bugsnag.notify("handled string")
render json: {}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class SendCodeController < ActionController::Base
protect_from_forgery

def initializer
Bugsnag.notify("handled string")
render json: {}
end

def after
Bugsnag.configure do |conf|
conf.send_code = false
end
Bugsnag.notify("handled string")
render json: {}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class SendEnvironmentController < ActionController::Base
protect_from_forgery

def initializer
Bugsnag.notify("handled string")
render json: {}
end
end
Loading

0 comments on commit 768d497

Please sign in to comment.