mack-data_mapper 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 (57) hide show
  1. data/README +6 -0
  2. data/lib/database.rb +94 -0
  3. data/lib/dm_patches/confirmation_validation.rb +19 -0
  4. data/lib/dm_patches/dm-cli.rb +1 -0
  5. data/lib/dm_patches/migrations.rb +23 -0
  6. data/lib/dm_patches/pooling.rb +229 -0
  7. data/lib/genosaurus_helpers.rb +40 -0
  8. data/lib/helpers/orm_helpers.rb +50 -21
  9. data/lib/mack-data_mapper.rb +43 -16
  10. data/lib/migration_generator/migration_generator.rb +28 -17
  11. data/lib/migration_generator/templates/db/migrations/%=@migration_name%.rb.template +6 -6
  12. data/lib/model_column.rb +42 -0
  13. data/lib/model_generator/manifest.yml +9 -2
  14. data/lib/model_generator/model_generator.rb +25 -20
  15. data/lib/model_generator/templates/model.rb.template +4 -4
  16. data/lib/model_generator/templates/rspec.rb.template +7 -0
  17. data/lib/model_generator/templates/{test.rb.template → test_case.rb.template} +0 -0
  18. data/lib/resource.rb +17 -0
  19. data/lib/runner.rb +17 -0
  20. data/lib/scaffold_generator/manifest.yml +14 -3
  21. data/lib/scaffold_generator/scaffold_generator.rb +4 -4
  22. data/lib/scaffold_generator/templates/app/controllers/controller.rb.template +10 -9
  23. data/lib/scaffold_generator/templates/app/helpers/controllers/helper.rb.template +7 -0
  24. data/lib/scaffold_generator/templates/app/views/edit.html.erb.template +1 -1
  25. data/lib/scaffold_generator/templates/app/views/new.html.erb.template +1 -1
  26. data/lib/scaffold_generator/templates/test/functional/rspec.rb.template +47 -0
  27. data/lib/scaffold_generator/templates/{test.rb.template → test/functional/test_case.rb.template} +0 -0
  28. data/lib/tasks/db_create_drop_tasks.rake +43 -62
  29. data/lib/tasks/db_migration_tasks.rake +25 -62
  30. data/lib/tasks/test_tasks.rake +12 -0
  31. data/lib/test_extensions.rb +90 -0
  32. metadata +28 -52
  33. data/lib/configuration.rb +0 -22
  34. data/lib/persistence.rb +0 -9
  35. data/test/database.yml +0 -3
  36. data/test/fixtures/add_users_migration.rb.fixture +0 -9
  37. data/test/fixtures/album.rb.fixture +0 -4
  38. data/test/fixtures/album_unit_test.rb.fixture +0 -9
  39. data/test/fixtures/album_with_cols.rb.fixture +0 -7
  40. data/test/fixtures/create_users_migration.rb.fixture +0 -12
  41. data/test/fixtures/routes.rb.fixture +0 -3
  42. data/test/fixtures/zoo_no_cols/edit.html.erb.fixture +0 -11
  43. data/test/fixtures/zoo_no_cols/index.html.erb.fixture +0 -20
  44. data/test/fixtures/zoo_no_cols/new.html.erb.fixture +0 -11
  45. data/test/fixtures/zoo_no_cols/show.html.erb.fixture +0 -6
  46. data/test/fixtures/zoo_with_cols/edit.html.erb.fixture +0 -19
  47. data/test/fixtures/zoo_with_cols/index.html.erb.fixture +0 -26
  48. data/test/fixtures/zoo_with_cols/new.html.erb.fixture +0 -19
  49. data/test/fixtures/zoo_with_cols/show.html.erb.fixture +0 -22
  50. data/test/fixtures/zoo_with_cols/zoo.rb.fixture +0 -4
  51. data/test/fixtures/zoo_with_cols/zoos_controller.rb.fixture +0 -50
  52. data/test/generators/migration_generator_test.rb +0 -71
  53. data/test/generators/model_generator_test.rb +0 -37
  54. data/test/generators/scaffold_generator_test.rb +0 -61
  55. data/test/lib/user.rb +0 -6
  56. data/test/tasks/db_migration_tasks_test.rb +0 -57
  57. data/test/test_helper.rb +0 -77
