mack-active_record 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/lib/database.rb +118 -0
  2. data/lib/genosaurus_helpers.rb +40 -0
  3. data/lib/helpers/orm_helpers.rb +15 -15
  4. data/lib/mack-active_record.rb +16 -14
  5. data/lib/migration_generator/migration_generator.rb +1 -1
  6. data/lib/model_column.rb +55 -0
  7. data/lib/model_generator/manifest.yml +9 -1
  8. data/lib/model_generator/model_generator.rb +5 -1
  9. data/lib/model_generator/templates/rspec.rb.template +9 -0
  10. data/lib/scaffold_generator/manifest.yml +9 -2
  11. data/lib/scaffold_generator/scaffold_generator.rb +6 -5
  12. data/lib/scaffold_generator/templates/app/controllers/controller.rb.template +8 -7
  13. data/lib/scaffold_generator/templates/spec.rb.template +47 -0
  14. data/lib/tasks/db_create_drop_tasks.rake +39 -57
  15. data/lib/tasks/db_migration_tasks.rake +9 -74
  16. metadata +15 -45
  17. data/test/database.yml +0 -3
  18. data/test/fixtures/add_users_migration.rb.fixture +0 -9
  19. data/test/fixtures/album.rb.fixture +0 -3
  20. data/test/fixtures/album_unit_test.rb.fixture +0 -9
  21. data/test/fixtures/create_users_migration.rb.fixture +0 -12
  22. data/test/fixtures/routes.rb.fixture +0 -3
  23. data/test/fixtures/zoo.rb.fixture +0 -3
  24. data/test/fixtures/zoo_no_cols/edit.html.erb.fixture +0 -11
  25. data/test/fixtures/zoo_no_cols/index.html.erb.fixture +0 -20
  26. data/test/fixtures/zoo_no_cols/new.html.erb.fixture +0 -11
  27. data/test/fixtures/zoo_no_cols/show.html.erb.fixture +0 -6
  28. data/test/fixtures/zoo_with_cols/edit.html.erb.fixture +0 -19
  29. data/test/fixtures/zoo_with_cols/index.html.erb.fixture +0 -26
  30. data/test/fixtures/zoo_with_cols/new.html.erb.fixture +0 -19
  31. data/test/fixtures/zoo_with_cols/show.html.erb.fixture +0 -22
  32. data/test/fixtures/zoo_with_cols/zoos_controller.rb.fixture +0 -50
  33. data/test/generators/migration_generator_test.rb +0 -71
  34. data/test/generators/model_generator_test.rb +0 -37
  35. data/test/generators/scaffold_generator_test.rb +0 -61
  36. data/test/lib/user.rb +0 -3
  37. data/test/tasks/db_migration_tasks_test.rb +0 -57
  38. data/test/test_helper.rb +0 -77
