1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00
paper-trail-gem--paper_trail/spec/generators/install_generator_spec.rb
Jared Beck f92cfbc23d Inherit from the new versioned migration class
e.g. `ActiveRecord::Migration[5.1]`

Fixes #949

Following the example of the devise gem, use erb. In addition, add
the `.erb` file extension to fix syntax highlighting in editor.

Deletes create_versions_spec.rb because the file is no longer valid
ruby so those tests will have to be re-written. We can either
generate a valid ruby file and continue to use similar assertions,
or we can convert those features to use erb, which will have the
benefit of cleaner generated files.
2017-04-10 11:10:15 -04:00

81 lines
2.3 KiB
Ruby

require "rails_helper"
require "generator_spec/test_case"
require File.expand_path("../../../lib/generators/paper_trail/install_generator", __FILE__)
RSpec.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
expected_parent_class = lambda {
old_school = "ActiveRecord::Migration"
ar_version = ActiveRecord::VERSION
if ar_version::MAJOR >= 5
format("%s[%d.%d]", old_school, ar_version::MAJOR, ar_version::MINOR)
else
old_school
end
}.call
expect(destination_root).to(
have_structure {
directory("db") {
directory("migrate") {
migration("create_versions") {
contains("class CreateVersions < " + expected_parent_class)
contains "def change"
contains "create_table :versions"
}
}
}
}
)
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
expect(destination_root).to(
have_structure {
directory("db") {
directory("migrate") {
migration("create_versions") {
contains "class CreateVersions"
contains "def change"
contains "create_table :versions"
}
}
}
}
)
end
it "generates a migration for adding the 'object_changes' column to the 'versions' table" do
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"
}
}
}
}
)
end
end
end