declare_schema 0.2.0.pre.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -2
- data/Gemfile.lock +13 -13
- data/README.md +20 -0
- data/lib/declare_schema/model.rb +30 -23
- data/lib/declare_schema/model/field_spec.rb +1 -1
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migrator.rb +41 -29
- data/lib/generators/declare_schema/migration/templates/migration.rb.erb +1 -1
- data/spec/lib/declare_schema/api_spec.rb +6 -7
- data/spec/lib/declare_schema/generator_spec.rb +51 -10
- data/spec/lib/declare_schema/interactive_primary_key_spec.rb +3 -3
- data/spec/lib/declare_schema/migration_generator_spec.rb +422 -198
- data/spec/lib/declare_schema/prepare_testapp.rb +2 -0
- data/spec/lib/generators/declare_schema/migration/migrator_spec.rb +72 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/acceptance_spec_helpers.rb +57 -0
- metadata +4 -2
@@ -18,6 +18,8 @@ require "#{TESTAPP_PATH}/config/environment"
|
|
18
18
|
require 'rails/generators'
|
19
19
|
Rails::Generators.configure!(Rails.application.config.generators)
|
20
20
|
|
21
|
+
ActiveRecord::Base.connection.schema_cache.clear!
|
22
|
+
|
21
23
|
(ActiveRecord::Base.connection.tables - Generators::DeclareSchema::Migration::Migrator.always_ignore_tables).each do |table|
|
22
24
|
ActiveRecord::Base.connection.execute("DROP TABLE #{ActiveRecord::Base.connection.quote_table_name(table)}")
|
23
25
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails'
|
4
|
+
require 'rails/generators'
|
5
|
+
|
6
|
+
module Generators
|
7
|
+
module DeclareSchema
|
8
|
+
module Migration
|
9
|
+
RSpec.describe Migrator do
|
10
|
+
before do
|
11
|
+
ActiveRecord::Base.connection.tables
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { described_class.new }
|
15
|
+
|
16
|
+
describe 'format_options' do
|
17
|
+
let(:mysql_longtext_limit) { 0xffff_ffff }
|
18
|
+
|
19
|
+
context 'MySQL' do
|
20
|
+
before do
|
21
|
+
expect(::DeclareSchema::Model::FieldSpec).to receive(:mysql_text_limits?).and_return(true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns text limits' do
|
25
|
+
expect(subject.format_options({ limit: mysql_longtext_limit }, :text)).to eq(["limit: #{mysql_longtext_limit}"])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'non-MySQL' do
|
30
|
+
before do
|
31
|
+
expect(::DeclareSchema::Model::FieldSpec).to receive(:mysql_text_limits?).and_return(false)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns text limits' do
|
35
|
+
expect(subject.format_options({ limit: mysql_longtext_limit }, :text)).to eq([])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#before_generating_migration' do
|
41
|
+
it 'requires a block be passed' do
|
42
|
+
expect { described_class.before_generating_migration }.to raise_error(ArgumentError, 'A block is required when setting the before_generating_migration callback')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'load_rails_models' do
|
47
|
+
before do
|
48
|
+
expect(Rails.application).to receive(:eager_load!)
|
49
|
+
expect(Rails::Engine).to receive(:subclasses).and_return([])
|
50
|
+
end
|
51
|
+
|
52
|
+
subject { described_class.new.load_rails_models }
|
53
|
+
|
54
|
+
context 'when a before_generating_migration callback is configured' do
|
55
|
+
let(:dummy_proc) { -> {} }
|
56
|
+
|
57
|
+
before do
|
58
|
+
described_class.before_generating_migration(&dummy_proc)
|
59
|
+
expect(dummy_proc).to receive(:call).and_return(true)
|
60
|
+
end
|
61
|
+
|
62
|
+
it { should be_truthy }
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when no before_generating_migration callback is configured' do
|
66
|
+
it { should be_nil }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,11 @@ require "bundler/setup"
|
|
4
4
|
require "declare_schema"
|
5
5
|
require "climate_control"
|
6
6
|
|
7
|
+
require_relative "./support/acceptance_spec_helpers"
|
8
|
+
|
7
9
|
RSpec.configure do |config|
|
10
|
+
config.include AcceptanceSpecHelpers
|
11
|
+
|
8
12
|
# Enable flags like --only-failures and --next-failure
|
9
13
|
config.example_status_persistence_file_path = ".rspec_status"
|
10
14
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AcceptanceSpecHelpers
|
4
|
+
def generate_model(model_name, *fields)
|
5
|
+
Rails::Generators.invoke('declare_schema:model', [model_name, *fields])
|
6
|
+
end
|
7
|
+
|
8
|
+
def generate_migrations(*flags)
|
9
|
+
Rails::Generators.invoke('declare_schema:migration', flags)
|
10
|
+
end
|
11
|
+
|
12
|
+
def expect_model_definition_to_eq(model, expectation)
|
13
|
+
expect_file_to_eq("#{TESTAPP_PATH}/app/models/#{model}.rb", expectation)
|
14
|
+
end
|
15
|
+
|
16
|
+
def expect_test_definition_to_eq(model, expectation)
|
17
|
+
expect_file_to_eq("#{TESTAPP_PATH}/test/models/#{model}_test.rb", expectation)
|
18
|
+
end
|
19
|
+
|
20
|
+
def expect_test_fixture_to_eq(model, expectation)
|
21
|
+
expect_file_to_eq("#{TESTAPP_PATH}/test/fixtures/#{model}.yml", expectation)
|
22
|
+
end
|
23
|
+
|
24
|
+
def expect_file_to_eq(file_path, expectation)
|
25
|
+
expect(File.exist?(file_path)).to be_truthy
|
26
|
+
expect(File.read(file_path)).to eq(expectation)
|
27
|
+
end
|
28
|
+
|
29
|
+
def clean_up_model(model)
|
30
|
+
system("rm -rf #{TESTAPP_PATH}/app/models/#{model}.rb #{TESTAPP_PATH}/test/models/#{model}.rb #{TESTAPP_PATH}/test/fixtures/#{model}.rb")
|
31
|
+
end
|
32
|
+
|
33
|
+
def load_models
|
34
|
+
Rails.application.config.autoload_paths += ["#{TESTAPP_PATH}/app/models"]
|
35
|
+
$LOAD_PATH << "#{TESTAPP_PATH}/app/models"
|
36
|
+
end
|
37
|
+
|
38
|
+
def migrate_up(expected_value)
|
39
|
+
MigrationUpEquals.new(expected_value)
|
40
|
+
end
|
41
|
+
|
42
|
+
def migrate_down(expected_value)
|
43
|
+
MigrationDownEquals.new(expected_value)
|
44
|
+
end
|
45
|
+
|
46
|
+
class MigrationUpEquals < RSpec::Matchers::BuiltIn::Eq
|
47
|
+
def matches?(subject)
|
48
|
+
super(subject[0])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class MigrationDownEquals < RSpec::Matchers::BuiltIn::Eq
|
53
|
+
def matches?(subject)
|
54
|
+
super(subject[1])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: declare_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca Development adapted from hobo_fields by Tom Locke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -77,7 +77,9 @@ files:
|
|
77
77
|
- spec/lib/declare_schema/interactive_primary_key_spec.rb
|
78
78
|
- spec/lib/declare_schema/migration_generator_spec.rb
|
79
79
|
- spec/lib/declare_schema/prepare_testapp.rb
|
80
|
+
- spec/lib/generators/declare_schema/migration/migrator_spec.rb
|
80
81
|
- spec/spec_helper.rb
|
82
|
+
- spec/support/acceptance_spec_helpers.rb
|
81
83
|
- test_responses.txt
|
82
84
|
homepage: https://github.com/Invoca/declare_schema
|
83
85
|
licenses: []
|