diff --git a/README.markdown b/README.markdown index e63e518..d13afcc 100644 --- a/README.markdown +++ b/README.markdown @@ -10,7 +10,8 @@ Enumerations for Rails Done Right. ## Versions -* PowerEnum 4.0.X (this version) supports Rails 6.X, and Rails 7.0 (Experimental) +* PowerEnum 5.0.X (this version) supports Rails 7.X +* PowerEnum 4.0.X supports Rails 6.X, and Rails 7.0 (Experimental) * PowerEnum 3.X supports Rails 4.2, Rails 5.X and Rails 6.0 * PowerEnum 2.X supports Rails 4.X and Rails 5.0 * PowerEnum 1.X supports Rails 3.1/3.2, available here: https://github.com/albertosaurus/power_enum @@ -121,7 +122,7 @@ rails generate enum booking_status You should see output similar to this: create app/models/booking_status.rb - create db/migrate/20110926012928_create_enum_booking_status.rb + create db/migrate/20110926012928_create_power_enum_booking_status.rb invoke test_unit create test/unit/booking_status_test.rb @@ -138,7 +139,7 @@ When you open your migration file, it will look something like this: class CreateEnumBookingStatus < ActiveRecord::Migration def change - create_enum :booking_status + create_power_enum :booking_status end end @@ -147,15 +148,13 @@ end You can now customize it. ```ruby -create_enum :booking_status, :name_limit => 50 +create_power_enum :booking_status, :name_limit => 50 # The above is equivalent to saying # create_table :booking_statuses do |t| # t.string :name, :limit => 50, :null => false # end ``` -**WARNING - This conflicts with PostgreSQL enum support in Rails 7+ and will be renamed in future versions.** - Now, when you create your Booking model, your migration should create a reference column for status id's and a foreign key relationship to the booking\_statuses table. @@ -187,9 +186,7 @@ end There are two methods added to Rails migrations: -##### create\_enum(enum\_name, options = {}, &block) - -**WARNING - This conflicts with PostgreSQL enum support in Rails 7+ and will be renamed in future versions.** +##### create\_power\_enum(enum\_name, options = {}, &block) Creates a new enum table. `enum_name` will be automatically pluralized. The following options are supported: @@ -207,7 +204,7 @@ You can also pass in a block that takes a table object as an argument, like `cre Example: ```ruby -create_enum :booking_status +create_power_enum :booking_status ``` is the equivalent of @@ -222,7 +219,7 @@ add_index :booking_statuses, [:name], :unique => true In a more complex case: ```ruby -create_enum :booking_status, +create_power_enum :booking_status, :name_column => :booking_name, :name_limit => 50, :description => true, @@ -247,7 +244,7 @@ add_index :booking_statuses, [:booking_name], :unique => true You can also customize the creation process by using a block: ```ruby -create_enum :booking_status do |t| +create_power_enum :booking_status do |t| t.boolean :first_booking, :null => false end ``` @@ -264,14 +261,14 @@ add_index :booking_statuses, [:name], :unique => true Notice that a unique index is automatically created on the specified name column. -##### remove\_enum(enum\_name) +##### remove\_power\_enum(enum\_name) Drops the enum table. `enum_name` will be automatically pluralized. Example: ```ruby -remove_enum :booking_status +remove_power_enum :booking_status ``` is the equivalent of diff --git a/VERSION b/VERSION index 1454f6e..0062ac9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.1 +5.0.0 diff --git a/lib/generators/enum/USAGE b/lib/generators/enum/USAGE index 738d31a..d460a3b 100644 --- a/lib/generators/enum/USAGE +++ b/lib/generators/enum/USAGE @@ -6,5 +6,5 @@ Example: This will create: BookingStatus model: app/models/booking_status.rb - Migration to create tables: db/migrate/20110925195833_create_enum_booking_status.rb + Migration to create tables: db/migrate/20110925195833_create_power_enum_booking_status.rb Unit test for model: test/unit/booking_status_test.rb diff --git a/lib/generators/enum/enum_generator.rb b/lib/generators/enum/enum_generator.rb index 6c4f0b2..4e3302b 100644 --- a/lib/generators/enum/enum_generator.rb +++ b/lib/generators/enum/enum_generator.rb @@ -20,7 +20,7 @@ def generate_model # Generates the migration to create the enum table. def generate_migration @description = options.description? - migration_template 'rails31_migration.rb.erb', "db/migrate/create_enum_#{table_name}.rb" if options.migration? + migration_template 'rails31_migration.rb.erb', "db/migrate/create_power_enum_#{table_name}.rb" if options.migration? end # Do not pluralize enumeration names diff --git a/lib/generators/enum/enum_generator_helpers/migration_number.rb b/lib/generators/enum/enum_generator_helpers/migration_number.rb index fefcc80..db9a303 100644 --- a/lib/generators/enum/enum_generator_helpers/migration_number.rb +++ b/lib/generators/enum/enum_generator_helpers/migration_number.rb @@ -9,7 +9,7 @@ def next_migration_number(dirname) # Lifted directly from ActiveRecord::Generators::Migration # Unfortunately, no API is provided by Rails at this time. next_migration_number = current_migration_number(dirname) + 1 - if ActiveRecord::Base.timestamped_migrations + if ActiveRecord.timestamped_migrations [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max else "%.3d" % next_migration_number diff --git a/lib/generators/enum/templates/rails31_migration.rb.erb b/lib/generators/enum/templates/rails31_migration.rb.erb index a8f20b9..fb73900 100644 --- a/lib/generators/enum/templates/rails31_migration.rb.erb +++ b/lib/generators/enum/templates/rails31_migration.rb.erb @@ -1,7 +1,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= Rails.version =~ /^4\.2\.*/ ? "" : "[5.0]" %> def change - create_enum :<%=file_name%><%= ", description: true" if @description %> + create_power_enum :<%=file_name%><%= ", description: true" if @description %> end end diff --git a/lib/power_enum/migration/command_recorder.rb b/lib/power_enum/migration/command_recorder.rb index 8e247cb..20a5990 100644 --- a/lib/power_enum/migration/command_recorder.rb +++ b/lib/power_enum/migration/command_recorder.rb @@ -5,22 +5,22 @@ module PowerEnum::Migration # :nodoc: # Extensions for CommandRecorder module CommandRecorder - # Records create_enum - def create_enum(*args) - record(:create_enum, args) + # Records create_power_enum + def create_power_enum(*args) + record(:create_power_enum, args) end - # Records remove_enum - def remove_enum(*args) - record(:remove_enum, args) + # Records remove_power_enum + def remove_power_enum(*args) + record(:remove_power_enum, args) end - # The inversion of create_enum is remove_enum - # @param [Array] args Arguments to create_enum - # @return [Array] [:remove_enum, [enum_name]] - def invert_create_enum(args) + # The inversion of create_power_enum is remove_power_enum + # @param [Array] args Arguments to create_power_enum + # @return [Array] [:remove_power_enum, [enum_name]] + def invert_create_power_enum(args) enum_name = args[0] - [:remove_enum, [enum_name]] + [:remove_power_enum, [enum_name]] end end diff --git a/lib/power_enum/schema/schema_statements.rb b/lib/power_enum/schema/schema_statements.rb index ad29c29..f9cacd8 100644 --- a/lib/power_enum/schema/schema_statements.rb +++ b/lib/power_enum/schema/schema_statements.rb @@ -8,9 +8,7 @@ module SchemaStatements def self.included(base) # :nodoc: base::AbstractAdapter.class_eval do - # This squashes the "#create_enum" in the PostgreSQL adapter in Rails 7+. - # .../activerecord-7.0.X.Y/lib/active_record/connection_adapters/postgresql_adapter.rb - prepend PowerEnum::Schema::AbstractAdapter + include PowerEnum::Schema::AbstractAdapter end end @@ -42,7 +40,7 @@ module AbstractAdapter # # ===== Examples # ====== Basic Enum - # create_enum :connector_type + # create_power_enum :connector_type # is the equivalent of # create_table :connector_types do |t| # t.string :name, :null => false @@ -50,7 +48,7 @@ module AbstractAdapter # add_index :connector_types, [:name], :unique => true # # ====== Advanced Enum - # create_enum :connector_type, :name_column => :connector, + # create_power_enum :connector_type, :name_column => :connector, # :name_limit => 50, # :description => true, # :desc_limit => 100, @@ -67,7 +65,7 @@ module AbstractAdapter # add_index :connector_types, [:connector], :unique => true # # ====== Customizing Enum with a block - # create_enum :connector_type, :description => true do |t| + # create_power_enum :connector_type, :description => true do |t| # t.boolean :has_sound # end # is the equivalent of @@ -79,7 +77,7 @@ module AbstractAdapter # add_index :connector_types, [:connector], :unique => true # # Notice that a unique index is automatically created in each case on the proper name column. - def create_enum(enum_name, options = {}, &block) + def create_power_enum(enum_name, options = {}, &block) enum_table_name = enum_name.pluralize # For compatibility with PgPower/PgSaurus @@ -117,10 +115,10 @@ def create_enum(enum_name, options = {}, &block) # Drops the enum table. +enum_name+ will be automatically pluralized. # # ===== Example - # remove_enum :connector_type + # remove_power_enum :connector_type # is the equivalent of # drop_table :connector_types - def remove_enum(enum_name) + def remove_power_enum(enum_name) drop_table enum_name.pluralize end diff --git a/power_enum.gemspec b/power_enum.gemspec index 36d9ed2..4df4811 100644 --- a/power_enum.gemspec +++ b/power_enum.gemspec @@ -40,7 +40,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '> 1.7' spec.add_development_dependency 'rake' spec.add_development_dependency 'rspec', '~> 3.1' - spec.add_development_dependency 'rails', '>= 6.0', '< 8' + spec.add_development_dependency 'rails', '>= 7.0', '< 8' spec.add_runtime_dependency 'railties', '>= 6.0', '< 8' spec.add_runtime_dependency 'activerecord', '>= 6.0', '< 8' diff --git a/spec/dummy/db/migrate/20110920062020_create_connector_types.rb b/spec/dummy/db/migrate/20110920062020_create_connector_types.rb index b721553..e9adcfc 100644 --- a/spec/dummy/db/migrate/20110920062020_create_connector_types.rb +++ b/spec/dummy/db/migrate/20110920062020_create_connector_types.rb @@ -1,6 +1,6 @@ class CreateConnectorTypes < ActiveRecord::Migration[4.2] def change - create_enum :connector_type, + create_power_enum :connector_type, :description => true, :name_limit => 50, :active => true, diff --git a/spec/dummy/db/migrate/20120823014841_create_enum_color.rb b/spec/dummy/db/migrate/20120823014841_create_enum_color.rb index 553583e..11fd484 100644 --- a/spec/dummy/db/migrate/20120823014841_create_enum_color.rb +++ b/spec/dummy/db/migrate/20120823014841_create_enum_color.rb @@ -1,7 +1,7 @@ class CreateEnumColor < ActiveRecord::Migration[4.2] def change - create_enum :color + create_power_enum :color end end diff --git a/spec/dummy/db/migrate/20120909203515_create_enum_fruit.rb b/spec/dummy/db/migrate/20120909203515_create_enum_fruit.rb index 3b360d7..d26191f 100644 --- a/spec/dummy/db/migrate/20120909203515_create_enum_fruit.rb +++ b/spec/dummy/db/migrate/20120909203515_create_enum_fruit.rb @@ -1,7 +1,7 @@ class CreateEnumFruit < ActiveRecord::Migration[4.2] def up - create_enum :fruit, :name_column => :fruit_name, :description => :true + create_power_enum :fruit, :name_column => :fruit_name, :description => :true ActiveRecord::Base.connection.execute "INSERT INTO fruits (fruit_name, description) VALUES ('apple', 'Apple');" ActiveRecord::Base.connection.execute "INSERT INTO fruits (fruit_name, description) VALUES ('pear', 'Pear');" @@ -10,7 +10,7 @@ def up end def down - remove_enum :fruit + remove_power_enum :fruit end end diff --git a/spec/dummy/db/migrate/20120909235526_create_virtual_enum.rb b/spec/dummy/db/migrate/20120909235526_create_virtual_enum.rb index e9b5577..614e863 100644 --- a/spec/dummy/db/migrate/20120909235526_create_virtual_enum.rb +++ b/spec/dummy/db/migrate/20120909235526_create_virtual_enum.rb @@ -1,11 +1,11 @@ class CreateVirtualEnum < ActiveRecord::Migration[4.2] def up - create_enum :virtual_enum + create_power_enum :virtual_enum ActiveRecord::Base.connection.execute "INSERT INTO virtual_enums (name) VALUES ('virtual_enum');" end def down - remove_enum :virtual_enum + remove_power_enum :virtual_enum end end diff --git a/spec/functional/create_enum_spec.rb b/spec/functional/create_enum_spec.rb index 335bb8d..7d0eef2 100644 --- a/spec/functional/create_enum_spec.rb +++ b/spec/functional/create_enum_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "create_enum migration methods" do +describe "create_power_enum migration methods" do it "connector type should be defined" do expect{ diff --git a/spec/migration/command_recorder_spec.rb b/spec/migration/command_recorder_spec.rb index 8a4d841..723faec 100644 --- a/spec/migration/command_recorder_spec.rb +++ b/spec/migration/command_recorder_spec.rb @@ -9,19 +9,19 @@ class CommandRecorderStub CommandRecorderStub.new } - it '.create_enum' do - recorder.should_receive(:record).with(:create_enum, []) + it '.create_power_enum' do + recorder.should_receive(:record).with(:create_power_enum, []) - recorder.create_enum + recorder.create_power_enum end - it '.remove_enum' do - recorder.should_receive(:record).with(:remove_enum, []) + it '.remove_power_enum' do + recorder.should_receive(:record).with(:remove_power_enum, []) - recorder.remove_enum + recorder.remove_power_enum end - it '.invert_create_enum' do - recorder.invert_create_enum([:foo]).should eq([:remove_enum, [:foo]]) + it '.invert_create_power_enum' do + recorder.invert_create_power_enum([:foo]).should eq([:remove_power_enum, [:foo]]) end end \ No newline at end of file diff --git a/spec/migration/schema_statements_spec.rb b/spec/migration/schema_statements_spec.rb index 739b6cb..fb5cede 100644 --- a/spec/migration/schema_statements_spec.rb +++ b/spec/migration/schema_statements_spec.rb @@ -63,8 +63,8 @@ def add_index(table_name, *args) { :foo => 1, :bar => 2, :baz => 3 } } - it 'should create the enum table on \'create_enum\'' do - adapter_stub.create_enum( + it 'should create the enum table on \'create_power_enum\'' do + adapter_stub.create_power_enum( 'test_enum', :name_column => 'name_column', :description => true, @@ -88,10 +88,10 @@ def add_index(table_name, *args) end - it 'should drop the enum table on \'remove_enum\'' do + it 'should drop the enum table on \'remove_power_enum\'' do adapter_stub.should_receive(:drop_table).with('test_enums') - adapter_stub.remove_enum('test_enum') + adapter_stub.remove_power_enum('test_enum') end end \ No newline at end of file