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

fix: base resource overriding #3077

Merged
merged 23 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/avo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def init
Avo::Current.error_manager = Avo::ErrorManager.build
# Check rails version issues only on NON Production environments
unless Rails.env.production?
check_rails_version_issues
check_rails_version_issues
display_menu_editor_warning
end
Avo::Current.resource_manager = Avo::Resources::ResourceManager.build
Expand Down
3 changes: 3 additions & 0 deletions lib/avo/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Engine < ::Rails::Engine
Rails.autoloaders.main.push_dir(avo_directory, namespace: Avo)
app.config.watchable_dirs[avo_directory] = [:rb]
end

Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved
Rails.autoloaders.main.push_dir(Avo::Engine.root.join("app", "avo").to_s, namespace: Avo)
require_relative Avo::Engine.root.join("app", "avo", "base_resource.rb").to_s
end

initializer "avo.reloader" do |app|
Expand Down
34 changes: 34 additions & 0 deletions spec/features/avo/resource_extension_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require "rails_helper"

RSpec.feature "Resource extension", type: :feature do
Avo::Resources::CourseLink.define_method :test_base_resource_extension do
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved
some_extended_method
end

it "no extension" do
expect(TestBuddy).not_to receive(:hi).with("Extension successfully")
expect { Avo::Resources::CourseLink.new.test_base_resource_extension }.to raise_error(NameError)
end

it "with extension" do
file_path = Rails.root.join("app/avo/base_resource.rb")
FileUtils.mkdir_p(File.dirname(file_path))
File.write file_path,
<<~RUBY
module Avo
class BaseResource < Avo::Resources::Base
def some_extended_method
TestBuddy.hi("Extension successfully")
end
end
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved
end
RUBY

load file_path

expect(TestBuddy).to receive(:hi).with("Extension successfully").at_least :once
expect { Avo::Resources::CourseLink.new.test_base_resource_extension }.not_to raise_error

File.delete(file_path) if File.exist?(file_path)
end
end
Loading