Sha256: a2dd36d30acb721fbf018c15416c35e0205d208c10de7f3688f451162204485c
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe ActiveRecord::Schema do let(:schema) { ActiveRecord::Schema } let(:connection) { ActiveRecord::Base.connection } after(:all) do # revert to general schema ActiveRecord::Migration.suppress_messages do load 'schema/schema.rb' end end context "defining with auto_index" do it "should pass" do with_auto_index do expect { define_schema }.should_not raise_error end end it "should create only explicity added indexes" do with_auto_index do define_schema connection.tables.collect { |table| connection.indexes(table) }.flatten.should have(1).item end end end protected def define_schema ActiveRecord::Migration.suppress_messages do schema.define do create_table :users, :force => true do end create_table :posts, :force => true do |t| t.integer :user_id end # mysql will create index on FK automatically unless AutomaticForeignKeyHelpers.mysql? add_index :posts, :user_id end end end end def with_auto_index(value = true) old_value = AutomaticForeignKey.auto_index AutomaticForeignKey.auto_index = value begin yield ensure AutomaticForeignKey.auto_index = old_value end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
automatic_foreign_key-1.3.0 | spec/schema_spec.rb |
automatic_foreign_key-1.2.0 | spec/schema_spec.rb |