@@ -0,0 +1,7 @@
1
+ module Mack
2
+ module ControllerHelpers
3
+ module <%= @name_plural_camel %>Controller
4
+ # methods here will automatically be included as protected methods into <%= @name_plural_camel %>Controller
5
+ end
6
+ end
7
+ end
@@ -12,7 +12,7 @@
12
12
  <% end -%>
13
13
  <% end -%>
14
14
  <p>
15
- <input id="<%= @name_singular %>_submit" name="commit" type="submit" value="Update" />
15
+ <%%= submit_tag("Update") %>
16
16
  </p>
17
17
  <%% end %>
18
18
 
@@ -12,7 +12,7 @@
12
12
  <% end -%>
13
13
  <% end -%>
14
14
  <p>
15
- <input id="<%= @name_singular %>_submit" name="commit" type="submit" value="Create" />
15
+ <%%= submit_tag("Create") %>
16
16
  </p>
17
17
  <%% end %>
18
18
 
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
+
3
+ describe <%= @name_plural_camel %>Controller do
4
+
5
+ describe "index" do
6
+
7
+ it "should list <%= @name_plural %>"
8
+
9
+ end
10
+
11
+ describe "show" do
12
+
13
+ it "should show a <%= @name_singular %>"
14
+
15
+ end
16
+
17
+ describe "new" do
18
+
19
+ it "should show a form to create a new <%= @name_singular %>"
20
+
21
+ end
22
+
23
+ describe "edit" do
24
+
25
+ it "should edit a <%= @name_singular %>"
26
+
27
+ end
28
+
29
+ describe "create" do
30
+
31
+ it "should create a <%= @name_singular %>"
32
+
33
+ end
34
+
35
+ describe "update" do
36
+
37
+ it "should update a <%= @name_singular %>"
38
+
39
+ end
40
+
41
+ describe "delete" do
42
+
43
+ it "should delete a <%= @name_singular %>"
44
+
45
+ end
46
+
47
+ end
@@ -1,76 +1,57 @@
1
1
  require 'rake'
2
2
  namespace :db do
3
3
 
4
- desc "Create the database for your environment."
4
+ desc "Drops (if it exists) the database and then creates it for your environment."
5
+ task :recreate => :environment do
6
+ Mack::Database.drop(Mack.env, repis)
7
+ Mack::Database.create(Mack.env, repis)
8
+ end
9
+
10
+ desc "Creates the database for your environment."
5
11
  task :create => :environment do
6
- Mack::Configuration.load_database_configurations(Mack::Configuration.env)
7
- database(:default) do
8
- drop_create_database
9
- end
12
+ Mack::Database.create(Mack.env, repis)
13
+ end
14
+
15
+ desc "Drops the database for your environment."
16
+ task :drop => :environment do
17
+ Mack::Database.drop(Mack.env, repis)
10
18
  end
11
19
 
12
20
  namespace :create do
13
21
 
14
- desc "Creates your Full environment. Does NOT create your production database!"
22
+ desc "Creates your test and development databases. Does NOT create your production database!"
15
23
  task :all => :environment do
16
- Mack::Configuration.load_database_configurations("test")
17
- database(:default) do
18
- drop_create_database
19
- end
20
- Mack::Configuration.load_database_configurations("development")
21
- database(:default) do
22
- drop_create_database
23
- end
24
- Rake::Task["db:migrate"].invoke
24
+ Mack::Database.create("test", repis)
25
+ Mack::Database.create("development", repis)
25
26
  end
26
27
 
27
28
  end
