temping 1.3.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metadata +67 -62
- data/.gitignore +0 -1
- data/LICENSE +0 -20
- data/README.md +0 -96
- data/Rakefile +0 -23
- data/VERSION +0 -1
- data/lib/temping.rb +0 -53
- data/spec/spec_helper.rb +0 -15
- data/spec/temping_spec.rb +0 -73
metadata
CHANGED
|
@@ -1,83 +1,88 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: temping
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.0
|
|
5
|
+
prerelease:
|
|
5
6
|
platform: ruby
|
|
6
|
-
authors:
|
|
7
|
+
authors:
|
|
7
8
|
- John Pignata
|
|
8
9
|
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
date: 2011-11-13 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: activerecord
|
|
16
|
+
requirement: &70268845765620 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 3.1.1
|
|
17
22
|
type: :runtime
|
|
18
|
-
|
|
19
|
-
version_requirements:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *70268845765620
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: activesupport
|
|
27
|
+
requirement: &70268845764940 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ~>
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 3.1.1
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *70268845764940
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
37
|
+
name: sqlite3
|
|
38
|
+
requirement: &70268845764280 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ~>
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 1.3.4
|
|
44
|
+
type: :runtime
|
|
45
|
+
prerelease: false
|
|
46
|
+
version_requirements: *70268845764280
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
26
48
|
name: rspec
|
|
49
|
+
requirement: &70268845763540 !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 2.7.0
|
|
27
55
|
type: :development
|
|
28
|
-
|
|
29
|
-
version_requirements:
|
|
30
|
-
requirements:
|
|
31
|
-
- - "="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: 1.2.9
|
|
34
|
-
version:
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: *70268845763540
|
|
35
58
|
description:
|
|
36
|
-
email: john
|
|
59
|
+
email: john@pignata.com
|
|
37
60
|
executables: []
|
|
38
|
-
|
|
39
61
|
extensions: []
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
- LICENSE
|
|
43
|
-
- README.md
|
|
44
|
-
files:
|
|
45
|
-
- .gitignore
|
|
46
|
-
- LICENSE
|
|
47
|
-
- README.md
|
|
48
|
-
- Rakefile
|
|
49
|
-
- VERSION
|
|
50
|
-
- lib/temping.rb
|
|
51
|
-
- spec/spec_helper.rb
|
|
52
|
-
- spec/temping_spec.rb
|
|
53
|
-
has_rdoc: true
|
|
62
|
+
extra_rdoc_files: []
|
|
63
|
+
files: []
|
|
54
64
|
homepage: http://github.com/jpignata/temping
|
|
55
65
|
licenses: []
|
|
56
|
-
|
|
57
66
|
post_install_message:
|
|
58
|
-
rdoc_options:
|
|
59
|
-
|
|
60
|
-
require_paths:
|
|
67
|
+
rdoc_options: []
|
|
68
|
+
require_paths:
|
|
61
69
|
- lib
|
|
62
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
|
+
none: false
|
|
72
|
+
requirements:
|
|
73
|
+
- - ! '>='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
|
+
none: false
|
|
78
|
+
requirements:
|
|
79
|
+
- - ! '>='
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
74
82
|
requirements: []
|
|
75
|
-
|
|
76
83
|
rubyforge_project:
|
|
77
|
-
rubygems_version: 1.
|
|
84
|
+
rubygems_version: 1.8.10
|
|
78
85
|
signing_key:
|
|
79
86
|
specification_version: 3
|
|
80
87
|
summary: Create temporary table-backed ActiveRecord models for use in tests
|
|
81
|
-
test_files:
|
|
82
|
-
- spec/spec_helper.rb
|
|
83
|
-
- spec/temping_spec.rb
|
|
88
|
+
test_files: []
|
data/.gitignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pkg
|
data/LICENSE
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# Temping
|
|
2
|
-
|
|
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.
|
|
19
|
-
|
|
20
|
-
require 'temping'
|
|
21
|
-
include Temping
|
|
22
|
-
|
|
23
|
-
create_model :dog
|
|
24
|
-
|
|
25
|
-
Dog.create => #<Dog id: 1>
|
|
26
|
-
|
|
27
|
-
Additional database columns can be specified via the _with_columns_ method which uses Rails migration syntax:
|
|
28
|
-
|
|
29
|
-
require 'temping'
|
|
30
|
-
include Temping
|
|
31
|
-
|
|
32
|
-
create_model :dog do
|
|
33
|
-
with_columns do |t|
|
|
34
|
-
t.string :name
|
|
35
|
-
t.integer :age, :weight
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
Dog.create => #<Dog id: 1, name: nil, age: nil, weight: nil>
|
|
40
|
-
|
|
41
|
-
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.
|
|
42
|
-
|
|
43
|
-
require 'temping'
|
|
44
|
-
include Temping
|
|
45
|
-
|
|
46
|
-
create_model :dog do
|
|
47
|
-
include Duckish
|
|
48
|
-
|
|
49
|
-
with_columns do |t|
|
|
50
|
-
t.string :name
|
|
51
|
-
t.integer :age, :weight
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
validates_presence_of :name
|
|
55
|
-
|
|
56
|
-
def quack
|
|
57
|
-
"arf!"
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
Dog.create! => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
|
|
62
|
-
codey = Dog.create!(:name => 'Codey')
|
|
63
|
-
codey.quack => "arf!"
|
|
64
|
-
|
|
65
|
-
## Installation
|
|
66
|
-
|
|
67
|
-
jp@populuxe:~$ gem install temping
|
|
68
|
-
|
|
69
|
-
## Bugs, Features, Feedback
|
|
70
|
-
|
|
71
|
-
Tickets can be submitted by via GitHub issues.
|
|
72
|
-
|
|
73
|
-
## LICENSE:
|
|
74
|
-
|
|
75
|
-
(The MIT License)
|
|
76
|
-
|
|
77
|
-
Copyright (c) 2009-2010 John Pignata
|
|
78
|
-
|
|
79
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
80
|
-
a copy of this software and associated documentation files (the
|
|
81
|
-
'Software'), to deal in the Software without restriction, including
|
|
82
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
83
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
84
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
85
|
-
the following conditions:
|
|
86
|
-
|
|
87
|
-
The above copyright notice and this permission notice shall be
|
|
88
|
-
included in all copies or substantial portions of the Software.
|
|
89
|
-
|
|
90
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
91
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
92
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
93
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
94
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
95
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
96
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
require 'spec/rake/spectask'
|
|
2
|
-
|
|
3
|
-
task :default => [:spec]
|
|
4
|
-
|
|
5
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
|
6
|
-
spec.libs << 'lib' << 'spec'
|
|
7
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
begin
|
|
11
|
-
require 'jeweler'
|
|
12
|
-
Jeweler::Tasks.new do |gem|
|
|
13
|
-
gem.name = "temping"
|
|
14
|
-
gem.summary = "Create temporary table-backed ActiveRecord models for use in tests"
|
|
15
|
-
gem.homepage = "http://github.com/jpignata/temping"
|
|
16
|
-
gem.email = "john.pignata@gmail.com"
|
|
17
|
-
gem.authors = ["John Pignata"]
|
|
18
|
-
gem.add_dependency "rails", ">= 2.3.3"
|
|
19
|
-
gem.add_development_dependency "rspec", "1.2.9"
|
|
20
|
-
end
|
|
21
|
-
rescue LoadError
|
|
22
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
|
23
|
-
end
|
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1.3.0
|
data/lib/temping.rb
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
require 'active_record'
|
|
2
|
-
|
|
3
|
-
module Temping
|
|
4
|
-
def self.included(base)
|
|
5
|
-
unless ActiveRecord::Base.connected?
|
|
6
|
-
ActiveRecord::Base.configurations['temping'] = {
|
|
7
|
-
:adapter => 'sqlite3', :database => ':memory:'
|
|
8
|
-
}
|
|
9
|
-
ActiveRecord::Base.establish_connection 'temping'
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def create_model(model_name, &block)
|
|
14
|
-
model_class = model_name.to_s.classify
|
|
15
|
-
unless eval("defined?(#{model_class})")
|
|
16
|
-
factory = ModelFactory.new(model_class, &block)
|
|
17
|
-
factory.klass
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
class ModelFactory
|
|
22
|
-
attr_accessor :klass
|
|
23
|
-
|
|
24
|
-
def initialize(model_class, &block)
|
|
25
|
-
@klass = Class.new(ActiveRecord::Base)
|
|
26
|
-
Object.const_set(model_class, @klass)
|
|
27
|
-
create_table
|
|
28
|
-
add_methods
|
|
29
|
-
@klass.class_eval(&block) if block_given?
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
def create_table
|
|
35
|
-
@klass.connection.create_table(@klass.table_name, :temporary => true) do |table|
|
|
36
|
-
table.integer :id
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def add_methods
|
|
41
|
-
class << @klass
|
|
42
|
-
def with_columns
|
|
43
|
-
connection.change_table(table_name) { |table| yield(table) }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def table_exists?
|
|
47
|
-
true
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
$: << File.join(File.dirname(__FILE__), "/../lib")
|
|
2
|
-
|
|
3
|
-
require 'spec'
|
|
4
|
-
require 'temping'
|
|
5
|
-
|
|
6
|
-
ActiveRecord::Base.configurations = {
|
|
7
|
-
'mysql' => { :adapter => 'mysql',
|
|
8
|
-
:username => 'rails',
|
|
9
|
-
:database => 'activerecord_unittest',
|
|
10
|
-
:host => '127.0.0.1' },
|
|
11
|
-
|
|
12
|
-
'postgres' => { :adapter => 'postgresql',
|
|
13
|
-
:database => 'activerecord_unittest',
|
|
14
|
-
:min_messages => 'warning' }
|
|
15
|
-
}
|
data/spec/temping_spec.rb
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "/spec_helper")
|
|
2
|
-
|
|
3
|
-
describe Temping do
|
|
4
|
-
include Temping
|
|
5
|
-
|
|
6
|
-
describe ".create_model" do
|
|
7
|
-
it "creates and returns an AR::Base-derived model" do
|
|
8
|
-
post_class = create_model :post
|
|
9
|
-
post_class.ancestors.should include(ActiveRecord::Base)
|
|
10
|
-
post_class.should == Post
|
|
11
|
-
post_class.table_name.should == "posts"
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "evals all statements passed in through a block" do
|
|
15
|
-
create_model :vote do
|
|
16
|
-
with_columns do |table|
|
|
17
|
-
table.string :voter
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
validates_presence_of :voter
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
vote = Vote.new
|
|
24
|
-
vote.should_not be_valid
|
|
25
|
-
|
|
26
|
-
vote.voter = "Foo Bar"
|
|
27
|
-
vote.should be_valid
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "silently skips initialization if a const is already defined" do
|
|
31
|
-
lambda { 2.times { create_model :dog } }.should_not raise_error
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "returns nil if a const is already defined" do
|
|
35
|
-
create_model :cat
|
|
36
|
-
create_model(:cat).should be_nil
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe ".with_columns" do
|
|
40
|
-
it "creates columns passed in through a block" do
|
|
41
|
-
create_model :comment do
|
|
42
|
-
with_columns do |table|
|
|
43
|
-
table.integer :count
|
|
44
|
-
table.string :headline
|
|
45
|
-
table.text :body
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
Comment.columns.map(&:name).should include("count", "headline", "body")
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe "database agnostism" do
|
|
55
|
-
it "supports Sqlite3" do
|
|
56
|
-
ActiveRecord::Base.establish_connection 'temping'
|
|
57
|
-
create_model(:orange).should == Orange
|
|
58
|
-
Orange.table_name.should == "oranges"
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "supports MySQL" do
|
|
62
|
-
ActiveRecord::Base.establish_connection 'mysql'
|
|
63
|
-
create_model(:apple).should == Apple
|
|
64
|
-
Apple.table_name.should == "apples"
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "supports PostgreSQL" do
|
|
68
|
-
ActiveRecord::Base.establish_connection 'postgres'
|
|
69
|
-
create_model(:cherry).should == Cherry
|
|
70
|
-
Cherry.table_name.should == "cherries"
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|