-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: base resource overriding (#3077)
* fix: base resource overriding * fix: base resource extension * lint * . * mv base * . * . * . * . * . * . * require base resource * Revert "." This reverts commit cb5ed40. * lint * fix warning * fix test * lint * require instead require_relative * just require * proper load
- Loading branch information
Showing
3 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "rails_helper" | ||
|
||
RSpec.feature "Resource extension", type: :feature do | ||
before_all do | ||
Avo::Resources::CourseLink.define_method :test_base_resource_extension do | ||
some_extended_method | ||
end | ||
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 | ||
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 |