28
-
29
- end
30
-
31
- private
32
- def drop_create_database
33
- configuration = database.adapter.instance_variable_get('@configuration')
34
- case database.adapter.class.name
35
- when "DataMapper::Adapters::MysqlAdapter"
36
- DataMapper::Database.setup(:tmp, {
37
- :adapter => "mysql",
38
- :host => "localhost",
39
- :database => "mysql",
40
- :username => ENV["DB_USERNAME"] || "root",
41
- :password => ENV["DB_PASSWORD"] || ""
42
- })
43
- database(:tmp) do
44
- puts "Dropping (MySQL): #{configuration.database}"
45
- database.execute "DROP DATABASE IF EXISTS `#{configuration.database}`"
46
- puts "Creating (MySQL): #{configuration.database}"
47
- database.execute "CREATE DATABASE `#{configuration.database}` DEFAULT CHARACTER SET `utf8`"
48
- begin
49
- database.adapter.flush_connections!
50
- rescue Exception => e
51
- end
52
- end
53
- when "DataMapper::Adapters::PostgresqlAdapter"
54
- ENV['PGHOST'] = configuration.host if configuration.host
55
- ENV['PGPORT'] = configuration.port.to_s if configuration.port
56
- ENV['PGPASSWORD'] = configuration.password.to_s if configuration.password
57
-
58
- database.adapter.flush_connections!
59
- begin
60
- puts "Dropping (PostgreSQL): #{configuration.database}"
61
- `dropdb -U "#{configuration.username}" #{configuration.database}`
62
- rescue Exception => e
63
- end
64
-
65
- begin
66
- puts "Creating (PostgreSQL): #{configuration.database}"
67
- `createdb -U "#{configuration.username}" #{configuration.database}`
68
- rescue Exception => e
69
- end
70
- when 'DataMapper::Adapters::Sqlite3Adapter'
71
- puts "Dropping (SQLite3): #{configuration.database}"
72
- FileUtils.rm_rf(configuration.database)
73
- else
74
- raise "Task not supported for '#{database.adapter}'"
29
+
30
+ namespace :drop do
31
+
32
+ desc "Drops your test and development databases. Does NOT create your production database!"
33
+ task :all => :environment do
34
+ Mack::Database.drop("test", repis)
35
+ Mack::Database.drop("development", repis)
36
+ end
37
+
75
38
  end
39
+
40
+ namespace :recreate do
41
+
42
+ desc "Drops and creates your test and development databases. Does NOT create your production database!"
43
+ task :all => :environment do
44
+ Mack::Database.drop("test", repis)
45
+ Mack::Database.create("test", repis)
46
+ Mack::Database.drop("development", repis)
47
+ Mack::Database.create("development", repis)
48
+ end
49
+
50
+ end
51
+
52
+ private
53
+ def repis
54
+ (ENV["REPO"] ||= "default").to_sym
55
+ end
56
+
76
57
  end
@@ -1,83 +1,46 @@
1
1
  require 'rake'
2
2
  namespace :db do
3
3
 
4
+
5
+
4
6
  desc "Migrate the database through scripts in db/migrations"
5
- task :migrate => "db:schema:create" do
6
- migration_files.each do |migration|
7
- require migration
8
- migration = File.basename(migration, ".rb")
9
- m_number = migration_number(migration)
10
- if m_number > @schema_info.version
11
- migration_name(migration).camelcase.constantize.up
12
- @schema_info.version += 1
13
- @schema_info.save
14
- end
15
- end # each
7
+ task :migrate => "mack:environment" do
8
+ require 'migration_runner'
9
+ include DataMapper::Types
10
+ DataMapper::MigrationRunner.reset!
11
+ migration_files.each { |mig| load mig }
12
+ DataMapper::MigrationRunner.migrate_up!
16
13
  end # migrate
17
14
 
18
15
  desc "Rolls the schema back to the previous version. Specify the number of steps with STEP=n"
