Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration test using force #81

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ruby_version: 2.7
ignore:
- 'dummyapp/**/*'
- 'spec/dummyapp/**/*'
- 'spec/templates/**/*'
45 changes: 45 additions & 0 deletions spec/integration/annotate_file_with_existing_annotations_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require "integration_spec_helper"

RSpec.describe "Annotate a file with existing annotations", type: "aruba" do
let(:models_dir) { "app/models" }
let(:command_timeout_seconds) { 10 }

before do
copy(Dir[File.join(aruba.config.root_directory, "spec/dummyapp/*")], aruba.config.home_directory)

# Unset the bundler context from running annotaterb integration specs.
# This way, when `run_command("bundle exec annotaterb")` runs, it runs as if it's within the context of dummyapp.
unset_bundler_env_vars
end

let(:templates_dir) { File.join(aruba.config.root_directory, "spec/templates/#{ENV["DATABASE_ADAPTER"]}") }
let(:model_file) { "app/models/test_default.rb" }

context "when using 'force' option and 'position: bottom'" do
before do
# Copy file with existing annotations at the top
copy(File.join(templates_dir, "test_default.rb"), "app/models")
end

it "moves annotations to the bottom of the file" do
expected_test_default = read(File.join(templates_dir, "test_default_with_bottom_annotations.rb")).join("\n")
original_test_default = read(File.join(models_dir, "test_default.rb")).join("\n")

# Check that files have been copied over correctly
expect(expected_test_default).not_to eq(original_test_default)

_cmd = run_command_and_stop(
"bundle exec annotaterb models #{model_file} --force --position bottom",
fail_on_error: true,
exit_timeout: command_timeout_seconds
)

annotated_test_default = read(File.join(models_dir, "test_default.rb")).join("\n")

expect(last_command_started).to be_successfully_executed
expect(annotated_test_default).to eq(expected_test_default)
end
end
end
19 changes: 19 additions & 0 deletions spec/templates/mysql2/test_default_with_bottom_annotations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true
class TestDefault < ApplicationRecord
end

# == Schema Information
#
# Table name: test_defaults
#
# id :bigint not null, primary key
# boolean :boolean default(FALSE)
# date :date default(Tue, 04 Jul 2023)
# datetime :datetime default(Tue, 04 Jul 2023 12:34:56.000000000 UTC +00:00)
# decimal :decimal(14, 2) default(43.21)
# float :float(24) default(12.34)
# integer :integer default(99)
# string :string(255) default("hello world!")
# created_at :datetime not null
# updated_at :datetime not null
#
19 changes: 19 additions & 0 deletions spec/templates/pg/test_default_with_bottom_annotations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true
class TestDefault < ApplicationRecord
end

# == Schema Information
#
# Table name: test_defaults
#
# id :bigint not null, primary key
# boolean :boolean default(FALSE)
# date :date default(Tue, 04 Jul 2023)
# datetime :datetime default(Tue, 04 Jul 2023 12:34:56.000000000 UTC +00:00)
# decimal :decimal(14, 2) default(43.21)
# float :float default(12.34)
# integer :integer default(99)
# string :string default("hello world!")
# created_at :datetime not null
# updated_at :datetime not null
#
19 changes: 19 additions & 0 deletions spec/templates/sqlite3/test_default_with_bottom_annotations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true
class TestDefault < ApplicationRecord
end

# == Schema Information
#
# Table name: test_defaults
#
# id :integer not null, primary key
# boolean :boolean default(FALSE)
# date :date default(Tue, 04 Jul 2023)
# datetime :datetime default(Tue, 04 Jul 2023 12:34:56.000000000 UTC +00:00)
# decimal :decimal(14, 2) default(43.21)
# float :float default(12.34)
# integer :integer default(99)
# string :string default("hello world!")
# created_at :datetime not null
# updated_at :datetime not null
#
Loading