From 21b19db5a30fcb6db83f4ac9302cc94c6320a0db Mon Sep 17 00:00:00 2001 From: Jamie Winsor Date: Mon, 1 Aug 2011 11:27:28 -0700 Subject: refactor engine testing scenario Engine is now tested standalone by leveraging a dummy rails app Enable Guard for speedy testing Move factories to the more standard location `spec/factories/*` Update README with a Testing section Rename migrations to contain datetimestamps for their version to fix migration order issues when migrating the dummy application --- .../db/migrate/20110802081571_create_seo_meta.rb | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 spec/dummy/db/migrate/20110802081571_create_seo_meta.rb (limited to 'spec/dummy/db/migrate/20110802081571_create_seo_meta.rb') diff --git a/spec/dummy/db/migrate/20110802081571_create_seo_meta.rb b/spec/dummy/db/migrate/20110802081571_create_seo_meta.rb new file mode 100644 index 0000000..abc2178 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081571_create_seo_meta.rb @@ -0,0 +1,86 @@ +class CreateSeoMeta < ActiveRecord::Migration + + def self.up + create_table :seo_meta do |t| + t.integer :seo_meta_id + t.string :seo_meta_type + + t.string :browser_title + t.string :meta_keywords + t.text :meta_description + + t.timestamps + end + + add_index :seo_meta, :id + add_index :seo_meta, [:seo_meta_id, :seo_meta_type] + + # Grab the attributes of the records that currently exist + existing_translations = ::Refinery::Page.translation_class.all.map(&:attributes) + + # Remove columns + ::SeoMeta.attributes.keys.each do |field| + if ::Refinery::Page.translation_class.column_names.map(&:to_sym).include?(field) + remove_column ::Refinery::Page.translation_class.table_name, field + end + end + + # Reset column information because otherwise the old columns will still exist. + ::Refinery::Page.translation_class.reset_column_information + + # Re-attach seo_meta + ::Refinery::Page.translation_class.send :is_seo_meta + + # Migrate data + existing_translations.each do |translation| + ::Refinery::Page.translation_class.find(translation['id']).update_attributes( + ::SeoMeta.attributes.keys.inject({}) {|attributes, name| + attributes.merge(name => translation[name.to_s]) + } + ) + end + + # Reset column information again because otherwise the old columns will still exist. + ::Refinery::Page.reset_column_information + end + + def self.down + # Grab the attributes of the records that currently exist + existing_translations = ::Refinery::Page.translation_class.all.map(&:attributes) + + # Add columns back to your model + ::SeoMeta.attributes.each do |field, field_type| + unless ::Refinery::Page.translation_class.column_names.map(&:to_sym).include?(field) + add_column ::Refinery::Page.translation_class.table_name, field, field_type + end + end + + # Reset column information because otherwise the new columns won't exist yet. + ::Refinery::Page.translation_class.reset_column_information + + # Migrate data + existing_translations.each do |translation| + ::Refinery::Page.translation_class.update_all( + ::SeoMeta.attributes.keys.inject({}) {|attributes, name| + attributes.merge(name => translation[name.to_s]) + }, :id => translation['id'] + ) + end + + ::SeoMeta.attributes.keys.each do |k| + ::Refinery::Page.translation_class.module_eval %{ + def #{k} + end + + def #{k}=(*args) + end + } + end + + # Reset column information again because otherwise the old columns will still exist. + ::Refinery::Page.reset_column_information + + drop_table :seo_meta + end + +end -- cgit v1.2.3