19
- task :rollback => ["db:schema:create", "db:abort_if_pending_migrations"] do
20
- migrations = migration_files.reverse
21
- (ENV["STEP"] || 1).to_i.times do |step|
22
- migration = migrations[step]
23
- require migration
24
- migration = File.basename(migration, ".rb")
25
- m_number = migration_number(migration)
26
- if m_number == @schema_info.version
27
- migration_name(migration).camelcase.constantize.down
28
- @schema_info.version -= 1
29
- @schema_info.save
30
- end
16
+ task :rollback => ["mack:environment", "db:abort_if_pending_migrations"] do
17
+ require 'dm-core/types'
18
+ require 'migration_runner'
19
+ include DataMapper::Types
20
+ DataMapper::MigrationRunner.reset!
21
+ migration_files.each { |mig| load mig }
22
+ step = (ENV["STEP"] || 1).to_i
23
+ migrations = DataMapper::MigrationRunner.migrations.sort.reverse
24
+ step.times do |i|
25
+ migrations[migrations.size - (i + 1)].perform_down
31
26
  end
32
-
33
27
  end # rollback
34
28
 
35
29
  desc "Raises an error if there are pending migrations"
36
30
  task :abort_if_pending_migrations do
37
- migrations = migration_files.reverse
38
- return if migrations.empty?
39
- migration = migrations.first
40
- migration = File.basename(migration, ".rb")
41
- m_number = migration_number(migration)
42
- if m_number > @schema_info.version
43
- raise Mack::Errors::UnrunMigrations.new(m_number - @schema_info.version)
31
+ require 'dm-core/types'
32
+ require 'migration_runner'
33
+ migration_files.each { |mig| load mig }
34
+ DataMapper::MigrationRunner.migrations.each do |mig|
35
+ raise Mack::Errors::UnrunMigrations.new(mig.name) if mig.send("needs_up?")
44
36
  end
45
- end
46
-
47
- desc "Displays the current schema version of your database"
48
- task :version => "db:schema:create" do
49
- puts "\nYour database is currently at version: #{@schema_info.version}\n"
37
+ DataMapper::MigrationRunner.migrations.clear
50
38
  end
51
39
 
52
40
  private
53
- namespace :schema do
54
-
55
- task :create => "mack:environment" do
56
- require 'data_mapper/migration'
57
- unless SchemaInfo.table.exists?
58
- class SchemaInfo
59
- include DataMapper::Persistence
60
- property :version, :integer
61
- end
62
- SchemaInfo.auto_migrate!
63
- SchemaInfo.create(:version => 0, :id => 1)
64
- end
65
- @schema_info = SchemaInfo.first
66
- end # create
67
-
68
- end # schema
69
-
70
41
 
71
42
  def migration_files
72
- Dir.glob(File.join(Mack::Configuration.root, "db", "migrations", "*.rb"))
73
- end
74
-
75
- def migration_number(migration)
76
- migration.match(/(^\d+)/).captures.last.to_i
77
- end
78
-
79
- def migration_name(migration)
80
- migration.match(/^\d+_(.+)/).captures.last
43
+ Dir.glob(File.join(Mack.root, "db", "migrations", "*.rb"))
81
44
  end
82
45
 
83
46
  end # db
