diff --git a/lib/generators/impressionist/templates/create_impressions_table.rb b/lib/generators/impressionist/templates/create_impressions_table.rb index c2b4533..751b536 100644 --- a/lib/generators/impressionist/templates/create_impressions_table.rb +++ b/lib/generators/impressionist/templates/create_impressions_table.rb @@ -12,9 +12,16 @@ class CreateImpressionsTable < ActiveRecord::Migration t.string :message t.timestamps end + add_index :impressions, [:impressionable_type, :impressionable_id, :request_hash, :ip_address], :name => "poly_index", :unique => false + add_index :impressions, [:controller_name,:action_name,:request_hash,:ip_address], :name => "controlleraction_index", :unique => false + add_index :impressions, :user_id end def self.down + remove_index :impressions, :name => :poly_index + remove_index :impressions, :name => :controlleraction_index + remove_index :impressions, :user_id + drop_table :impressions end end \ No newline at end of file diff --git a/test_app/Gemfile.lock b/test_app/Gemfile.lock index 2a76d08..59b0e5d 100644 --- a/test_app/Gemfile.lock +++ b/test_app/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: /rails_plugins/mine/impressionist specs: - impressionist (0.1.2) + impressionist (0.2.0) GEM remote: http://rubygems.org/ diff --git a/test_app/spec/generators_spec.rb b/test_app/spec/generators_spec.rb new file mode 100644 index 0000000..f44472c --- /dev/null +++ b/test_app/spec/generators_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' +require 'systemu' + +describe Impressionist do + it "should delete existing migration and generate the migration file" do + migrations_dir = "#{Rails.root}/db/migrate" + impressions_migration = Dir.entries(migrations_dir).grep(/impressions/)[0] + File.delete("#{migrations_dir}/#{impressions_migration}") unless impressions_migration.blank? + generator_output = systemu("rails g impressionist")[1] + migration_name = generator_output.split("migrate/")[1].strip + Dir.entries(migrations_dir).include?(migration_name).should be true + end + + it "should run the migration created in the previous spec" do + migrate_output = systemu("rake db:migrate") + migrate_output[1].include?("CreateImpressionsTable: migrated").should be true + end +end \ No newline at end of file