temping 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +78 -34
- data/VERSION +1 -1
- data/lib/temping.rb +3 -5
- data/spec/temping_spec.rb +3 -3
- metadata +4 -2
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009-2010 John Pignata
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,49 +1,93 @@
|
|
1
1
|
# Temping
|
2
2
|
|
3
|
-
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Temping allows you to create arbitrary ActiveRecord models backed by a temporary SQL table for use in tests.
|
6
|
+
|
7
|
+
Use cases for this include:
|
8
|
+
|
9
|
+
* Testing a module that extends an ActiveRecord::Base-derived model without depending on a concrete Class in your application that's subject to change or disappear
|
10
|
+
* Tests for ActiveRecord extending plug-ins that must be tested against an ActiveRecord::Base-derived Class
|
11
|
+
|
12
|
+
Temping will use your existing database connection. If one does not exist, it will create and connect to an in-memory SQLite3 instance.
|
13
|
+
|
14
|
+
As we're using temporary tables all data will be dropped when the database connection is terminated.
|
15
|
+
|
16
|
+
## Examples
|
17
|
+
|
18
|
+
The basic setup of a model involves calling _create_model_ with a symbol that represents the plural table name of the model you wish to create. By default, this will create a temporary table with an _id_ column.
|
4
19
|
|
5
20
|
include Temping
|
6
21
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
validates_presence_of :headline
|
16
|
-
|
17
|
-
def popular?
|
18
|
-
view_count > 100
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
+
create_model :dogs
|
23
|
+
|
24
|
+
Dog.create => #<Dog id: 1>
|
25
|
+
|
26
|
+
Additional database columns can be specified via the _with_columns_ method which uses Rails migration syntax:
|
27
|
+
|
28
|
+
include Temping
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
p.headline = "Headline"
|
28
|
-
p.view_count = 200
|
29
|
-
end
|
30
|
-
|
31
|
-
post.should be_popular
|
32
|
-
end
|
30
|
+
create_model :dogs do
|
31
|
+
with_columns do |t|
|
32
|
+
t.string :name
|
33
|
+
t.integer :age, :weight
|
33
34
|
end
|
34
|
-
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
Dog.create => #<Dog id: 1, name: nil, age: nil, weight: nil>
|
38
|
+
|
39
|
+
When a block is passed to _create_model_, it is evaluated in the context of the ActiveRecord class. This means anything you do in an ActiveRecord model can be accomplished in the block including method definitions, validations, module includes, etc.
|
40
|
+
|
39
41
|
include Temping
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
create_model :dogs do
|
44
|
+
include Duckish
|
45
|
+
|
46
|
+
with_columns do |t|
|
47
|
+
t.string :name
|
48
|
+
t.integer :age, :weight
|
49
|
+
end
|
50
|
+
|
51
|
+
validates_presence_of :name
|
52
|
+
|
53
|
+
def quack
|
54
|
+
"arf!"
|
44
55
|
end
|
45
56
|
end
|
46
57
|
|
47
|
-
|
58
|
+
Dog.create! => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
|
59
|
+
codey = Dog.create!(:name => 'Codey')
|
60
|
+
codey.quack => "arf!"
|
48
61
|
|
49
|
-
|
62
|
+
## Installation
|
63
|
+
|
64
|
+
jp@populuxe:~$ gem install temping
|
65
|
+
|
66
|
+
## Bugs, Features, Feedback
|
67
|
+
|
68
|
+
Tickets can be submitted by via GitHub issues.
|
69
|
+
|
70
|
+
## LICENSE:
|
71
|
+
|
72
|
+
(The MIT License)
|
73
|
+
|
74
|
+
Copyright (c) 2009-2010 John Pignata
|
75
|
+
|
76
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
77
|
+
a copy of this software and associated documentation files (the
|
78
|
+
'Software'), to deal in the Software without restriction, including
|
79
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
80
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
81
|
+
permit persons to whom the Software is furnished to do so, subject to
|
82
|
+
the following conditions:
|
83
|
+
|
84
|
+
The above copyright notice and this permission notice shall be
|
85
|
+
included in all copies or substantial portions of the Software.
|
86
|
+
|
87
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
88
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
89
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
90
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
91
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
92
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
93
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/temping.rb
CHANGED
@@ -9,12 +9,10 @@ module Temping
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def create_model(model_name, &block)
|
12
|
-
|
13
|
-
|
12
|
+
unless eval("defined?(#{model_name.to_s.classify})")
|
13
|
+
factory = ModelFactory.new(model_name, &block)
|
14
|
+
factory.klass
|
14
15
|
end
|
15
|
-
|
16
|
-
factory = ModelFactory.new(model_name, &block)
|
17
|
-
factory.klass
|
18
16
|
end
|
19
17
|
|
20
18
|
class ModelFactory
|
data/spec/temping_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Temping do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "evals all statements passed in through a block" do
|
13
|
-
|
13
|
+
create_model :votes do
|
14
14
|
with_columns do |table|
|
15
15
|
table.string :voter
|
16
16
|
end
|
@@ -25,8 +25,8 @@ describe Temping do
|
|
25
25
|
vote.should be_valid
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
29
|
-
lambda { 2.times { create_model :dogs }}.
|
28
|
+
it "silently skip initialization if a const is already defined" do
|
29
|
+
lambda { 2.times { create_model :dogs }}.should_not raise_error(Temping::ModelAlreadyDefined)
|
30
30
|
end
|
31
31
|
|
32
32
|
describe ".with_columns" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: temping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Pignata
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-30 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -39,9 +39,11 @@ executables: []
|
|
39
39
|
extensions: []
|
40
40
|
|
41
41
|
extra_rdoc_files:
|
42
|
+
- LICENSE
|
42
43
|
- README.md
|
43
44
|
files:
|
44
45
|
- .gitignore
|
46
|
+
- LICENSE
|
45
47
|
- README.md
|
46
48
|
- Rakefile
|
47
49
|
- VERSION
|