Skip to content

Commit

Permalink
Merge pull request #95 from onk/add_index_in_create_table
Browse files Browse the repository at this point in the history
Fix support activerecord 7.1
  • Loading branch information
sue445 committed Feb 27, 2024
2 parents 0cc63c4 + ec7e7e2 commit 1097b13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/active_record/simple_index_name/active_record_ext_7_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ def legacy_index_name(table_name, options)
ActiveRecord::Migration::Compatibility::V7_0.class_eval do
prepend ActiveRecord::SimpleIndexName::ActiveRecordExt_7_1::V7_0
end
ActiveRecord::Migration::Compatibility::V7_0::TableDefinition.module_eval do
prepend ActiveRecord::SimpleIndexName::ActiveRecordExt_7_1::V7_0
end
8 changes: 8 additions & 0 deletions spec/activerecord/simple_index_name/active_record_ext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
context "When index name of renamed table" do
it { expect(index_name_of(:new_table, :anonymous_name)).to eq "anonymous_name" }
end

context "When add index in create_table" do
it { expect(index_name_of(:user_stocks, :foo_id)).to eq "foo_id" }
end
end

context "When auto_shorten is disabled" do
Expand All @@ -38,6 +42,10 @@
context "When index name of renamed table" do
it { expect(index_name_of(:new_table, :anonymous_name)).to eq "index_new_table_on_anonymous_name" }
end

context "When add index in create_table" do
it { expect(index_name_of(:user_stocks, :foo_id)).to eq "index_user_stocks_on_foo_id" }
end
end

context "When auto_shorten is either enabled or disabled" do
Expand Down
2 changes: 2 additions & 0 deletions spec/db/migrate/0001_create_user_stocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ def change
create_table :user_stocks do |t|
t.integer :user_id, null: false
t.integer :article_id, null: false
t.integer :foo_id
t.timestamps null: false
t.index :foo_id
end
add_index :user_stocks, [:user_id, :article_id]
end
Expand Down

0 comments on commit 1097b13

Please sign in to comment.