test_dummy 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -5
- data/VERSION +1 -1
- data/lib/test_dummy/railtie.rb +5 -1
- data/lib/test_dummy.rb +18 -1
- data/test/helper.rb +14 -1
- data/test/models/simple.rb +2 -2
- data/test/test_test_dummy.rb +5 -1
- data/test_dummy.gemspec +2 -2
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -9,20 +9,18 @@ declare how to dummy something:
|
|
9
9
|
|
10
10
|
class MyModel < ActiveRecord::Base
|
11
11
|
# Pass a block that defines how to dummy this attribute
|
12
|
-
|
12
|
+
dummy :name do
|
13
13
|
"user%d" % rand(10e6)
|
14
14
|
end
|
15
15
|
|
16
16
|
# Pass a block that defines how to dummy several attributes
|
17
|
-
|
17
|
+
dummy :password, :password_confirmation do
|
18
18
|
'tester'
|
19
19
|
end
|
20
20
|
|
21
21
|
# Use one of the pre-defined helper methods to dummy this attribute
|
22
|
-
|
22
|
+
dummy :nickname, :use => :random_phonetic_string
|
23
23
|
end
|
24
|
-
|
25
|
-
A standard method
|
26
24
|
|
27
25
|
== Copyright
|
28
26
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/test_dummy/railtie.rb
CHANGED
@@ -8,12 +8,16 @@ when 2
|
|
8
8
|
end
|
9
9
|
else
|
10
10
|
class TestDummy::Railtie < Rails::Railtie
|
11
|
-
|
11
|
+
def self.apply!
|
12
12
|
if (defined?(ActiveRecord))
|
13
13
|
ActiveRecord::Base.send(:include, TestDummy)
|
14
14
|
end
|
15
15
|
|
16
16
|
ActiveSupport::TestCase.send(:include, TestDummy::TestHelper)
|
17
17
|
end
|
18
|
+
|
19
|
+
config.before_configuration do
|
20
|
+
apply!
|
21
|
+
end
|
18
22
|
end
|
19
23
|
end
|
data/lib/test_dummy.rb
CHANGED
@@ -9,6 +9,10 @@ module TestDummy
|
|
9
9
|
base.send(:include, InstanceMethods)
|
10
10
|
end
|
11
11
|
|
12
|
+
def self.declare(on_class, &block)
|
13
|
+
on_class.instance_eval(&block)
|
14
|
+
end
|
15
|
+
|
12
16
|
module Support
|
13
17
|
# Combines several sets of parameters together into a single set in order
|
14
18
|
# of lowest priority to highest priority. Supplied list can contain nil
|
@@ -118,6 +122,19 @@ module TestDummy
|
|
118
122
|
# the dummy operation is completed. Returns a dummy model which has not
|
119
123
|
# been saved.
|
120
124
|
def build_dummy(with_attributes = nil)
|
125
|
+
unless (defined?(@_dummy_module))
|
126
|
+
@_dummy_module =
|
127
|
+
begin
|
128
|
+
dummy_path = File.expand_path("models/dummy/#{name.underscore}.rb", Rails.root)
|
129
|
+
|
130
|
+
if (File.exist?(dummy_path))
|
131
|
+
require dummy_path
|
132
|
+
end
|
133
|
+
rescue LoadError
|
134
|
+
false
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
121
138
|
model = new(TestDummy::Support.combine_attributes(scoped.scope_for_create, with_attributes))
|
122
139
|
|
123
140
|
yield(model) if (block_given?)
|
@@ -211,7 +228,7 @@ module TestDummy
|
|
211
228
|
when 1
|
212
229
|
block.call(model)
|
213
230
|
else
|
214
|
-
block
|
231
|
+
model.instance_eval(&block)
|
215
232
|
end
|
216
233
|
end
|
217
234
|
|
data/test/helper.rb
CHANGED
@@ -1,14 +1,27 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
|
+
ENV['RAILS_ENV'] = 'test'
|
5
|
+
|
4
6
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
7
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
8
|
|
7
9
|
gem 'rails'
|
8
10
|
require 'rails'
|
9
|
-
|
11
|
+
require 'active_record'
|
10
12
|
|
11
13
|
require 'test_dummy'
|
12
14
|
|
15
|
+
TestDummy::Railtie.apply!
|
16
|
+
|
13
17
|
class Test::Unit::TestCase
|
14
18
|
end
|
19
|
+
|
20
|
+
module TestDummy
|
21
|
+
class Application < Rails::Application
|
22
|
+
config.active_support.deprecation = :warn
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
TestDummy::Application.initialize!
|
27
|
+
ActiveRecord::Base.establish_connection(Rails.env)
|
data/test/models/simple.rb
CHANGED
data/test/test_test_dummy.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
+
require 'models/simple'
|
4
|
+
|
3
5
|
class TestTestDummy < Test::Unit::TestCase
|
4
6
|
def test_simple_model
|
5
|
-
simple = Simple.
|
7
|
+
simple = Simple.dummy
|
8
|
+
|
9
|
+
assert_equal Simple, simple.class
|
6
10
|
|
7
11
|
assert_equal [ ], simple.errors.full_messages
|
8
12
|
assert !simple.new_record?
|
data/test_dummy.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{test_dummy}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["tadman"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-06}
|
13
13
|
s.description = %q{Test Dummy allows you to define how to fake models automatically so that you can use dummy data for testing instead of fixtures. Dummy models are always generated using the current schema and don't need to me migrated like fixtures.}
|
14
14
|
s.email = %q{github@tadman.ca}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- tadman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-10-06 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|