2016-03-05 22:07:32 +00:00
|
|
|
require "rails_helper"
|
|
|
|
require "generator_spec/test_case"
|
|
|
|
require File.expand_path("../../../lib/generators/paper_trail/install_generator", __FILE__)
|
2014-03-07 21:06:18 +00:00
|
|
|
|
2017-04-01 04:33:33 +00:00
|
|
|
RSpec.describe PaperTrail::InstallGenerator, type: :generator do
|
2014-03-07 21:06:18 +00:00
|
|
|
include GeneratorSpec::TestCase
|
2016-03-05 22:07:32 +00:00
|
|
|
destination File.expand_path("../tmp", __FILE__)
|
2014-03-07 21:06:18 +00:00
|
|
|
|
|
|
|
after(:all) { prepare_destination } # cleanup the tmp directory
|
|
|
|
|
|
|
|
describe "no options" do
|
|
|
|
before(:all) do
|
|
|
|
prepare_destination
|
|
|
|
run_generator
|
|
|
|
end
|
2015-12-24 06:50:14 +00:00
|
|
|
|
2014-03-07 21:06:18 +00:00
|
|
|
it "generates a migration for creating the 'versions' table" do
|
2017-04-01 04:33:33 +00:00
|
|
|
expect(destination_root).to(
|
|
|
|
have_structure {
|
|
|
|
directory("db") {
|
|
|
|
directory("migrate") {
|
|
|
|
migration("create_versions") {
|
|
|
|
contains "class CreateVersions"
|
|
|
|
contains "def change"
|
|
|
|
contains "create_table :versions"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-03-07 21:06:18 +00:00
|
|
|
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
|
2017-04-01 04:33:33 +00:00
|
|
|
expect(destination_root).to(
|
|
|
|
have_structure {
|
|
|
|
directory("db") {
|
|
|
|
directory("migrate") {
|
|
|
|
migration("create_versions") {
|
|
|
|
contains "class CreateVersions"
|
|
|
|
contains "def change"
|
|
|
|
contains "create_table :versions"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-03-07 21:06:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a migration for adding the 'object_changes' column to the 'versions' table" do
|
2017-04-01 04:33:33 +00:00
|
|
|
expect(destination_root).to(
|
|
|
|
have_structure {
|
|
|
|
directory("db") {
|
|
|
|
directory("migrate") {
|
|
|
|
migration("add_object_changes_to_versions") {
|
|
|
|
contains "class AddObjectChangesToVersions"
|
|
|
|
contains "def change"
|
|
|
|
contains "add_column :versions, :object_changes, :text"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-03-07 21:06:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|