@@ -0,0 +1,12 @@
1
+ namespace :test do
2
+
3
+ task :setup do
4
+ unless ENV["MACK_TEST_ENV_SETUP?"] == "true"
5
+ ENV["MACK_ENV"] = "test"
6
+ Rake::Task["db:recreate"].invoke
7
+ Rake::Task["db:migrate"].invoke
8
+ ENV["MACK_TEST_ENV_SETUP?"] = "true"
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,90 @@
1
+ require "test/unit"
2
+ require 'spec'
3
+
4
+ if Mack.env == "test"
5
+ module Mack
6
+ module Testing # :nodoc:
7
+ end
8
+ end
9
+
10
+ # Wrap it so we don't accidentally alias the run method n times and run out of db connections!
11
+ unless Mack::Testing.const_defined?("DmTestTransactionWrapper")
12
+
13
+ module Mack
14
+ module Testing
15
+ module Helpers
16
+ alias_method :mack_rake_task, :rake_task
17
+
18
+ def rake_task(name, env = {})
19
+ DataMapper::MigrationRunner.reset!
20
+ mack_rake_task(name, env, [File.join(File.dirname(__FILE__), "..", "lib", "tasks", "db_create_drop_tasks.rake"),
21
+ File.join(File.dirname(__FILE__), "..", "lib", "tasks", "db_migration_tasks.rake")])
22
+ end
23
+ end # Helpers
24
+
25
+ class DmTestTransactionWrapper # :nodoc:
26
+ include DataMapper::Resource
27
+ end
28
+
29
+ module DataMapperHelpers
30
+ def rollback_transaction
31
+ begin
32
+ Mack::Testing::DmTestTransactionWrapper.transaction do
33
+ # DataMapper::Transaction.new.commit do
34
+ yield if block_given?
35
+ raise "Rollback!"
36
+ end
37
+ rescue => ex
38
+ # we need to do this so we can throw up actual errors!
39
+ unless ex.to_s == "Rollback!"
40
+ raise ex
41
+ end
42
+ end
43
+ end # rollback_transaction
44
+ end # DataMapperHelpers
45
+ end # Testing
46
+ end # Mack
47
+
48
+
49
+ module Spec # :nodoc:
50
+ module Example # :nodoc:
51
+ module ExampleMethods # :nodoc:
52
+ include Mack::Testing::DataMapperHelpers
53
+
54
+ alias_method :dm_spec_execute, :execute
55
+
56
+ def execute(options, instance_variables)
57
+ rollback_transaction do
58
+ @__res = dm_spec_execute(options, instance_variables)
59
+ end
60
+ @__res
61
+ end
62
+
63
+ end # ExampleGroup
64
+ end # Example
65
+ end # Spec
66
+
67
+ module Test # :nodoc:
68
+ module Unit # :nodoc:
69
+ class TestCase # :nodoc:
70
+ include Mack::Testing::DataMapperHelpers
71
+
72
+ # Let's alias the run method in the class above us so we can create a new one here
73
+ # but still reference it.
74
+ alias_method :dm_test_case_run, :run # :nodoc:
75
+
76
+ # We need to wrap the run method so we can do things like
77
+ # run a cleanup method if it exists
78
+ def run(result, &progress_block) # :nodoc:
79
+ rollback_transaction do
80
+ dm_test_case_run(result, &progress_block)
81
+ end
82
+ end
83
+
84
+ end # TestCase
85
+ end # Unit
86
+ end # Test
87
+
88
+ end
89
+
90
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mack-data_mapper
3
- version: &id001 !ruby/object:Gem::Version
4
- version: 0.5.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
@@ -9,59 +9,63 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-21 00:00:00 -04:00
12
+ date: 2008-07-16 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: mack-orm_common
17
- version_requirement:
18
- version_requirements: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - "="
21
- - *id001
22
- version:
23
- - !ruby/object:Gem::Dependency
24
- name: datamapper
16
+ name: data_mapper
25
17
  version_requirement:
26
18
  version_requirements: !ruby/object:Gem::Requirement
27
19
  requirements:
28
20
  - - "="
29
21
  - !ruby/object:Gem::Version
30
- version: 0.3.2
22
+ version: 0.9.2
31
23
  version:
32
24
  description: "mack-data_mapper was developed by: markbates"
33
- email:
25
+ email: mark@mackframework.com
34
26
  executables: []
35
27
 
36
28
  extensions: []
37
29
 
38
- extra_rdoc_files: []
39
-
30
+ extra_rdoc_files:
31
+ - README
40
32
  files:
41
- - lib/configuration.rb
33
+ - lib/database.rb
34
+ - lib/dm_patches/confirmation_validation.rb
35
+ - lib/dm_patches/dm-cli.rb
36
+ - lib/dm_patches/migrations.rb
37
+ - lib/dm_patches/pooling.rb
38
+ - lib/genosaurus_helpers.rb
42
39
  - lib/helpers/orm_helpers.rb
43
40
  - lib/mack-data_mapper.rb
44
41
  - lib/mack-data_mapper_tasks.rb
45
42
  - lib/migration_generator/migration_generator.rb
46
43
  - lib/migration_generator/templates/db/migrations/%=@migration_name%.rb.template
