Skip to content

Commit

Permalink
Merge pull request #5 from bdurand:handle_anonymous_classes
Browse files Browse the repository at this point in the history
Ignore anonymous classes when calling sync_all!
  • Loading branch information
bdurand authored May 2, 2024
2 parents e311c38 + 112d1d4 commit 3a488d4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.1.2

### Fixed

- Ignore anonymous ActiveRecord classes when calling `sync_all!`.

## 1.1.1

- Freeze values returned from helper methods.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1
1.1.2
3 changes: 2 additions & 1 deletion lib/support_table_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ def support_table_classes(*extra_classes)
end
end

ActiveRecord::Base.descendants.sort_by(&:name).each do |klass|
active_record_classes = ActiveRecord::Base.descendants.reject { |klass| klass.name.nil? }
active_record_classes.sort_by(&:name).each do |klass|
next unless klass.include?(SupportTableData)
next if klass.abstract_class?
next if classes.include?(klass)
Expand Down
7 changes: 6 additions & 1 deletion spec/support_table_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@
expect(all_changes[Color]).to_not eq([])
end

it "can be called with a list of classes to inlude" do
it "can be called with a list of classes to include" do
expect { SupportTableData.sync_all!(Color) }.to_not raise_error
end

it "ignores anonomous classes" do
Class.new(ActiveRecord::Base)
expect { SupportTableData.sync_all! }.to_not raise_error
end
end

describe "named instances" do
Expand Down

0 comments on commit 3a488d4

Please sign in to comment.