2014-10-09 15:04:17 -04:00
|
|
|
require 'rails_helper'
|
2014-03-07 16:06:18 -05:00
|
|
|
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
|
2015-12-24 01:50:14 -05:00
|
|
|
|
2014-03-07 16:06:18 -05:00
|
|
|
it "generates a migration for creating the 'versions' table" do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(destination_root).to have_structure {
|
2014-03-07 16:06:18 -05:00
|
|
|
directory 'db' do
|
|
|
|
directory 'migrate' do
|
|
|
|
migration 'create_versions' do
|
|
|
|
contains 'class CreateVersions'
|
|
|
|
contains 'def change'
|
2015-12-24 01:50:14 -05:00
|
|
|
contains 'create_table :versions'
|
2014-03-07 16:06:18 -05:00
|
|
|
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
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(destination_root).to have_structure {
|
2014-03-07 16:06:18 -05:00
|
|
|
directory 'db' do
|
|
|
|
directory 'migrate' do
|
|
|
|
migration 'create_versions' do
|
|
|
|
contains 'class CreateVersions'
|
|
|
|
contains 'def change'
|
2015-12-24 01:50:14 -05:00
|
|
|
contains 'create_table :versions'
|
2014-03-07 16:06:18 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a migration for adding the 'object_changes' column to the 'versions' table" do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(destination_root).to have_structure {
|
2014-03-07 16:06:18 -05:00
|
|
|
directory 'db' do
|
|
|
|
directory 'migrate' do
|
2014-03-07 16:28:04 -05:00
|
|
|
migration 'add_object_changes_to_versions' do
|
|
|
|
contains 'class AddObjectChangesToVersions'
|
2014-03-07 16:06:18 -05:00
|
|
|
contains 'def change'
|
|
|
|
contains 'add_column :versions, :object_changes, :text'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|