@@ -1,57 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- class DbTasksTest < Test::Unit::TestCase
4
-
5
- $current_rake_task = File.join(File.dirname(__FILE__), "..", "..", "lib", "tasks", "db_migration_tasks.rake")
6
-
7
- def test_db_rollback
8
- test_db_migrate
9
- si = SchemaInfo.find(:first)
10
- assert_equal 2, si.version
11
- assert_equal 1, User.count
12
- rake_task("db:rollback")
13
- si = SchemaInfo.find(:first)
14
- assert_equal 1, si.version
15
- assert_equal 0, User.count
16
- end
17
-
18
- def test_db_rollback_two_steps
19
- test_db_migrate
20
- si = SchemaInfo.find(:first)
21
- assert_equal 2, si.version
22
- rake_task("db:rollback", "STEP" => "2")
23
- si = SchemaInfo.find(:first)
24
- assert_equal 0, si.version
25
- assert !User.table_exists?
26
- end
27
-
28
- def test_db_rollback_unrun_migrations
29
- test_db_migrate
30
- MigrationGenerator.run("name" => "create_comments")
31
- si = SchemaInfo.find(:first)
32
- assert_equal 2, si.version
33
- assert_raise(Mack::Errors::UnrunMigrations) { rake_task("db:rollback") }
34
- end
35
-
36
- def test_db_migrate
37
- assert !SchemaInfo.table_exists?
38
- rake_task("db:migrate") do
39
- assert SchemaInfo.table_exists?
40
- si = SchemaInfo.find(:first)
41
- assert_equal 0, si.version
42
- end
43
- FileUtils.cp(fixture_path("create_users_migration.rb"), File.join(migrations_directory, "001_create_users.rb"))
44
- assert !User.table_exists?
45
- rake_task("db:migrate")
46
- assert User.table_exists?
47
- si = SchemaInfo.find(:first)
48
- assert_equal 1, si.version
49
- FileUtils.cp(fixture_path("add_users_migration.rb"), File.join(migrations_directory, "002_add_users.rb"))
50
- assert_equal 0, User.count
51
- rake_task("db:migrate")
52
- assert_equal 1, User.count
53
- si = SchemaInfo.find(:first)
54
- assert_equal 2, si.version
55
- end
56
-
57
- end
data/test/test_helper.rb DELETED
@@ -1,77 +0,0 @@
1
- require "test/unit"
2
- require File.join(File.dirname(__FILE__), "..", "..", "test_helpers")
3
-
4
- module Mack
5
- module Configuration
6
- def self.method_missing(sym, *args)
7
- ev = "_mack_#{sym}".downcase
8
- return ENV[ev]
9
- end
10
-
11
- def self.set(name, value)
12
- ENV["_mack_#{name.to_s.downcase}"] = value
13
- end
14
- end
15
- end
16
-
17
- $genosaurus_output_directory = File.join(File.dirname(__FILE__), "..", "tmp")
18
-
19
- ENV["_mack_config_directory"] = File.dirname(__FILE__)
20
- ENV["_mack_root"] = $genosaurus_output_directory
21
- ENV["_mack_app_directory"] = File.join($genosaurus_output_directory, "app")
22
- ENV["_mack_env"] = "test"
23
- ENV["_mack_views_directory"] = File.join(ENV["_mack_app_directory"], "views")
24
-
25
- require File.join(File.dirname(__FILE__), "..", "lib", "mack-active_record")
26
- require File.join(File.dirname(__FILE__), "..", "..", "mack-orm_common", "lib", "mack-orm_common")
27
-
28
-
29
- load File.join(File.dirname(__FILE__), "lib", "user.rb")
30
-
31
- class Test::Unit::TestCase
32
-
33
- # place common methods, assertions, and other type things in this file so
34
- # other tests will have access to them.
35
-
36
- def cleanup
37
- ActiveRecord::Base.clear_active_connections!
38
- FileUtils.rm_rf($genosaurus_output_directory)
39
- FileUtils.rm_rf(File.join(Mack::Configuration.config_directory, "routes.rb"))
40
- end
41
-
42
- def teardown
43
- cleanup
44
- end
45
-
46
- def setup
47
- ActiveRecord::Base.clear_active_connections!
48
- [$genosaurus_output_directory, migrations_directory, models_directory].each do |d|
49
- FileUtils.mkdir_p(d)
50
- end
51
- FileUtils.cp(fixture_path("routes.rb"), File.join(Mack::Configuration.config_directory, "routes.rb"))
52
- end
53
-
54
- def migrations_directory
55
- File.join($genosaurus_output_directory, "db", "migrations")
56
- end
57
-
58
- def models_directory
59
- File.join($genosaurus_output_directory, "app", "models")
60
- end
61
-
62
- def test_directory
63
- File.join($genosaurus_output_directory, "test")
64
- end
65
-
66
- def fixture_path(*name)
67
- path = [File.dirname(__FILE__), "fixtures"]
68
- path << name
69
- path.flatten!
70
- File.join(path) + ".fixture"
71
- end
72
-
73
- def fixture(*name)
74
- File.open(fixture_path(name)).read
75
- end
76
-
77
- end