Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djezzzl committed Dec 24, 2024
1 parent 911960f commit 16d7ce3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
6 changes: 5 additions & 1 deletion spec/checkers/enum_type_checker/postgresql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
let(:enum) { entity_class.defined_enums.keys.first }
let!(:entity_class) do
define_class do |klass|
klass.enum field: { value1: 'value1', value2: 'value2' }
if ActiveRecord::VERSION::MAJOR >= 8
klass.enum field: { value1: 'value1', value2: 'value2' }
else
klass.enum :field, { value1: 'value1', value2: 'value2' }
end
end
end

Expand Down
6 changes: 5 additions & 1 deletion spec/checkers/enum_type_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
let(:enum) { entity_class.defined_enums.keys.first }
let!(:entity_class) do
define_class do |klass|
klass.enum field: %i[value1 value2]
if ActiveRecord::VERSION::MAJOR >= 8
klass.enum :field, %i[value1 value2]
else
klass.enum field: %i[value1 value2]
end
end
end

Expand Down
27 changes: 24 additions & 3 deletions spec/checkers/enum_value_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
context 'when values are consistent' do
let(:klass) do
define_class do |klass|
klass.enum :status, { value1: 'value1', value2: 'value2' }
if ActiveRecord::VERSION::MAJOR >= 8
klass.enum :status, { value1: 'value1', value2: 'value2' }
else
klass.enum status: { value1: 'value1', value2: 'value2' }
end

klass.validates :status, inclusion: { in: %w[value1 value2] }
end
end
Expand Down Expand Up @@ -94,7 +99,15 @@
end

context 'when enum values are inconsistent' do
let(:klass) { define_class { |klass| klass.enum :status, { value1: 'value1', something: 'something' } } }
let(:klass) do
define_class do |klass|
if ActiveRecord::VERSION::MAJOR >= 8
klass.enum :status, { value1: 'value1', something: 'something' }
else
klass.enum status: { value1: 'value1', something: 'something' }
end
end
end

specify do
expect(checker.report.first).to have_attributes(
Expand All @@ -111,7 +124,15 @@
end

context 'when enum values are out of order' do
let(:klass) { define_class { |klass| klass.enum :status, { value2: 'value2', value1: 'value1' } } }
let(:klass) do
define_class do |klass|
if ActiveRecord::VERSION::MAJOR >= 8
klass.enum :status, { value2: 'value2', value1: 'value1' }
else
klass.enum status: { value2: 'value2', value1: 'value1' }
end
end
end

specify do
expect(checker.report.first).to have_attributes(
Expand Down

0 comments on commit 16d7ce3

Please sign in to comment.