Add generator spec for InstallGenerator; Use 'change' method for migrations
This commit is contained in:
parent
d139722f0d
commit
8cd1426b01
|
@ -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
|
||||
|
|
|
@ -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 @@ class CreateVersions < ActiveRecord::Migration
|
|||
end
|
||||
add_index :versions, [:item_type, :item_id]
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_index :versions, [:item_type, :item_id]
|
||||
drop_table :versions
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue