Browse files

Add generator spec for InstallGenerator; Use 'change' method for migr…

…ations
  • Loading branch information...
1 parent d139722 commit 8cd1426b01f42be20890b77b30257937b46e77de @batter batter committed Mar 7, 2014
View
6 lib/generators/paper_trail/templates/add_object_changes_column_to_versions.rb
@@ -1,9 +1,5 @@
class AddObjectChangesColumnToVersions < ActiveRecord::Migration
- def self.up
+ def change
add_column :versions, :object_changes, :text
end
-
- def self.down
- remove_column :versions, :object_changes
- end
end
View
7 lib/generators/paper_trail/templates/create_versions.rb
@@ -1,5 +1,5 @@
class CreateVersions < ActiveRecord::Migration
- def self.up
+ def change
create_table :versions do |t|
t.string :item_type, :null => false
t.integer :item_id, :null => false
@@ -10,9 +10,4 @@ def self.up
end
add_index :versions, [:item_type, :item_id]
end
-
- def self.down
- remove_index :versions, [:item_type, :item_id]
- drop_table :versions
- end
end
View
1 paper_trail.gemspec
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'sinatra', '~> 1.0'
s.add_development_dependency 'rack-test', '>= 0.6'
s.add_development_dependency 'rspec-rails', '~> 2.14'
+ s.add_development_dependency 'generator_spec'
# JRuby support for the test ENV
unless defined?(JRUBY_VERSION)
View
67 spec/generators/install_generator_spec.rb
@@ -0,0 +1,67 @@
+require 'spec_helper'
+require 'generator_spec/test_case'
+require File.expand_path('../../../lib/generators/paper_trail/install_generator', __FILE__)
+
+describe PaperTrail::InstallGenerator, :type => :generator do
+ include GeneratorSpec::TestCase
+ destination File.expand_path('../tmp', __FILE__)
+
+ after(:all) { prepare_destination } # cleanup the tmp directory
+
+ describe "no options" do
+ before(:all) do
+ prepare_destination
+ run_generator
+ end
+
+ it "generates a migration for creating the 'versions' table" do
+ destination_root.should have_structure {
+ directory 'db' do
+ directory 'migrate' do
+ migration 'create_versions' do
+ contains 'class CreateVersions'
+ contains 'def change'
+ contains 'create_table :versions do |t|'
+ end
+ end
+ end
+ }
+ end
+ end
+
+ describe "`--with-changes` option set to `true`" do
+ before(:all) do
+ prepare_destination
+ run_generator %w(--with-changes)
+ end
+
+ it "generates a migration for creating the 'versions' table" do
+ destination_root.should have_structure {
+ directory 'db' do
+ directory 'migrate' do
+ migration 'create_versions' do
+ contains 'class CreateVersions'
+ contains 'def change'
+ contains 'create_table :versions do |t|'
+ end
+ end
+ end
+ }
+ end
+
+ it "generates a migration for adding the 'object_changes' column to the 'versions' table" do
+ destination_root.should have_structure {
+ directory 'db' do
+ directory 'migrate' do
+ migration 'add_object_changes_column_to_versions' do
+ contains 'class AddObjectChangesColumnToVersions'
+ contains 'def change'
+ contains 'add_column :versions, :object_changes, :text'
+ end
+ end
+ end
+ }
+ end
+ end
+
+end

0 comments on commit 8cd1426

Please sign in to comment.