declare_schema 0.1.3 → 0.3.0

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -1
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +1 -3
  5. data/README.md +20 -0
  6. data/Rakefile +13 -20
  7. data/gemfiles/rails_4.gemfile +0 -1
  8. data/gemfiles/rails_5.gemfile +0 -1
  9. data/gemfiles/rails_6.gemfile +0 -1
  10. data/lib/declare_schema/model.rb +27 -24
  11. data/lib/declare_schema/model/field_spec.rb +1 -12
  12. data/lib/declare_schema/version.rb +1 -1
  13. data/lib/generators/declare_schema/migration/migration_generator.rb +20 -14
  14. data/lib/generators/declare_schema/migration/migrator.rb +50 -31
  15. data/lib/generators/declare_schema/migration/templates/migration.rb.erb +1 -1
  16. data/lib/generators/declare_schema/support/eval_template.rb +12 -3
  17. data/lib/generators/declare_schema/support/model.rb +77 -2
  18. data/spec/lib/declare_schema/api_spec.rb +125 -0
  19. data/spec/lib/declare_schema/field_declaration_dsl_spec.rb +8 -4
  20. data/spec/lib/declare_schema/generator_spec.rb +57 -0
  21. data/spec/lib/declare_schema/interactive_primary_key_spec.rb +51 -0
  22. data/spec/lib/declare_schema/migration_generator_spec.rb +795 -0
  23. data/spec/lib/declare_schema/prepare_testapp.rb +31 -0
  24. data/spec/lib/generators/declare_schema/migration/migrator_spec.rb +72 -0
  25. data/spec/spec_helper.rb +26 -0
  26. metadata +11 -12
  27. data/lib/generators/declare_schema/model/templates/model_injection.rb.erb +0 -25
  28. data/test/api.rdoctest +0 -136
  29. data/test/generators.rdoctest +0 -62
  30. data/test/interactive_primary_key.rdoctest +0 -56
  31. data/test/migration_generator.rdoctest +0 -846
  32. data/test/migration_generator_comments.rdoctestDISABLED +0 -74
  33. data/test/prepare_testapp.rb +0 -15
@@ -1,74 +0,0 @@
1
- # DeclareSchema - Migration Generator Comments
2
-
3
- Our test requires to prepare the testapp for a different environment:
4
- {.hidden}
5
-
6
- doctest_require: ENV["RAILS_ENV"] = 'mysql_test'; 'prepare_testapp'
7
-
8
- >> system "cd #{TESTAPP_PATH} && rake --trace db:setup"
9
- => true
10
-
11
- >> p Rails.env
12
- >>
13
- def nuke_model_class(klass)
14
- ActiveSupport::DescendantsTracker.instance_eval do
15
- class_variable_get('@@direct_descendants')[ActiveRecord::Base].delete(klass)
16
- end
17
- Object.instance_eval { remove_const klass.name.to_sym }
18
- end
19
-
20
- {.hidden}
21
-
22
-
23
- ## Comments
24
-
25
- Comments can be added to tables and fields with DeclareSchema.
26
-
27
- >>
28
- class Product < ActiveRecord::Base
29
- fields do
30
- name :string, comment: "short name"
31
- description :string
32
- end
33
- end
34
- >> Rails.env
35
- => "mysql_test"
36
- >> Rails::Generators.invoke 'declare_schema:migration', %w(-n -m)
37
-
38
- These comments will be saved to your schema if you have the [column_comments](http://github.com/bryanlarsen/column_comments) plugin installed. If you do not have this plugin installed, the comments will be available by querying `field_specs`:
39
-
40
- >> Product.field_specs["name"].comment
41
- => "short name"
42
-
43
- The plugin [activerecord-comments](http://github.com/bryanlarsen/activerecord-comments) may be used to get the comments from the database directly. If the plugin is installed, use this instead:
44
-
45
- Product.column("name").comment
46
-
47
- Because it will be quite common for people not to have both [column_comments](http://github.com/bryanlarsen/column_comments) and [activerecord-comments](http://github.com/bryanlarsen/activerecord-comments) installed, it is impossible for DeclareSchema to determine the difference between no previous comment and a previously missing plugin. Therefore, DeclareSchema will not generate a migration if the only change was to add a comment. DeclareSchema will generate a migration for a comment change, but only if the plugin is installed.
48
-
49
- >> require 'activerecord-comments'
50
-
51
- >> # manually add comment as the column_comments plugin would
52
- >> Product.connection.execute "alter table `products` modify `name` varchar(255) default null comment 'short name';"
53
-
54
- >>
55
- class Product < ActiveRecord::Base
56
- fields do
57
- name :string, comment: "Short namex"
58
- description :string, comment: "Long name"
59
- end
60
- end
61
- >> up, down = Generators::DeclareSchema::Migration::Migrator.run
62
- >> up.split(',').slice(0,3).join(',')
63
- => 'change_column :products, :name, :string'
64
- >> up.split(',').slice(3,2).sort.join(',')
65
- => " :comment => \"Short namex\", :limit => 255"
66
-
67
-
68
- Cleanup
69
- {.hidden}
70
-
71
- >> nuke_model_class(Product)
72
- >> ActiveRecord::Base.connection.execute "drop table `products`;"
73
- >> system "cd #{TESTAPP_PATH} && rake db:drop RAILS_ENV=mysql_test"
74
- {.hidden}
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'fileutils'
4
- require 'tmpdir'
5
-
6
- TESTAPP_PATH = ENV['TESTAPP_PATH'] || File.join(Dir.tmpdir, 'declare_schema_testapp')
7
- system %(rake test:prepare_testapp TESTAPP_PATH=#{TESTAPP_PATH})
8
- system %(echo "gem 'kramdown'" >> #{TESTAPP_PATH}/Gemfile)
9
- system %(echo "gem 'RedCloth'" >> #{TESTAPP_PATH}/Gemfile)
10
- FileUtils.chdir TESTAPP_PATH
11
- system "mkdir -p #{TESTAPP_PATH}/app/assets/config"
12
- system "echo '' >> #{TESTAPP_PATH}/app/assets/config/manifest.js"
13
- require "#{TESTAPP_PATH}/config/environment"
14
- require 'rails/generators'
15
- Rails::Generators.configure!(Rails.application.config.generators)