add indexes to impressions table

This commit is contained in:
cowboycoded 2011-02-11 22:23:33 -05:00
parent 17558312c4
commit 22e83c58ba
3 changed files with 26 additions and 1 deletions

View File

@ -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

View File

@ -1,7 +1,7 @@
PATH
remote: /rails_plugins/mine/impressionist
specs:
impressionist (0.1.2)
impressionist (0.2.0)
GEM
remote: http://rubygems.org/

View File

@ -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