mack-active_record 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/helpers/orm_helpers.rb +2 -2
- data/lib/mack-active_record.rb +2 -3
- data/lib/scaffold_generator/scaffold_generator.rb +1 -1
- data/lib/tasks/{db_migration_tasks.rake → db_tasks.rake} +1 -2
- data/test/database.yml +1 -1
- data/test/generators/scaffold_generator_test.rb +5 -5
- data/test/tasks/{db_migration_tasks_test.rb → db_tasks_test.rb} +1 -1
- data/test/test_helper.rb +7 -20
- metadata +5 -6
- data/lib/tasks/db_create_drop_tasks.rake +0 -70
data/lib/helpers/orm_helpers.rb
CHANGED
@@ -55,10 +55,10 @@ module Mack
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
-
File.join(
|
58
|
+
File.join(MACK_VIEWS, "application", "_error_messages.html.erb")
|
59
59
|
unless app_errors.empty?
|
60
60
|
if view_partial.nil?
|
61
|
-
if File.exist?(File.join(
|
61
|
+
if File.exist?(File.join(MACK_VIEWS, "application", "_error_messages.html.erb"))
|
62
62
|
render :partial => "application/error_messages", :locals => {:errors => app_errors}
|
63
63
|
else
|
64
64
|
render :text => DEFAULT_PARTIAL, :locals => {:errors => app_errors}
|
data/lib/mack-active_record.rb
CHANGED
@@ -4,15 +4,14 @@ require 'erubis'
|
|
4
4
|
begin
|
5
5
|
require 'mack-orm_common'
|
6
6
|
rescue Exception => e
|
7
|
-
puts e
|
8
7
|
end
|
9
8
|
|
10
9
|
require 'activerecord'
|
11
10
|
|
12
|
-
dbs =
|
11
|
+
dbs = YAML::load(Erubis::Eruby.new(IO.read(File.join(MACK_CONFIG, "database.yml"))).result)
|
13
12
|
|
14
13
|
unless dbs.nil?
|
15
|
-
ActiveRecord::Base.establish_connection(dbs[
|
14
|
+
ActiveRecord::Base.establish_connection(dbs[MACK_ENV])
|
16
15
|
class SchemaInfo < ActiveRecord::Base # :nodoc:
|
17
16
|
set_table_name 'schema_info'
|
18
17
|
end
|
@@ -20,7 +20,7 @@ class ScaffoldGenerator < Genosaurus
|
|
20
20
|
|
21
21
|
def update_routes_file
|
22
22
|
# update routes.rb
|
23
|
-
routes = File.join(
|
23
|
+
routes = File.join(MACK_CONFIG, "routes.rb")
|
24
24
|
rf = File.open(routes).read
|
25
25
|
unless rf.match(".resource :#{@name_plural}")
|
26
26
|
puts "Updating routes.rb"
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'rake'
|
2
1
|
namespace :db do
|
3
2
|
|
4
3
|
desc "Migrate the database through scripts in db/migrations"
|
@@ -72,7 +71,7 @@ namespace :db do
|
|
72
71
|
|
73
72
|
|
74
73
|
def migration_files
|
75
|
-
Dir.glob(File.join(
|
74
|
+
Dir.glob(File.join(MACK_ROOT, "db", "migrations", "*.rb"))
|
76
75
|
end
|
77
76
|
|
78
77
|
def migration_number(migration)
|
data/test/database.yml
CHANGED
@@ -4,7 +4,7 @@ class ScaffoldGeneratorTest < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
def test_generate_data_mapper
|
6
6
|
sg = ScaffoldGenerator.run("name" => "zoo")
|
7
|
-
File.open(File.join(
|
7
|
+
File.open(File.join(MACK_CONFIG, "routes.rb")) do |f|
|
8
8
|
assert_match "r.resource :zoos # Added by rake generate:scaffold name=zoo", f.read
|
9
9
|
end
|
10
10
|
|
@@ -24,7 +24,7 @@ class ScaffoldGeneratorTest < Test::Unit::TestCase
|
|
24
24
|
|
25
25
|
def test_generate_data_mapper_with_columns
|
26
26
|
sg = ScaffoldGenerator.run("name" => "zoo", "cols" => "name:string,description:text,created_at:datetime,updated_at:datetime")
|
27
|
-
File.open(File.join(
|
27
|
+
File.open(File.join(MACK_CONFIG, "routes.rb")) do |f|
|
28
28
|
assert_match "r.resource :zoos # Added by rake generate:scaffold name=zoo", f.read
|
29
29
|
end
|
30
30
|
assert File.exists?(views_directory)
|
@@ -43,15 +43,15 @@ class ScaffoldGeneratorTest < Test::Unit::TestCase
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def views_directory
|
46
|
-
File.join(
|
46
|
+
File.join(MACK_VIEWS, "zoos")
|
47
47
|
end
|
48
48
|
|
49
49
|
def model_file
|
50
|
-
File.join(
|
50
|
+
File.join(MACK_APP, "models", "zoo.rb")
|
51
51
|
end
|
52
52
|
|
53
53
|
def controller_file
|
54
|
-
File.join(
|
54
|
+
File.join(MACK_APP, "controllers", "zoos_controller.rb")
|
55
55
|
end
|
56
56
|
|
57
57
|
def migration_file
|
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../test_helper.rb'
|
|
2
2
|
|
3
3
|
class DbTasksTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
$current_rake_task = File.join(File.dirname(__FILE__), "..", "..", "lib", "tasks", "
|
5
|
+
$current_rake_task = File.join(File.dirname(__FILE__), "..", "..", "lib", "tasks", "db_tasks.rake")
|
6
6
|
|
7
7
|
def test_db_rollback
|
8
8
|
test_db_migrate
|
data/test/test_helper.rb
CHANGED
@@ -1,26 +1,13 @@
|
|
1
1
|
require "test/unit"
|
2
2
|
require File.join(File.dirname(__FILE__), "..", "..", "test_helpers")
|
3
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
4
|
$genosaurus_output_directory = File.join(File.dirname(__FILE__), "..", "tmp")
|
18
5
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
6
|
+
Object::MACK_CONFIG = File.dirname(__FILE__) unless Object.const_defined?("MACK_CONFIG")
|
7
|
+
Object::MACK_ROOT = $genosaurus_output_directory unless Object.const_defined?("MACK_ROOT")
|
8
|
+
Object::MACK_APP = File.join($genosaurus_output_directory, "app") unless Object.const_defined?("MACK_APP")
|
9
|
+
Object::MACK_ENV = "test" unless Object.const_defined?("MACK_ENV")
|
10
|
+
Object::MACK_VIEWS = File.join(MACK_APP, "views") unless Object.const_defined?("MACK_VIEWS")
|
24
11
|
|
25
12
|
require File.join(File.dirname(__FILE__), "..", "lib", "mack-active_record")
|
26
13
|
require File.join(File.dirname(__FILE__), "..", "..", "mack-orm_common", "lib", "mack-orm_common")
|
@@ -36,7 +23,7 @@ class Test::Unit::TestCase
|
|
36
23
|
def cleanup
|
37
24
|
ActiveRecord::Base.clear_active_connections!
|
38
25
|
FileUtils.rm_rf($genosaurus_output_directory)
|
39
|
-
FileUtils.rm_rf(File.join(
|
26
|
+
FileUtils.rm_rf(File.join(MACK_CONFIG, "routes.rb"))
|
40
27
|
end
|
41
28
|
|
42
29
|
def teardown
|
@@ -48,7 +35,7 @@ class Test::Unit::TestCase
|
|
48
35
|
[$genosaurus_output_directory, migrations_directory, models_directory].each do |d|
|
49
36
|
FileUtils.mkdir_p(d)
|
50
37
|
end
|
51
|
-
FileUtils.cp(fixture_path("routes.rb"), File.join(
|
38
|
+
FileUtils.cp(fixture_path("routes.rb"), File.join(MACK_CONFIG, "routes.rb"))
|
52
39
|
end
|
53
40
|
|
54
41
|
def migrations_directory
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mack-active_record
|
3
3
|
version: &id001 !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markbates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-05-
|
12
|
+
date: 2008-05-04 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -55,8 +55,7 @@ files:
|
|
55
55
|
- lib/scaffold_generator/templates/app/views/new.html.erb.template
|
56
56
|
- lib/scaffold_generator/templates/app/views/show.html.erb.template
|
57
57
|
- lib/scaffold_generator/templates/test.rb.template
|
58
|
-
- lib/tasks/
|
59
|
-
- lib/tasks/db_migration_tasks.rake
|
58
|
+
- lib/tasks/db_tasks.rake
|
60
59
|
- README
|
61
60
|
has_rdoc: true
|
62
61
|
homepage:
|
@@ -81,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
80
|
requirements: []
|
82
81
|
|
83
82
|
rubyforge_project: magrathea
|
84
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.1.1
|
85
84
|
signing_key:
|
86
85
|
specification_version: 2
|
87
86
|
summary: ActiveRecord ORM support for Mack
|
@@ -112,5 +111,5 @@ test_files:
|
|
112
111
|
- test/lib
|
113
112
|
- test/lib/user.rb
|
114
113
|
- test/tasks
|
115
|
-
- test/tasks/
|
114
|
+
- test/tasks/db_tasks_test.rb
|
116
115
|
- test/test_helper.rb
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
namespace :db do
|
3
|
-
|
4
|
-
desc "Create the database for your environment."
|
5
|
-
task :create => :environment do
|
6
|
-
drop_create_database
|
7
|
-
end
|
8
|
-
|
9
|
-
namespace :create do
|
10
|
-
|
11
|
-
desc "Creates your Full environment. Does NOT create your production database!"
|
12
|
-
task :all => :environment do
|
13
|
-
drop_create_database("development")
|
14
|
-
drop_create_database("test")
|
15
|
-
ActiveRecord::Base.establish_connection(Mack::Configuration.database_configurations["development"])
|
16
|
-
Rake::Task["db:migrate"].invoke
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
def drop_create_database(env = Mack::Configuration.env)
|
25
|
-
abcs = Mack::Configuration.database_configurations
|
26
|
-
db_settings = abcs[env]
|
27
|
-
case db_settings["adapter"]
|
28
|
-
when "mysql"
|
29
|
-
ActiveRecord::Base.establish_connection(
|
30
|
-
:adapter => "mysql",
|
31
|
-
:host => "localhost",
|
32
|
-
:database => "mysql",
|
33
|
-
:username => ENV["DB_USERNAME"] || "root",
|
34
|
-
:password => ENV["DB_PASSWORD"] || ""
|
35
|
-
)
|
36
|
-
puts "Dropping (MySQL): #{db_settings["database"]}"
|
37
|
-
ActiveRecord::Base.connection.execute "DROP DATABASE IF EXISTS `#{db_settings["database"]}`"
|
38
|
-
|
39
|
-
if db_settings["collation"]
|
40
|
-
puts "Dropping (MySQL): #{db_settings["database"]}"
|
41
|
-
ActiveRecord::Base.connection.execute "CREATE DATABASE `#{db_settings["database"]}` DEFAULT CHARACTER SET `#{db_settings["charset"] || 'utf8'}` COLLATE `#{db_settings["collation"]}`"
|
42
|
-
else
|
43
|
-
puts "Creating (MySQL): #{db_settings["database"]}"
|
44
|
-
ActiveRecord::Base.connection.execute "CREATE DATABASE `#{db_settings["database"]}` DEFAULT CHARACTER SET `#{db_settings["charset"] || 'utf8'}`"
|
45
|
-
end
|
46
|
-
when "postgresql"
|
47
|
-
ENV['PGHOST'] = db_settings["host"] if db_settings["host"]
|
48
|
-
ENV['PGPORT'] = db_settings["port"].to_s if db_settings["port"]
|
49
|
-
ENV['PGPASSWORD'] = db_settings["password"].to_s if db_settings["password"]
|
50
|
-
enc_option = "-E #{db_settings["encoding"]}" if db_settings["encoding"]
|
51
|
-
|
52
|
-
ActiveRecord::Base.clear_active_connections!
|
53
|
-
begin
|
54
|
-
puts "Dropping (PostgreSQL): #{db_settings["database"]}"
|
55
|
-
`dropdb -U "#{db_settings["username"]}" #{db_settings["database"]}`
|
56
|
-
rescue Exception => e
|
57
|
-
end
|
58
|
-
|
59
|
-
begin
|
60
|
-
puts "Creating (PostgreSQL): #{db_settings["database"]}"
|
61
|
-
`createdb #{enc_option} -U "#{db_settings["username"]}" #{db_settings["database"]}`
|
62
|
-
rescue Exception => e
|
63
|
-
end
|
64
|
-
when 'sqlite3'
|
65
|
-
ActiveRecord::Base.clear_active_connections!
|
66
|
-
FileUtils.rm_rf(db_settings["database"])
|
67
|
-
else
|
68
|
-
raise "Task not supported by '#{db_settings["adapter"]}'"
|
69
|
-
end
|
70
|
-
end
|