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
@@ -1,22 +0,0 @@
1
- module Mack
2
- module Configuration
3
-
4
- def self.load_database_configurations(env = Mack::Configuration.env)
5
- dbs = Mack::Configuration.database_configurations
6
- unless dbs.nil?
7
- settings = dbs[env]
8
- settings.symbolize_keys!
9
- if settings[:default]
10
- settings.each do |k,v|
11
- DataMapper::Database.setup(k, v.symbolize_keys)
12
- end
13
- else
14
- DataMapper::Database.setup(settings)
15
- end
16
- end
17
- end # load_database_configurations
18
-
19
- end # Configuration
20
- end # Mack
21
-
22
- Mack::Configuration.load_database_configurations
@@ -1,9 +0,0 @@
1
- module DataMapper
2
- module Persistence
3
-
4
- def to_param
5
- self.key
6
- end
7
-
8
- end
9
- end
@@ -1,3 +0,0 @@
1
- test:
2
- adapter: sqlite3
3
- database: <%= File.join(Mack::Configuration.root, "mack-data_mapper_test.db") %>
@@ -1,9 +0,0 @@
1
- class AddUsers < DataMapper::Migration
2
- def self.up
3
- User.create(:username => "markbates", :email => "mark@mackframework.com")
4
- end
5
-
6
- def self.down
7
- User.delete_all
8
- end
9
- end
@@ -1,4 +0,0 @@
1
- class Album
2
- include DataMapper::Persistence
3
-
4
- end
@@ -1,9 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- class AlbumTest < Test::Unit::TestCase
4
-
5
- def test_truth
6
- assert true
7
- end
8
-
9
- end
@@ -1,7 +0,0 @@
1
- class Album
2
- include DataMapper::Persistence
3
-
4
- property :title, :string
5
- property :artist_id, :integer
6
- property :description, :text
7
- end
@@ -1,12 +0,0 @@
1
- class CreateUsers < DataMapper::Migration
2
- def self.up
3
- create_table :users do |t|
4
- t.column :username, :string
5
- t.column :email, :string
6
- end
7
- end
8
-
9
- def self.down
10
- drop_table :users
11
- end
12
- end
@@ -1,3 +0,0 @@
1
- Mack::Routes.build do |r|
2
-
3
- end
@@ -1,11 +0,0 @@
1
- <h1>Edit Zoo</h1>
2
-
3
- <%= error_messages_for :zoo %>
4
-
5
- <% form(zoos_update_url(:id => @zoo), :class => "edit_zoo", :id => "edit_zoo", :method => :put) do %>
6
- <p>
7
- <input id="zoo_submit" name="commit" type="submit" value="Update" />
8
- </p>
9
- <% end %>
10
-
11
- <%= link_to("Back", zoos_index_url) %>
@@ -1,20 +0,0 @@
1
- <h1>Listing Zoos</h1>
2
-
3
- <table>
4
- <tr>
5
- <th>&nbsp;</th>
6
- </tr>
7
-
8
- <% for zoo in @zoos %>
9
- <tr>
10
- <td>&nbsp;</td>
11
- <td><%= link_to("Show", zoos_show_url(:id => zoo)) %></td>
12
- <td><%= link_to("Edit", zoos_edit_url(:id => zoo)) %></td>
13
- <td><%= link_to("Delete", zoos_delete_url(:id => zoo), :method => :delete, :confirm => "Are you sure?") %></td>
14
- </tr>
15
- <% end %>
16
- </table>
17
-
18
- <br />
19
-
20
- <%= link_to("New Zoo", zoos_new_url) %>
@@ -1,11 +0,0 @@
1
- <h1>New Zoo</h1>
2
-
3
- <%= error_messages_for :zoo %>
4
-
5
- <% form(zoos_create_url, :class => "new_zoo", :id => "new_zoo") do %>
6
- <p>
7
- <input id="zoo_submit" name="commit" type="submit" value="Create" />
8
- </p>
9
- <% end %>
10
-
11
- <%= link_to("Back", zoos_index_url) %>
@@ -1,6 +0,0 @@
1
- <p>
2
- <h1>Zoo</h1>
3
- </p>
4
-
5
- <%= link_to("Edit", zoos_edit_url(:id => @zoo)) %> |
6
- <%= link_to("Back", zoos_index_url) %>
@@ -1,19 +0,0 @@
1
- <h1>Edit Zoo</h1>
2
-
3
- <%= error_messages_for :zoo %>
4
-
5
- <% form(zoos_update_url(:id => @zoo), :class => "edit_zoo", :id => "edit_zoo", :method => :put) do %>
6
- <p>
7
- <b>Name</b><br />
8
- <input type="text" name="zoo[name]" id="zoo_name" size="30" value="<%= @zoo.name %>" />
9
- </p>
10
- <p>
11
- <b>Description</b><br />
12
- <textarea name="zoo[description]" id="zoo_description" cols="60" rows="20"><%= @zoo.description %></textarea>
13
- </p>
14
- <p>
15
- <input id="zoo_submit" name="commit" type="submit" value="Update" />
16
- </p>
17
- <% end %>
18
-
19
- <%= link_to("Back", zoos_index_url) %>
@@ -1,26 +0,0 @@
1
- <h1>Listing Zoos</h1>
2
-
3
- <table>
4
- <tr>
5
- <th>Name</th>
6
- <th>Description</th>
7
- <th>CreatedAt</th>
8
- <th>UpdatedAt</th>
9
- </tr>
10
-
11
- <% for zoo in @zoos %>
12
- <tr>
13
- <td><%= zoo.name %></td>
14
- <td><%= zoo.description %></td>
15
- <td><%= zoo.created_at %></td>
16
- <td><%= zoo.updated_at %></td>
17
- <td><%= link_to("Show", zoos_show_url(:id => zoo)) %></td>
18
- <td><%= link_to("Edit", zoos_edit_url(:id => zoo)) %></td>
19
- <td><%= link_to("Delete", zoos_delete_url(:id => zoo), :method => :delete, :confirm => "Are you sure?") %></td>
20
- </tr>
21
- <% end %>
22
- </table>
23
-
24
- <br />
25
-
26
- <%= link_to("New Zoo", zoos_new_url) %>
@@ -1,19 +0,0 @@
1
- <h1>New Zoo</h1>
2
-
3
- <%= error_messages_for :zoo %>
4
-
5
- <% form(zoos_create_url, :class => "new_zoo", :id => "new_zoo") do %>
6
- <p>
7
- <b>Name</b><br />
8
- <input type="text" name="zoo[name]" id="zoo_name" size="30" value="<%= @zoo.name %>" />
9
- </p>
10
- <p>
11
- <b>Description</b><br />
12
- <textarea name="zoo[description]" id="zoo_description" cols="60" rows="20"><%= @zoo.description %></textarea>
13
- </p>
14
- <p>
15
- <input id="zoo_submit" name="commit" type="submit" value="Create" />
16
- </p>
17
- <% end %>
18
-
19
- <%= link_to("Back", zoos_index_url) %>
@@ -1,22 +0,0 @@
1
- <p>
2
- <h1>Zoo</h1>
3
- </p>
4
- <p>
5
- <b>Name</b><br />
6
- <%= @zoo.name %>
7
- </p>
8
- <p>
9
- <b>Description</b><br />
10
- <%= @zoo.description %>
11
- </p>
12
- <p>
13
- <b>CreatedAt</b><br />
14
- <%= @zoo.created_at %>
15
- </p>
16
- <p>
17
- <b>UpdatedAt</b><br />
18
- <%= @zoo.updated_at %>
19
- </p>
20
-
21
- <%= link_to("Edit", zoos_edit_url(:id => @zoo)) %> |
22
- <%= link_to("Back", zoos_index_url) %>
@@ -1,4 +0,0 @@
1
- class Zoo
2
- include DataMapper::Persistence
3
-
4
- end
@@ -1,50 +0,0 @@
1
- class ZoosController < Mack::Controller::Base
2
-
3
- # GET /zoos
4
- def index
5
- @zoos = Zoo.all
6
- end
7
-
8
- # GET /zoos/1
9
- def show
10
- @zoo = Zoo.first(params(:id))
11
- end
12
-
13
- # GET /zoos/new
14
- def new
15
- @zoo = Zoo.new
16
- end
17
-
18
- # GET /zoos/1/edit
19
- def edit
20
- @zoo = Zoo.first(params(:id))
21
- end
22
-
23
- # POST /zoos
24
- def create
25
- @zoo = Zoo.new(params(:zoo))
26
- if @zoo.save
27
- redirect_to(zoos_show_url(:id => @zoo))
28
- else
29
- render(:action, "new")
30
- end
31
- end
32
-
33
- # PUT /zoos/1
34
- def update
35
- @zoo = Zoo.first(params(:id))
36
- if @zoo.update_attributes(params(:zoo))
37
- redirect_to(zoos_show_url(:id => @zoo))
38
- else
39
- render(:action, "edit")
40
- end
41
- end
42
-
43
- # DELETE /zoos/1
44
- def delete
45
- @zoo = Zoo.first(params(:id))
46
- @zoo.destroy!
47
- redirect_to(zoos_index_url)
48
- end
49
-
50
- end
@@ -1,71 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- class MigrationGeneratorTest < Test::Unit::TestCase
4
-
5
- def test_next_migration_number
6
- mg = MigrationGenerator.new("NAME" => "foo")
7
- assert_equal "001", mg.next_migration_number
8
- FileUtils.mkdir_p(migrations_directory)
9
- assert File.exists?(migrations_directory)
10
- File.open(File.join(migrations_directory, "001_foo.rb"), "w") {|f| f.puts ""}
11
- assert_equal "002", mg.next_migration_number
12
- end
13
-
14
- def test_generate_data_mapper
15
- generate_common
16
- mig = <<-MIG
17
- class FooBar < DataMapper::Migration
18
-
19
- def self.up
20
- end
21
-
22
- def self.down
23
- end
24
-
25
- end
26
- MIG
27
- assert_equal mig, @file_body
28
- end
29
-
30
- def test_generate_data_mapper_with_columns
31
- generate_common({"NAME" => "create_users", "cols" => "username:string,email_address:string,created_at:datetime,updated_at:datetime"})
32
- mig = <<-MIG
33
- class CreateUsers < DataMapper::Migration
34
-
35
- def self.up
36
- create_table :users do |t|
37
- t.column :username, :string
38
- t.column :email_address, :string
39
- t.column :created_at, :datetime
40
- t.column :updated_at, :datetime
41
- end
42
- end
43
-
44
- def self.down
45
- drop_table :users
46
- end
47
-
48
- end
49
- MIG
50
- assert_equal mig, @file_body
51
- end
52
-
53
- def generate_common(opts = {})
54
- 5.times do |i|
55
- options = {"NAME" => "foo_bar"}.merge(opts)
56
- mg = MigrationGenerator.run(options)
57
- assert File.exists?(migrations_directory)
58
- assert File.exists?(File.join(migrations_directory, "00#{i+1}_#{options["NAME"]}.rb"))
59
- File.open(File.join(migrations_directory, "00#{i+1}_#{options["NAME"]}.rb"), "r") do |file|
60
- @file_body = file.read
61
- end
62
- end
63
- end
64
-
65
- def test_required_params
66
- assert_raise(ArgumentError) { MigrationGenerator.new }
67
- mg = MigrationGenerator.new("NAME" => "foo")
68
- assert_not_nil mg
69
- end
70
-
71
- end
@@ -1,37 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- class ModelGeneratorTest < Test::Unit::TestCase
4
-
5
- def test_generate_data_mapper
6
- ModelGenerator.new("name" => "album").generate
7
- assert File.exists?(model_loc)
8
- assert_equal fixture("album.rb"), File.open(model_loc).read
9
- assert File.exists?(migration_loc)
10
- end
11
-
12
- def test_generate_data_mapper_with_columns
13
- ModelGenerator.new("name" => "albums", "cols" => "title:string,artist_id:integer,description:text").generate
14
- assert File.exists?(model_loc)
15
- assert_equal fixture("album_with_cols.rb"), File.open(model_loc).read
16
- assert File.exists?(migration_loc)
17
- end
18
-
19
- def test_unit_test_created
20
- ModelGenerator.new("name" => "album").generate
21
- assert File.exists?(unit_test_loc)
22
- assert_equal fixture("album_unit_test.rb"), File.open(unit_test_loc).read
23
- end
24
-
25
- def unit_test_loc
26
- File.join(test_directory, "unit", "album_test.rb")
27
- end
28
-
29
- def model_loc
30
- File.join(models_directory, "album.rb")
31
- end
32
-
33
- def migration_loc
34
- File.join(migrations_directory, "001_create_albums.rb")
35
- end
36
-
37
- end
@@ -1,61 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- class ScaffoldGeneratorTest < Test::Unit::TestCase
4
-
5
- def test_generate_data_mapper
6
- sg = ScaffoldGenerator.run("name" => "zoo")
7
- File.open(File.join(Mack::Configuration.config_directory, "routes.rb")) do |f|
8
- assert_match "r.resource :zoos # Added by rake generate:scaffold name=zoo", f.read
9
- end
10
-
11
- assert File.exists?(views_directory)
12
- assert_equal fixture("zoo_no_cols", "edit.html.erb"), File.open(File.join(views_directory, "edit.html.erb")).read
13
- assert_equal fixture("zoo_no_cols", "index.html.erb"), File.open(File.join(views_directory, "index.html.erb")).read
14
- assert_equal fixture("zoo_no_cols", "new.html.erb"), File.open(File.join(views_directory, "new.html.erb")).read
15
- assert_equal fixture("zoo_no_cols", "show.html.erb"), File.open(File.join(views_directory, "show.html.erb")).read
16
-
17
- assert File.exists?(model_file)
18
- assert File.exists?(controller_file)
19
- assert File.exists?(migration_file)
20
- assert File.exists?(functional_test_file)
21
- assert_equal fixture("zoo_with_cols", "zoos_controller.rb"), File.open(controller_file).read
22
- assert_equal fixture("zoo_with_cols", "zoo.rb"), File.open(model_file).read
23
- end
24
-
25
- def test_generate_data_mapper_with_columns
26
- sg = ScaffoldGenerator.run("name" => "zoo", "cols" => "name:string,description:text,created_at:datetime,updated_at:datetime")
27
- File.open(File.join(Mack::Configuration.config_directory, "routes.rb")) do |f|
28
- assert_match "r.resource :zoos # Added by rake generate:scaffold name=zoo", f.read
29
- end
30
- assert File.exists?(views_directory)
31
- assert_equal fixture("zoo_with_cols", "edit.html.erb"), File.open(File.join(views_directory, "edit.html.erb")).read
32
- assert_equal fixture("zoo_with_cols", "index.html.erb"), File.open(File.join(views_directory, "index.html.erb")).read
33
- assert_equal fixture("zoo_with_cols", "new.html.erb"), File.open(File.join(views_directory, "new.html.erb")).read
34
- assert_equal fixture("zoo_with_cols", "show.html.erb"), File.open(File.join(views_directory, "show.html.erb")).read
35
-
36
- assert File.exists?(model_file)
37
- assert File.exists?(controller_file)
38
- assert File.exists?(migration_file)
39
- end
40
-
41
- def functional_test_file
42
- File.join(test_directory, "functional", "zoos_controller_test.rb")
43
- end
44
-
45
- def views_directory
46
- File.join(Mack::Configuration.views_directory, "zoos")
47
- end
48
-
49
- def model_file
50
- File.join(Mack::Configuration.app_directory, "models", "zoo.rb")
51
- end
52
-
53
- def controller_file
54
- File.join(Mack::Configuration.app_directory, "controllers", "zoos_controller.rb")
55
- end
56
-
57
- def migration_file
58
- File.join(migrations_directory, "001_create_zoos.rb")
59
- end
60
-
61
- end