Sutto-reversible_data 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/reversible_data/table.rb +1 -1
- data/test/table_test.rb +30 -3
- data/test/test_helper.rb +15 -0
- metadata +3 -4
@@ -62,7 +62,7 @@ module ReversibleData
|
|
62
62
|
return if Object.const_defined?(@model_name)
|
63
63
|
@model = Class.new(ActiveRecord::Base)
|
64
64
|
@model.class_eval(&@model_definition) unless @model_definition.nil?
|
65
|
-
@model.blueprint(&@blueprint) unless @blueprint.nil?
|
65
|
+
@model.blueprint(&@blueprint) unless @blueprint.nil? || !@model.respond_to?(:blueprint)
|
66
66
|
Object.const_set(@model_name, @model)
|
67
67
|
end
|
68
68
|
|
data/test/table_test.rb
CHANGED
@@ -76,9 +76,25 @@ class TableTest < Test::Unit::TestCase
|
|
76
76
|
assert !defined?(::User)
|
77
77
|
end
|
78
78
|
|
79
|
-
should 'let you call up! to create the table and the model'
|
79
|
+
should 'let you call up! to create the table and the model' do
|
80
|
+
assert !defined?(::User)
|
81
|
+
assert !ActiveRecord::Base.connection.table_exists?(:users)
|
82
|
+
table = ReversibleData::Table.new(:user) { |t| t.string :name }
|
83
|
+
table.up!
|
84
|
+
assert defined?(::User)
|
85
|
+
assert ActiveRecord::Base.connection.table_exists?(:users)
|
86
|
+
assert User < ActiveRecord::Base
|
87
|
+
end
|
80
88
|
|
81
|
-
should 'let you call down! to clean up'
|
89
|
+
should 'let you call down! to clean up' do
|
90
|
+
table = ReversibleData::Table.new(:user) { |t| t.string :name }
|
91
|
+
table.up!
|
92
|
+
assert ActiveRecord::Base.connection.table_exists?(:users)
|
93
|
+
assert User < ActiveRecord::Base
|
94
|
+
table.down!
|
95
|
+
assert !ActiveRecord::Base.connection.table_exists?(:users)
|
96
|
+
assert !defined?(::User)
|
97
|
+
end
|
82
98
|
|
83
99
|
should 'default to skipping model if the constant exists' do
|
84
100
|
::Awesome = true
|
@@ -107,7 +123,18 @@ class TableTest < Test::Unit::TestCase
|
|
107
123
|
table.remove_model
|
108
124
|
end
|
109
125
|
|
110
|
-
should 'let
|
126
|
+
should 'let not call the blueprint if none is specified' do
|
127
|
+
table = ReversibleData::Table.new(:user) { |t| t.string :name }
|
128
|
+
table.up!
|
129
|
+
assert !User.blueprint_called
|
130
|
+
end
|
131
|
+
|
132
|
+
should 'call the blueprint if present' do
|
133
|
+
table = ReversibleData::Table.new(:user) { |t| t.string :name }
|
134
|
+
table.blueprint {}
|
135
|
+
table.up!
|
136
|
+
assert User.blueprint_called
|
137
|
+
end
|
111
138
|
|
112
139
|
end
|
113
140
|
end
|
data/test/test_helper.rb
CHANGED
@@ -7,4 +7,19 @@ require 'reversible_data'
|
|
7
7
|
|
8
8
|
class Test::Unit::TestCase
|
9
9
|
include RR::Adapters::TestUnit
|
10
|
+
end
|
11
|
+
|
12
|
+
module MockBlueprints
|
13
|
+
|
14
|
+
def blueprint(&blk)
|
15
|
+
# Use this as a kind of hacky way to ensure it is called.
|
16
|
+
self.blueprint_called = true
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
ActiveRecord::Base.class_eval do
|
22
|
+
class_inheritable_accessor :blueprint_called
|
23
|
+
self.blueprint_called = false
|
24
|
+
extend MockBlueprints
|
10
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Sutto-reversible_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darcy Laycock
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -33,7 +33,6 @@ files:
|
|
33
33
|
- test/test_helper.rb
|
34
34
|
has_rdoc: false
|
35
35
|
homepage: http://sutto.net/
|
36
|
-
licenses:
|
37
36
|
post_install_message:
|
38
37
|
rdoc_options: []
|
39
38
|
|
@@ -54,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
53
|
requirements: []
|
55
54
|
|
56
55
|
rubyforge_project:
|
57
|
-
rubygems_version: 1.
|
56
|
+
rubygems_version: 1.2.0
|
58
57
|
signing_key:
|
59
58
|
specification_version: 3
|
60
59
|
summary: Reversible Data provides migration-like functionality for tests etc - All with temporary models.
|