44
+ - lib/model_column.rb
47
45
  - lib/model_generator/manifest.yml
48
46
  - lib/model_generator/model_generator.rb
49
47
  - lib/model_generator/templates/model.rb.template
50
- - lib/model_generator/templates/test.rb.template
51
- - lib/persistence.rb
48
+ - lib/model_generator/templates/rspec.rb.template
49
+ - lib/model_generator/templates/test_case.rb.template
50
+ - lib/resource.rb
51
+ - lib/runner.rb
52
52
  - lib/scaffold_generator/manifest.yml
53
53
  - lib/scaffold_generator/scaffold_generator.rb
54
54
  - lib/scaffold_generator/templates/app/controllers/controller.rb.template
55
+ - lib/scaffold_generator/templates/app/helpers/controllers/helper.rb.template
55
56
  - lib/scaffold_generator/templates/app/views/edit.html.erb.template
56
57
  - lib/scaffold_generator/templates/app/views/index.html.erb.template
57
58
  - lib/scaffold_generator/templates/app/views/new.html.erb.template
58
59
  - lib/scaffold_generator/templates/app/views/show.html.erb.template
59
- - lib/scaffold_generator/templates/test.rb.template
60
+ - lib/scaffold_generator/templates/test/functional/rspec.rb.template
61
+ - lib/scaffold_generator/templates/test/functional/test_case.rb.template
60
62
  - lib/tasks/db_create_drop_tasks.rake
61
63
  - lib/tasks/db_migration_tasks.rake
64
+ - lib/tasks/test_tasks.rake
65
+ - lib/test_extensions.rb
62
66
  - README
63
67
  has_rdoc: true
64
- homepage:
68
+ homepage: http://www.mackframework.com
65
69
  post_install_message:
66
70
  rdoc_options: []
67
71
 
@@ -72,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
76
  requirements:
73
77
  - - ">="
74
78
  - !ruby/object:Gem::Version
75
- version: "0"
79
+ version: 1.8.6
76
80
  version:
77
81
  required_rubygems_version: !ruby/object:Gem::Requirement
78
82
  requirements:
@@ -87,33 +91,5 @@ rubygems_version: 1.1.1
87
91
  signing_key:
88
92
  specification_version: 2
89
93
  summary: DataMapper ORM support for Mack
90
- test_files:
91
- - test/database.yml
92
- - test/fixtures
93
- - test/fixtures/add_users_migration.rb.fixture
94
- - test/fixtures/album.rb.fixture
95
- - test/fixtures/album_unit_test.rb.fixture
96
- - test/fixtures/album_with_cols.rb.fixture
97
- - test/fixtures/create_users_migration.rb.fixture
98
- - test/fixtures/routes.rb.fixture
99
- - test/fixtures/zoo_no_cols
100
- - test/fixtures/zoo_no_cols/edit.html.erb.fixture
101
- - test/fixtures/zoo_no_cols/index.html.erb.fixture
102
- - test/fixtures/zoo_no_cols/new.html.erb.fixture
103
- - test/fixtures/zoo_no_cols/show.html.erb.fixture
104
- - test/fixtures/zoo_with_cols
105
- - test/fixtures/zoo_with_cols/edit.html.erb.fixture
106
- - test/fixtures/zoo_with_cols/index.html.erb.fixture
107
- - test/fixtures/zoo_with_cols/new.html.erb.fixture
108
- - test/fixtures/zoo_with_cols/show.html.erb.fixture
109
- - test/fixtures/zoo_with_cols/zoo.rb.fixture
110
- - test/fixtures/zoo_with_cols/zoos_controller.rb.fixture
111
- - test/generators
112
- - test/generators/migration_generator_test.rb
113
- - test/generators/model_generator_test.rb
114
- - test/generators/scaffold_generator_test.rb
115
- - test/lib
116
- - test/lib/user.rb
117
- - test/tasks
118
- - test/tasks/db_migration_tasks_test.rb
119
- - test/test_helper.rb
94
+ test_files: []
95
+